Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / ui / ash / chrome_shell_delegate_chromeos.cc
blob0ea94183a530a8297de637a5e4ce8086ffe33a7e
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/launcher/chrome_launcher_controller.h"
29 #include "chrome/browser/ui/ash/media_delegate_chromeos.h"
30 #include "chrome/browser/ui/ash/session_state_delegate_chromeos.h"
31 #include "chrome/browser/ui/ash/system_tray_delegate_chromeos.h"
32 #include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h"
33 #include "chrome/browser/ui/browser.h"
34 #include "chrome/browser/ui/browser_finder.h"
35 #include "chrome/browser/ui/browser_window.h"
36 #include "chrome/grit/generated_resources.h"
37 #include "chromeos/chromeos_switches.h"
38 #include "content/public/browser/notification_service.h"
39 #include "content/public/browser/user_metrics.h"
40 #include "ui/aura/window.h"
41 #include "ui/base/ime/chromeos/input_method_manager.h"
42 #include "ui/base/l10n/l10n_util.h"
44 namespace {
46 void InitAfterFirstSessionStart() {
47 // Restore focus after the user session is started. It's needed because some
48 // windows can be opened in background while login UI is still active because
49 // we currently restore browser windows before login UI is deleted.
50 ash::Shell* shell = ash::Shell::GetInstance();
51 ash::MruWindowTracker::WindowList mru_list =
52 shell->mru_window_tracker()->BuildMruWindowList();
53 if (!mru_list.empty())
54 mru_list.front()->Focus();
56 // Enable magnifier scroll keys as there may be no mouse cursor in kiosk mode.
57 ash::MagnifierKeyScroller::SetEnabled(chrome::IsRunningInForcedAppMode());
59 // Enable long press action to toggle spoken feedback with hotrod
60 // remote which can't handle shortcut.
61 ash::SpokenFeedbackToggler::SetEnabled(chrome::IsRunningInForcedAppMode());
64 class AccessibilityDelegateImpl : public ash::AccessibilityDelegate {
65 public:
66 AccessibilityDelegateImpl() {}
67 ~AccessibilityDelegateImpl() override {}
69 void ToggleHighContrast() override {
70 DCHECK(chromeos::AccessibilityManager::Get());
71 chromeos::AccessibilityManager::Get()->EnableHighContrast(
72 !chromeos::AccessibilityManager::Get()->IsHighContrastEnabled());
75 bool IsSpokenFeedbackEnabled() const override {
76 DCHECK(chromeos::AccessibilityManager::Get());
77 return chromeos::AccessibilityManager::Get()->IsSpokenFeedbackEnabled();
80 void ToggleSpokenFeedback(
81 ui::AccessibilityNotificationVisibility notify) override {
82 DCHECK(chromeos::AccessibilityManager::Get());
83 chromeos::AccessibilityManager::Get()->ToggleSpokenFeedback(notify);
86 bool IsHighContrastEnabled() const override {
87 DCHECK(chromeos::AccessibilityManager::Get());
88 return chromeos::AccessibilityManager::Get()->IsHighContrastEnabled();
91 void SetMagnifierEnabled(bool enabled) override {
92 DCHECK(chromeos::MagnificationManager::Get());
93 return chromeos::MagnificationManager::Get()->SetMagnifierEnabled(enabled);
96 void SetMagnifierType(ui::MagnifierType type) override {
97 DCHECK(chromeos::MagnificationManager::Get());
98 return chromeos::MagnificationManager::Get()->SetMagnifierType(type);
101 bool IsMagnifierEnabled() const override {
102 DCHECK(chromeos::MagnificationManager::Get());
103 return chromeos::MagnificationManager::Get()->IsMagnifierEnabled();
106 ui::MagnifierType GetMagnifierType() const override {
107 DCHECK(chromeos::MagnificationManager::Get());
108 return chromeos::MagnificationManager::Get()->GetMagnifierType();
111 void SetLargeCursorEnabled(bool enabled) override {
112 DCHECK(chromeos::AccessibilityManager::Get());
113 return chromeos::AccessibilityManager::Get()->EnableLargeCursor(enabled);
116 bool IsLargeCursorEnabled() const override {
117 DCHECK(chromeos::AccessibilityManager::Get());
118 return chromeos::AccessibilityManager::Get()->IsLargeCursorEnabled();
121 void SetAutoclickEnabled(bool enabled) override {
122 DCHECK(chromeos::AccessibilityManager::Get());
123 return chromeos::AccessibilityManager::Get()->EnableAutoclick(enabled);
126 bool IsAutoclickEnabled() const override {
127 DCHECK(chromeos::AccessibilityManager::Get());
128 return chromeos::AccessibilityManager::Get()->IsAutoclickEnabled();
131 void SetVirtualKeyboardEnabled(bool enabled) override {
132 DCHECK(chromeos::AccessibilityManager::Get());
133 return chromeos::AccessibilityManager::Get()->
134 EnableVirtualKeyboard(enabled);
137 bool IsVirtualKeyboardEnabled() const override {
138 DCHECK(chromeos::AccessibilityManager::Get());
139 return chromeos::AccessibilityManager::Get()->IsVirtualKeyboardEnabled();
142 bool ShouldShowAccessibilityMenu() const override {
143 DCHECK(chromeos::AccessibilityManager::Get());
144 return chromeos::AccessibilityManager::Get()->
145 ShouldShowAccessibilityMenu();
148 bool IsBrailleDisplayConnected() const override {
149 DCHECK(chromeos::AccessibilityManager::Get());
150 return chromeos::AccessibilityManager::Get()->IsBrailleDisplayConnected();
153 void SilenceSpokenFeedback() const override {
154 TtsController::GetInstance()->Stop();
157 void SaveScreenMagnifierScale(double scale) override {
158 if (chromeos::MagnificationManager::Get())
159 chromeos::MagnificationManager::Get()->SaveScreenMagnifierScale(scale);
162 double GetSavedScreenMagnifierScale() override {
163 if (chromeos::MagnificationManager::Get()) {
164 return chromeos::MagnificationManager::Get()->
165 GetSavedScreenMagnifierScale();
167 return std::numeric_limits<double>::min();
170 void TriggerAccessibilityAlert(ui::AccessibilityAlert alert) override {
171 Profile* profile = ProfileManager::GetActiveUserProfile();
172 if (profile) {
173 switch (alert) {
174 case ui::A11Y_ALERT_WINDOW_NEEDED: {
175 AutomationManagerAura::GetInstance()->HandleAlert(
176 profile, l10n_util::GetStringUTF8(IDS_A11Y_ALERT_WINDOW_NEEDED));
177 break;
179 case ui::A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED: {
180 AutomationManagerAura::GetInstance()->HandleAlert(
181 profile, l10n_util::GetStringUTF8(
182 IDS_A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED));
183 break;
185 case ui::A11Y_ALERT_NONE:
186 break;
191 ui::AccessibilityAlert GetLastAccessibilityAlert() override {
192 return ui::A11Y_ALERT_NONE;
195 void PlayEarcon(int sound_key) override {
196 DCHECK(chromeos::AccessibilityManager::Get());
197 return chromeos::AccessibilityManager::Get()->PlayEarcon(sound_key);
200 base::TimeDelta PlayShutdownSound() const override {
201 return chromeos::AccessibilityManager::Get()->PlayShutdownSound();
204 private:
205 DISALLOW_COPY_AND_ASSIGN(AccessibilityDelegateImpl);
208 } // anonymous namespace
210 bool ChromeShellDelegate::IsFirstRunAfterBoot() const {
211 return base::CommandLine::ForCurrentProcess()->HasSwitch(
212 chromeos::switches::kFirstExecAfterBoot);
215 void ChromeShellDelegate::PreInit() {
216 chromeos::LoadDisplayPreferences(IsFirstRunAfterBoot());
217 // Set the observer now so that we can save the initial state
218 // in Shell::Init.
219 display_configuration_observer_.reset(
220 new chromeos::DisplayConfigurationObserver());
222 chrome_user_metrics_recorder_.reset(new ChromeUserMetricsRecorder);
225 void ChromeShellDelegate::PreShutdown() {
226 display_configuration_observer_.reset();
227 chrome_user_metrics_recorder_.reset();
230 ash::SessionStateDelegate* ChromeShellDelegate::CreateSessionStateDelegate() {
231 return new SessionStateDelegateChromeos;
234 ash::AccessibilityDelegate* ChromeShellDelegate::CreateAccessibilityDelegate() {
235 return new AccessibilityDelegateImpl;
238 ash::NewWindowDelegate* ChromeShellDelegate::CreateNewWindowDelegate() {
239 return new ChromeNewWindowDelegateChromeos;
242 ash::MediaDelegate* ChromeShellDelegate::CreateMediaDelegate() {
243 return new MediaDelegateChromeOS;
246 ash::SystemTrayDelegate* ChromeShellDelegate::CreateSystemTrayDelegate() {
247 return chromeos::CreateSystemTrayDelegate();
250 ash::UserWallpaperDelegate* ChromeShellDelegate::CreateUserWallpaperDelegate() {
251 return chromeos::CreateUserWallpaperDelegate();
254 void ChromeShellDelegate::Observe(int type,
255 const content::NotificationSource& source,
256 const content::NotificationDetails& details) {
257 switch (type) {
258 case chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED: {
259 Profile* profile = content::Details<Profile>(details).ptr();
260 if (!chromeos::ProfileHelper::IsSigninProfile(profile) &&
261 !profile->IsGuestSession() && !profile->IsSupervised()) {
262 // Start the error notifier services to show auth/sync notifications.
263 SigninErrorNotifierFactory::GetForProfile(profile);
264 SyncErrorNotifierFactory::GetForProfile(profile);
266 // Do not use chrome::NOTIFICATION_PROFILE_ADDED because the
267 // profile is not fully initialized by user_manager. Use
268 // chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED instead.
269 if (shelf_delegate_)
270 shelf_delegate_->OnUserProfileReadyToSwitch(profile);
271 ash::Shell::GetInstance()->OnLoginUserProfilePrepared();
272 break;
274 case chrome::NOTIFICATION_SESSION_STARTED:
275 // InitAfterFirstSessionStart() should only be called once upon system
276 // start.
277 if (user_manager::UserManager::Get()->GetLoggedInUsers().size() < 2)
278 InitAfterFirstSessionStart();
279 ash::Shell::GetInstance()->ShowShelf();
280 break;
281 default:
282 NOTREACHED() << "Unexpected notification " << type;
286 void ChromeShellDelegate::PlatformInit() {
287 registrar_.Add(this,
288 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
289 content::NotificationService::AllSources());
290 registrar_.Add(this,
291 chrome::NOTIFICATION_SESSION_STARTED,
292 content::NotificationService::AllSources());