1 // Copyright (c) 2012 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/system_tray_delegate_win.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/logging.h"
16 #include "base/time/time.h"
17 #include "chrome/browser/chrome_notification_types.h"
18 #include "chrome/browser/lifetime/application_lifetime.h"
19 #include "chrome/browser/profiles/profile_manager.h"
20 #include "chrome/browser/ui/chrome_pages.h"
21 #include "chrome/browser/ui/host_desktop.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"
30 class SystemTrayDelegateWin
: public ash::SystemTrayDelegate
,
31 public content::NotificationObserver
{
33 SystemTrayDelegateWin()
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
);
39 chrome::NOTIFICATION_UPGRADE_RECOMMENDED
,
40 content::NotificationService::AllSources());
43 virtual ~SystemTrayDelegateWin() {
47 // Overridden from ash::SystemTrayDelegate:
48 virtual void Initialize() OVERRIDE
{
52 virtual void Shutdown() OVERRIDE
{
55 virtual bool GetTrayVisibilityOnStartup() OVERRIDE
{
59 virtual ash::user::LoginStatus
GetUserLoginStatus() const OVERRIDE
{
60 return ash::user::LOGGED_IN_OWNER
;
63 virtual void ChangeProfilePicture() OVERRIDE
{
66 virtual const std::string
GetEnterpriseDomain() const OVERRIDE
{
70 virtual const base::string16
GetEnterpriseMessage() const OVERRIDE
{
71 return base::string16();
74 virtual const std::string
GetSupervisedUserManager() const OVERRIDE
{
78 virtual const base::string16
GetSupervisedUserManagerName() const OVERRIDE
{
79 return base::string16();
82 virtual const base::string16
GetSupervisedUserMessage() const OVERRIDE
{
83 return base::string16();
86 virtual bool SystemShouldUpgrade() const OVERRIDE
{
87 return UpgradeDetector::GetInstance()->notify_upgrade();
90 virtual base::HourClockType
GetHourClockType() const OVERRIDE
{
94 virtual void ShowSettings() OVERRIDE
{
97 virtual bool ShouldShowSettings() OVERRIDE
{
101 virtual void ShowDateSettings() OVERRIDE
{
104 virtual void ShowSetTimeDialog() OVERRIDE
{
107 virtual void ShowNetworkSettings(const std::string
& service_path
) OVERRIDE
{
110 virtual void ShowBluetoothSettings() OVERRIDE
{
113 virtual void ShowDisplaySettings() OVERRIDE
{
116 virtual void ShowChromeSlow() OVERRIDE
{
119 virtual bool ShouldShowDisplayNotification() OVERRIDE
{
123 virtual void ShowIMESettings() OVERRIDE
{
126 virtual void ShowHelp() OVERRIDE
{
127 chrome::ShowHelpForProfile(
128 ProfileManager::GetLastUsedProfile(),
129 chrome::HOST_DESKTOP_TYPE_ASH
,
130 chrome::HELP_SOURCE_MENU
);
133 virtual void ShowAccessibilityHelp() OVERRIDE
{
136 virtual void ShowAccessibilitySettings() OVERRIDE
{
139 virtual void ShowPublicAccountInfo() OVERRIDE
{
142 virtual void ShowSupervisedUserInfo() OVERRIDE
{
145 virtual void ShowEnterpriseInfo() OVERRIDE
{
148 virtual void ShowUserLogin() OVERRIDE
{
151 virtual bool ShowSpringChargerReplacementDialog() OVERRIDE
{
155 virtual bool IsSpringChargerReplacementDialogVisible() OVERRIDE
{
159 virtual bool HasUserConfirmedSafeSpringCharger() OVERRIDE
{
163 virtual void ShutDown() OVERRIDE
{
166 virtual void SignOut() OVERRIDE
{
169 virtual void RequestLockScreen() OVERRIDE
{
172 virtual void RequestRestartForUpdate() OVERRIDE
{
173 chrome::AttemptRestart();
176 virtual void GetAvailableBluetoothDevices(
177 ash::BluetoothDeviceList
* list
) OVERRIDE
{
180 virtual void BluetoothStartDiscovering() OVERRIDE
{
183 virtual void BluetoothStopDiscovering() OVERRIDE
{
186 virtual void ConnectToBluetoothDevice(const std::string
& address
) OVERRIDE
{
189 virtual bool IsBluetoothDiscovering() OVERRIDE
{
193 virtual void GetCurrentIME(ash::IMEInfo
* info
) OVERRIDE
{
196 virtual void GetAvailableIMEList(ash::IMEInfoList
* list
) OVERRIDE
{
199 virtual void GetCurrentIMEProperties(
200 ash::IMEPropertyInfoList
* list
) OVERRIDE
{
203 virtual void SwitchIME(const std::string
& ime_id
) OVERRIDE
{
206 virtual void ActivateIMEProperty(const std::string
& key
) OVERRIDE
{
209 virtual void ShowNetworkConfigure(const std::string
& network_id
,
210 gfx::NativeWindow parent_window
) OVERRIDE
{
213 virtual bool EnrollNetwork(const std::string
& network_id
,
214 gfx::NativeWindow parent_window
) OVERRIDE
{
218 virtual void ManageBluetoothDevices() OVERRIDE
{
221 virtual void ToggleBluetooth() OVERRIDE
{
224 virtual void ShowMobileSimDialog() OVERRIDE
{
227 virtual void ShowMobileSetupDialog(const std::string
& service_path
) OVERRIDE
{
230 virtual void ShowOtherNetworkDialog(const std::string
& type
) OVERRIDE
{
233 virtual bool GetBluetoothAvailable() OVERRIDE
{
237 virtual bool GetBluetoothEnabled() OVERRIDE
{
241 virtual bool GetBluetoothDiscovering() OVERRIDE
{
245 virtual void ChangeProxySettings() OVERRIDE
{
248 virtual ash::VolumeControlDelegate
*
249 GetVolumeControlDelegate() const OVERRIDE
{
253 virtual void SetVolumeControlDelegate(
254 scoped_ptr
<ash::VolumeControlDelegate
> delegate
) OVERRIDE
{
257 virtual bool GetSessionStartTime(
258 base::TimeTicks
* session_start_time
) OVERRIDE
{
262 virtual bool GetSessionLengthLimit(
263 base::TimeDelta
* session_length_limit
) OVERRIDE
{
267 virtual int GetSystemTrayMenuWidth() OVERRIDE
{
268 return l10n_util::GetLocalizedContentsWidthInPixels(
269 IDS_SYSTEM_TRAY_MENU_BUBBLE_WIDTH_PIXELS
);
272 virtual void ActiveUserWasChanged() OVERRIDE
{
275 virtual bool IsSearchKeyMappedToCapsLock() OVERRIDE
{
279 virtual ash::tray::UserAccountsDelegate
* GetUserAccountsDelegate(
280 const std::string
& user_id
) OVERRIDE
{
285 ash::SystemTrayNotifier
* GetSystemTrayNotifier() {
286 return ash::Shell::GetInstance()->system_tray_notifier();
289 void UpdateClockType() {
290 clock_type_
= (base::GetHourClockType() == base::k24HourClock
) ?
291 base::k24HourClock
: base::k12HourClock
;
292 GetSystemTrayNotifier()->NotifyDateFormatChanged();
295 // content::NotificationObserver implementation.
296 virtual void Observe(int type
,
297 const content::NotificationSource
& source
,
298 const content::NotificationDetails
& details
) OVERRIDE
{
299 if (type
== chrome::NOTIFICATION_UPGRADE_RECOMMENDED
) {
300 UpgradeDetector
* detector
=
301 content::Source
<UpgradeDetector
>(source
).ptr();
302 ash::UpdateObserver::UpdateSeverity severity
=
303 ash::UpdateObserver::UPDATE_NORMAL
;
304 switch (detector
->upgrade_notification_stage()) {
305 case UpgradeDetector::UPGRADE_ANNOYANCE_CRITICAL
:
306 case UpgradeDetector::UPGRADE_ANNOYANCE_SEVERE
:
307 severity
= ash::UpdateObserver::UPDATE_SEVERE_RED
;
309 case UpgradeDetector::UPGRADE_ANNOYANCE_HIGH
:
310 severity
= ash::UpdateObserver::UPDATE_HIGH_ORANGE
;
312 case UpgradeDetector::UPGRADE_ANNOYANCE_ELEVATED
:
313 severity
= ash::UpdateObserver::UPDATE_LOW_GREEN
;
315 case UpgradeDetector::UPGRADE_ANNOYANCE_LOW
:
316 case UpgradeDetector::UPGRADE_ANNOYANCE_NONE
:
317 severity
= ash::UpdateObserver::UPDATE_NORMAL
;
320 GetSystemTrayNotifier()->NotifyUpdateRecommended(severity
);
326 scoped_ptr
<content::NotificationRegistrar
> registrar_
;
327 base::HourClockType clock_type_
;
329 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegateWin
);
335 ash::SystemTrayDelegate
* CreateWindowsSystemTrayDelegate() {
336 return new SystemTrayDelegateWin();