| 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/date_format_observer.h" | 12 #include "ash/system/power/date_format_observer.h" |
| 12 #include "ash/system/power/power_status_controller.h" | 13 #include "ash/system/power/power_status_controller.h" |
| 13 #include "ash/system/tray/system_tray.h" | 14 #include "ash/system/tray/system_tray.h" |
| 14 #include "ash/system/tray/system_tray_delegate.h" | 15 #include "ash/system/tray/system_tray_delegate.h" |
| 15 #include "ash/system/user/update_controller.h" | 16 #include "ash/system/user/update_controller.h" |
| 16 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/browser/chromeos/audio/audio_handler.h" | 19 #include "chrome/browser/chromeos/audio/audio_handler.h" |
| 18 #include "chrome/browser/chromeos/cros/cros_library.h" | 20 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 19 #include "chrome/browser/chromeos/cros/network_library.h" | 21 #include "chrome/browser/chromeos/cros/network_library.h" |
| 20 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | 22 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
| 21 #include "chrome/browser/chromeos/dbus/power_manager_client.h" | 23 #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" |
| 22 #include "chrome/browser/chromeos/login/user.h" | 26 #include "chrome/browser/chromeos/login/user.h" |
| 23 #include "chrome/browser/chromeos/login/user_manager.h" | 27 #include "chrome/browser/chromeos/login/user_manager.h" |
| 28 #include "chrome/browser/chromeos/status/network_menu.h" |
| 24 #include "chrome/browser/chromeos/status/network_menu_icon.h" | 29 #include "chrome/browser/chromeos/status/network_menu_icon.h" |
| 25 #include "chrome/browser/prefs/pref_service.h" | 30 #include "chrome/browser/prefs/pref_service.h" |
| 26 #include "chrome/browser/profiles/profile_manager.h" | 31 #include "chrome/browser/profiles/profile_manager.h" |
| 27 #include "chrome/browser/ui/browser.h" | 32 #include "chrome/browser/ui/browser.h" |
| 28 #include "chrome/browser/ui/browser_list.h" | 33 #include "chrome/browser/ui/browser_list.h" |
| 29 #include "chrome/browser/upgrade_detector.h" | 34 #include "chrome/browser/upgrade_detector.h" |
| 30 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
| 31 #include "chrome/common/chrome_notification_types.h" | 36 #include "chrome/common/chrome_notification_types.h" |
| 32 #include "content/public/browser/notification_observer.h" | 37 #include "content/public/browser/notification_observer.h" |
| 33 #include "content/public/browser/notification_service.h" | 38 #include "content/public/browser/notification_service.h" |
| 39 #include "grit/generated_resources.h" |
| 40 #include "ui/base/l10n/l10n_util.h" |
| 34 | 41 |
| 35 namespace chromeos { | 42 namespace chromeos { |
| 36 | 43 |
| 37 namespace { | 44 namespace { |
| 38 | 45 |
| 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 |
| 39 class SystemTrayDelegate : public ash::SystemTrayDelegate, | 55 class SystemTrayDelegate : public ash::SystemTrayDelegate, |
| 40 public AudioHandler::VolumeObserver, | 56 public AudioHandler::VolumeObserver, |
| 41 public PowerManagerClient::Observer, | 57 public PowerManagerClient::Observer, |
| 42 public NetworkMenuIcon::Delegate, | 58 public NetworkMenuIcon::Delegate, |
| 59 public NetworkMenu::Delegate, |
| 43 public NetworkLibrary::NetworkManagerObserver, | 60 public NetworkLibrary::NetworkManagerObserver, |
| 44 public NetworkLibrary::NetworkObserver, | 61 public NetworkLibrary::NetworkObserver, |
| 45 public NetworkLibrary::CellularDataPlanObserver, | 62 public NetworkLibrary::CellularDataPlanObserver, |
| 46 public content::NotificationObserver { | 63 public content::NotificationObserver { |
| 47 public: | 64 public: |
| 48 explicit SystemTrayDelegate(ash::SystemTray* tray) | 65 explicit SystemTrayDelegate(ash::SystemTray* tray) |
| 49 : tray_(tray), | 66 : tray_(tray), |
| 50 network_icon_(ALLOW_THIS_IN_INITIALIZER_LIST( | 67 network_icon_(ALLOW_THIS_IN_INITIALIZER_LIST( |
| 51 new NetworkMenuIcon(this, NetworkMenuIcon::MENU_MODE))) { | 68 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))) { |
| 52 AudioHandler::GetInstance()->AddVolumeObserver(this); | 72 AudioHandler::GetInstance()->AddVolumeObserver(this); |
| 53 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); | 73 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); |
| 54 DBusThreadManager::Get()->GetPowerManagerClient()->RequestStatusUpdate( | 74 DBusThreadManager::Get()->GetPowerManagerClient()->RequestStatusUpdate( |
| 55 PowerManagerClient::UPDATE_USER); | 75 PowerManagerClient::UPDATE_USER); |
| 56 | 76 |
| 57 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); | 77 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); |
| 58 crosnet->AddNetworkManagerObserver(this); | 78 crosnet->AddNetworkManagerObserver(this); |
| 59 OnNetworkManagerChanged(crosnet); | 79 OnNetworkManagerChanged(crosnet); |
| 60 crosnet->AddCellularDataPlanObserver(this); | 80 crosnet->AddCellularDataPlanObserver(this); |
| 61 | 81 |
| 62 registrar_.Add(this, | 82 registrar_.Add(this, |
| 63 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 83 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| 64 content::NotificationService::AllSources()); | 84 content::NotificationService::AllSources()); |
| 65 registrar_.Add(this, | 85 registrar_.Add(this, |
| 66 chrome::NOTIFICATION_UPGRADE_RECOMMENDED, | 86 chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
| 67 content::NotificationService::AllSources()); | 87 content::NotificationService::AllSources()); |
| 68 | 88 |
| 69 InitializePrefChangeRegistrar(); | 89 InitializePrefChangeRegistrar(); |
| 90 |
| 91 network_icon_large_->SetResourceSize(NetworkMenuIcon::SIZE_LARGE); |
| 70 } | 92 } |
| 71 | 93 |
| 72 virtual ~SystemTrayDelegate() { | 94 virtual ~SystemTrayDelegate() { |
| 73 AudioHandler* audiohandler = AudioHandler::GetInstance(); | 95 AudioHandler* audiohandler = AudioHandler::GetInstance(); |
| 74 if (audiohandler) | 96 if (audiohandler) |
| 75 audiohandler->RemoveVolumeObserver(this); | 97 audiohandler->RemoveVolumeObserver(this); |
| 76 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | 98 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); |
| 77 } | 99 } |
| 78 | 100 |
| 79 // Overridden from ash::SystemTrayDelegate: | 101 // Overridden from ash::SystemTrayDelegate: |
| (...skipping 29 matching lines...) Expand all Loading... |
| 109 UpgradeDetector::UPGRADE_ICON_TYPE_MENU_ICON); | 131 UpgradeDetector::UPGRADE_ICON_TYPE_MENU_ICON); |
| 110 } | 132 } |
| 111 | 133 |
| 112 virtual base::HourClockType GetHourClockType() const OVERRIDE { | 134 virtual base::HourClockType GetHourClockType() const OVERRIDE { |
| 113 Profile* profile = ProfileManager::GetDefaultProfile(); | 135 Profile* profile = ProfileManager::GetDefaultProfile(); |
| 114 return !profile || profile->GetPrefs()->GetBoolean(prefs::kUse24HourClock) ? | 136 return !profile || profile->GetPrefs()->GetBoolean(prefs::kUse24HourClock) ? |
| 115 base::k24HourClock : base::k12HourClock; | 137 base::k24HourClock : base::k12HourClock; |
| 116 } | 138 } |
| 117 | 139 |
| 118 virtual void ShowSettings() OVERRIDE { | 140 virtual void ShowSettings() OVERRIDE { |
| 119 BrowserList::GetLastActive()->OpenOptionsDialog(); | 141 GetAppropriateBrowser()->OpenOptionsDialog(); |
| 120 } | 142 } |
| 121 | 143 |
| 122 virtual void ShowDateSettings() OVERRIDE { | 144 virtual void ShowDateSettings() OVERRIDE { |
| 123 BrowserList::GetLastActive()->OpenAdvancedOptionsDialog(); | 145 GetAppropriateBrowser()->OpenAdvancedOptionsDialog(); |
| 146 } |
| 147 |
| 148 virtual void ShowNetworkSettings() OVERRIDE { |
| 149 GetAppropriateBrowser()->OpenInternetOptionsDialog(); |
| 124 } | 150 } |
| 125 | 151 |
| 126 virtual void ShowHelp() OVERRIDE { | 152 virtual void ShowHelp() OVERRIDE { |
| 127 BrowserList::GetLastActive()->ShowHelpTab(); | 153 GetAppropriateBrowser()->ShowHelpTab(); |
| 128 } | 154 } |
| 129 | 155 |
| 130 virtual bool IsAudioMuted() const OVERRIDE { | 156 virtual bool IsAudioMuted() const OVERRIDE { |
| 131 return AudioHandler::GetInstance()->IsMuted(); | 157 return AudioHandler::GetInstance()->IsMuted(); |
| 132 } | 158 } |
| 133 | 159 |
| 134 virtual void SetAudioMuted(bool muted) OVERRIDE { | 160 virtual void SetAudioMuted(bool muted) OVERRIDE { |
| 135 return AudioHandler::GetInstance()->SetMuted(muted); | 161 return AudioHandler::GetInstance()->SetMuted(muted); |
| 136 } | 162 } |
| 137 | 163 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 149 | 175 |
| 150 virtual void SignOut() OVERRIDE { | 176 virtual void SignOut() OVERRIDE { |
| 151 BrowserList::AttemptUserExit(); | 177 BrowserList::AttemptUserExit(); |
| 152 } | 178 } |
| 153 | 179 |
| 154 virtual void RequestLockScreen() OVERRIDE { | 180 virtual void RequestLockScreen() OVERRIDE { |
| 155 DBusThreadManager::Get()->GetPowerManagerClient()-> | 181 DBusThreadManager::Get()->GetPowerManagerClient()-> |
| 156 NotifyScreenLockRequested(); | 182 NotifyScreenLockRequested(); |
| 157 } | 183 } |
| 158 | 184 |
| 159 virtual ash::NetworkIconInfo GetMostRelevantNetworkIcon() OVERRIDE { | 185 virtual ash::NetworkIconInfo GetMostRelevantNetworkIcon(bool large) OVERRIDE { |
| 160 ash::NetworkIconInfo info; | 186 ash::NetworkIconInfo info; |
| 161 info.image = network_icon_->GetIconAndText(&info.description); | 187 info.image = !large ? network_icon_->GetIconAndText(&info.description) : |
| 188 network_icon_large_->GetIconAndText(&info.description); |
| 162 return info; | 189 return info; |
| 163 } | 190 } |
| 164 | 191 |
| 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 |
| 165 private: | 258 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 |
| 166 void InitializePrefChangeRegistrar() { | 268 void InitializePrefChangeRegistrar() { |
| 167 Profile* profile = ProfileManager::GetDefaultProfile(); | 269 Profile* profile = ProfileManager::GetDefaultProfile(); |
| 168 pref_registrar_.reset(new PrefChangeRegistrar); | 270 pref_registrar_.reset(new PrefChangeRegistrar); |
| 169 pref_registrar_->Init(profile->GetPrefs()); | 271 pref_registrar_->Init(profile->GetPrefs()); |
| 170 pref_registrar_->Add(prefs::kUse24HourClock, this); | 272 pref_registrar_->Add(prefs::kUse24HourClock, this); |
| 171 } | 273 } |
| 172 | 274 |
| 173 void NotifyRefreshNetwork() { | 275 void NotifyRefreshNetwork() { |
| 174 ash::NetworkController* controller = | 276 ash::NetworkController* controller = |
| 175 ash::Shell::GetInstance()->network_controller(); | 277 ash::Shell::GetInstance()->network_controller(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 325 |
| 224 virtual void UnlockScreen() OVERRIDE { | 326 virtual void UnlockScreen() OVERRIDE { |
| 225 } | 327 } |
| 226 | 328 |
| 227 virtual void UnlockScreenFailed() OVERRIDE { | 329 virtual void UnlockScreenFailed() OVERRIDE { |
| 228 } | 330 } |
| 229 | 331 |
| 230 // TODO(sad): Override more from PowerManagerClient::Observer here (e.g. | 332 // TODO(sad): Override more from PowerManagerClient::Observer here (e.g. |
| 231 // PowerButtonStateChanged etc.). | 333 // PowerButtonStateChanged etc.). |
| 232 | 334 |
| 233 // Overridden from StatusMenuIcon::Delegate. | 335 // Overridden from NetworkMenuIcon::Delegate. |
| 234 virtual void NetworkMenuIconChanged() OVERRIDE { | 336 virtual void NetworkMenuIconChanged() OVERRIDE { |
| 235 NotifyRefreshNetwork(); | 337 NotifyRefreshNetwork(); |
| 236 } | 338 } |
| 237 | 339 |
| 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 |
| 238 // Overridden from NetworkLibrary::NetworkManagerObserver. | 359 // Overridden from NetworkLibrary::NetworkManagerObserver. |
| 239 virtual void OnNetworkManagerChanged(NetworkLibrary* crosnet) OVERRIDE { | 360 virtual void OnNetworkManagerChanged(NetworkLibrary* crosnet) OVERRIDE { |
| 240 RefreshNetworkObserver(crosnet); | 361 RefreshNetworkObserver(crosnet); |
| 241 RefreshNetworkDeviceObserver(crosnet); | 362 RefreshNetworkDeviceObserver(crosnet); |
| 242 | 363 |
| 243 // TODO: ShowOptionalMobileDataPromoNotification? | 364 // TODO: ShowOptionalMobileDataPromoNotification? |
| 244 | 365 |
| 245 NotifyRefreshNetwork(); | 366 NotifyRefreshNetwork(); |
| 246 } | 367 } |
| 247 | 368 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 observer->OnDateFormatChanged(); | 405 observer->OnDateFormatChanged(); |
| 285 break; | 406 break; |
| 286 } | 407 } |
| 287 default: | 408 default: |
| 288 NOTREACHED(); | 409 NOTREACHED(); |
| 289 } | 410 } |
| 290 } | 411 } |
| 291 | 412 |
| 292 ash::SystemTray* tray_; | 413 ash::SystemTray* tray_; |
| 293 scoped_ptr<NetworkMenuIcon> network_icon_; | 414 scoped_ptr<NetworkMenuIcon> network_icon_; |
| 415 scoped_ptr<NetworkMenuIcon> network_icon_large_; |
| 416 scoped_ptr<NetworkMenu> network_menu_; |
| 294 content::NotificationRegistrar registrar_; | 417 content::NotificationRegistrar registrar_; |
| 295 scoped_ptr<PrefChangeRegistrar> pref_registrar_; | 418 scoped_ptr<PrefChangeRegistrar> pref_registrar_; |
| 296 std::string cellular_device_path_; | 419 std::string cellular_device_path_; |
| 297 std::string active_network_path_; | 420 std::string active_network_path_; |
| 421 scoped_ptr<LoginHtmlDialog> proxy_settings_dialog_; |
| 298 | 422 |
| 299 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); | 423 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); |
| 300 }; | 424 }; |
| 301 | 425 |
| 302 } // namespace | 426 } // namespace |
| 303 | 427 |
| 304 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) { | 428 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) { |
| 305 return new chromeos::SystemTrayDelegate(tray); | 429 return new chromeos::SystemTrayDelegate(tray); |
| 306 } | 430 } |
| 307 | 431 |
| 308 } // namespace chromeos | 432 } // namespace chromeos |
| OLD | NEW |