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"
9 #include "ash/accessibility_delegate.h"
10 #include "ash/magnifier/magnifier_constants.h"
11 #include "ash/media_delegate.h"
12 #include "ash/system/tray/default_system_tray_delegate.h"
13 #include "ash/wm/window_util.h"
14 #include "base/command_line.h"
15 #include "chrome/browser/accessibility/accessibility_events.h"
16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/chrome_notification_types.h"
18 #include "chrome/browser/prefs/session_startup_pref.h"
19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/profiles/profile_manager.h"
21 #include "chrome/browser/signin/signin_error_notifier_factory_ash.h"
22 #include "chrome/browser/sync/sync_error_notifier_factory_ash.h"
23 #include "chrome/browser/ui/ash/chrome_new_window_delegate.h"
24 #include "chrome/browser/ui/ash/session_state_delegate_views.h"
25 #include "chrome/browser/ui/browser.h"
26 #include "chrome/browser/ui/browser_finder.h"
27 #include "chrome/browser/ui/browser_list.h"
28 #include "chrome/browser/ui/browser_tabstrip.h"
29 #include "chrome/browser/ui/browser_window.h"
30 #include "chrome/browser/ui/host_desktop.h"
31 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
32 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h"
33 #include "chrome/common/chrome_switches.h"
34 #include "content/public/browser/notification_service.h"
37 #include "chrome/browser/ui/ash/system_tray_delegate_win.h"
38 #include "chrome/browser/ui/ash/user_wallpaper_delegate_win.h"
43 class NewWindowDelegateImpl
: public ChromeNewWindowDelegate
{
45 NewWindowDelegateImpl() {}
46 virtual ~NewWindowDelegateImpl() {}
48 // Overridden from ash::NewWindowDelegate:
49 virtual void OpenFileManager() OVERRIDE
{}
50 virtual void OpenCrosh() OVERRIDE
{}
51 virtual void ShowKeyboardOverlay() OVERRIDE
{}
54 DISALLOW_COPY_AND_ASSIGN(NewWindowDelegateImpl
);
57 class MediaDelegateImpl
: public ash::MediaDelegate
{
59 MediaDelegateImpl() {}
60 virtual ~MediaDelegateImpl() {}
61 virtual void HandleMediaNextTrack() OVERRIDE
{}
62 virtual void HandleMediaPlayPause() OVERRIDE
{}
63 virtual void HandleMediaPrevTrack() OVERRIDE
{}
64 virtual ash::MediaCaptureState
GetMediaCaptureState(
65 content::BrowserContext
* context
) OVERRIDE
{
66 return ash::MEDIA_CAPTURE_NONE
;
70 DISALLOW_COPY_AND_ASSIGN(MediaDelegateImpl
);
73 class EmptyAccessibilityDelegate
: public ash::AccessibilityDelegate
{
75 EmptyAccessibilityDelegate() {}
76 virtual ~EmptyAccessibilityDelegate() {}
78 virtual void ToggleHighContrast() OVERRIDE
{
81 virtual bool IsHighContrastEnabled() const OVERRIDE
{
85 virtual bool IsSpokenFeedbackEnabled() const OVERRIDE
{
89 virtual void ToggleSpokenFeedback(
90 ash::AccessibilityNotificationVisibility notify
) OVERRIDE
{
93 virtual void SetLargeCursorEnabled(bool enalbed
) OVERRIDE
{
96 virtual bool IsLargeCursorEnabled() const OVERRIDE
{
100 virtual void SetMagnifierEnabled(bool enabled
) OVERRIDE
{
103 virtual void SetMagnifierType(ash::MagnifierType type
) OVERRIDE
{
106 virtual bool IsMagnifierEnabled() const OVERRIDE
{
110 virtual void SetAutoclickEnabled(bool enabled
) OVERRIDE
{
113 virtual bool IsAutoclickEnabled() const OVERRIDE
{
117 virtual ash::MagnifierType
GetMagnifierType() const OVERRIDE
{
118 return ash::kDefaultMagnifierType
;
121 virtual void SaveScreenMagnifierScale(double scale
) OVERRIDE
{
124 virtual double GetSavedScreenMagnifierScale() OVERRIDE
{
125 return std::numeric_limits
<double>::min();
128 virtual bool ShouldShowAccessibilityMenu() const OVERRIDE
{
132 virtual bool IsBrailleDisplayConnected() const OVERRIDE
{ return false; }
134 virtual void SilenceSpokenFeedback() const OVERRIDE
{
137 virtual void SetVirtualKeyboardEnabled(bool enabled
) OVERRIDE
{
140 virtual bool IsVirtualKeyboardEnabled() const OVERRIDE
{
144 virtual void TriggerAccessibilityAlert(
145 ash::AccessibilityAlert alert
) OVERRIDE
{
148 virtual ash::AccessibilityAlert
GetLastAccessibilityAlert() OVERRIDE
{
149 return ash::A11Y_ALERT_NONE
;
152 base::TimeDelta
PlayShutdownSound() const OVERRIDE
{
153 return base::TimeDelta();
157 DISALLOW_COPY_AND_ASSIGN(EmptyAccessibilityDelegate
);
162 bool ChromeShellDelegate::IsFirstRunAfterBoot() const {
166 void ChromeShellDelegate::PreInit() {
169 void ChromeShellDelegate::PreShutdown() {
172 ash::NewWindowDelegate
* ChromeShellDelegate::CreateNewWindowDelegate() {
173 return new NewWindowDelegateImpl
;
176 ash::MediaDelegate
* ChromeShellDelegate::CreateMediaDelegate() {
177 return new MediaDelegateImpl
;
180 ash::SessionStateDelegate
* ChromeShellDelegate::CreateSessionStateDelegate() {
181 return new SessionStateDelegate
;
184 ash::SystemTrayDelegate
* ChromeShellDelegate::CreateSystemTrayDelegate() {
186 return CreateWindowsSystemTrayDelegate();
188 return new ash::DefaultSystemTrayDelegate
;
192 ash::AccessibilityDelegate
* ChromeShellDelegate::CreateAccessibilityDelegate() {
193 return new EmptyAccessibilityDelegate
;
196 ash::UserWallpaperDelegate
* ChromeShellDelegate::CreateUserWallpaperDelegate() {
198 return ::CreateUserWallpaperDelegate();
204 void ChromeShellDelegate::Observe(int type
,
205 const content::NotificationSource
& source
,
206 const content::NotificationDetails
& details
) {
208 case chrome::NOTIFICATION_PROFILE_ADDED
: {
209 // Start the error notifier services to show sync/auth notifications.
210 Profile
* profile
= content::Source
<Profile
>(source
).ptr();
211 SigninErrorNotifierFactory::GetForProfile(profile
);
212 SyncErrorNotifierFactory::GetForProfile(profile
);
215 case chrome::NOTIFICATION_ASH_SESSION_STARTED
: {
216 // Start the error notifier services for the already loaded profiles.
217 const std::vector
<Profile
*> profiles
=
218 g_browser_process
->profile_manager()->GetLoadedProfiles();
219 for (std::vector
<Profile
*>::const_iterator it
= profiles
.begin();
220 it
!= profiles
.end(); ++it
) {
221 SigninErrorNotifierFactory::GetForProfile(*it
);
222 SyncErrorNotifierFactory::GetForProfile(*it
);
226 // If we are launched to service a windows 8 search request then let the
227 // IPC which carries the search string create the browser and initiate
229 if (CommandLine::ForCurrentProcess()->HasSwitch(
230 switches::kWindows8Search
))
233 // If Chrome ASH is launched when no browser is open in the desktop,
234 // we should execute the startup code.
235 // If there are browsers open in the desktop, we create a browser window
236 // and open a new tab page, if session restore is not on.
237 BrowserList
* desktop_list
= BrowserList::GetInstance(
238 chrome::HOST_DESKTOP_TYPE_NATIVE
);
239 if (desktop_list
->empty()) {
240 // We pass a dummy command line here, because the browser is launched in
241 // silent-mode by the metro viewer process, which causes the
242 // StartupBrowserCreatorImpl class to not create any browsers which is
243 // not the behavior we want.
244 CommandLine
dummy(CommandLine::NO_PROGRAM
);
245 StartupBrowserCreatorImpl
startup_impl(
248 chrome::startup::IS_NOT_FIRST_RUN
);
250 ProfileManager::GetActiveUserProfile(),
253 chrome::HOST_DESKTOP_TYPE_ASH
);
256 chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow());
257 if (browser
&& browser
->is_type_tabbed()) {
258 chrome::AddTabAt(browser
, GURL(), -1, true);
262 chrome::ScopedTabbedBrowserDisplayer
displayer(
263 ProfileManager::GetActiveUserProfile(),
264 chrome::HOST_DESKTOP_TYPE_ASH
);
265 chrome::AddTabAt(displayer
.browser(), GURL(), -1, true);
269 case chrome::NOTIFICATION_ASH_SESSION_ENDED
:
272 NOTREACHED() << "Unexpected notification " << type
;
276 void ChromeShellDelegate::PlatformInit() {
279 chrome::NOTIFICATION_PROFILE_ADDED
,
280 content::NotificationService::AllSources());
282 chrome::NOTIFICATION_ASH_SESSION_STARTED
,
283 content::NotificationService::AllSources());
285 chrome::NOTIFICATION_ASH_SESSION_ENDED
,
286 content::NotificationService::AllSources());