Chromium Code Reviews| Index: chrome/browser/chromeos/system/ash_system_tray_delegate.cc |
| diff --git a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc |
| index 6c7712fa1d12d979a2eb3bcd6a750b3caf08b9f5..54240547b17a652920ffbd96129667f95394012c 100644 |
| --- a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc |
| +++ b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc |
| @@ -5,6 +5,7 @@ |
| #include "chrome/browser/chromeos/system/ash_system_tray_delegate.h" |
| #include "ash/shell.h" |
| +#include "ash/shell_window_ids.h" |
| #include "ash/system/audio/audio_controller.h" |
| #include "ash/system/brightness/brightness_controller.h" |
| #include "ash/system/network/network_controller.h" |
| @@ -12,28 +13,44 @@ |
| #include "ash/system/tray/system_tray.h" |
| #include "ash/system/tray/system_tray_delegate.h" |
| #include "base/logging.h" |
| +#include "base/utf_string_conversions.h" |
| #include "chrome/browser/chromeos/audio/audio_handler.h" |
| #include "chrome/browser/chromeos/cros/cros_library.h" |
| #include "chrome/browser/chromeos/cros/network_library.h" |
| #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
| #include "chrome/browser/chromeos/dbus/power_manager_client.h" |
| +#include "chrome/browser/chromeos/login/login_html_dialog.h" |
| +#include "chrome/browser/chromeos/login/proxy_settings_dialog.h" |
| #include "chrome/browser/chromeos/login/user.h" |
| #include "chrome/browser/chromeos/login/user_manager.h" |
| +#include "chrome/browser/chromeos/status/network_menu.h" |
| #include "chrome/browser/chromeos/status/network_menu_icon.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/browser_list.h" |
| #include "chrome/common/chrome_notification_types.h" |
| #include "content/public/browser/notification_observer.h" |
| #include "content/public/browser/notification_service.h" |
| +#include "grit/generated_resources.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| namespace chromeos { |
| namespace { |
| +ash::NetworkIconInfo CreateNetworkIconInfo(const Network* network, |
| + NetworkMenuIcon* network_icon) { |
| + ash::NetworkIconInfo info; |
| + info.name = UTF8ToUTF16(network->name()); |
| + info.image = network_icon->GetBitmap(network, NetworkMenuIcon::SIZE_SMALL); |
| + info.unique_id = network->unique_id(); |
| + return info; |
| +} |
| + |
| class SystemTrayDelegate : public ash::SystemTrayDelegate, |
| public AudioHandler::VolumeObserver, |
| public PowerManagerClient::Observer, |
| public NetworkMenuIcon::Delegate, |
| + public NetworkMenu::Delegate, |
| public NetworkLibrary::NetworkManagerObserver, |
| public NetworkLibrary::NetworkObserver, |
| public NetworkLibrary::CellularDataPlanObserver, |
| @@ -42,7 +59,10 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, |
| explicit SystemTrayDelegate(ash::SystemTray* tray) |
| : tray_(tray), |
| network_icon_(ALLOW_THIS_IN_INITIALIZER_LIST( |
| - new NetworkMenuIcon(this, NetworkMenuIcon::MENU_MODE))) { |
| + new NetworkMenuIcon(this, NetworkMenuIcon::MENU_MODE))), |
| + network_icon_large_(ALLOW_THIS_IN_INITIALIZER_LIST( |
| + new NetworkMenuIcon(this, NetworkMenuIcon::MENU_MODE))), |
| + network_menu_(ALLOW_THIS_IN_INITIALIZER_LIST(new NetworkMenu(this))) { |
| AudioHandler::GetInstance()->AddVolumeObserver(this); |
| DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); |
| DBusThreadManager::Get()->GetPowerManagerClient()->RequestStatusUpdate( |
| @@ -56,6 +76,8 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, |
| registrar_.Add(this, |
| chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| content::NotificationService::AllSources()); |
| + |
| + network_icon_large_->SetResourceSize(NetworkMenuIcon::SIZE_LARGE); |
| } |
| virtual ~SystemTrayDelegate() { |
| @@ -90,15 +112,27 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, |
| } |
| virtual void ShowSettings() OVERRIDE { |
| - BrowserList::GetLastActive()->OpenOptionsDialog(); |
| + Browser* browser = BrowserList::GetLastActive(); |
| + if (browser) |
| + browser->OpenOptionsDialog(); |
| } |
| virtual void ShowDateSettings() OVERRIDE { |
| - BrowserList::GetLastActive()->OpenAdvancedOptionsDialog(); |
| + Browser* browser = BrowserList::GetLastActive(); |
| + if (browser) |
| + browser->OpenAdvancedOptionsDialog(); |
| + } |
| + |
| + virtual void ShowNetworkSettings() OVERRIDE { |
| + Browser* browser = BrowserList::GetLastActive(); |
| + if (browser) |
| + browser->OpenInternetOptionsDialog(); |
| } |
| virtual void ShowHelp() OVERRIDE { |
| - BrowserList::GetLastActive()->ShowHelpTab(); |
| + Browser* browser = BrowserList::GetLastActive(); |
| + if (browser) |
| + browser->ShowHelpTab(); |
| } |
| virtual bool IsAudioMuted() const OVERRIDE { |
| @@ -130,12 +164,81 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, |
| NotifyScreenLockRequested(); |
| } |
| - virtual ash::NetworkIconInfo GetMostRelevantNetworkIcon() OVERRIDE { |
| + virtual ash::NetworkIconInfo GetMostRelevantNetworkIcon(bool large) OVERRIDE { |
| ash::NetworkIconInfo info; |
| - info.image = network_icon_->GetIconAndText(&info.description); |
| + info.image = !large ? network_icon_->GetIconAndText(&info.description) : |
| + network_icon_large_->GetIconAndText(&info.description); |
| return info; |
| } |
| + virtual void GetAvailableNetworks( |
| + std::vector<ash::NetworkIconInfo>* list) OVERRIDE { |
| + NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); |
| + crosnet->RequestNetworkScan(); |
| + |
| + // Ethernet. |
| + if (crosnet->ethernet_enabled()) { |
| + const EthernetNetwork* ethernet_network = crosnet->ethernet_network(); |
| + if (ethernet_network) { |
| + ash::NetworkIconInfo info; |
| + info.image = network_icon_->GetBitmap(ethernet_network, |
| + NetworkMenuIcon::SIZE_SMALL); |
| + if (!ethernet_network->name().empty()) |
| + info.name = UTF8ToUTF16(ethernet_network->name()); |
| + else |
| + info.name = |
| + l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET); |
| + info.unique_id = ethernet_network->unique_id(); |
| + list->push_back(info); |
| + } |
| + } |
| + |
| + // Wifi. |
| + if (crosnet->wifi_available() && crosnet->wifi_enabled()) { |
| + const WifiNetworkVector& wifi = crosnet->wifi_networks(); |
| + for (size_t i = 0; i < wifi.size(); ++i) |
| + list->push_back(CreateNetworkIconInfo(wifi[i], network_icon_.get())); |
| + } |
| + |
| + // Cellular. |
| + if (crosnet->cellular_available() && crosnet->cellular_enabled()) { |
| + const CellularNetworkVector& cell = crosnet->cellular_networks(); |
| + for (size_t i = 0; i < cell.size(); ++i) |
| + list->push_back(CreateNetworkIconInfo(cell[i], network_icon_.get())); |
| + } |
| + |
| + // VPN (only if logged in). |
| + if (GetUserLoginStatus() == ash::user::LOGGED_IN_NONE) |
| + return; |
| + if (crosnet->connected_network() || crosnet->virtual_network_connected()) { |
| + const VirtualNetworkVector& vpns = crosnet->virtual_networks(); |
| + for (size_t i = 0; i < vpns.size(); ++i) |
| + list->push_back(CreateNetworkIconInfo(vpns[i], network_icon_.get())); |
| + } |
| + } |
| + |
| + virtual void ConnectToNetwork(const std::string& network_id) OVERRIDE { |
| + NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); |
| + Network* network = crosnet->FindNetworkByUniqueId(network_id); |
| + if (network) |
| + network_menu_->ConnectToNetwork(network); |
| + } |
| + |
| + virtual void ToggleAirplaneMode() OVERRIDE { |
| + NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); |
| + crosnet->EnableOfflineMode(!crosnet->offline_mode()); |
| + } |
| + |
| + virtual void ChangeProxySettings() OVERRIDE { |
| + CHECK(GetUserLoginStatus() == ash::user::LOGGED_IN_NONE); |
| + if (!proxy_settings_dialog_.get()) { |
| + ash::Shell* shell = ash::Shell::GetInstance(); |
| + proxy_settings_dialog_.reset(new ProxySettingsDialog(NULL, shell-> |
| + GetContainer(ash::internal::kShellWindowId_SettingBubbleContainer))); |
| + } |
| + proxy_settings_dialog_->Show(); |
| + } |
| + |
| private: |
| void NotifyRefreshNetwork() { |
| ash::NetworkController* controller = |
| @@ -197,11 +300,27 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, |
| // TODO(sad): Override more from PowerManagerClient::Observer here (e.g. |
| // PowerButtonStateChanged etc.). |
| - // Overridden from StatusMenuIcon::Delegate. |
| + // Overridden from NetworkMenuIcon::Delegate. |
| virtual void NetworkMenuIconChanged() OVERRIDE { |
| NotifyRefreshNetwork(); |
| } |
| + // Overridden from NetworkMenu::Delegate. |
| + virtual views::MenuButton* GetMenuButton() OVERRIDE { |
| + return NULL; |
| + } |
| + |
| + virtual gfx::NativeWindow GetNativeWindow() const OVERRIDE { |
| + return NULL; |
|
Nikita (slow)
2012/03/13 15:36:33
This method is not called when NetworkMenu opens i
Nikita (slow)
2012/03/13 15:37:04
This was a question.
sadrul
2012/03/13 15:48:39
I have changed this to return the ash container in
|
| + } |
| + |
| + virtual void OpenButtonOptions() OVERRIDE { |
| + } |
| + |
| + virtual bool ShouldOpenButtonOptions() const OVERRIDE { |
| + return false; |
| + } |
| + |
| // Overridden from NetworkLibrary::NetworkManagerObserver. |
| virtual void OnNetworkManagerChanged(NetworkLibrary* crosnet) OVERRIDE { |
| RefreshNetworkObserver(crosnet); |
| @@ -239,9 +358,12 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, |
| ash::SystemTray* tray_; |
| scoped_ptr<NetworkMenuIcon> network_icon_; |
| + scoped_ptr<NetworkMenuIcon> network_icon_large_; |
| + scoped_ptr<NetworkMenu> network_menu_; |
| content::NotificationRegistrar registrar_; |
| std::string cellular_device_path_; |
| std::string active_network_path_; |
| + scoped_ptr<LoginHtmlDialog> proxy_settings_dialog_; |
|
Nikita (slow)
2012/03/13 15:36:33
Should be removed.
sadrul
2012/03/13 15:48:39
Done.
|
| DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); |
| }; |