Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / ui / ash / chrome_shell_delegate_chromeos.cc
blob138ad5aabe7870a026037c6749a7531aad6b5937
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/accessibility/accessibility_events.h"
15 #include "chrome/browser/app_mode/app_mode_utils.h"
16 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
18 #include "chrome/browser/chromeos/accessibility/magnification_manager.h"
19 #include "chrome/browser/chromeos/background/ash_user_wallpaper_delegate.h"
20 #include "chrome/browser/chromeos/display/display_configuration_observer.h"
21 #include "chrome/browser/chromeos/display/display_preferences.h"
22 #include "chrome/browser/chromeos/profiles/profile_helper.h"
23 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/profiles/profile_manager.h"
25 #include "chrome/browser/signin/signin_error_notifier_factory_ash.h"
26 #include "chrome/browser/speech/tts_controller.h"
27 #include "chrome/browser/sync/sync_error_notifier_factory_ash.h"
28 #include "chrome/browser/ui/ash/chrome_new_window_delegate_chromeos.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/browser.h"
33 #include "chrome/browser/ui/browser_finder.h"
34 #include "chrome/browser/ui/browser_window.h"
35 #include "chrome/common/pref_names.h"
36 #include "chromeos/chromeos_switches.h"
37 #include "chromeos/ime/input_method_manager.h"
38 #include "content/public/browser/notification_service.h"
39 #include "content/public/browser/user_metrics.h"
40 #include "grit/generated_resources.h"
41 #include "ui/aura/window.h"
42 #include "ui/base/l10n/l10n_util.h"
44 namespace {
46 void InitAfterSessionStart() {
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 #if defined(USE_X11)
57 // Enable magnifier scroll keys as there may be no mouse cursor in kiosk mode.
58 ash::MagnifierKeyScroller::SetEnabled(chrome::IsRunningInForcedAppMode());
60 // Enable long press action to toggle spoken feedback with hotrod
61 // remote which can't handle shortcut.
62 ash::SpokenFeedbackToggler::SetEnabled(chrome::IsRunningInForcedAppMode());
63 #endif
66 class AccessibilityDelegateImpl : public ash::AccessibilityDelegate {
67 public:
68 AccessibilityDelegateImpl() {}
69 virtual ~AccessibilityDelegateImpl() {}
71 virtual void ToggleHighContrast() OVERRIDE {
72 DCHECK(chromeos::AccessibilityManager::Get());
73 chromeos::AccessibilityManager::Get()->EnableHighContrast(
74 !chromeos::AccessibilityManager::Get()->IsHighContrastEnabled());
77 virtual bool IsSpokenFeedbackEnabled() const OVERRIDE {
78 DCHECK(chromeos::AccessibilityManager::Get());
79 return chromeos::AccessibilityManager::Get()->IsSpokenFeedbackEnabled();
82 virtual void ToggleSpokenFeedback(
83 ash::AccessibilityNotificationVisibility notify) OVERRIDE {
84 DCHECK(chromeos::AccessibilityManager::Get());
85 chromeos::AccessibilityManager::Get()->ToggleSpokenFeedback(notify);
88 virtual bool IsHighContrastEnabled() const OVERRIDE {
89 DCHECK(chromeos::AccessibilityManager::Get());
90 return chromeos::AccessibilityManager::Get()->IsHighContrastEnabled();
93 virtual void SetMagnifierEnabled(bool enabled) OVERRIDE {
94 DCHECK(chromeos::MagnificationManager::Get());
95 return chromeos::MagnificationManager::Get()->SetMagnifierEnabled(enabled);
98 virtual void SetMagnifierType(ash::MagnifierType type) OVERRIDE {
99 DCHECK(chromeos::MagnificationManager::Get());
100 return chromeos::MagnificationManager::Get()->SetMagnifierType(type);
103 virtual bool IsMagnifierEnabled() const OVERRIDE {
104 DCHECK(chromeos::MagnificationManager::Get());
105 return chromeos::MagnificationManager::Get()->IsMagnifierEnabled();
108 virtual ash::MagnifierType GetMagnifierType() const OVERRIDE {
109 DCHECK(chromeos::MagnificationManager::Get());
110 return chromeos::MagnificationManager::Get()->GetMagnifierType();
113 virtual void SetLargeCursorEnabled(bool enabled) OVERRIDE {
114 DCHECK(chromeos::AccessibilityManager::Get());
115 return chromeos::AccessibilityManager::Get()->EnableLargeCursor(enabled);
118 virtual bool IsLargeCursorEnabled() const OVERRIDE {
119 DCHECK(chromeos::AccessibilityManager::Get());
120 return chromeos::AccessibilityManager::Get()->IsLargeCursorEnabled();
123 virtual void SetAutoclickEnabled(bool enabled) OVERRIDE {
124 DCHECK(chromeos::AccessibilityManager::Get());
125 return chromeos::AccessibilityManager::Get()->EnableAutoclick(enabled);
128 virtual bool IsAutoclickEnabled() const OVERRIDE {
129 DCHECK(chromeos::AccessibilityManager::Get());
130 return chromeos::AccessibilityManager::Get()->IsAutoclickEnabled();
133 virtual void SetVirtualKeyboardEnabled(bool enabled) OVERRIDE {
134 DCHECK(chromeos::AccessibilityManager::Get());
135 return chromeos::AccessibilityManager::Get()->
136 EnableVirtualKeyboard(enabled);
139 virtual bool IsVirtualKeyboardEnabled() const OVERRIDE {
140 DCHECK(chromeos::AccessibilityManager::Get());
141 return chromeos::AccessibilityManager::Get()->IsVirtualKeyboardEnabled();
144 virtual bool ShouldShowAccessibilityMenu() const OVERRIDE {
145 DCHECK(chromeos::AccessibilityManager::Get());
146 return chromeos::AccessibilityManager::Get()->
147 ShouldShowAccessibilityMenu();
150 virtual bool IsBrailleDisplayConnected() const OVERRIDE {
151 DCHECK(chromeos::AccessibilityManager::Get());
152 return chromeos::AccessibilityManager::Get()->IsBrailleDisplayConnected();
155 virtual void SilenceSpokenFeedback() const OVERRIDE {
156 TtsController::GetInstance()->Stop();
159 virtual void SaveScreenMagnifierScale(double scale) OVERRIDE {
160 if (chromeos::MagnificationManager::Get())
161 chromeos::MagnificationManager::Get()->SaveScreenMagnifierScale(scale);
164 virtual double GetSavedScreenMagnifierScale() OVERRIDE {
165 if (chromeos::MagnificationManager::Get()) {
166 return chromeos::MagnificationManager::Get()->
167 GetSavedScreenMagnifierScale();
169 return std::numeric_limits<double>::min();
172 virtual void TriggerAccessibilityAlert(
173 ash::AccessibilityAlert alert) OVERRIDE {
174 Profile* profile = ProfileManager::GetActiveUserProfile();
175 if (profile) {
176 switch (alert) {
177 case ash::A11Y_ALERT_WINDOW_NEEDED: {
178 AccessibilityAlertInfo event(
179 profile, l10n_util::GetStringUTF8(IDS_A11Y_ALERT_WINDOW_NEEDED));
180 SendControlAccessibilityNotification(
181 ui::AX_EVENT_ALERT, &event);
182 break;
184 case ash::A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED: {
185 AccessibilityAlertInfo event(
186 profile, l10n_util::GetStringUTF8(
187 IDS_A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED));
188 SendControlAccessibilityNotification(
189 ui::AX_EVENT_ALERT, &event);
190 break;
192 case ash::A11Y_ALERT_NONE:
193 break;
198 virtual ash::AccessibilityAlert GetLastAccessibilityAlert() OVERRIDE {
199 return ash::A11Y_ALERT_NONE;
202 virtual base::TimeDelta PlayShutdownSound() const OVERRIDE {
203 return chromeos::AccessibilityManager::Get()->PlayShutdownSound();
206 private:
207 DISALLOW_COPY_AND_ASSIGN(AccessibilityDelegateImpl);
210 } // anonymous namespace
212 bool ChromeShellDelegate::IsFirstRunAfterBoot() const {
213 return CommandLine::ForCurrentProcess()->HasSwitch(
214 chromeos::switches::kFirstExecAfterBoot);
217 void ChromeShellDelegate::PreInit() {
218 chromeos::LoadDisplayPreferences(IsFirstRunAfterBoot());
219 // Set the observer now so that we can save the initial state
220 // in Shell::Init.
221 display_configuration_observer_.reset(
222 new chromeos::DisplayConfigurationObserver());
225 void ChromeShellDelegate::PreShutdown() {
226 display_configuration_observer_.reset();
229 ash::SessionStateDelegate* ChromeShellDelegate::CreateSessionStateDelegate() {
230 return new SessionStateDelegateChromeos;
233 ash::AccessibilityDelegate* ChromeShellDelegate::CreateAccessibilityDelegate() {
234 return new AccessibilityDelegateImpl;
237 ash::NewWindowDelegate* ChromeShellDelegate::CreateNewWindowDelegate() {
238 return new ChromeNewWindowDelegateChromeos;
241 ash::MediaDelegate* ChromeShellDelegate::CreateMediaDelegate() {
242 return new MediaDelegateChromeOS;
245 ash::SystemTrayDelegate* ChromeShellDelegate::CreateSystemTrayDelegate() {
246 return chromeos::CreateSystemTrayDelegate();
249 ash::UserWallpaperDelegate* ChromeShellDelegate::CreateUserWallpaperDelegate() {
250 return chromeos::CreateUserWallpaperDelegate();
253 void ChromeShellDelegate::Observe(int type,
254 const content::NotificationSource& source,
255 const content::NotificationDetails& details) {
256 switch (type) {
257 case chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED: {
258 Profile* profile = content::Details<Profile>(details).ptr();
259 if (!chromeos::ProfileHelper::IsSigninProfile(profile) &&
260 !profile->IsGuestSession() && !profile->IsManaged()) {
261 // Start the error notifier services to show auth/sync notifications.
262 SigninErrorNotifierFactory::GetForProfile(profile);
263 SyncErrorNotifierFactory::GetForProfile(profile);
265 ash::Shell::GetInstance()->OnLoginUserProfilePrepared();
266 break;
268 case chrome::NOTIFICATION_SESSION_STARTED:
269 InitAfterSessionStart();
270 ash::Shell::GetInstance()->ShowShelf();
271 break;
272 default:
273 NOTREACHED() << "Unexpected notification " << type;
277 void ChromeShellDelegate::PlatformInit() {
278 registrar_.Add(this,
279 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
280 content::NotificationService::AllSources());
281 registrar_.Add(this,
282 chrome::NOTIFICATION_SESSION_STARTED,
283 content::NotificationService::AllSources());