Chromium Code Reviews| 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" | |
| 8 #include "ash/system/audio/audio_controller.h" | 9 #include "ash/system/audio/audio_controller.h" |
| 9 #include "ash/system/brightness/brightness_controller.h" | 10 #include "ash/system/brightness/brightness_controller.h" |
| 10 #include "ash/system/network/network_controller.h" | 11 #include "ash/system/network/network_controller.h" |
| 11 #include "ash/system/power/power_status_controller.h" | 12 #include "ash/system/power/power_status_controller.h" |
| 12 #include "ash/system/tray/system_tray.h" | 13 #include "ash/system/tray/system_tray.h" |
| 13 #include "ash/system/tray/system_tray_delegate.h" | 14 #include "ash/system/tray/system_tray_delegate.h" |
| 14 #include "ash/system/user/update_controller.h" | 15 #include "ash/system/user/update_controller.h" |
| 15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/utf_string_conversions.h" | |
| 16 #include "chrome/browser/chromeos/audio/audio_handler.h" | 18 #include "chrome/browser/chromeos/audio/audio_handler.h" |
| 17 #include "chrome/browser/chromeos/cros/cros_library.h" | 19 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 18 #include "chrome/browser/chromeos/cros/network_library.h" | 20 #include "chrome/browser/chromeos/cros/network_library.h" |
| 19 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | 21 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
| 20 #include "chrome/browser/chromeos/dbus/power_manager_client.h" | 22 #include "chrome/browser/chromeos/dbus/power_manager_client.h" |
| 23 #include "chrome/browser/chromeos/login/base_login_display_host.h" | |
| 24 #include "chrome/browser/chromeos/login/login_display_host.h" | |
| 21 #include "chrome/browser/chromeos/login/user.h" | 25 #include "chrome/browser/chromeos/login/user.h" |
| 22 #include "chrome/browser/chromeos/login/user_manager.h" | 26 #include "chrome/browser/chromeos/login/user_manager.h" |
| 27 #include "chrome/browser/chromeos/status/network_menu.h" | |
| 23 #include "chrome/browser/chromeos/status/network_menu_icon.h" | 28 #include "chrome/browser/chromeos/status/network_menu_icon.h" |
| 29 #include "chrome/browser/profiles/profile_manager.h" | |
| 24 #include "chrome/browser/ui/browser.h" | 30 #include "chrome/browser/ui/browser.h" |
| 25 #include "chrome/browser/ui/browser_list.h" | 31 #include "chrome/browser/ui/browser_list.h" |
| 26 #include "chrome/browser/upgrade_detector.h" | 32 #include "chrome/browser/upgrade_detector.h" |
| 27 #include "chrome/common/chrome_notification_types.h" | 33 #include "chrome/common/chrome_notification_types.h" |
| 28 #include "content/public/browser/notification_observer.h" | 34 #include "content/public/browser/notification_observer.h" |
| 29 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
| 36 #include "grit/generated_resources.h" | |
| 37 #include "ui/base/l10n/l10n_util.h" | |
| 30 | 38 |
| 31 namespace chromeos { | 39 namespace chromeos { |
| 32 | 40 |
| 33 namespace { | 41 namespace { |
| 34 | 42 |
| 43 ash::NetworkIconInfo CreateNetworkIconInfo(const Network* network, | |
| 44 NetworkMenuIcon* network_icon) { | |
| 45 ash::NetworkIconInfo info; | |
| 46 info.name = UTF8ToUTF16(network->name()); | |
| 47 info.image = network_icon->GetBitmap(network, NetworkMenuIcon::SIZE_SMALL); | |
| 48 info.unique_id = network->unique_id(); | |
| 49 return info; | |
| 50 } | |
| 51 | |
| 35 class SystemTrayDelegate : public ash::SystemTrayDelegate, | 52 class SystemTrayDelegate : public ash::SystemTrayDelegate, |
| 36 public AudioHandler::VolumeObserver, | 53 public AudioHandler::VolumeObserver, |
| 37 public PowerManagerClient::Observer, | 54 public PowerManagerClient::Observer, |
| 38 public NetworkMenuIcon::Delegate, | 55 public NetworkMenuIcon::Delegate, |
| 56 public NetworkMenu::Delegate, | |
| 39 public NetworkLibrary::NetworkManagerObserver, | 57 public NetworkLibrary::NetworkManagerObserver, |
| 40 public NetworkLibrary::NetworkObserver, | 58 public NetworkLibrary::NetworkObserver, |
| 41 public NetworkLibrary::CellularDataPlanObserver, | 59 public NetworkLibrary::CellularDataPlanObserver, |
| 42 public content::NotificationObserver { | 60 public content::NotificationObserver { |
| 43 public: | 61 public: |
| 44 explicit SystemTrayDelegate(ash::SystemTray* tray) | 62 explicit SystemTrayDelegate(ash::SystemTray* tray) |
| 45 : tray_(tray), | 63 : tray_(tray), |
| 46 network_icon_(ALLOW_THIS_IN_INITIALIZER_LIST( | 64 network_icon_(ALLOW_THIS_IN_INITIALIZER_LIST( |
| 47 new NetworkMenuIcon(this, NetworkMenuIcon::MENU_MODE))) { | 65 new NetworkMenuIcon(this, NetworkMenuIcon::MENU_MODE))), |
| 66 network_icon_large_(ALLOW_THIS_IN_INITIALIZER_LIST( | |
| 67 new NetworkMenuIcon(this, NetworkMenuIcon::MENU_MODE))), | |
| 68 network_menu_(ALLOW_THIS_IN_INITIALIZER_LIST(new NetworkMenu(this))) { | |
| 48 AudioHandler::GetInstance()->AddVolumeObserver(this); | 69 AudioHandler::GetInstance()->AddVolumeObserver(this); |
| 49 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); | 70 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); |
| 50 DBusThreadManager::Get()->GetPowerManagerClient()->RequestStatusUpdate( | 71 DBusThreadManager::Get()->GetPowerManagerClient()->RequestStatusUpdate( |
| 51 PowerManagerClient::UPDATE_USER); | 72 PowerManagerClient::UPDATE_USER); |
| 52 | 73 |
| 53 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); | 74 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); |
| 54 crosnet->AddNetworkManagerObserver(this); | 75 crosnet->AddNetworkManagerObserver(this); |
| 55 OnNetworkManagerChanged(crosnet); | 76 OnNetworkManagerChanged(crosnet); |
| 56 crosnet->AddCellularDataPlanObserver(this); | 77 crosnet->AddCellularDataPlanObserver(this); |
| 57 | 78 |
| 58 registrar_.Add(this, | 79 registrar_.Add(this, |
| 59 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 80 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| 60 content::NotificationService::AllSources()); | 81 content::NotificationService::AllSources()); |
| 61 registrar_.Add(this, | 82 registrar_.Add(this, |
| 62 chrome::NOTIFICATION_UPGRADE_RECOMMENDED, | 83 chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
| 63 content::NotificationService::AllSources()); | 84 content::NotificationService::AllSources()); |
| 85 | |
| 86 network_icon_large_->SetResourceSize(NetworkMenuIcon::SIZE_LARGE); | |
| 64 } | 87 } |
| 65 | 88 |
| 66 virtual ~SystemTrayDelegate() { | 89 virtual ~SystemTrayDelegate() { |
| 67 AudioHandler* audiohandler = AudioHandler::GetInstance(); | 90 AudioHandler* audiohandler = AudioHandler::GetInstance(); |
| 68 if (audiohandler) | 91 if (audiohandler) |
| 69 audiohandler->RemoveVolumeObserver(this); | 92 audiohandler->RemoveVolumeObserver(this); |
| 70 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | 93 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); |
| 71 } | 94 } |
| 72 | 95 |
| 73 // Overridden from ash::SystemTrayDelegate: | 96 // Overridden from ash::SystemTrayDelegate: |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 97 virtual bool SystemShouldUpgrade() const OVERRIDE { | 120 virtual bool SystemShouldUpgrade() const OVERRIDE { |
| 98 return UpgradeDetector::GetInstance()->notify_upgrade(); | 121 return UpgradeDetector::GetInstance()->notify_upgrade(); |
| 99 } | 122 } |
| 100 | 123 |
| 101 virtual int GetSystemUpdateIconResource() const OVERRIDE { | 124 virtual int GetSystemUpdateIconResource() const OVERRIDE { |
| 102 return UpgradeDetector::GetInstance()->GetIconResourceID( | 125 return UpgradeDetector::GetInstance()->GetIconResourceID( |
| 103 UpgradeDetector::UPGRADE_ICON_TYPE_MENU_ICON); | 126 UpgradeDetector::UPGRADE_ICON_TYPE_MENU_ICON); |
| 104 } | 127 } |
| 105 | 128 |
| 106 virtual void ShowSettings() OVERRIDE { | 129 virtual void ShowSettings() OVERRIDE { |
| 107 BrowserList::GetLastActive()->OpenOptionsDialog(); | 130 GetAppropriateBrowser()->OpenOptionsDialog(); |
| 108 } | 131 } |
| 109 | 132 |
| 110 virtual void ShowDateSettings() OVERRIDE { | 133 virtual void ShowDateSettings() OVERRIDE { |
| 111 BrowserList::GetLastActive()->OpenAdvancedOptionsDialog(); | 134 GetAppropriateBrowser()->OpenAdvancedOptionsDialog(); |
| 135 } | |
| 136 | |
| 137 virtual void ShowNetworkSettings() OVERRIDE { | |
| 138 GetAppropriateBrowser()->OpenInternetOptionsDialog(); | |
| 112 } | 139 } |
| 113 | 140 |
| 114 virtual void ShowHelp() OVERRIDE { | 141 virtual void ShowHelp() OVERRIDE { |
| 115 BrowserList::GetLastActive()->ShowHelpTab(); | 142 GetAppropriateBrowser()->ShowHelpTab(); |
| 116 } | 143 } |
| 117 | 144 |
| 118 virtual bool IsAudioMuted() const OVERRIDE { | 145 virtual bool IsAudioMuted() const OVERRIDE { |
| 119 return AudioHandler::GetInstance()->IsMuted(); | 146 return AudioHandler::GetInstance()->IsMuted(); |
| 120 } | 147 } |
| 121 | 148 |
| 122 virtual void SetAudioMuted(bool muted) OVERRIDE { | 149 virtual void SetAudioMuted(bool muted) OVERRIDE { |
| 123 return AudioHandler::GetInstance()->SetMuted(muted); | 150 return AudioHandler::GetInstance()->SetMuted(muted); |
| 124 } | 151 } |
| 125 | 152 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 137 | 164 |
| 138 virtual void SignOut() OVERRIDE { | 165 virtual void SignOut() OVERRIDE { |
| 139 BrowserList::AttemptUserExit(); | 166 BrowserList::AttemptUserExit(); |
| 140 } | 167 } |
| 141 | 168 |
| 142 virtual void RequestLockScreen() OVERRIDE { | 169 virtual void RequestLockScreen() OVERRIDE { |
| 143 DBusThreadManager::Get()->GetPowerManagerClient()-> | 170 DBusThreadManager::Get()->GetPowerManagerClient()-> |
| 144 NotifyScreenLockRequested(); | 171 NotifyScreenLockRequested(); |
| 145 } | 172 } |
| 146 | 173 |
| 147 virtual ash::NetworkIconInfo GetMostRelevantNetworkIcon() OVERRIDE { | 174 virtual ash::NetworkIconInfo GetMostRelevantNetworkIcon(bool large) OVERRIDE { |
| 148 ash::NetworkIconInfo info; | 175 ash::NetworkIconInfo info; |
| 149 info.image = network_icon_->GetIconAndText(&info.description); | 176 info.image = !large ? network_icon_->GetIconAndText(&info.description) : |
| 177 network_icon_large_->GetIconAndText(&info.description); | |
| 150 return info; | 178 return info; |
| 151 } | 179 } |
| 152 | 180 |
| 181 virtual void GetAvailableNetworks( | |
| 182 std::vector<ash::NetworkIconInfo>* list) OVERRIDE { | |
| 183 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); | |
| 184 crosnet->RequestNetworkScan(); | |
| 185 | |
| 186 // Ethernet. | |
| 187 if (crosnet->ethernet_enabled()) { | |
|
Nikita (slow)
2012/03/14 16:48:45
Please add crosnet->ethernet_available().
sadrul
2012/03/14 18:37:46
Done.
| |
| 188 const EthernetNetwork* ethernet_network = crosnet->ethernet_network(); | |
| 189 if (ethernet_network) { | |
| 190 ash::NetworkIconInfo info; | |
| 191 info.image = network_icon_->GetBitmap(ethernet_network, | |
| 192 NetworkMenuIcon::SIZE_SMALL); | |
| 193 if (!ethernet_network->name().empty()) | |
| 194 info.name = UTF8ToUTF16(ethernet_network->name()); | |
| 195 else | |
| 196 info.name = | |
| 197 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET); | |
| 198 info.unique_id = ethernet_network->unique_id(); | |
| 199 list->push_back(info); | |
| 200 } | |
| 201 } | |
| 202 | |
| 203 // Wifi. | |
| 204 if (crosnet->wifi_available() && crosnet->wifi_enabled()) { | |
| 205 const WifiNetworkVector& wifi = crosnet->wifi_networks(); | |
| 206 for (size_t i = 0; i < wifi.size(); ++i) | |
| 207 list->push_back(CreateNetworkIconInfo(wifi[i], network_icon_.get())); | |
| 208 } | |
| 209 | |
| 210 // Cellular. | |
| 211 if (crosnet->cellular_available() && crosnet->cellular_enabled()) { | |
| 212 const CellularNetworkVector& cell = crosnet->cellular_networks(); | |
| 213 for (size_t i = 0; i < cell.size(); ++i) | |
| 214 list->push_back(CreateNetworkIconInfo(cell[i], network_icon_.get())); | |
|
Nikita (slow)
2012/03/14 16:48:45
We have special cases for cellular:
1. If cellular
sadrul
2012/03/14 18:37:46
Done.
| |
| 215 } | |
| 216 | |
| 217 // VPN (only if logged in). | |
| 218 if (GetUserLoginStatus() == ash::user::LOGGED_IN_NONE) | |
| 219 return; | |
| 220 if (crosnet->connected_network() || crosnet->virtual_network_connected()) { | |
| 221 const VirtualNetworkVector& vpns = crosnet->virtual_networks(); | |
| 222 for (size_t i = 0; i < vpns.size(); ++i) | |
| 223 list->push_back(CreateNetworkIconInfo(vpns[i], network_icon_.get())); | |
| 224 } | |
| 225 } | |
| 226 | |
| 227 virtual void ConnectToNetwork(const std::string& network_id) OVERRIDE { | |
| 228 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); | |
| 229 Network* network = crosnet->FindNetworkByUniqueId(network_id); | |
| 230 if (network) | |
| 231 network_menu_->ConnectToNetwork(network); | |
| 232 } | |
| 233 | |
| 234 virtual void ToggleAirplaneMode() OVERRIDE { | |
| 235 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); | |
| 236 crosnet->EnableOfflineMode(!crosnet->offline_mode()); | |
| 237 } | |
| 238 | |
| 239 virtual void ChangeProxySettings() OVERRIDE { | |
| 240 CHECK(GetUserLoginStatus() == ash::user::LOGGED_IN_NONE); | |
| 241 BaseLoginDisplayHost::default_host()->OpenProxySettings(); | |
| 242 } | |
| 243 | |
| 153 private: | 244 private: |
| 245 // Returns the last active browser. If there is no such browser, creates a new | |
| 246 // browser window with an empty tab and returns it. | |
| 247 Browser* GetAppropriateBrowser() { | |
| 248 Browser* browser = BrowserList::GetLastActive(); | |
| 249 if (!browser) | |
| 250 browser = Browser::NewEmptyWindow(ProfileManager::GetDefaultProfile()); | |
| 251 return browser; | |
| 252 } | |
| 253 | |
| 154 void NotifyRefreshNetwork() { | 254 void NotifyRefreshNetwork() { |
| 155 ash::NetworkController* controller = | 255 ash::NetworkController* controller = |
| 156 ash::Shell::GetInstance()->network_controller(); | 256 ash::Shell::GetInstance()->network_controller(); |
| 157 if (controller) { | 257 if (controller) { |
| 158 ash::NetworkIconInfo info; | 258 ash::NetworkIconInfo info; |
| 159 info.image = network_icon_->GetIconAndText(&info.description); | 259 info.image = network_icon_->GetIconAndText(&info.description); |
| 160 controller->OnNetworkRefresh(info); | 260 controller->OnNetworkRefresh(info); |
| 161 } | 261 } |
| 162 } | 262 } |
| 163 | 263 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 | 304 |
| 205 virtual void UnlockScreen() OVERRIDE { | 305 virtual void UnlockScreen() OVERRIDE { |
| 206 } | 306 } |
| 207 | 307 |
| 208 virtual void UnlockScreenFailed() OVERRIDE { | 308 virtual void UnlockScreenFailed() OVERRIDE { |
| 209 } | 309 } |
| 210 | 310 |
| 211 // TODO(sad): Override more from PowerManagerClient::Observer here (e.g. | 311 // TODO(sad): Override more from PowerManagerClient::Observer here (e.g. |
| 212 // PowerButtonStateChanged etc.). | 312 // PowerButtonStateChanged etc.). |
| 213 | 313 |
| 214 // Overridden from StatusMenuIcon::Delegate. | 314 // Overridden from NetworkMenuIcon::Delegate. |
| 215 virtual void NetworkMenuIconChanged() OVERRIDE { | 315 virtual void NetworkMenuIconChanged() OVERRIDE { |
| 216 NotifyRefreshNetwork(); | 316 NotifyRefreshNetwork(); |
| 217 } | 317 } |
| 218 | 318 |
| 319 // Overridden from NetworkMenu::Delegate. | |
| 320 virtual views::MenuButton* GetMenuButton() OVERRIDE { | |
| 321 return NULL; | |
| 322 } | |
| 323 | |
| 324 virtual gfx::NativeWindow GetNativeWindow() const OVERRIDE { | |
| 325 return ash::Shell::GetInstance()->GetContainer( | |
| 326 GetUserLoginStatus() == ash::user::LOGGED_IN_NONE ? | |
| 327 ash::internal::kShellWindowId_LockSystemModalContainer : | |
|
Nikita (slow)
2012/03/14 16:48:45
nit: 4 spaces alignment.
sadrul
2012/03/14 18:37:46
Done.
| |
| 328 ash::internal::kShellWindowId_SystemModalContainer); | |
| 329 } | |
| 330 | |
| 331 virtual void OpenButtonOptions() OVERRIDE { | |
| 332 } | |
| 333 | |
| 334 virtual bool ShouldOpenButtonOptions() const OVERRIDE { | |
| 335 return false; | |
| 336 } | |
| 337 | |
| 219 // Overridden from NetworkLibrary::NetworkManagerObserver. | 338 // Overridden from NetworkLibrary::NetworkManagerObserver. |
| 220 virtual void OnNetworkManagerChanged(NetworkLibrary* crosnet) OVERRIDE { | 339 virtual void OnNetworkManagerChanged(NetworkLibrary* crosnet) OVERRIDE { |
| 221 RefreshNetworkObserver(crosnet); | 340 RefreshNetworkObserver(crosnet); |
| 222 RefreshNetworkDeviceObserver(crosnet); | 341 RefreshNetworkDeviceObserver(crosnet); |
| 223 | 342 |
| 224 // TODO: ShowOptionalMobileDataPromoNotification? | 343 // TODO: ShowOptionalMobileDataPromoNotification? |
| 225 | 344 |
| 226 NotifyRefreshNetwork(); | 345 NotifyRefreshNetwork(); |
| 227 } | 346 } |
| 228 | 347 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 253 controller->OnUpdateRecommended(); | 372 controller->OnUpdateRecommended(); |
| 254 break; | 373 break; |
| 255 } | 374 } |
| 256 default: | 375 default: |
| 257 NOTREACHED(); | 376 NOTREACHED(); |
| 258 } | 377 } |
| 259 } | 378 } |
| 260 | 379 |
| 261 ash::SystemTray* tray_; | 380 ash::SystemTray* tray_; |
| 262 scoped_ptr<NetworkMenuIcon> network_icon_; | 381 scoped_ptr<NetworkMenuIcon> network_icon_; |
| 382 scoped_ptr<NetworkMenuIcon> network_icon_large_; | |
| 383 scoped_ptr<NetworkMenu> network_menu_; | |
| 263 content::NotificationRegistrar registrar_; | 384 content::NotificationRegistrar registrar_; |
| 264 std::string cellular_device_path_; | 385 std::string cellular_device_path_; |
| 265 std::string active_network_path_; | 386 std::string active_network_path_; |
| 387 scoped_ptr<LoginHtmlDialog> proxy_settings_dialog_; | |
| 266 | 388 |
| 267 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); | 389 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); |
| 268 }; | 390 }; |
| 269 | 391 |
| 270 } // namespace | 392 } // namespace |
| 271 | 393 |
| 272 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) { | 394 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) { |
| 273 return new chromeos::SystemTrayDelegate(tray); | 395 return new chromeos::SystemTrayDelegate(tray); |
| 274 } | 396 } |
| 275 | 397 |
| 276 } // namespace chromeos | 398 } // namespace chromeos |
| OLD | NEW |