Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / ash / chrome_shell_delegate_chromeos.cc
blobe2204523a5ceae03868b8a5c23299be8945e58ec
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/ash/chrome_shell_delegate.h"
7 #include "ash/accelerators/magnifier_key_scroller.h"
8 #include "ash/accelerators/spoken_feedback_toggler.h"
9 #include "ash/accessibility_delegate.h"
10 #include "ash/wm/mru_window_tracker.h"
11 #include "ash/wm/window_util.h"
12 #include "base/command_line.h"
13 #include "base/prefs/pref_service.h"
14 #include "chrome/browser/app_mode/app_mode_utils.h"
15 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
17 #include "chrome/browser/chromeos/accessibility/magnification_manager.h"
18 #include "chrome/browser/chromeos/background/ash_user_wallpaper_delegate.h"
19 #include "chrome/browser/chromeos/display/display_configuration_observer.h"
20 #include "chrome/browser/chromeos/display/display_preferences.h"
21 #include "chrome/browser/chromeos/profiles/profile_helper.h"
22 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/profiles/profile_manager.h"
24 #include "chrome/browser/signin/signin_error_notifier_factory_ash.h"
25 #include "chrome/browser/speech/tts_controller.h"
26 #include "chrome/browser/sync/sync_error_notifier_factory_ash.h"
27 #include "chrome/browser/ui/ash/chrome_new_window_delegate_chromeos.h"
28 #include "chrome/browser/ui/ash/media_delegate_chromeos.h"
29 #include "chrome/browser/ui/ash/session_state_delegate_chromeos.h"
30 #include "chrome/browser/ui/ash/system_tray_delegate_chromeos.h"
31 #include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h"
32 #include "chrome/browser/ui/browser.h"
33 #include "chrome/browser/ui/browser_finder.h"
34 #include "chrome/browser/ui/browser_window.h"
35 #include "chrome/grit/generated_resources.h"
36 #include "chromeos/chromeos_switches.h"
37 #include "content/public/browser/notification_service.h"
38 #include "content/public/browser/user_metrics.h"
39 #include "ui/aura/window.h"
40 #include "ui/base/ime/chromeos/input_method_manager.h"
41 #include "ui/base/l10n/l10n_util.h"
43 namespace {
45 void InitAfterSessionStart() {
46 // Restore focus after the user session is started. It's needed because some
47 // windows can be opened in background while login UI is still active because
48 // we currently restore browser windows before login UI is deleted.
49 ash::Shell* shell = ash::Shell::GetInstance();
50 ash::MruWindowTracker::WindowList mru_list =
51 shell->mru_window_tracker()->BuildMruWindowList();
52 if (!mru_list.empty())
53 mru_list.front()->Focus();
55 // Enable magnifier scroll keys as there may be no mouse cursor in kiosk mode.
56 ash::MagnifierKeyScroller::SetEnabled(chrome::IsRunningInForcedAppMode());
58 // Enable long press action to toggle spoken feedback with hotrod
59 // remote which can't handle shortcut.
60 ash::SpokenFeedbackToggler::SetEnabled(chrome::IsRunningInForcedAppMode());
63 class AccessibilityDelegateImpl : public ash::AccessibilityDelegate {
64 public:
65 AccessibilityDelegateImpl() {}
66 ~AccessibilityDelegateImpl() override {}
68 void ToggleHighContrast() override {
69 DCHECK(chromeos::AccessibilityManager::Get());
70 chromeos::AccessibilityManager::Get()->EnableHighContrast(
71 !chromeos::AccessibilityManager::Get()->IsHighContrastEnabled());
74 bool IsSpokenFeedbackEnabled() const override {
75 DCHECK(chromeos::AccessibilityManager::Get());
76 return chromeos::AccessibilityManager::Get()->IsSpokenFeedbackEnabled();
79 void ToggleSpokenFeedback(
80 ui::AccessibilityNotificationVisibility notify) override {
81 DCHECK(chromeos::AccessibilityManager::Get());
82 chromeos::AccessibilityManager::Get()->ToggleSpokenFeedback(notify);
85 bool IsHighContrastEnabled() const override {
86 DCHECK(chromeos::AccessibilityManager::Get());
87 return chromeos::AccessibilityManager::Get()->IsHighContrastEnabled();
90 void SetMagnifierEnabled(bool enabled) override {
91 DCHECK(chromeos::MagnificationManager::Get());
92 return chromeos::MagnificationManager::Get()->SetMagnifierEnabled(enabled);
95 void SetMagnifierType(ui::MagnifierType type) override {
96 DCHECK(chromeos::MagnificationManager::Get());
97 return chromeos::MagnificationManager::Get()->SetMagnifierType(type);
100 bool IsMagnifierEnabled() const override {
101 DCHECK(chromeos::MagnificationManager::Get());
102 return chromeos::MagnificationManager::Get()->IsMagnifierEnabled();
105 ui::MagnifierType GetMagnifierType() const override {
106 DCHECK(chromeos::MagnificationManager::Get());
107 return chromeos::MagnificationManager::Get()->GetMagnifierType();
110 void SetLargeCursorEnabled(bool enabled) override {
111 DCHECK(chromeos::AccessibilityManager::Get());
112 return chromeos::AccessibilityManager::Get()->EnableLargeCursor(enabled);
115 bool IsLargeCursorEnabled() const override {
116 DCHECK(chromeos::AccessibilityManager::Get());
117 return chromeos::AccessibilityManager::Get()->IsLargeCursorEnabled();
120 void SetAutoclickEnabled(bool enabled) override {
121 DCHECK(chromeos::AccessibilityManager::Get());
122 return chromeos::AccessibilityManager::Get()->EnableAutoclick(enabled);
125 bool IsAutoclickEnabled() const override {
126 DCHECK(chromeos::AccessibilityManager::Get());
127 return chromeos::AccessibilityManager::Get()->IsAutoclickEnabled();
130 void SetVirtualKeyboardEnabled(bool enabled) override {
131 DCHECK(chromeos::AccessibilityManager::Get());
132 return chromeos::AccessibilityManager::Get()->
133 EnableVirtualKeyboard(enabled);
136 bool IsVirtualKeyboardEnabled() const override {
137 DCHECK(chromeos::AccessibilityManager::Get());
138 return chromeos::AccessibilityManager::Get()->IsVirtualKeyboardEnabled();
141 bool ShouldShowAccessibilityMenu() const override {
142 DCHECK(chromeos::AccessibilityManager::Get());
143 return chromeos::AccessibilityManager::Get()->
144 ShouldShowAccessibilityMenu();
147 bool IsBrailleDisplayConnected() const override {
148 DCHECK(chromeos::AccessibilityManager::Get());
149 return chromeos::AccessibilityManager::Get()->IsBrailleDisplayConnected();
152 void SilenceSpokenFeedback() const override {
153 TtsController::GetInstance()->Stop();
156 void SaveScreenMagnifierScale(double scale) override {
157 if (chromeos::MagnificationManager::Get())
158 chromeos::MagnificationManager::Get()->SaveScreenMagnifierScale(scale);
161 double GetSavedScreenMagnifierScale() override {
162 if (chromeos::MagnificationManager::Get()) {
163 return chromeos::MagnificationManager::Get()->
164 GetSavedScreenMagnifierScale();
166 return std::numeric_limits<double>::min();
169 void TriggerAccessibilityAlert(ui::AccessibilityAlert alert) override {
170 Profile* profile = ProfileManager::GetActiveUserProfile();
171 if (profile) {
172 switch (alert) {
173 case ui::A11Y_ALERT_WINDOW_NEEDED: {
174 AutomationManagerAura::GetInstance()->HandleAlert(
175 profile, l10n_util::GetStringUTF8(IDS_A11Y_ALERT_WINDOW_NEEDED));
176 break;
178 case ui::A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED: {
179 AutomationManagerAura::GetInstance()->HandleAlert(
180 profile, l10n_util::GetStringUTF8(
181 IDS_A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED));
182 break;
184 case ui::A11Y_ALERT_NONE:
185 break;
190 ui::AccessibilityAlert GetLastAccessibilityAlert() override {
191 return ui::A11Y_ALERT_NONE;
194 void PlayEarcon(int sound_key) override {
195 DCHECK(chromeos::AccessibilityManager::Get());
196 return chromeos::AccessibilityManager::Get()->PlayEarcon(sound_key);
199 base::TimeDelta PlayShutdownSound() const override {
200 return chromeos::AccessibilityManager::Get()->PlayShutdownSound();
203 private:
204 DISALLOW_COPY_AND_ASSIGN(AccessibilityDelegateImpl);
207 } // anonymous namespace
209 bool ChromeShellDelegate::IsFirstRunAfterBoot() const {
210 return base::CommandLine::ForCurrentProcess()->HasSwitch(
211 chromeos::switches::kFirstExecAfterBoot);
214 void ChromeShellDelegate::PreInit() {
215 chromeos::LoadDisplayPreferences(IsFirstRunAfterBoot());
216 // Set the observer now so that we can save the initial state
217 // in Shell::Init.
218 display_configuration_observer_.reset(
219 new chromeos::DisplayConfigurationObserver());
222 void ChromeShellDelegate::PreShutdown() {
223 display_configuration_observer_.reset();
226 ash::SessionStateDelegate* ChromeShellDelegate::CreateSessionStateDelegate() {
227 return new SessionStateDelegateChromeos;
230 ash::AccessibilityDelegate* ChromeShellDelegate::CreateAccessibilityDelegate() {
231 return new AccessibilityDelegateImpl;
234 ash::NewWindowDelegate* ChromeShellDelegate::CreateNewWindowDelegate() {
235 return new ChromeNewWindowDelegateChromeos;
238 ash::MediaDelegate* ChromeShellDelegate::CreateMediaDelegate() {
239 return new MediaDelegateChromeOS;
242 ash::SystemTrayDelegate* ChromeShellDelegate::CreateSystemTrayDelegate() {
243 return chromeos::CreateSystemTrayDelegate();
246 ash::UserWallpaperDelegate* ChromeShellDelegate::CreateUserWallpaperDelegate() {
247 return chromeos::CreateUserWallpaperDelegate();
250 void ChromeShellDelegate::Observe(int type,
251 const content::NotificationSource& source,
252 const content::NotificationDetails& details) {
253 switch (type) {
254 case chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED: {
255 Profile* profile = content::Details<Profile>(details).ptr();
256 if (!chromeos::ProfileHelper::IsSigninProfile(profile) &&
257 !profile->IsGuestSession() && !profile->IsSupervised()) {
258 // Start the error notifier services to show auth/sync notifications.
259 SigninErrorNotifierFactory::GetForProfile(profile);
260 SyncErrorNotifierFactory::GetForProfile(profile);
262 ash::Shell::GetInstance()->OnLoginUserProfilePrepared();
263 break;
265 case chrome::NOTIFICATION_SESSION_STARTED:
266 InitAfterSessionStart();
267 ash::Shell::GetInstance()->ShowShelf();
268 break;
269 default:
270 NOTREACHED() << "Unexpected notification " << type;
274 void ChromeShellDelegate::PlatformInit() {
275 registrar_.Add(this,
276 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
277 content::NotificationService::AllSources());
278 registrar_.Add(this,
279 chrome::NOTIFICATION_SESSION_STARTED,
280 content::NotificationService::AllSources());