NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / ash / chrome_shell_delegate_views.cc
blob6c148328123245b4f66b678288f533a9e32c47ed
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/accessibility_delegate.h"
8 #include "ash/magnifier/magnifier_constants.h"
9 #include "ash/media_delegate.h"
10 #include "ash/system/tray/default_system_tray_delegate.h"
11 #include "ash/wm/window_util.h"
12 #include "base/command_line.h"
13 #include "chrome/browser/accessibility/accessibility_events.h"
14 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/prefs/session_startup_pref.h"
16 #include "chrome/browser/profiles/profile_manager.h"
17 #include "chrome/browser/ui/ash/caps_lock_delegate_views.h"
18 #include "chrome/browser/ui/ash/chrome_new_window_delegate.h"
19 #include "chrome/browser/ui/ash/session_state_delegate_views.h"
20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_finder.h"
22 #include "chrome/browser/ui/browser_list.h"
23 #include "chrome/browser/ui/browser_tabstrip.h"
24 #include "chrome/browser/ui/browser_window.h"
25 #include "chrome/browser/ui/host_desktop.h"
26 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
27 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h"
28 #include "chrome/common/chrome_switches.h"
29 #include "content/public/browser/notification_service.h"
31 #if defined(OS_WIN)
32 #include "chrome/browser/ui/ash/system_tray_delegate_win.h"
33 #include "chrome/browser/ui/ash/user_wallpaper_delegate_win.h"
34 #endif
36 namespace {
38 class NewWindowDelegateImpl : public ChromeNewWindowDelegate {
39 public:
40 NewWindowDelegateImpl() {}
41 virtual ~NewWindowDelegateImpl() {}
43 // Overridden from ash::NewWindowDelegate:
44 virtual void OpenFileManager() OVERRIDE {}
45 virtual void OpenCrosh() OVERRIDE {}
46 virtual void ShowKeyboardOverlay() OVERRIDE {}
48 private:
49 DISALLOW_COPY_AND_ASSIGN(NewWindowDelegateImpl);
52 class MediaDelegateImpl : public ash::MediaDelegate {
53 public:
54 MediaDelegateImpl() {}
55 virtual ~MediaDelegateImpl() {}
56 virtual void HandleMediaNextTrack() OVERRIDE {}
57 virtual void HandleMediaPlayPause() OVERRIDE {}
58 virtual void HandleMediaPrevTrack() OVERRIDE {}
60 private:
61 DISALLOW_COPY_AND_ASSIGN(MediaDelegateImpl);
64 class EmptyAccessibilityDelegate : public ash::AccessibilityDelegate {
65 public:
66 EmptyAccessibilityDelegate() {}
67 virtual ~EmptyAccessibilityDelegate() {}
69 virtual void ToggleHighContrast() OVERRIDE {
72 virtual bool IsHighContrastEnabled() const OVERRIDE {
73 return false;
76 virtual bool IsSpokenFeedbackEnabled() const OVERRIDE {
77 return false;
80 virtual void ToggleSpokenFeedback(
81 ash::AccessibilityNotificationVisibility notify) OVERRIDE {
84 virtual void SetLargeCursorEnabled(bool enalbed) OVERRIDE {
87 virtual bool IsLargeCursorEnabled() const OVERRIDE {
88 return false;
91 virtual void SetMagnifierEnabled(bool enabled) OVERRIDE {
94 virtual void SetMagnifierType(ash::MagnifierType type) OVERRIDE {
97 virtual bool IsMagnifierEnabled() const OVERRIDE {
98 return false;
101 virtual void SetAutoclickEnabled(bool enabled) OVERRIDE {
104 virtual bool IsAutoclickEnabled() const OVERRIDE {
105 return false;
108 virtual ash::MagnifierType GetMagnifierType() const OVERRIDE {
109 return ash::kDefaultMagnifierType;
112 virtual void SaveScreenMagnifierScale(double scale) OVERRIDE {
115 virtual double GetSavedScreenMagnifierScale() OVERRIDE {
116 return std::numeric_limits<double>::min();
119 virtual bool ShouldShowAccessibilityMenu() const OVERRIDE {
120 return false;
123 virtual void SilenceSpokenFeedback() const OVERRIDE {
126 virtual void SetVirtualKeyboardEnabled(bool enabled) OVERRIDE {
129 virtual bool IsVirtualKeyboardEnabled() const OVERRIDE {
130 return false;
133 virtual void TriggerAccessibilityAlert(
134 ash::AccessibilityAlert alert) OVERRIDE {
137 virtual ash::AccessibilityAlert GetLastAccessibilityAlert() OVERRIDE {
138 return ash::A11Y_ALERT_NONE;
141 base::TimeDelta PlayShutdownSound() const OVERRIDE {
142 return base::TimeDelta();
145 private:
146 DISALLOW_COPY_AND_ASSIGN(EmptyAccessibilityDelegate);
149 } // namespace
151 bool ChromeShellDelegate::IsFirstRunAfterBoot() const {
152 return false;
155 void ChromeShellDelegate::PreInit() {
158 void ChromeShellDelegate::Shutdown() {
161 ash::NewWindowDelegate* ChromeShellDelegate::CreateNewWindowDelegate() {
162 return new NewWindowDelegateImpl;
165 ash::MediaDelegate* ChromeShellDelegate::CreateMediaDelegate() {
166 return new MediaDelegateImpl;
169 ash::CapsLockDelegate* ChromeShellDelegate::CreateCapsLockDelegate() {
170 return new CapsLockDelegate();
173 ash::SessionStateDelegate* ChromeShellDelegate::CreateSessionStateDelegate() {
174 return new SessionStateDelegate;
177 ash::SystemTrayDelegate* ChromeShellDelegate::CreateSystemTrayDelegate() {
178 #if defined(OS_WIN)
179 return CreateWindowsSystemTrayDelegate();
180 #else
181 return new ash::DefaultSystemTrayDelegate;
182 #endif
185 ash::AccessibilityDelegate* ChromeShellDelegate::CreateAccessibilityDelegate() {
186 return new EmptyAccessibilityDelegate;
189 ash::UserWallpaperDelegate* ChromeShellDelegate::CreateUserWallpaperDelegate() {
190 #if defined(OS_WIN)
191 return ::CreateUserWallpaperDelegate();
192 #else
193 return NULL;
194 #endif
197 void ChromeShellDelegate::Observe(int type,
198 const content::NotificationSource& source,
199 const content::NotificationDetails& details) {
200 switch (type) {
201 case chrome::NOTIFICATION_ASH_SESSION_STARTED: {
202 #if defined(OS_WIN)
203 // If we are launched to service a windows 8 search request then let the
204 // IPC which carries the search string create the browser and initiate
205 // the navigation.
206 if (CommandLine::ForCurrentProcess()->HasSwitch(
207 switches::kWindows8Search))
208 break;
209 #endif
210 // If Chrome ASH is launched when no browser is open in the desktop,
211 // we should execute the startup code.
212 // If there are browsers open in the desktop, we create a browser window
213 // and open a new tab page, if session restore is not on.
214 BrowserList* desktop_list = BrowserList::GetInstance(
215 chrome::HOST_DESKTOP_TYPE_NATIVE);
216 if (desktop_list->empty()) {
217 // We pass a dummy command line here, because the browser is launched in
218 // silent-mode by the metro viewer process, which causes the
219 // StartupBrowserCreatorImpl class to not create any browsers which is
220 // not the behavior we want.
221 CommandLine dummy(CommandLine::NO_PROGRAM);
222 StartupBrowserCreatorImpl startup_impl(
223 base::FilePath(),
224 dummy,
225 chrome::startup::IS_NOT_FIRST_RUN);
226 startup_impl.Launch(
227 ProfileManager::GetActiveUserProfile(),
228 std::vector<GURL>(),
229 true,
230 chrome::HOST_DESKTOP_TYPE_ASH);
231 } else {
232 Browser* browser =
233 chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow());
234 if (browser && browser->is_type_tabbed()) {
235 chrome::AddTabAt(browser, GURL(), -1, true);
236 return;
239 chrome::ScopedTabbedBrowserDisplayer displayer(
240 ProfileManager::GetActiveUserProfile(),
241 chrome::HOST_DESKTOP_TYPE_ASH);
242 chrome::AddTabAt(displayer.browser(), GURL(), -1, true);
244 break;
246 case chrome::NOTIFICATION_ASH_SESSION_ENDED:
247 break;
248 default:
249 NOTREACHED() << "Unexpected notification " << type;
253 void ChromeShellDelegate::PlatformInit() {
254 #if defined(OS_WIN)
255 registrar_.Add(this,
256 chrome::NOTIFICATION_ASH_SESSION_STARTED,
257 content::NotificationService::AllSources());
258 registrar_.Add(this,
259 chrome::NOTIFICATION_ASH_SESSION_ENDED,
260 content::NotificationService::AllSources());
261 #endif