Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Side by Side Diff: chrome/browser/ui/ash/chrome_shell_delegate_chromeos.cc

Issue 1960293003: Remove OS_CHROMEOS from ui/ash code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/ui/ash/chrome_shell_delegate.h"
6
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/macros.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/policy/display_rotation_default_handler.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/launcher/chrome_launcher_controller.h"
30 #include "chrome/browser/ui/ash/media_delegate_chromeos.h"
31 #include "chrome/browser/ui/ash/session_state_delegate_chromeos.h"
32 #include "chrome/browser/ui/ash/system_tray_delegate_chromeos.h"
33 #include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h"
34 #include "chrome/browser/ui/browser.h"
35 #include "chrome/browser/ui/browser_finder.h"
36 #include "chrome/browser/ui/browser_window.h"
37 #include "chrome/grit/generated_resources.h"
38 #include "chromeos/chromeos_switches.h"
39 #include "components/prefs/pref_service.h"
40 #include "content/public/browser/notification_service.h"
41 #include "content/public/browser/user_metrics.h"
42 #include "ui/aura/window.h"
43 #include "ui/base/ime/chromeos/input_method_manager.h"
44 #include "ui/base/l10n/l10n_util.h"
45
46 namespace {
47
48 void InitAfterFirstSessionStart() {
49 // Restore focus after the user session is started. It's needed because some
50 // windows can be opened in background while login UI is still active because
51 // we currently restore browser windows before login UI is deleted.
52 ash::Shell* shell = ash::Shell::GetInstance();
53 ash::MruWindowTracker::WindowList mru_list =
54 shell->mru_window_tracker()->BuildMruWindowList();
55 if (!mru_list.empty())
56 mru_list.front()->Focus();
57
58 // Enable magnifier scroll keys as there may be no mouse cursor in kiosk mode.
59 ash::MagnifierKeyScroller::SetEnabled(chrome::IsRunningInForcedAppMode());
60
61 // Enable long press action to toggle spoken feedback with hotrod
62 // remote which can't handle shortcut.
63 ash::SpokenFeedbackToggler::SetEnabled(chrome::IsRunningInForcedAppMode());
64 }
65
66 class AccessibilityDelegateImpl : public ash::AccessibilityDelegate {
67 public:
68 AccessibilityDelegateImpl() {
69 ash::Shell::GetInstance()->AddShellObserver(
70 chromeos::AccessibilityManager::Get());
71 }
72 ~AccessibilityDelegateImpl() override {
73 ash::Shell::GetInstance()->RemoveShellObserver(
74 chromeos::AccessibilityManager::Get());
75 }
76
77 void ToggleHighContrast() override {
78 DCHECK(chromeos::AccessibilityManager::Get());
79 chromeos::AccessibilityManager::Get()->EnableHighContrast(
80 !chromeos::AccessibilityManager::Get()->IsHighContrastEnabled());
81 }
82
83 bool IsSpokenFeedbackEnabled() const override {
84 DCHECK(chromeos::AccessibilityManager::Get());
85 return chromeos::AccessibilityManager::Get()->IsSpokenFeedbackEnabled();
86 }
87
88 void ToggleSpokenFeedback(
89 ui::AccessibilityNotificationVisibility notify) override {
90 DCHECK(chromeos::AccessibilityManager::Get());
91 chromeos::AccessibilityManager::Get()->ToggleSpokenFeedback(notify);
92 }
93
94 bool IsHighContrastEnabled() const override {
95 DCHECK(chromeos::AccessibilityManager::Get());
96 return chromeos::AccessibilityManager::Get()->IsHighContrastEnabled();
97 }
98
99 void SetMagnifierEnabled(bool enabled) override {
100 DCHECK(chromeos::MagnificationManager::Get());
101 return chromeos::MagnificationManager::Get()->SetMagnifierEnabled(enabled);
102 }
103
104 void SetMagnifierType(ui::MagnifierType type) override {
105 DCHECK(chromeos::MagnificationManager::Get());
106 return chromeos::MagnificationManager::Get()->SetMagnifierType(type);
107 }
108
109 bool IsMagnifierEnabled() const override {
110 DCHECK(chromeos::MagnificationManager::Get());
111 return chromeos::MagnificationManager::Get()->IsMagnifierEnabled();
112 }
113
114 ui::MagnifierType GetMagnifierType() const override {
115 DCHECK(chromeos::MagnificationManager::Get());
116 return chromeos::MagnificationManager::Get()->GetMagnifierType();
117 }
118
119 void SetLargeCursorEnabled(bool enabled) override {
120 DCHECK(chromeos::AccessibilityManager::Get());
121 return chromeos::AccessibilityManager::Get()->EnableLargeCursor(enabled);
122 }
123
124 bool IsLargeCursorEnabled() const override {
125 DCHECK(chromeos::AccessibilityManager::Get());
126 return chromeos::AccessibilityManager::Get()->IsLargeCursorEnabled();
127 }
128
129 void SetAutoclickEnabled(bool enabled) override {
130 DCHECK(chromeos::AccessibilityManager::Get());
131 return chromeos::AccessibilityManager::Get()->EnableAutoclick(enabled);
132 }
133
134 bool IsAutoclickEnabled() const override {
135 DCHECK(chromeos::AccessibilityManager::Get());
136 return chromeos::AccessibilityManager::Get()->IsAutoclickEnabled();
137 }
138
139 void SetVirtualKeyboardEnabled(bool enabled) override {
140 DCHECK(chromeos::AccessibilityManager::Get());
141 return chromeos::AccessibilityManager::Get()->
142 EnableVirtualKeyboard(enabled);
143 }
144
145 bool IsVirtualKeyboardEnabled() const override {
146 DCHECK(chromeos::AccessibilityManager::Get());
147 return chromeos::AccessibilityManager::Get()->IsVirtualKeyboardEnabled();
148 }
149
150 void SetMonoAudioEnabled(bool enabled) override {
151 DCHECK(chromeos::AccessibilityManager::Get());
152 return chromeos::AccessibilityManager::Get()->
153 EnableMonoAudio(enabled);
154 }
155
156 bool IsMonoAudioEnabled() const override {
157 DCHECK(chromeos::AccessibilityManager::Get());
158 return chromeos::AccessibilityManager::Get()->IsMonoAudioEnabled();
159 }
160
161 void SetCaretHighlightEnabled(bool enabled) override {
162 DCHECK(chromeos::AccessibilityManager::Get());
163 chromeos::AccessibilityManager::Get()->SetCaretHighlightEnabled(enabled);
164 }
165
166 bool IsCaretHighlightEnabled() const override {
167 DCHECK(chromeos::AccessibilityManager::Get());
168 return chromeos::AccessibilityManager::Get()->IsCaretHighlightEnabled();
169 }
170
171 void SetCursorHighlightEnabled(bool enabled) override {
172 DCHECK(chromeos::AccessibilityManager::Get());
173 chromeos::AccessibilityManager::Get()->SetCursorHighlightEnabled(enabled);
174 }
175
176 bool IsCursorHighlightEnabled() const override {
177 DCHECK(chromeos::AccessibilityManager::Get());
178 return chromeos::AccessibilityManager::Get()->IsCursorHighlightEnabled();
179 }
180
181 void SetFocusHighlightEnabled(bool enabled) override {
182 DCHECK(chromeos::AccessibilityManager::Get());
183 chromeos::AccessibilityManager::Get()->SetFocusHighlightEnabled(enabled);
184 }
185
186 bool IsFocusHighlightEnabled() const override {
187 DCHECK(chromeos::AccessibilityManager::Get());
188 return chromeos::AccessibilityManager::Get()->IsFocusHighlightEnabled();
189 }
190
191 void SetSelectToSpeakEnabled(bool enabled) override {
192 DCHECK(chromeos::AccessibilityManager::Get());
193 chromeos::AccessibilityManager::Get()->SetSelectToSpeakEnabled(enabled);
194 }
195
196 bool IsSelectToSpeakEnabled() const override {
197 DCHECK(chromeos::AccessibilityManager::Get());
198 return chromeos::AccessibilityManager::Get()->IsSelectToSpeakEnabled();
199 }
200
201 void SetSwitchAccessEnabled(bool enabled) override {
202 DCHECK(chromeos::AccessibilityManager::Get());
203 chromeos::AccessibilityManager::Get()->SetSwitchAccessEnabled(enabled);
204 }
205
206 bool IsSwitchAccessEnabled() const override {
207 DCHECK(chromeos::AccessibilityManager::Get());
208 return chromeos::AccessibilityManager::Get()->IsSwitchAccessEnabled();
209 }
210
211 bool ShouldShowAccessibilityMenu() const override {
212 DCHECK(chromeos::AccessibilityManager::Get());
213 return chromeos::AccessibilityManager::Get()->
214 ShouldShowAccessibilityMenu();
215 }
216
217 bool IsBrailleDisplayConnected() const override {
218 DCHECK(chromeos::AccessibilityManager::Get());
219 return chromeos::AccessibilityManager::Get()->IsBrailleDisplayConnected();
220 }
221
222 void SilenceSpokenFeedback() const override {
223 TtsController::GetInstance()->Stop();
224 }
225
226 void SaveScreenMagnifierScale(double scale) override {
227 if (chromeos::MagnificationManager::Get())
228 chromeos::MagnificationManager::Get()->SaveScreenMagnifierScale(scale);
229 }
230
231 double GetSavedScreenMagnifierScale() override {
232 if (chromeos::MagnificationManager::Get()) {
233 return chromeos::MagnificationManager::Get()->
234 GetSavedScreenMagnifierScale();
235 }
236 return std::numeric_limits<double>::min();
237 }
238
239 void TriggerAccessibilityAlert(ui::AccessibilityAlert alert) override {
240 Profile* profile = ProfileManager::GetActiveUserProfile();
241 if (profile) {
242 switch (alert) {
243 case ui::A11Y_ALERT_WINDOW_NEEDED: {
244 AutomationManagerAura::GetInstance()->HandleAlert(
245 profile, l10n_util::GetStringUTF8(IDS_A11Y_ALERT_WINDOW_NEEDED));
246 break;
247 }
248 case ui::A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED: {
249 AutomationManagerAura::GetInstance()->HandleAlert(
250 profile, l10n_util::GetStringUTF8(
251 IDS_A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED));
252 break;
253 }
254 case ui::A11Y_ALERT_NONE:
255 break;
256 }
257 }
258 }
259
260 ui::AccessibilityAlert GetLastAccessibilityAlert() override {
261 return ui::A11Y_ALERT_NONE;
262 }
263
264 void PlayEarcon(int sound_key) override {
265 DCHECK(chromeos::AccessibilityManager::Get());
266 return chromeos::AccessibilityManager::Get()->PlayEarcon(sound_key);
267 }
268
269 base::TimeDelta PlayShutdownSound() const override {
270 return chromeos::AccessibilityManager::Get()->PlayShutdownSound();
271 }
272
273 private:
274 DISALLOW_COPY_AND_ASSIGN(AccessibilityDelegateImpl);
275 };
276
277 } // anonymous namespace
278
279 bool ChromeShellDelegate::IsFirstRunAfterBoot() const {
280 return base::CommandLine::ForCurrentProcess()->HasSwitch(
281 chromeos::switches::kFirstExecAfterBoot);
282 }
283
284 void ChromeShellDelegate::PreInit() {
285 chromeos::LoadDisplayPreferences(IsFirstRunAfterBoot());
286 // Object owns itself, and deletes itself when Observer::OnShutdown is called:
287 new policy::DisplayRotationDefaultHandler();
288 // Set the observer now so that we can save the initial state
289 // in Shell::Init.
290 display_configuration_observer_.reset(
291 new chromeos::DisplayConfigurationObserver());
292
293 chrome_user_metrics_recorder_.reset(new ChromeUserMetricsRecorder);
294 }
295
296 void ChromeShellDelegate::PreShutdown() {
297 display_configuration_observer_.reset();
298
299 chrome_user_metrics_recorder_.reset();
300 }
301
302 ash::SessionStateDelegate* ChromeShellDelegate::CreateSessionStateDelegate() {
303 return new SessionStateDelegateChromeos;
304 }
305
306 ash::AccessibilityDelegate* ChromeShellDelegate::CreateAccessibilityDelegate() {
307 return new AccessibilityDelegateImpl;
308 }
309
310 ash::NewWindowDelegate* ChromeShellDelegate::CreateNewWindowDelegate() {
311 return new ChromeNewWindowDelegateChromeos;
312 }
313
314 ash::MediaDelegate* ChromeShellDelegate::CreateMediaDelegate() {
315 return new MediaDelegateChromeOS;
316 }
317
318 ash::SystemTrayDelegate* ChromeShellDelegate::CreateSystemTrayDelegate() {
319 return chromeos::CreateSystemTrayDelegate();
320 }
321
322 ash::UserWallpaperDelegate* ChromeShellDelegate::CreateUserWallpaperDelegate() {
323 return chromeos::CreateUserWallpaperDelegate();
324 }
325
326 void ChromeShellDelegate::Observe(int type,
327 const content::NotificationSource& source,
328 const content::NotificationDetails& details) {
329 switch (type) {
330 case chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED: {
331 Profile* profile = content::Details<Profile>(details).ptr();
332 if (!chromeos::ProfileHelper::IsSigninProfile(profile) &&
333 !profile->IsGuestSession() && !profile->IsSupervised()) {
334 // Start the error notifier services to show auth/sync notifications.
335 SigninErrorNotifierFactory::GetForProfile(profile);
336 SyncErrorNotifierFactory::GetForProfile(profile);
337 }
338 // Do not use chrome::NOTIFICATION_PROFILE_ADDED because the
339 // profile is not fully initialized by user_manager. Use
340 // chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED instead.
341 if (shelf_delegate_)
342 shelf_delegate_->OnUserProfileReadyToSwitch(profile);
343 ash::Shell::GetInstance()->OnLoginUserProfilePrepared();
344 break;
345 }
346 case chrome::NOTIFICATION_SESSION_STARTED:
347 // InitAfterFirstSessionStart() should only be called once upon system
348 // start.
349 if (user_manager::UserManager::Get()->GetLoggedInUsers().size() < 2)
350 InitAfterFirstSessionStart();
351 ash::Shell::GetInstance()->ShowShelf();
352 break;
353 default:
354 NOTREACHED() << "Unexpected notification " << type;
355 }
356 }
357
358 void ChromeShellDelegate::PlatformInit() {
359 registrar_.Add(this,
360 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
361 content::NotificationService::AllSources());
362 registrar_.Add(this,
363 chrome::NOTIFICATION_SESSION_STARTED,
364 content::NotificationService::AllSources());
365 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/chrome_shell_delegate.cc ('k') | chrome/browser/ui/ash/chrome_shell_delegate_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698