Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / ui / ash / chrome_shell_delegate_views.cc
blob3522aa50d4b7e70bcd549103f2ff70e03c5e75f7
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 <vector>
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"
36 #if defined(OS_WIN)
37 #include "chrome/browser/ui/ash/system_tray_delegate_win.h"
38 #include "chrome/browser/ui/ash/user_wallpaper_delegate_win.h"
39 #endif
41 namespace {
43 class NewWindowDelegateImpl : public ChromeNewWindowDelegate {
44 public:
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 {}
53 private:
54 DISALLOW_COPY_AND_ASSIGN(NewWindowDelegateImpl);
57 class MediaDelegateImpl : public ash::MediaDelegate {
58 public:
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;
69 private:
70 DISALLOW_COPY_AND_ASSIGN(MediaDelegateImpl);
73 class EmptyAccessibilityDelegate : public ash::AccessibilityDelegate {
74 public:
75 EmptyAccessibilityDelegate() {}
76 virtual ~EmptyAccessibilityDelegate() {}
78 virtual void ToggleHighContrast() OVERRIDE {
81 virtual bool IsHighContrastEnabled() const OVERRIDE {
82 return false;
85 virtual bool IsSpokenFeedbackEnabled() const OVERRIDE {
86 return false;
89 virtual void ToggleSpokenFeedback(
90 ash::AccessibilityNotificationVisibility notify) OVERRIDE {
93 virtual void SetLargeCursorEnabled(bool enalbed) OVERRIDE {
96 virtual bool IsLargeCursorEnabled() const OVERRIDE {
97 return false;
100 virtual void SetMagnifierEnabled(bool enabled) OVERRIDE {
103 virtual void SetMagnifierType(ash::MagnifierType type) OVERRIDE {
106 virtual bool IsMagnifierEnabled() const OVERRIDE {
107 return false;
110 virtual void SetAutoclickEnabled(bool enabled) OVERRIDE {
113 virtual bool IsAutoclickEnabled() const OVERRIDE {
114 return false;
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 {
129 return false;
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 {
141 return false;
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();
156 private:
157 DISALLOW_COPY_AND_ASSIGN(EmptyAccessibilityDelegate);
160 } // namespace
162 bool ChromeShellDelegate::IsFirstRunAfterBoot() const {
163 return false;
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() {
185 #if defined(OS_WIN)
186 return CreateWindowsSystemTrayDelegate();
187 #else
188 return new ash::DefaultSystemTrayDelegate;
189 #endif
192 ash::AccessibilityDelegate* ChromeShellDelegate::CreateAccessibilityDelegate() {
193 return new EmptyAccessibilityDelegate;
196 ash::UserWallpaperDelegate* ChromeShellDelegate::CreateUserWallpaperDelegate() {
197 #if defined(OS_WIN)
198 return ::CreateUserWallpaperDelegate();
199 #else
200 return NULL;
201 #endif
204 void ChromeShellDelegate::Observe(int type,
205 const content::NotificationSource& source,
206 const content::NotificationDetails& details) {
207 switch (type) {
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);
213 break;
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);
225 #if defined(OS_WIN)
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
228 // the navigation.
229 if (CommandLine::ForCurrentProcess()->HasSwitch(
230 switches::kWindows8Search))
231 break;
232 #endif
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(
246 base::FilePath(),
247 dummy,
248 chrome::startup::IS_NOT_FIRST_RUN);
249 startup_impl.Launch(
250 ProfileManager::GetActiveUserProfile(),
251 std::vector<GURL>(),
252 true,
253 chrome::HOST_DESKTOP_TYPE_ASH);
254 } else {
255 Browser* browser =
256 chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow());
257 if (browser && browser->is_type_tabbed()) {
258 chrome::AddTabAt(browser, GURL(), -1, true);
259 return;
262 chrome::ScopedTabbedBrowserDisplayer displayer(
263 ProfileManager::GetActiveUserProfile(),
264 chrome::HOST_DESKTOP_TYPE_ASH);
265 chrome::AddTabAt(displayer.browser(), GURL(), -1, true);
267 break;
269 case chrome::NOTIFICATION_ASH_SESSION_ENDED:
270 break;
271 default:
272 NOTREACHED() << "Unexpected notification " << type;
276 void ChromeShellDelegate::PlatformInit() {
277 #if defined(OS_WIN)
278 registrar_.Add(this,
279 chrome::NOTIFICATION_PROFILE_ADDED,
280 content::NotificationService::AllSources());
281 registrar_.Add(this,
282 chrome::NOTIFICATION_ASH_SESSION_STARTED,
283 content::NotificationService::AllSources());
284 registrar_.Add(this,
285 chrome::NOTIFICATION_ASH_SESSION_ENDED,
286 content::NotificationService::AllSources());
287 #endif