| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/ui/ash/chrome_shell_delegate.h" | |
| 6 | |
| 7 #include <vector> | |
| 8 | |
| 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 "base/macros.h" | |
| 14 #include "build/build_config.h" | |
| 15 #include "chrome/browser/browser_process.h" | |
| 16 #include "chrome/browser/chrome_notification_types.h" | |
| 17 #include "chrome/browser/prefs/session_startup_pref.h" | |
| 18 #include "chrome/browser/profiles/profile.h" | |
| 19 #include "chrome/browser/profiles/profile_manager.h" | |
| 20 #include "chrome/browser/signin/signin_error_notifier_factory_ash.h" | |
| 21 #include "chrome/browser/sync/sync_error_notifier_factory_ash.h" | |
| 22 #include "chrome/browser/ui/ash/chrome_new_window_delegate.h" | |
| 23 #include "chrome/browser/ui/ash/session_state_delegate_views.h" | |
| 24 #include "chrome/browser/ui/ash/solid_color_user_wallpaper_delegate.h" | |
| 25 #include "chrome/browser/ui/ash/system_tray_delegate_common.h" | |
| 26 #include "chrome/browser/ui/browser.h" | |
| 27 #include "chrome/browser/ui/browser_finder.h" | |
| 28 #include "chrome/browser/ui/browser_list.h" | |
| 29 #include "chrome/browser/ui/browser_tabstrip.h" | |
| 30 #include "chrome/browser/ui/browser_window.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" | |
| 35 #include "ui/chromeos/accessibility_types.h" | |
| 36 | |
| 37 namespace { | |
| 38 | |
| 39 class NewWindowDelegateImpl : public ChromeNewWindowDelegate { | |
| 40 public: | |
| 41 NewWindowDelegateImpl() {} | |
| 42 ~NewWindowDelegateImpl() override {} | |
| 43 | |
| 44 // Overridden from ash::NewWindowDelegate: | |
| 45 void OpenFileManager() override {} | |
| 46 void OpenCrosh() override {} | |
| 47 void OpenGetHelp() override {} | |
| 48 void ShowKeyboardOverlay() override {} | |
| 49 | |
| 50 private: | |
| 51 DISALLOW_COPY_AND_ASSIGN(NewWindowDelegateImpl); | |
| 52 }; | |
| 53 | |
| 54 class MediaDelegateImpl : public ash::MediaDelegate { | |
| 55 public: | |
| 56 MediaDelegateImpl() {} | |
| 57 ~MediaDelegateImpl() override {} | |
| 58 void HandleMediaNextTrack() override {} | |
| 59 void HandleMediaPlayPause() override {} | |
| 60 void HandleMediaPrevTrack() override {} | |
| 61 ash::MediaCaptureState GetMediaCaptureState(ash::UserIndex index) override { | |
| 62 return ash::MEDIA_CAPTURE_NONE; | |
| 63 } | |
| 64 | |
| 65 private: | |
| 66 DISALLOW_COPY_AND_ASSIGN(MediaDelegateImpl); | |
| 67 }; | |
| 68 | |
| 69 class EmptyAccessibilityDelegate : public ash::AccessibilityDelegate { | |
| 70 public: | |
| 71 EmptyAccessibilityDelegate() {} | |
| 72 ~EmptyAccessibilityDelegate() override {} | |
| 73 | |
| 74 void ToggleHighContrast() override {} | |
| 75 | |
| 76 bool IsHighContrastEnabled() const override { return false; } | |
| 77 | |
| 78 bool IsSpokenFeedbackEnabled() const override { return false; } | |
| 79 | |
| 80 void ToggleSpokenFeedback( | |
| 81 ui::AccessibilityNotificationVisibility notify) override {} | |
| 82 | |
| 83 void SetLargeCursorEnabled(bool enalbed) override {} | |
| 84 | |
| 85 bool IsLargeCursorEnabled() const override { return false; } | |
| 86 | |
| 87 void SetMagnifierEnabled(bool enabled) override {} | |
| 88 | |
| 89 void SetMagnifierType(ui::MagnifierType type) override {} | |
| 90 | |
| 91 bool IsMagnifierEnabled() const override { return false; } | |
| 92 | |
| 93 void SetAutoclickEnabled(bool enabled) override {} | |
| 94 | |
| 95 bool IsAutoclickEnabled() const override { return false; } | |
| 96 | |
| 97 void SetCaretHighlightEnabled(bool enabled) override {} | |
| 98 | |
| 99 bool IsCaretHighlightEnabled() const override { return false; } | |
| 100 | |
| 101 void SetCursorHighlightEnabled(bool enabled) override {} | |
| 102 | |
| 103 bool IsCursorHighlightEnabled() const override { return false; } | |
| 104 | |
| 105 void SetFocusHighlightEnabled(bool enabled) override {} | |
| 106 | |
| 107 bool IsFocusHighlightEnabled() const override { return false; } | |
| 108 | |
| 109 void SetSelectToSpeakEnabled(bool enabled) override {} | |
| 110 | |
| 111 bool IsSelectToSpeakEnabled() const override { return false; } | |
| 112 | |
| 113 void SetSwitchAccessEnabled(bool enabled) override {} | |
| 114 | |
| 115 bool IsSwitchAccessEnabled() const override { return false; } | |
| 116 | |
| 117 ui::MagnifierType GetMagnifierType() const override { | |
| 118 return ui::kDefaultMagnifierType; | |
| 119 } | |
| 120 | |
| 121 void SaveScreenMagnifierScale(double scale) override {} | |
| 122 | |
| 123 double GetSavedScreenMagnifierScale() override { | |
| 124 return std::numeric_limits<double>::min(); | |
| 125 } | |
| 126 | |
| 127 bool ShouldShowAccessibilityMenu() const override { return false; } | |
| 128 | |
| 129 bool IsBrailleDisplayConnected() const override { return false; } | |
| 130 | |
| 131 void SilenceSpokenFeedback() const override {} | |
| 132 | |
| 133 void SetVirtualKeyboardEnabled(bool enabled) override {} | |
| 134 | |
| 135 bool IsVirtualKeyboardEnabled() const override { return false; } | |
| 136 | |
| 137 void TriggerAccessibilityAlert(ui::AccessibilityAlert alert) override {} | |
| 138 | |
| 139 ui::AccessibilityAlert GetLastAccessibilityAlert() override { | |
| 140 return ui::A11Y_ALERT_NONE; | |
| 141 } | |
| 142 | |
| 143 void PlayEarcon(int sound_key) override {} | |
| 144 | |
| 145 base::TimeDelta PlayShutdownSound() const override { | |
| 146 return base::TimeDelta(); | |
| 147 } | |
| 148 | |
| 149 private: | |
| 150 DISALLOW_COPY_AND_ASSIGN(EmptyAccessibilityDelegate); | |
| 151 }; | |
| 152 | |
| 153 } // namespace | |
| 154 | |
| 155 bool ChromeShellDelegate::IsFirstRunAfterBoot() const { | |
| 156 return false; | |
| 157 } | |
| 158 | |
| 159 void ChromeShellDelegate::PreInit() { | |
| 160 } | |
| 161 | |
| 162 void ChromeShellDelegate::PreShutdown() { | |
| 163 } | |
| 164 | |
| 165 ash::NewWindowDelegate* ChromeShellDelegate::CreateNewWindowDelegate() { | |
| 166 return new NewWindowDelegateImpl; | |
| 167 } | |
| 168 | |
| 169 ash::MediaDelegate* ChromeShellDelegate::CreateMediaDelegate() { | |
| 170 return new MediaDelegateImpl; | |
| 171 } | |
| 172 | |
| 173 ash::SessionStateDelegate* ChromeShellDelegate::CreateSessionStateDelegate() { | |
| 174 return new SessionStateDelegate; | |
| 175 } | |
| 176 | |
| 177 ash::SystemTrayDelegate* ChromeShellDelegate::CreateSystemTrayDelegate() { | |
| 178 return new SystemTrayDelegateCommon(); | |
| 179 } | |
| 180 | |
| 181 ash::AccessibilityDelegate* ChromeShellDelegate::CreateAccessibilityDelegate() { | |
| 182 return new EmptyAccessibilityDelegate; | |
| 183 } | |
| 184 | |
| 185 ash::UserWallpaperDelegate* ChromeShellDelegate::CreateUserWallpaperDelegate() { | |
| 186 return CreateSolidColorUserWallpaperDelegate(); | |
| 187 } | |
| 188 | |
| 189 void ChromeShellDelegate::Observe(int type, | |
| 190 const content::NotificationSource& source, | |
| 191 const content::NotificationDetails& details) { | |
| 192 switch (type) { | |
| 193 case chrome::NOTIFICATION_PROFILE_ADDED: { | |
| 194 // Start the error notifier services to show sync/auth notifications. | |
| 195 Profile* profile = content::Source<Profile>(source).ptr(); | |
| 196 SigninErrorNotifierFactory::GetForProfile(profile); | |
| 197 SyncErrorNotifierFactory::GetForProfile(profile); | |
| 198 break; | |
| 199 } | |
| 200 case chrome::NOTIFICATION_ASH_SESSION_STARTED: { | |
| 201 // Start the error notifier services for the already loaded profiles. | |
| 202 const std::vector<Profile*> profiles = | |
| 203 g_browser_process->profile_manager()->GetLoadedProfiles(); | |
| 204 for (std::vector<Profile*>::const_iterator it = profiles.begin(); | |
| 205 it != profiles.end(); ++it) { | |
| 206 SigninErrorNotifierFactory::GetForProfile(*it); | |
| 207 SyncErrorNotifierFactory::GetForProfile(*it); | |
| 208 } | |
| 209 | |
| 210 #if defined(OS_WIN) | |
| 211 // If we are launched to service a windows 8 search request then let the | |
| 212 // IPC which carries the search string create the browser and initiate | |
| 213 // the navigation. | |
| 214 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 215 switches::kWindows8Search)) | |
| 216 break; | |
| 217 #endif | |
| 218 // If Chrome ASH is launched when no browser is open in the desktop, | |
| 219 // we should execute the startup code. | |
| 220 // If there are browsers open in the desktop, we create a browser window | |
| 221 // and open a new tab page, if session restore is not on. | |
| 222 BrowserList* desktop_list = BrowserList::GetInstance(); | |
| 223 if (desktop_list->empty()) { | |
| 224 // We pass a dummy command line here, because the browser is launched in | |
| 225 // silent-mode by the metro viewer process, which causes the | |
| 226 // StartupBrowserCreatorImpl class to not create any browsers which is | |
| 227 // not the behavior we want. | |
| 228 base::CommandLine dummy(base::CommandLine::NO_PROGRAM); | |
| 229 StartupBrowserCreatorImpl startup_impl( | |
| 230 base::FilePath(), | |
| 231 dummy, | |
| 232 chrome::startup::IS_NOT_FIRST_RUN); | |
| 233 startup_impl.Launch(ProfileManager::GetActiveUserProfile(), | |
| 234 std::vector<GURL>(), true); | |
| 235 } else { | |
| 236 Browser* browser = | |
| 237 chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()); | |
| 238 if (browser && browser->is_type_tabbed()) { | |
| 239 chrome::AddTabAt(browser, GURL(), -1, true); | |
| 240 return; | |
| 241 } | |
| 242 | |
| 243 chrome::ScopedTabbedBrowserDisplayer displayer( | |
| 244 ProfileManager::GetActiveUserProfile()); | |
| 245 chrome::AddTabAt(displayer.browser(), GURL(), -1, true); | |
| 246 } | |
| 247 break; | |
| 248 } | |
| 249 case chrome::NOTIFICATION_ASH_SESSION_ENDED: | |
| 250 break; | |
| 251 default: | |
| 252 NOTREACHED() << "Unexpected notification " << type; | |
| 253 } | |
| 254 } | |
| 255 | |
| 256 void ChromeShellDelegate::PlatformInit() { | |
| 257 #if defined(OS_WIN) | |
| 258 registrar_.Add(this, | |
| 259 chrome::NOTIFICATION_PROFILE_ADDED, | |
| 260 content::NotificationService::AllSources()); | |
| 261 registrar_.Add(this, | |
| 262 chrome::NOTIFICATION_ASH_SESSION_STARTED, | |
| 263 content::NotificationService::AllSources()); | |
| 264 registrar_.Add(this, | |
| 265 chrome::NOTIFICATION_ASH_SESSION_ENDED, | |
| 266 content::NotificationService::AllSources()); | |
| 267 #endif | |
| 268 } | |
| OLD | NEW |