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