Upstream version 9.38.198.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 GetSupervisedUserManager() const OVERRIDE {
76     return std::string();
77   }
78
79   virtual const base::string16 GetSupervisedUserManagerName() const OVERRIDE {
80     return base::string16();
81   }
82
83   virtual const base::string16 GetSupervisedUserMessage() const OVERRIDE {
84     return base::string16();
85   }
86
87   virtual bool SystemShouldUpgrade() const OVERRIDE {
88     return UpgradeDetector::GetInstance()->notify_upgrade();
89   }
90
91   virtual base::HourClockType GetHourClockType() const OVERRIDE {
92     return clock_type_;
93   }
94
95   virtual void ShowSettings() OVERRIDE {
96   }
97
98   virtual bool ShouldShowSettings() OVERRIDE {
99     return true;
100   }
101
102   virtual void ShowDateSettings() OVERRIDE {
103   }
104
105   virtual void ShowSetTimeDialog() OVERRIDE {
106   }
107
108   virtual void ShowNetworkSettings(const std::string& service_path) OVERRIDE {
109   }
110
111   virtual void ShowBluetoothSettings() OVERRIDE {
112   }
113
114   virtual void ShowDisplaySettings() OVERRIDE {
115   }
116
117   virtual void ShowChromeSlow() OVERRIDE {
118   }
119
120   virtual bool ShouldShowDisplayNotification() OVERRIDE {
121     return false;
122   }
123
124   virtual void ShowIMESettings() OVERRIDE {
125   }
126
127   virtual void ShowHelp() OVERRIDE {
128     chrome::ShowHelpForProfile(
129         ProfileManager::GetLastUsedProfile(),
130         chrome::HOST_DESKTOP_TYPE_ASH,
131         chrome::HELP_SOURCE_MENU);
132   }
133
134   virtual void ShowAccessibilityHelp() OVERRIDE {
135   }
136
137   virtual void ShowAccessibilitySettings() OVERRIDE {
138   }
139
140   virtual void ShowPublicAccountInfo() OVERRIDE {
141   }
142
143   virtual void ShowSupervisedUserInfo() OVERRIDE {
144   }
145
146   virtual void ShowEnterpriseInfo() OVERRIDE {
147   }
148
149   virtual void ShowUserLogin() OVERRIDE {
150   }
151
152   virtual bool ShowSpringChargerReplacementDialog() OVERRIDE {
153     return false;
154   }
155
156   virtual bool IsSpringChargerReplacementDialogVisible() OVERRIDE {
157     return false;
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 ShowNetworkConfigure(const std::string& network_id,
211                                     gfx::NativeWindow parent_window) OVERRIDE {
212   }
213
214   virtual bool EnrollNetwork(const std::string& network_id,
215                              gfx::NativeWindow parent_window) OVERRIDE {
216     return true;
217   }
218
219   virtual void ManageBluetoothDevices() OVERRIDE {
220   }
221
222   virtual void ToggleBluetooth() OVERRIDE {
223   }
224
225   virtual void ShowMobileSimDialog() OVERRIDE {
226   }
227
228   virtual void ShowMobileSetupDialog(const std::string& service_path) OVERRIDE {
229   }
230
231   virtual void ShowOtherNetworkDialog(const std::string& type) OVERRIDE {
232   }
233
234   virtual bool GetBluetoothAvailable() OVERRIDE {
235     return false;
236   }
237
238   virtual bool GetBluetoothEnabled() OVERRIDE {
239     return false;
240   }
241
242   virtual bool GetBluetoothDiscovering() OVERRIDE {
243     return false;
244   }
245
246   virtual void ChangeProxySettings() OVERRIDE {
247   }
248
249   virtual ash::VolumeControlDelegate*
250   GetVolumeControlDelegate() const OVERRIDE {
251     return NULL;
252   }
253
254   virtual void SetVolumeControlDelegate(
255       scoped_ptr<ash::VolumeControlDelegate> delegate) OVERRIDE {
256   }
257
258   virtual bool GetSessionStartTime(
259       base::TimeTicks* session_start_time) OVERRIDE {
260     return false;
261   }
262
263   virtual bool GetSessionLengthLimit(
264       base::TimeDelta* session_length_limit) OVERRIDE {
265     return false;
266   }
267
268   virtual int GetSystemTrayMenuWidth() OVERRIDE {
269     return l10n_util::GetLocalizedContentsWidthInPixels(
270         IDS_SYSTEM_TRAY_MENU_BUBBLE_WIDTH_PIXELS);
271   }
272
273   virtual void ActiveUserWasChanged() OVERRIDE {
274   }
275
276   virtual bool IsSearchKeyMappedToCapsLock() OVERRIDE {
277     return false;
278   }
279
280   virtual ash::tray::UserAccountsDelegate* GetUserAccountsDelegate(
281       const std::string& user_id) OVERRIDE {
282     return NULL;
283   }
284
285  private:
286   ash::SystemTrayNotifier* GetSystemTrayNotifier() {
287     return ash::Shell::GetInstance()->system_tray_notifier();
288   }
289
290   void UpdateClockType() {
291     clock_type_ = (base::GetHourClockType() == base::k24HourClock) ?
292         base::k24HourClock : base::k12HourClock;
293     GetSystemTrayNotifier()->NotifyDateFormatChanged();
294   }
295
296   // content::NotificationObserver implementation.
297   virtual void Observe(int type,
298                        const content::NotificationSource& source,
299                        const content::NotificationDetails& details) OVERRIDE {
300     if (type == chrome::NOTIFICATION_UPGRADE_RECOMMENDED) {
301         UpgradeDetector* detector =
302             content::Source<UpgradeDetector>(source).ptr();
303       ash::UpdateObserver::UpdateSeverity severity =
304           ash::UpdateObserver::UPDATE_NORMAL;
305       switch (detector->upgrade_notification_stage()) {
306         case UpgradeDetector::UPGRADE_ANNOYANCE_CRITICAL:
307         case UpgradeDetector::UPGRADE_ANNOYANCE_SEVERE:
308           severity = ash::UpdateObserver::UPDATE_SEVERE_RED;
309           break;
310         case UpgradeDetector::UPGRADE_ANNOYANCE_HIGH:
311           severity = ash::UpdateObserver::UPDATE_HIGH_ORANGE;
312           break;
313         case UpgradeDetector::UPGRADE_ANNOYANCE_ELEVATED:
314           severity = ash::UpdateObserver::UPDATE_LOW_GREEN;
315           break;
316         case UpgradeDetector::UPGRADE_ANNOYANCE_LOW:
317         case UpgradeDetector::UPGRADE_ANNOYANCE_NONE:
318           severity = ash::UpdateObserver::UPDATE_NORMAL;
319           break;
320       }
321       GetSystemTrayNotifier()->NotifyUpdateRecommended(severity);
322     } else {
323       NOTREACHED();
324     }
325   }
326
327   scoped_ptr<content::NotificationRegistrar> registrar_;
328   base::HourClockType clock_type_;
329
330   DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegateWin);
331 };
332
333 }  // namespace
334
335
336 ash::SystemTrayDelegate* CreateWindowsSystemTrayDelegate() {
337   return new SystemTrayDelegateWin();
338 }