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"
32 #include "chrome/browser/ui/ash/system_tray_delegate_win.h"
33 #include "chrome/browser/ui/ash/user_wallpaper_delegate_win.h"
38 class NewWindowDelegateImpl
: public ChromeNewWindowDelegate
{
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
{}
49 DISALLOW_COPY_AND_ASSIGN(NewWindowDelegateImpl
);
52 class MediaDelegateImpl
: public ash::MediaDelegate
{
54 MediaDelegateImpl() {}
55 virtual ~MediaDelegateImpl() {}
56 virtual void HandleMediaNextTrack() OVERRIDE
{}
57 virtual void HandleMediaPlayPause() OVERRIDE
{}
58 virtual void HandleMediaPrevTrack() OVERRIDE
{}
61 DISALLOW_COPY_AND_ASSIGN(MediaDelegateImpl
);
64 class EmptyAccessibilityDelegate
: public ash::AccessibilityDelegate
{
66 EmptyAccessibilityDelegate() {}
67 virtual ~EmptyAccessibilityDelegate() {}
69 virtual void ToggleHighContrast() OVERRIDE
{
72 virtual bool IsHighContrastEnabled() const OVERRIDE
{
76 virtual bool IsSpokenFeedbackEnabled() const OVERRIDE
{
80 virtual void ToggleSpokenFeedback(
81 ash::AccessibilityNotificationVisibility notify
) OVERRIDE
{
84 virtual void SetLargeCursorEnabled(bool enalbed
) OVERRIDE
{
87 virtual bool IsLargeCursorEnabled() const OVERRIDE
{
91 virtual void SetMagnifierEnabled(bool enabled
) OVERRIDE
{
94 virtual void SetMagnifierType(ash::MagnifierType type
) OVERRIDE
{
97 virtual bool IsMagnifierEnabled() const OVERRIDE
{
101 virtual void SetAutoclickEnabled(bool enabled
) OVERRIDE
{
104 virtual bool IsAutoclickEnabled() const OVERRIDE
{
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
{
123 virtual void SilenceSpokenFeedback() const OVERRIDE
{
126 virtual void TriggerAccessibilityAlert(
127 ash::AccessibilityAlert alert
) OVERRIDE
{
130 virtual ash::AccessibilityAlert
GetLastAccessibilityAlert() OVERRIDE
{
131 return ash::A11Y_ALERT_NONE
;
134 base::TimeDelta
PlayShutdownSound() const OVERRIDE
{
135 return base::TimeDelta();
139 DISALLOW_COPY_AND_ASSIGN(EmptyAccessibilityDelegate
);
144 bool ChromeShellDelegate::IsFirstRunAfterBoot() const {
148 void ChromeShellDelegate::PreInit() {
151 void ChromeShellDelegate::Shutdown() {
154 ash::NewWindowDelegate
* ChromeShellDelegate::CreateNewWindowDelegate() {
155 return new NewWindowDelegateImpl
;
158 ash::MediaDelegate
* ChromeShellDelegate::CreateMediaDelegate() {
159 return new MediaDelegateImpl
;
162 ash::CapsLockDelegate
* ChromeShellDelegate::CreateCapsLockDelegate() {
163 return new CapsLockDelegate();
166 ash::SessionStateDelegate
* ChromeShellDelegate::CreateSessionStateDelegate() {
167 return new SessionStateDelegate
;
170 ash::SystemTrayDelegate
* ChromeShellDelegate::CreateSystemTrayDelegate() {
172 return CreateWindowsSystemTrayDelegate();
174 return new ash::DefaultSystemTrayDelegate
;
178 ash::AccessibilityDelegate
* ChromeShellDelegate::CreateAccessibilityDelegate() {
179 return new EmptyAccessibilityDelegate
;
182 ash::UserWallpaperDelegate
* ChromeShellDelegate::CreateUserWallpaperDelegate() {
184 return ::CreateUserWallpaperDelegate();
190 void ChromeShellDelegate::Observe(int type
,
191 const content::NotificationSource
& source
,
192 const content::NotificationDetails
& details
) {
194 case chrome::NOTIFICATION_ASH_SESSION_STARTED
: {
195 // If we are launched to service a windows 8 search request then let the
196 // IPC which carries the search string create the browser and initiate
198 if (CommandLine::ForCurrentProcess()->HasSwitch(
199 switches::kWindows8Search
))
201 // If Chrome ASH is launched when no browser is open in the desktop,
202 // we should execute the startup code.
203 // If there are browsers open in the desktop, we create a browser window
204 // and open a new tab page, if session restore is not on.
205 BrowserList
* desktop_list
= BrowserList::GetInstance(
206 chrome::HOST_DESKTOP_TYPE_NATIVE
);
207 if (desktop_list
->empty()) {
208 // We pass a dummy command line here, because the browser is launched in
209 // silent-mode by the metro viewer process, which causes the
210 // StartupBrowserCreatorImpl class to not create any browsers which is
211 // not the behavior we want.
212 CommandLine
dummy(CommandLine::NO_PROGRAM
);
213 StartupBrowserCreatorImpl
startup_impl(
216 chrome::startup::IS_NOT_FIRST_RUN
);
218 ProfileManager::GetActiveUserProfile(),
221 chrome::HOST_DESKTOP_TYPE_ASH
);
224 chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow());
225 if (browser
&& browser
->is_type_tabbed()) {
226 chrome::AddTabAt(browser
, GURL(), -1, true);
230 chrome::ScopedTabbedBrowserDisplayer
displayer(
231 ProfileManager::GetActiveUserProfile(),
232 chrome::HOST_DESKTOP_TYPE_ASH
);
233 chrome::AddTabAt(displayer
.browser(), GURL(), -1, true);
237 case chrome::NOTIFICATION_ASH_SESSION_ENDED
:
240 NOTREACHED() << "Unexpected notification " << type
;
244 void ChromeShellDelegate::PlatformInit() {
247 chrome::NOTIFICATION_ASH_SESSION_STARTED
,
248 content::NotificationService::AllSources());
250 chrome::NOTIFICATION_ASH_SESSION_ENDED
,
251 content::NotificationService::AllSources());