OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/system/ash_system_tray_delegate.h" | 5 #include "chrome/browser/chromeos/system/ash_system_tray_delegate.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/shell_window_ids.h" | |
9 #include "ash/system/audio/audio_controller.h" | 8 #include "ash/system/audio/audio_controller.h" |
10 #include "ash/system/brightness/brightness_controller.h" | 9 #include "ash/system/brightness/brightness_controller.h" |
11 #include "ash/system/network/network_controller.h" | 10 #include "ash/system/network/network_controller.h" |
12 #include "ash/system/power/date_format_observer.h" | 11 #include "ash/system/power/date_format_observer.h" |
13 #include "ash/system/power/power_status_controller.h" | 12 #include "ash/system/power/power_status_controller.h" |
14 #include "ash/system/tray/system_tray.h" | 13 #include "ash/system/tray/system_tray.h" |
15 #include "ash/system/tray/system_tray_delegate.h" | 14 #include "ash/system/tray/system_tray_delegate.h" |
16 #include "ash/system/user/update_controller.h" | 15 #include "ash/system/user/update_controller.h" |
17 #include "base/logging.h" | 16 #include "base/logging.h" |
18 #include "base/utf_string_conversions.h" | |
19 #include "chrome/browser/chromeos/audio/audio_handler.h" | 17 #include "chrome/browser/chromeos/audio/audio_handler.h" |
20 #include "chrome/browser/chromeos/cros/cros_library.h" | 18 #include "chrome/browser/chromeos/cros/cros_library.h" |
21 #include "chrome/browser/chromeos/cros/network_library.h" | 19 #include "chrome/browser/chromeos/cros/network_library.h" |
22 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | 20 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
23 #include "chrome/browser/chromeos/dbus/power_manager_client.h" | 21 #include "chrome/browser/chromeos/dbus/power_manager_client.h" |
24 #include "chrome/browser/chromeos/login/base_login_display_host.h" | |
25 #include "chrome/browser/chromeos/login/login_display_host.h" | |
26 #include "chrome/browser/chromeos/login/user.h" | 22 #include "chrome/browser/chromeos/login/user.h" |
27 #include "chrome/browser/chromeos/login/user_manager.h" | 23 #include "chrome/browser/chromeos/login/user_manager.h" |
28 #include "chrome/browser/chromeos/status/network_menu.h" | |
29 #include "chrome/browser/chromeos/status/network_menu_icon.h" | 24 #include "chrome/browser/chromeos/status/network_menu_icon.h" |
30 #include "chrome/browser/prefs/pref_service.h" | 25 #include "chrome/browser/prefs/pref_service.h" |
31 #include "chrome/browser/profiles/profile_manager.h" | 26 #include "chrome/browser/profiles/profile_manager.h" |
32 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
33 #include "chrome/browser/ui/browser_list.h" | 28 #include "chrome/browser/ui/browser_list.h" |
34 #include "chrome/browser/upgrade_detector.h" | 29 #include "chrome/browser/upgrade_detector.h" |
35 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
36 #include "chrome/common/chrome_notification_types.h" | 31 #include "chrome/common/chrome_notification_types.h" |
37 #include "content/public/browser/notification_observer.h" | 32 #include "content/public/browser/notification_observer.h" |
38 #include "content/public/browser/notification_service.h" | 33 #include "content/public/browser/notification_service.h" |
39 #include "grit/generated_resources.h" | |
40 #include "ui/base/l10n/l10n_util.h" | |
41 | 34 |
42 namespace chromeos { | 35 namespace chromeos { |
43 | 36 |
44 namespace { | 37 namespace { |
45 | 38 |
46 ash::NetworkIconInfo CreateNetworkIconInfo(const Network* network, | |
47 NetworkMenuIcon* network_icon) { | |
48 ash::NetworkIconInfo info; | |
49 info.name = UTF8ToUTF16(network->name()); | |
50 info.image = network_icon->GetBitmap(network, NetworkMenuIcon::SIZE_SMALL); | |
51 info.unique_id = network->unique_id(); | |
52 return info; | |
53 } | |
54 | |
55 class SystemTrayDelegate : public ash::SystemTrayDelegate, | 39 class SystemTrayDelegate : public ash::SystemTrayDelegate, |
56 public AudioHandler::VolumeObserver, | 40 public AudioHandler::VolumeObserver, |
57 public PowerManagerClient::Observer, | 41 public PowerManagerClient::Observer, |
58 public NetworkMenuIcon::Delegate, | 42 public NetworkMenuIcon::Delegate, |
59 public NetworkMenu::Delegate, | |
60 public NetworkLibrary::NetworkManagerObserver, | 43 public NetworkLibrary::NetworkManagerObserver, |
61 public NetworkLibrary::NetworkObserver, | 44 public NetworkLibrary::NetworkObserver, |
62 public NetworkLibrary::CellularDataPlanObserver, | 45 public NetworkLibrary::CellularDataPlanObserver, |
63 public content::NotificationObserver { | 46 public content::NotificationObserver { |
64 public: | 47 public: |
65 explicit SystemTrayDelegate(ash::SystemTray* tray) | 48 explicit SystemTrayDelegate(ash::SystemTray* tray) |
66 : tray_(tray), | 49 : tray_(tray), |
67 network_icon_(ALLOW_THIS_IN_INITIALIZER_LIST( | 50 network_icon_(ALLOW_THIS_IN_INITIALIZER_LIST( |
68 new NetworkMenuIcon(this, NetworkMenuIcon::MENU_MODE))), | 51 new NetworkMenuIcon(this, NetworkMenuIcon::MENU_MODE))) { |
69 network_icon_large_(ALLOW_THIS_IN_INITIALIZER_LIST( | |
70 new NetworkMenuIcon(this, NetworkMenuIcon::MENU_MODE))), | |
71 network_menu_(ALLOW_THIS_IN_INITIALIZER_LIST(new NetworkMenu(this))) { | |
72 AudioHandler::GetInstance()->AddVolumeObserver(this); | 52 AudioHandler::GetInstance()->AddVolumeObserver(this); |
73 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); | 53 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); |
74 DBusThreadManager::Get()->GetPowerManagerClient()->RequestStatusUpdate( | 54 DBusThreadManager::Get()->GetPowerManagerClient()->RequestStatusUpdate( |
75 PowerManagerClient::UPDATE_USER); | 55 PowerManagerClient::UPDATE_USER); |
76 | 56 |
77 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); | 57 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); |
78 crosnet->AddNetworkManagerObserver(this); | 58 crosnet->AddNetworkManagerObserver(this); |
79 OnNetworkManagerChanged(crosnet); | 59 OnNetworkManagerChanged(crosnet); |
80 crosnet->AddCellularDataPlanObserver(this); | 60 crosnet->AddCellularDataPlanObserver(this); |
81 | 61 |
82 registrar_.Add(this, | 62 registrar_.Add(this, |
83 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 63 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
84 content::NotificationService::AllSources()); | 64 content::NotificationService::AllSources()); |
85 registrar_.Add(this, | 65 registrar_.Add(this, |
86 chrome::NOTIFICATION_UPGRADE_RECOMMENDED, | 66 chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
87 content::NotificationService::AllSources()); | 67 content::NotificationService::AllSources()); |
88 | 68 |
89 InitializePrefChangeRegistrar(); | 69 InitializePrefChangeRegistrar(); |
90 | |
91 network_icon_large_->SetResourceSize(NetworkMenuIcon::SIZE_LARGE); | |
92 } | 70 } |
93 | 71 |
94 virtual ~SystemTrayDelegate() { | 72 virtual ~SystemTrayDelegate() { |
95 AudioHandler* audiohandler = AudioHandler::GetInstance(); | 73 AudioHandler* audiohandler = AudioHandler::GetInstance(); |
96 if (audiohandler) | 74 if (audiohandler) |
97 audiohandler->RemoveVolumeObserver(this); | 75 audiohandler->RemoveVolumeObserver(this); |
98 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | 76 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); |
99 } | 77 } |
100 | 78 |
101 // Overridden from ash::SystemTrayDelegate: | 79 // Overridden from ash::SystemTrayDelegate: |
(...skipping 29 matching lines...) Expand all Loading... |
131 UpgradeDetector::UPGRADE_ICON_TYPE_MENU_ICON); | 109 UpgradeDetector::UPGRADE_ICON_TYPE_MENU_ICON); |
132 } | 110 } |
133 | 111 |
134 virtual base::HourClockType GetHourClockType() const OVERRIDE { | 112 virtual base::HourClockType GetHourClockType() const OVERRIDE { |
135 Profile* profile = ProfileManager::GetDefaultProfile(); | 113 Profile* profile = ProfileManager::GetDefaultProfile(); |
136 return !profile || profile->GetPrefs()->GetBoolean(prefs::kUse24HourClock) ? | 114 return !profile || profile->GetPrefs()->GetBoolean(prefs::kUse24HourClock) ? |
137 base::k24HourClock : base::k12HourClock; | 115 base::k24HourClock : base::k12HourClock; |
138 } | 116 } |
139 | 117 |
140 virtual void ShowSettings() OVERRIDE { | 118 virtual void ShowSettings() OVERRIDE { |
141 GetAppropriateBrowser()->OpenOptionsDialog(); | 119 BrowserList::GetLastActive()->OpenOptionsDialog(); |
142 } | 120 } |
143 | 121 |
144 virtual void ShowDateSettings() OVERRIDE { | 122 virtual void ShowDateSettings() OVERRIDE { |
145 GetAppropriateBrowser()->OpenAdvancedOptionsDialog(); | 123 BrowserList::GetLastActive()->OpenAdvancedOptionsDialog(); |
146 } | |
147 | |
148 virtual void ShowNetworkSettings() OVERRIDE { | |
149 GetAppropriateBrowser()->OpenInternetOptionsDialog(); | |
150 } | 124 } |
151 | 125 |
152 virtual void ShowHelp() OVERRIDE { | 126 virtual void ShowHelp() OVERRIDE { |
153 GetAppropriateBrowser()->ShowHelpTab(); | 127 BrowserList::GetLastActive()->ShowHelpTab(); |
154 } | 128 } |
155 | 129 |
156 virtual bool IsAudioMuted() const OVERRIDE { | 130 virtual bool IsAudioMuted() const OVERRIDE { |
157 return AudioHandler::GetInstance()->IsMuted(); | 131 return AudioHandler::GetInstance()->IsMuted(); |
158 } | 132 } |
159 | 133 |
160 virtual void SetAudioMuted(bool muted) OVERRIDE { | 134 virtual void SetAudioMuted(bool muted) OVERRIDE { |
161 return AudioHandler::GetInstance()->SetMuted(muted); | 135 return AudioHandler::GetInstance()->SetMuted(muted); |
162 } | 136 } |
163 | 137 |
(...skipping 11 matching lines...) Expand all Loading... |
175 | 149 |
176 virtual void SignOut() OVERRIDE { | 150 virtual void SignOut() OVERRIDE { |
177 BrowserList::AttemptUserExit(); | 151 BrowserList::AttemptUserExit(); |
178 } | 152 } |
179 | 153 |
180 virtual void RequestLockScreen() OVERRIDE { | 154 virtual void RequestLockScreen() OVERRIDE { |
181 DBusThreadManager::Get()->GetPowerManagerClient()-> | 155 DBusThreadManager::Get()->GetPowerManagerClient()-> |
182 NotifyScreenLockRequested(); | 156 NotifyScreenLockRequested(); |
183 } | 157 } |
184 | 158 |
185 virtual ash::NetworkIconInfo GetMostRelevantNetworkIcon(bool large) OVERRIDE { | 159 virtual ash::NetworkIconInfo GetMostRelevantNetworkIcon() OVERRIDE { |
186 ash::NetworkIconInfo info; | 160 ash::NetworkIconInfo info; |
187 info.image = !large ? network_icon_->GetIconAndText(&info.description) : | 161 info.image = network_icon_->GetIconAndText(&info.description); |
188 network_icon_large_->GetIconAndText(&info.description); | |
189 return info; | 162 return info; |
190 } | 163 } |
191 | 164 |
192 virtual void GetAvailableNetworks( | |
193 std::vector<ash::NetworkIconInfo>* list) OVERRIDE { | |
194 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); | |
195 | |
196 // Ethernet. | |
197 if (crosnet->ethernet_available() && crosnet->ethernet_enabled()) { | |
198 const EthernetNetwork* ethernet_network = crosnet->ethernet_network(); | |
199 if (ethernet_network) { | |
200 ash::NetworkIconInfo info; | |
201 info.image = network_icon_->GetBitmap(ethernet_network, | |
202 NetworkMenuIcon::SIZE_SMALL); | |
203 if (!ethernet_network->name().empty()) | |
204 info.name = UTF8ToUTF16(ethernet_network->name()); | |
205 else | |
206 info.name = | |
207 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET); | |
208 info.unique_id = ethernet_network->unique_id(); | |
209 list->push_back(info); | |
210 } | |
211 } | |
212 | |
213 // Wifi. | |
214 if (crosnet->wifi_available() && crosnet->wifi_enabled()) { | |
215 const WifiNetworkVector& wifi = crosnet->wifi_networks(); | |
216 for (size_t i = 0; i < wifi.size(); ++i) | |
217 list->push_back(CreateNetworkIconInfo(wifi[i], network_icon_.get())); | |
218 } | |
219 | |
220 // Cellular. | |
221 if (crosnet->cellular_available() && crosnet->cellular_enabled()) { | |
222 // TODO(sad): There are different cases for cellular networks, e.g. | |
223 // de-activated networks, active networks that support data plan info, | |
224 // networks with top-up URLs etc. All of these need to be handled | |
225 // properly. | |
226 const CellularNetworkVector& cell = crosnet->cellular_networks(); | |
227 for (size_t i = 0; i < cell.size(); ++i) | |
228 list->push_back(CreateNetworkIconInfo(cell[i], network_icon_.get())); | |
229 } | |
230 | |
231 // VPN (only if logged in). | |
232 if (GetUserLoginStatus() == ash::user::LOGGED_IN_NONE) | |
233 return; | |
234 if (crosnet->connected_network() || crosnet->virtual_network_connected()) { | |
235 const VirtualNetworkVector& vpns = crosnet->virtual_networks(); | |
236 for (size_t i = 0; i < vpns.size(); ++i) | |
237 list->push_back(CreateNetworkIconInfo(vpns[i], network_icon_.get())); | |
238 } | |
239 } | |
240 | |
241 virtual void ConnectToNetwork(const std::string& network_id) OVERRIDE { | |
242 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); | |
243 Network* network = crosnet->FindNetworkByUniqueId(network_id); | |
244 if (network) | |
245 network_menu_->ConnectToNetwork(network); | |
246 } | |
247 | |
248 virtual void ToggleAirplaneMode() OVERRIDE { | |
249 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); | |
250 crosnet->EnableOfflineMode(!crosnet->offline_mode()); | |
251 } | |
252 | |
253 virtual void ChangeProxySettings() OVERRIDE { | |
254 CHECK(GetUserLoginStatus() == ash::user::LOGGED_IN_NONE); | |
255 BaseLoginDisplayHost::default_host()->OpenProxySettings(); | |
256 } | |
257 | |
258 private: | 165 private: |
259 // Returns the last active browser. If there is no such browser, creates a new | |
260 // browser window with an empty tab and returns it. | |
261 Browser* GetAppropriateBrowser() { | |
262 Browser* browser = BrowserList::GetLastActive(); | |
263 if (!browser) | |
264 browser = Browser::NewEmptyWindow(ProfileManager::GetDefaultProfile()); | |
265 return browser; | |
266 } | |
267 | |
268 void InitializePrefChangeRegistrar() { | 166 void InitializePrefChangeRegistrar() { |
269 Profile* profile = ProfileManager::GetDefaultProfile(); | 167 Profile* profile = ProfileManager::GetDefaultProfile(); |
270 pref_registrar_.reset(new PrefChangeRegistrar); | 168 pref_registrar_.reset(new PrefChangeRegistrar); |
271 pref_registrar_->Init(profile->GetPrefs()); | 169 pref_registrar_->Init(profile->GetPrefs()); |
272 pref_registrar_->Add(prefs::kUse24HourClock, this); | 170 pref_registrar_->Add(prefs::kUse24HourClock, this); |
273 } | 171 } |
274 | 172 |
275 void NotifyRefreshNetwork() { | 173 void NotifyRefreshNetwork() { |
276 ash::NetworkController* controller = | 174 ash::NetworkController* controller = |
277 ash::Shell::GetInstance()->network_controller(); | 175 ash::Shell::GetInstance()->network_controller(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 | 223 |
326 virtual void UnlockScreen() OVERRIDE { | 224 virtual void UnlockScreen() OVERRIDE { |
327 } | 225 } |
328 | 226 |
329 virtual void UnlockScreenFailed() OVERRIDE { | 227 virtual void UnlockScreenFailed() OVERRIDE { |
330 } | 228 } |
331 | 229 |
332 // TODO(sad): Override more from PowerManagerClient::Observer here (e.g. | 230 // TODO(sad): Override more from PowerManagerClient::Observer here (e.g. |
333 // PowerButtonStateChanged etc.). | 231 // PowerButtonStateChanged etc.). |
334 | 232 |
335 // Overridden from NetworkMenuIcon::Delegate. | 233 // Overridden from StatusMenuIcon::Delegate. |
336 virtual void NetworkMenuIconChanged() OVERRIDE { | 234 virtual void NetworkMenuIconChanged() OVERRIDE { |
337 NotifyRefreshNetwork(); | 235 NotifyRefreshNetwork(); |
338 } | 236 } |
339 | 237 |
340 // Overridden from NetworkMenu::Delegate. | |
341 virtual views::MenuButton* GetMenuButton() OVERRIDE { | |
342 return NULL; | |
343 } | |
344 | |
345 virtual gfx::NativeWindow GetNativeWindow() const OVERRIDE { | |
346 return ash::Shell::GetInstance()->GetContainer( | |
347 GetUserLoginStatus() == ash::user::LOGGED_IN_NONE ? | |
348 ash::internal::kShellWindowId_LockSystemModalContainer : | |
349 ash::internal::kShellWindowId_SystemModalContainer); | |
350 } | |
351 | |
352 virtual void OpenButtonOptions() OVERRIDE { | |
353 } | |
354 | |
355 virtual bool ShouldOpenButtonOptions() const OVERRIDE { | |
356 return false; | |
357 } | |
358 | |
359 // Overridden from NetworkLibrary::NetworkManagerObserver. | 238 // Overridden from NetworkLibrary::NetworkManagerObserver. |
360 virtual void OnNetworkManagerChanged(NetworkLibrary* crosnet) OVERRIDE { | 239 virtual void OnNetworkManagerChanged(NetworkLibrary* crosnet) OVERRIDE { |
361 RefreshNetworkObserver(crosnet); | 240 RefreshNetworkObserver(crosnet); |
362 RefreshNetworkDeviceObserver(crosnet); | 241 RefreshNetworkDeviceObserver(crosnet); |
363 | 242 |
364 // TODO: ShowOptionalMobileDataPromoNotification? | 243 // TODO: ShowOptionalMobileDataPromoNotification? |
365 | 244 |
366 NotifyRefreshNetwork(); | 245 NotifyRefreshNetwork(); |
367 } | 246 } |
368 | 247 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 observer->OnDateFormatChanged(); | 284 observer->OnDateFormatChanged(); |
406 break; | 285 break; |
407 } | 286 } |
408 default: | 287 default: |
409 NOTREACHED(); | 288 NOTREACHED(); |
410 } | 289 } |
411 } | 290 } |
412 | 291 |
413 ash::SystemTray* tray_; | 292 ash::SystemTray* tray_; |
414 scoped_ptr<NetworkMenuIcon> network_icon_; | 293 scoped_ptr<NetworkMenuIcon> network_icon_; |
415 scoped_ptr<NetworkMenuIcon> network_icon_large_; | |
416 scoped_ptr<NetworkMenu> network_menu_; | |
417 content::NotificationRegistrar registrar_; | 294 content::NotificationRegistrar registrar_; |
418 scoped_ptr<PrefChangeRegistrar> pref_registrar_; | 295 scoped_ptr<PrefChangeRegistrar> pref_registrar_; |
419 std::string cellular_device_path_; | 296 std::string cellular_device_path_; |
420 std::string active_network_path_; | 297 std::string active_network_path_; |
421 scoped_ptr<LoginHtmlDialog> proxy_settings_dialog_; | |
422 | 298 |
423 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); | 299 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); |
424 }; | 300 }; |
425 | 301 |
426 } // namespace | 302 } // namespace |
427 | 303 |
428 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) { | 304 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) { |
429 return new chromeos::SystemTrayDelegate(tray); | 305 return new chromeos::SystemTrayDelegate(tray); |
430 } | 306 } |
431 | 307 |
432 } // namespace chromeos | 308 } // namespace chromeos |
OLD | NEW |