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