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/media_delegate.h"
11 #include "ash/wm/window_util.h"
12 #include "base/command_line.h"
13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/prefs/session_startup_pref.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/profiles/profile_manager.h"
18 #include "chrome/browser/signin/signin_error_notifier_factory_ash.h"
19 #include "chrome/browser/sync/sync_error_notifier_factory_ash.h"
20 #include "chrome/browser/ui/ash/chrome_new_window_delegate.h"
21 #include "chrome/browser/ui/ash/session_state_delegate_views.h"
22 #include "chrome/browser/ui/ash/solid_color_user_wallpaper_delegate.h"
23 #include "chrome/browser/ui/ash/system_tray_delegate_common.h"
24 #include "chrome/browser/ui/browser.h"
25 #include "chrome/browser/ui/browser_finder.h"
26 #include "chrome/browser/ui/browser_list.h"
27 #include "chrome/browser/ui/browser_tabstrip.h"
28 #include "chrome/browser/ui/browser_window.h"
29 #include "chrome/browser/ui/host_desktop.h"
30 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
31 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h"
32 #include "chrome/common/chrome_switches.h"
33 #include "content/public/browser/notification_service.h"
34 #include "ui/chromeos/accessibility_types.h"
38 class NewWindowDelegateImpl
: public ChromeNewWindowDelegate
{
40 NewWindowDelegateImpl() {}
41 ~NewWindowDelegateImpl() override
{}
43 // Overridden from ash::NewWindowDelegate:
44 void OpenFileManager() override
{}
45 void OpenCrosh() override
{}
46 void OpenGetHelp() override
{}
47 void ShowKeyboardOverlay() override
{}
50 DISALLOW_COPY_AND_ASSIGN(NewWindowDelegateImpl
);
53 class MediaDelegateImpl
: public ash::MediaDelegate
{
55 MediaDelegateImpl() {}
56 ~MediaDelegateImpl() override
{}
57 void HandleMediaNextTrack() override
{}
58 void HandleMediaPlayPause() override
{}
59 void HandleMediaPrevTrack() override
{}
60 ash::MediaCaptureState
GetMediaCaptureState(
61 content::BrowserContext
* context
) override
{
62 return ash::MEDIA_CAPTURE_NONE
;
66 DISALLOW_COPY_AND_ASSIGN(MediaDelegateImpl
);
69 class EmptyAccessibilityDelegate
: public ash::AccessibilityDelegate
{
71 EmptyAccessibilityDelegate() {}
72 ~EmptyAccessibilityDelegate() override
{}
74 void ToggleHighContrast() override
{}
76 bool IsHighContrastEnabled() const override
{ return false; }
78 bool IsSpokenFeedbackEnabled() const override
{ return false; }
80 void ToggleSpokenFeedback(
81 ui::AccessibilityNotificationVisibility notify
) override
{}
83 void SetLargeCursorEnabled(bool enalbed
) override
{}
85 bool IsLargeCursorEnabled() const override
{ return false; }
87 void SetMagnifierEnabled(bool enabled
) override
{}
89 void SetMagnifierType(ui::MagnifierType type
) override
{}
91 bool IsMagnifierEnabled() const override
{ return false; }
93 void SetAutoclickEnabled(bool enabled
) override
{}
95 bool IsAutoclickEnabled() const override
{ return false; }
97 ui::MagnifierType
GetMagnifierType() const override
{
98 return ui::kDefaultMagnifierType
;
101 void SaveScreenMagnifierScale(double scale
) override
{}
103 double GetSavedScreenMagnifierScale() override
{
104 return std::numeric_limits
<double>::min();
107 bool ShouldShowAccessibilityMenu() const override
{ return false; }
109 bool IsBrailleDisplayConnected() const override
{ return false; }
111 void SilenceSpokenFeedback() const override
{}
113 void SetVirtualKeyboardEnabled(bool enabled
) override
{}
115 bool IsVirtualKeyboardEnabled() const override
{ return false; }
117 void TriggerAccessibilityAlert(ui::AccessibilityAlert alert
) override
{}
119 ui::AccessibilityAlert
GetLastAccessibilityAlert() override
{
120 return ui::A11Y_ALERT_NONE
;
123 void PlayEarcon(int sound_key
) override
{}
125 base::TimeDelta
PlayShutdownSound() const override
{
126 return base::TimeDelta();
130 DISALLOW_COPY_AND_ASSIGN(EmptyAccessibilityDelegate
);
135 bool ChromeShellDelegate::IsFirstRunAfterBoot() const {
139 void ChromeShellDelegate::PreInit() {
142 void ChromeShellDelegate::PreShutdown() {
145 ash::NewWindowDelegate
* ChromeShellDelegate::CreateNewWindowDelegate() {
146 return new NewWindowDelegateImpl
;
149 ash::MediaDelegate
* ChromeShellDelegate::CreateMediaDelegate() {
150 return new MediaDelegateImpl
;
153 ash::SessionStateDelegate
* ChromeShellDelegate::CreateSessionStateDelegate() {
154 return new SessionStateDelegate
;
157 ash::SystemTrayDelegate
* ChromeShellDelegate::CreateSystemTrayDelegate() {
158 return new SystemTrayDelegateCommon();
161 ash::AccessibilityDelegate
* ChromeShellDelegate::CreateAccessibilityDelegate() {
162 return new EmptyAccessibilityDelegate
;
165 ash::UserWallpaperDelegate
* ChromeShellDelegate::CreateUserWallpaperDelegate() {
166 return CreateSolidColorUserWallpaperDelegate();
169 void ChromeShellDelegate::Observe(int type
,
170 const content::NotificationSource
& source
,
171 const content::NotificationDetails
& details
) {
173 case chrome::NOTIFICATION_PROFILE_ADDED
: {
174 // Start the error notifier services to show sync/auth notifications.
175 Profile
* profile
= content::Source
<Profile
>(source
).ptr();
176 SigninErrorNotifierFactory::GetForProfile(profile
);
177 SyncErrorNotifierFactory::GetForProfile(profile
);
180 case chrome::NOTIFICATION_ASH_SESSION_STARTED
: {
181 // Start the error notifier services for the already loaded profiles.
182 const std::vector
<Profile
*> profiles
=
183 g_browser_process
->profile_manager()->GetLoadedProfiles();
184 for (std::vector
<Profile
*>::const_iterator it
= profiles
.begin();
185 it
!= profiles
.end(); ++it
) {
186 SigninErrorNotifierFactory::GetForProfile(*it
);
187 SyncErrorNotifierFactory::GetForProfile(*it
);
191 // If we are launched to service a windows 8 search request then let the
192 // IPC which carries the search string create the browser and initiate
194 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
195 switches::kWindows8Search
))
198 // If Chrome ASH is launched when no browser is open in the desktop,
199 // we should execute the startup code.
200 // If there are browsers open in the desktop, we create a browser window
201 // and open a new tab page, if session restore is not on.
202 BrowserList
* desktop_list
= BrowserList::GetInstance(
203 chrome::HOST_DESKTOP_TYPE_NATIVE
);
204 if (desktop_list
->empty()) {
205 // We pass a dummy command line here, because the browser is launched in
206 // silent-mode by the metro viewer process, which causes the
207 // StartupBrowserCreatorImpl class to not create any browsers which is
208 // not the behavior we want.
209 base::CommandLine
dummy(base::CommandLine::NO_PROGRAM
);
210 StartupBrowserCreatorImpl
startup_impl(
213 chrome::startup::IS_NOT_FIRST_RUN
);
215 ProfileManager::GetActiveUserProfile(),
218 chrome::HOST_DESKTOP_TYPE_ASH
);
221 chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow());
222 if (browser
&& browser
->is_type_tabbed()) {
223 chrome::AddTabAt(browser
, GURL(), -1, true);
227 chrome::ScopedTabbedBrowserDisplayer
displayer(
228 ProfileManager::GetActiveUserProfile(),
229 chrome::HOST_DESKTOP_TYPE_ASH
);
230 chrome::AddTabAt(displayer
.browser(), GURL(), -1, true);
234 case chrome::NOTIFICATION_ASH_SESSION_ENDED
:
237 NOTREACHED() << "Unexpected notification " << type
;
241 void ChromeShellDelegate::PlatformInit() {
244 chrome::NOTIFICATION_PROFILE_ADDED
,
245 content::NotificationService::AllSources());
247 chrome::NOTIFICATION_ASH_SESSION_STARTED
,
248 content::NotificationService::AllSources());
250 chrome::NOTIFICATION_ASH_SESSION_ENDED
,
251 content::NotificationService::AllSources());