Upstream version 8.37.180.0
[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 void ChangeProfilePicture() OVERRIDE {
65   }
66
67   virtual const std::string GetEnterpriseDomain() const OVERRIDE {
68     return std::string();
69   }
70
71   virtual const base::string16 GetEnterpriseMessage() const OVERRIDE {
72     return base::string16();
73   }
74
75   virtual const std::string GetLocallyManagedUserManager() const OVERRIDE {
76     return std::string();
77   }
78
79   virtual const base::string16 GetLocallyManagedUserManagerName() const
80         OVERRIDE {
81     return base::string16();
82   }
83
84   virtual const base::string16 GetLocallyManagedUserMessage() const OVERRIDE {
85     return base::string16();
86   }
87
88   virtual bool SystemShouldUpgrade() const OVERRIDE {
89     return UpgradeDetector::GetInstance()->notify_upgrade();
90   }
91
92   virtual base::HourClockType GetHourClockType() const OVERRIDE {
93     return clock_type_;
94   }
95
96   virtual void ShowSettings() OVERRIDE {
97   }
98
99   virtual bool ShouldShowSettings() OVERRIDE {
100     return true;
101   }
102
103   virtual void ShowDateSettings() OVERRIDE {
104   }
105
106   virtual void ShowSetTimeDialog() OVERRIDE {
107   }
108
109   virtual void ShowNetworkSettings(const std::string& service_path) OVERRIDE {
110   }
111
112   virtual void ShowBluetoothSettings() OVERRIDE {
113   }
114
115   virtual void ShowDisplaySettings() OVERRIDE {
116   }
117
118   virtual void ShowChromeSlow() OVERRIDE {
119   }
120
121   virtual bool ShouldShowDisplayNotification() OVERRIDE {
122     return false;
123   }
124
125   virtual void ShowDriveSettings() OVERRIDE {
126   }
127
128   virtual void ShowIMESettings() OVERRIDE {
129   }
130
131   virtual void ShowHelp() OVERRIDE {
132     chrome::ShowHelpForProfile(
133         ProfileManager::GetLastUsedProfile(),
134         chrome::HOST_DESKTOP_TYPE_ASH,
135         chrome::HELP_SOURCE_MENU);
136   }
137
138   virtual void ShowAccessibilityHelp() OVERRIDE {
139   }
140
141   virtual void ShowAccessibilitySettings() OVERRIDE {
142   }
143
144   virtual void ShowPublicAccountInfo() OVERRIDE {
145   }
146
147   virtual void ShowLocallyManagedUserInfo() OVERRIDE {
148   }
149
150   virtual void ShowEnterpriseInfo() OVERRIDE {
151   }
152
153   virtual void ShowUserLogin() OVERRIDE {
154   }
155
156   virtual bool ShowSpringChargerReplacementDialog() OVERRIDE {
157     return false;
158   }
159
160   virtual bool IsSpringChargerReplacementDialogVisible() OVERRIDE {
161     return false;
162   }
163
164   virtual bool HasUserConfirmedSafeSpringCharger() OVERRIDE {
165     return false;
166   }
167
168   virtual void ShutDown() OVERRIDE {
169   }
170
171   virtual void SignOut() OVERRIDE {
172   }
173
174   virtual void RequestLockScreen() OVERRIDE {
175   }
176
177   virtual void RequestRestartForUpdate() OVERRIDE {
178     chrome::AttemptRestart();
179   }
180
181   virtual void GetAvailableBluetoothDevices(
182       ash::BluetoothDeviceList* list) OVERRIDE {
183   }
184
185   virtual void BluetoothStartDiscovering() OVERRIDE {
186   }
187
188   virtual void BluetoothStopDiscovering() OVERRIDE {
189   }
190
191   virtual void ConnectToBluetoothDevice(const std::string& address) OVERRIDE {
192   }
193
194   virtual bool IsBluetoothDiscovering() OVERRIDE {
195     return false;
196   }
197
198   virtual void GetCurrentIME(ash::IMEInfo* info) OVERRIDE {
199   }
200
201   virtual void GetAvailableIMEList(ash::IMEInfoList* list) OVERRIDE {
202   }
203
204   virtual void GetCurrentIMEProperties(
205       ash::IMEPropertyInfoList* list) OVERRIDE {
206   }
207
208   virtual void SwitchIME(const std::string& ime_id) OVERRIDE {
209   }
210
211   virtual void ActivateIMEProperty(const std::string& key) OVERRIDE {
212   }
213
214   virtual void CancelDriveOperation(int32 operation_id) OVERRIDE {
215   }
216
217   virtual void GetDriveOperationStatusList(
218       ash::DriveOperationStatusList* list) OVERRIDE {
219   }
220
221   virtual void ShowNetworkConfigure(const std::string& network_id,
222                                     gfx::NativeWindow parent_window) OVERRIDE {
223   }
224
225   virtual bool EnrollNetwork(const std::string& network_id,
226                              gfx::NativeWindow parent_window) OVERRIDE {
227     return true;
228   }
229
230   virtual void ManageBluetoothDevices() OVERRIDE {
231   }
232
233   virtual void ToggleBluetooth() OVERRIDE {
234   }
235
236   virtual void ShowMobileSimDialog() OVERRIDE {
237   }
238
239   virtual void ShowMobileSetupDialog(const std::string& service_path) OVERRIDE {
240   }
241
242   virtual void ShowOtherNetworkDialog(const std::string& type) OVERRIDE {
243   }
244
245   virtual bool GetBluetoothAvailable() OVERRIDE {
246     return false;
247   }
248
249   virtual bool GetBluetoothEnabled() OVERRIDE {
250     return false;
251   }
252
253   virtual bool GetBluetoothDiscovering() OVERRIDE {
254     return false;
255   }
256
257   virtual void ChangeProxySettings() OVERRIDE {
258   }
259
260   virtual ash::VolumeControlDelegate*
261   GetVolumeControlDelegate() const OVERRIDE {
262     return NULL;
263   }
264
265   virtual void SetVolumeControlDelegate(
266       scoped_ptr<ash::VolumeControlDelegate> delegate) OVERRIDE {
267   }
268
269   virtual bool GetSessionStartTime(
270       base::TimeTicks* session_start_time) OVERRIDE {
271     return false;
272   }
273
274   virtual bool GetSessionLengthLimit(
275       base::TimeDelta* session_length_limit) OVERRIDE {
276     return false;
277   }
278
279   virtual int GetSystemTrayMenuWidth() OVERRIDE {
280     return l10n_util::GetLocalizedContentsWidthInPixels(
281         IDS_SYSTEM_TRAY_MENU_BUBBLE_WIDTH_PIXELS);
282   }
283
284   virtual void ActiveUserWasChanged() OVERRIDE {
285   }
286
287   virtual bool IsNetworkBehindCaptivePortal(
288       const std::string& service_path) const OVERRIDE {
289     return false;
290   }
291
292   virtual bool IsSearchKeyMappedToCapsLock() OVERRIDE {
293     return false;
294   }
295
296   virtual ash::tray::UserAccountsDelegate* GetUserAccountsDelegate(
297       const std::string& user_id) OVERRIDE {
298     return NULL;
299   }
300
301  private:
302   ash::SystemTrayNotifier* GetSystemTrayNotifier() {
303     return ash::Shell::GetInstance()->system_tray_notifier();
304   }
305
306   void UpdateClockType() {
307     clock_type_ = (base::GetHourClockType() == base::k24HourClock) ?
308         base::k24HourClock : base::k12HourClock;
309     GetSystemTrayNotifier()->NotifyDateFormatChanged();
310   }
311
312   // content::NotificationObserver implementation.
313   virtual void Observe(int type,
314                        const content::NotificationSource& source,
315                        const content::NotificationDetails& details) OVERRIDE {
316     if (type == chrome::NOTIFICATION_UPGRADE_RECOMMENDED) {
317         UpgradeDetector* detector =
318             content::Source<UpgradeDetector>(source).ptr();
319       ash::UpdateObserver::UpdateSeverity severity =
320           ash::UpdateObserver::UPDATE_NORMAL;
321       switch (detector->upgrade_notification_stage()) {
322         case UpgradeDetector::UPGRADE_ANNOYANCE_CRITICAL:
323         case UpgradeDetector::UPGRADE_ANNOYANCE_SEVERE:
324           severity = ash::UpdateObserver::UPDATE_SEVERE_RED;
325           break;
326         case UpgradeDetector::UPGRADE_ANNOYANCE_HIGH:
327           severity = ash::UpdateObserver::UPDATE_HIGH_ORANGE;
328           break;
329         case UpgradeDetector::UPGRADE_ANNOYANCE_ELEVATED:
330           severity = ash::UpdateObserver::UPDATE_LOW_GREEN;
331           break;
332         case UpgradeDetector::UPGRADE_ANNOYANCE_LOW:
333         case UpgradeDetector::UPGRADE_ANNOYANCE_NONE:
334           severity = ash::UpdateObserver::UPDATE_NORMAL;
335           break;
336       }
337       GetSystemTrayNotifier()->NotifyUpdateRecommended(severity);
338     } else {
339       NOTREACHED();
340     }
341   }
342
343   scoped_ptr<content::NotificationRegistrar> registrar_;
344   base::HourClockType clock_type_;
345
346   DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegateWin);
347 };
348
349 }  // namespace
350
351
352 ash::SystemTrayDelegate* CreateWindowsSystemTrayDelegate() {
353   return new SystemTrayDelegateWin();
354 }