1 // Copyright 2014 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/system_tray_delegate_linux.h" 6 7 #include <string> 8 9 #include "ash/shell.h" 10 #include "ash/shell_delegate.h" 11 #include "ash/system/tray/system_tray.h" 12 #include "ash/system/tray/system_tray_delegate.h" 13 #include "ash/system/tray/system_tray_notifier.h" 14 #include "ash/volume_control_delegate.h" 15 #include "base/time/time.h" 16 #include "chrome/browser/chrome_notification_types.h" 17 #include "chrome/browser/lifetime/application_lifetime.h" 18 #include "chrome/browser/profiles/profile_manager.h" 19 #include "chrome/browser/ui/chrome_pages.h" 20 #include "chrome/browser/ui/host_desktop.h" 21 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" 22 #include "chrome/browser/upgrade_detector.h" 23 #include "chrome/grit/locale_settings.h" 24 #include "content/public/browser/notification_observer.h" 25 #include "content/public/browser/notification_service.h" 26 #include "ui/base/l10n/l10n_util.h" 27 28 namespace { 29 30 class SystemTrayDelegateLinux : public ash::SystemTrayDelegate, 31 public content::NotificationObserver { 32 public: 33 SystemTrayDelegateLinux() 34 : clock_type_(base::GetHourClockType()) { 35 // Register notifications on construction so that events such as 36 // PROFILE_CREATED do not get missed if they happen before Initialize(). 37 registrar_.reset(new content::NotificationRegistrar); 38 registrar_->Add(this, 39 chrome::NOTIFICATION_UPGRADE_RECOMMENDED, 40 content::NotificationService::AllSources()); 41 } 42 43 virtual ~SystemTrayDelegateLinux() { 44 registrar_.reset(); 45 } 46 47 // Overridden from ash::SystemTrayDelegate: 48 virtual void Initialize() OVERRIDE { 49 UpdateClockType(); 50 } 51 52 virtual void Shutdown() OVERRIDE { 53 } 54 55 virtual bool GetTrayVisibilityOnStartup() OVERRIDE { 56 return true; 57 } 58 59 virtual ash::user::LoginStatus GetUserLoginStatus() const OVERRIDE { 60 return ash::user::LOGGED_IN_OWNER; 61 } 62 63 virtual void ChangeProfilePicture() OVERRIDE { 64 } 65 66 virtual const std::string GetEnterpriseDomain() const OVERRIDE { 67 return std::string(); 68 } 69 70 virtual const base::string16 GetEnterpriseMessage() const OVERRIDE { 71 return base::string16(); 72 } 73 74 virtual const std::string GetSupervisedUserManager() const OVERRIDE { 75 return std::string(); 76 } 77 78 virtual const base::string16 GetSupervisedUserManagerName() const OVERRIDE { 79 return base::string16(); 80 } 81 82 virtual const base::string16 GetSupervisedUserMessage() const OVERRIDE { 83 return base::string16(); 84 } 85 86 virtual bool IsUserSupervised() const OVERRIDE { 87 return false; 88 } 89 90 virtual bool SystemShouldUpgrade() const OVERRIDE { 91 return UpgradeDetector::GetInstance()->notify_upgrade(); 92 } 93 94 virtual base::HourClockType GetHourClockType() const OVERRIDE { 95 return clock_type_; 96 } 97 98 virtual void ShowSettings() OVERRIDE { 99 } 100 101 virtual bool ShouldShowSettings() OVERRIDE { 102 return true; 103 } 104 105 virtual void ShowDateSettings() OVERRIDE { 106 } 107 108 virtual void ShowSetTimeDialog() OVERRIDE { 109 } 110 111 virtual void ShowNetworkSettings(const std::string& service_path) OVERRIDE { 112 } 113 114 virtual void ShowBluetoothSettings() OVERRIDE { 115 } 116 117 virtual void ShowDisplaySettings() OVERRIDE { 118 } 119 120 virtual void ShowChromeSlow() OVERRIDE { 121 chrome::ScopedTabbedBrowserDisplayer displayer( 122 ProfileManager::GetPrimaryUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH); 123 chrome::ShowSlow(displayer.browser()); 124 } 125 126 virtual bool ShouldShowDisplayNotification() OVERRIDE { 127 return false; 128 } 129 130 virtual void ShowIMESettings() OVERRIDE { 131 } 132 133 virtual void ShowHelp() OVERRIDE { 134 chrome::ShowHelpForProfile( 135 ProfileManager::GetLastUsedProfile(), 136 chrome::HOST_DESKTOP_TYPE_ASH, 137 chrome::HELP_SOURCE_MENU); 138 } 139 140 virtual void ShowAccessibilityHelp() OVERRIDE { 141 } 142 143 virtual void ShowAccessibilitySettings() OVERRIDE { 144 } 145 146 virtual void ShowPublicAccountInfo() OVERRIDE { 147 } 148 149 virtual void ShowSupervisedUserInfo() OVERRIDE { 150 } 151 152 virtual void ShowEnterpriseInfo() OVERRIDE { 153 } 154 155 virtual void ShowUserLogin() OVERRIDE { 156 } 157 158 virtual bool ShowSpringChargerReplacementDialog() OVERRIDE { 159 return false; 160 } 161 162 virtual bool IsSpringChargerReplacementDialogVisible() OVERRIDE { 163 return false; 164 } 165 166 virtual bool HasUserConfirmedSafeSpringCharger() OVERRIDE { 167 return false; 168 } 169 170 virtual void ShutDown() OVERRIDE { 171 } 172 173 virtual void SignOut() OVERRIDE { 174 } 175 176 virtual void RequestLockScreen() OVERRIDE { 177 } 178 179 virtual void RequestRestartForUpdate() OVERRIDE { 180 chrome::AttemptRestart(); 181 } 182 183 virtual void GetAvailableBluetoothDevices( 184 ash::BluetoothDeviceList* list) OVERRIDE { 185 } 186 187 virtual void BluetoothStartDiscovering() OVERRIDE { 188 } 189 190 virtual void BluetoothStopDiscovering() OVERRIDE { 191 } 192 193 virtual void ConnectToBluetoothDevice(const std::string& address) OVERRIDE { 194 } 195 196 virtual bool IsBluetoothDiscovering() OVERRIDE { 197 return false; 198 } 199 200 virtual void GetCurrentIME(ash::IMEInfo* info) OVERRIDE { 201 } 202 203 virtual void GetAvailableIMEList(ash::IMEInfoList* list) OVERRIDE { 204 } 205 206 virtual void GetCurrentIMEProperties( 207 ash::IMEPropertyInfoList* list) OVERRIDE { 208 } 209 210 virtual void SwitchIME(const std::string& ime_id) OVERRIDE { 211 } 212 213 virtual void ActivateIMEProperty(const std::string& key) OVERRIDE { 214 } 215 216 virtual void ShowNetworkConfigure(const std::string& network_id) OVERRIDE { 217 } 218 219 virtual bool EnrollNetwork(const std::string& network_id) OVERRIDE { 220 return true; 221 } 222 223 virtual void ManageBluetoothDevices() OVERRIDE { 224 } 225 226 virtual void ToggleBluetooth() OVERRIDE { 227 } 228 229 virtual void ShowMobileSimDialog() OVERRIDE { 230 } 231 232 virtual void ShowMobileSetupDialog(const std::string& service_path) OVERRIDE { 233 } 234 235 virtual void ShowOtherNetworkDialog(const std::string& type) OVERRIDE { 236 } 237 238 virtual bool GetBluetoothAvailable() OVERRIDE { 239 return false; 240 } 241 242 virtual bool GetBluetoothEnabled() OVERRIDE { 243 return false; 244 } 245 246 virtual bool GetBluetoothDiscovering() OVERRIDE { 247 return false; 248 } 249 250 virtual void ChangeProxySettings() OVERRIDE { 251 } 252 253 virtual ash::VolumeControlDelegate* 254 GetVolumeControlDelegate() const OVERRIDE { 255 return NULL; 256 } 257 258 virtual void SetVolumeControlDelegate( 259 scoped_ptr<ash::VolumeControlDelegate> delegate) OVERRIDE { 260 } 261 262 virtual bool GetSessionStartTime( 263 base::TimeTicks* session_start_time) OVERRIDE { 264 return false; 265 } 266 267 virtual bool GetSessionLengthLimit( 268 base::TimeDelta* session_length_limit) OVERRIDE { 269 return false; 270 } 271 272 virtual int GetSystemTrayMenuWidth() OVERRIDE { 273 return l10n_util::GetLocalizedContentsWidthInPixels( 274 IDS_SYSTEM_TRAY_MENU_BUBBLE_WIDTH_PIXELS); 275 } 276 277 virtual void ActiveUserWasChanged() OVERRIDE { 278 } 279 280 virtual bool IsSearchKeyMappedToCapsLock() OVERRIDE { 281 return false; 282 } 283 284 virtual ash::tray::UserAccountsDelegate* GetUserAccountsDelegate( 285 const std::string& user_id) OVERRIDE { 286 return NULL; 287 } 288 289 private: 290 ash::SystemTrayNotifier* GetSystemTrayNotifier() { 291 return ash::Shell::GetInstance()->system_tray_notifier(); 292 } 293 294 void UpdateClockType() { 295 clock_type_ = (base::GetHourClockType() == base::k24HourClock) ? 296 base::k24HourClock : base::k12HourClock; 297 GetSystemTrayNotifier()->NotifyDateFormatChanged(); 298 } 299 300 // content::NotificationObserver implementation. 301 virtual void Observe(int type, 302 const content::NotificationSource& source, 303 const content::NotificationDetails& details) OVERRIDE { 304 if (type == chrome::NOTIFICATION_UPGRADE_RECOMMENDED) { 305 UpgradeDetector* detector = 306 content::Source<UpgradeDetector>(source).ptr(); 307 ash::UpdateObserver::UpdateSeverity severity = 308 ash::UpdateObserver::UPDATE_NORMAL; 309 switch (detector->upgrade_notification_stage()) { 310 case UpgradeDetector::UPGRADE_ANNOYANCE_CRITICAL: 311 case UpgradeDetector::UPGRADE_ANNOYANCE_SEVERE: 312 severity = ash::UpdateObserver::UPDATE_SEVERE_RED; 313 break; 314 case UpgradeDetector::UPGRADE_ANNOYANCE_HIGH: 315 severity = ash::UpdateObserver::UPDATE_HIGH_ORANGE; 316 break; 317 case UpgradeDetector::UPGRADE_ANNOYANCE_ELEVATED: 318 severity = ash::UpdateObserver::UPDATE_LOW_GREEN; 319 break; 320 case UpgradeDetector::UPGRADE_ANNOYANCE_LOW: 321 case UpgradeDetector::UPGRADE_ANNOYANCE_NONE: 322 severity = ash::UpdateObserver::UPDATE_NORMAL; 323 break; 324 } 325 GetSystemTrayNotifier()->NotifyUpdateRecommended(severity); 326 } else { 327 NOTREACHED(); 328 } 329 } 330 331 scoped_ptr<content::NotificationRegistrar> registrar_; 332 base::HourClockType clock_type_; 333 334 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegateLinux); 335 }; 336 337 } // namespace 338 339 340 ash::SystemTrayDelegate* CreateLinuxSystemTrayDelegate() { 341 return new SystemTrayDelegateLinux(); 342 } 343