diff options
author | nkostylev@chromium.org <nkostylev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-25 18:26:09 +0000 |
---|---|---|
committer | nkostylev@chromium.org <nkostylev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-25 18:26:09 +0000 |
commit | 81a92963a30b70f2f497c629932e6881d4a948f2 (patch) | |
tree | df8ca19be6f7e60592f323bd4a6eaa2288953e36 | |
parent | 72c40e69227f21d905fc917f02767a617e330e73 (diff) | |
download | chromium_src-81a92963a30b70f2f497c629932e6881d4a948f2.zip chromium_src-81a92963a30b70f2f497c629932e6881d4a948f2.tar.gz chromium_src-81a92963a30b70f2f497c629932e6881d4a948f2.tar.bz2 |
[cros] Add network tray item for mobile network setup.
This item is only shown for GSM modems w/o SIM card and when mobile config has setup URL defined (initial locale specific).
Initial locale (ex.: en-US, de, es) defines a country where ChromeOS device was bought.
Depends on http://codereview.chromium.org/10141006/
BUG=chrome-os-partner:8092
TEST=Manual.
Review URL: http://codereview.chromium.org/10201015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133941 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ash/ash_strings.grd | 3 | ||||
-rw-r--r-- | ash/shell.cc | 5 | ||||
-rw-r--r-- | ash/system/network/tray_network.cc | 35 | ||||
-rw-r--r-- | ash/system/tray/system_tray_delegate.h | 12 | ||||
-rw-r--r-- | chrome/browser/chromeos/cros/network_library.h | 6 | ||||
-rw-r--r-- | chrome/browser/chromeos/status/network_menu.cc | 26 | ||||
-rw-r--r-- | chrome/browser/chromeos/status/network_menu.h | 6 | ||||
-rw-r--r-- | chrome/browser/chromeos/system/ash_system_tray_delegate.cc | 36 | ||||
-rw-r--r-- | chrome/browser/ui/webui/options2/chromeos/internet_options_handler2.cc | 26 | ||||
-rw-r--r-- | chrome/browser/ui/webui/options2/chromeos/internet_options_handler2.h | 6 |
10 files changed, 129 insertions, 32 deletions
diff --git a/ash/ash_strings.grd b/ash/ash_strings.grd index 9fe6c05..0958984 100644 --- a/ash/ash_strings.grd +++ b/ash/ash_strings.grd @@ -240,6 +240,9 @@ This file contains the strings for ash. <message name="IDS_ASH_STATUS_TRAY_DISABLE_MOBILE" desc="The label used for the item to disable cellular networks."> Disable mobile data </message> + <message name="IDS_ASH_STATUS_TRAY_SETUP_MOBILE" desc="The label used for the item to setup cellular network when no SIM card in installed."> + Setup mobile data + </message> <message name="IDS_ASH_STATUS_TRAY_OTHER_MOBILE" desc="The label used for the item to display other cellular networks."> Mobile ... </message> diff --git a/ash/shell.cc b/ash/shell.cc index 83b7aac..38c7cb9 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -458,11 +458,12 @@ class DummySystemTrayDelegate : public SystemTrayDelegate { } virtual bool GetCellularCarrierInfo(std::string* carrier_id, - std::string* toup_url) OVERRIDE { + std::string* topup_url, + std::string* setup_url) OVERRIDE { return false; } - virtual void ShowCellularTopupURL(const std::string& topup_url) OVERRIDE { + virtual void ShowCellularURL(const std::string& url) OVERRIDE { } virtual void ChangeProxySettings() OVERRIDE { diff --git a/ash/system/network/tray_network.cc b/ash/system/network/tray_network.cc index 6b1c772..84e6dd03 100644 --- a/ash/system/network/tray_network.cc +++ b/ash/system/network/tray_network.cc @@ -168,7 +168,8 @@ class NetworkDetailedView : public views::View, info_icon_(NULL), button_wifi_(NULL), button_cellular_(NULL), - mobile_account_(NULL), + view_mobile_account_(NULL), + setup_mobile_account_(NULL), other_wifi_(NULL), other_mobile_(NULL), settings_(NULL), @@ -197,7 +198,8 @@ class NetworkDetailedView : public views::View, info_icon_ = NULL; button_wifi_ = NULL; button_cellular_ = NULL; - mobile_account_ = NULL; + view_mobile_account_ = NULL; + setup_mobile_account_ = NULL; other_wifi_ = NULL; other_mobile_ = NULL; settings_ = NULL; @@ -274,13 +276,17 @@ class NetworkDetailedView : public views::View, } if (login_ != user::LOGGED_IN_NONE) { - std::string carrier_id, topup_url; - if (delegate->GetCellularCarrierInfo(&carrier_id, &topup_url)) { + std::string carrier_id, topup_url, setup_url; + if (delegate->GetCellularCarrierInfo(&carrier_id, + &topup_url, + &setup_url)) { if (carrier_id != carrier_id_) { carrier_id_ = carrier_id; if (!topup_url.empty()) topup_url_ = topup_url; } + if (!setup_url.empty()) + setup_url_ = setup_url; if (!topup_url_.empty()) { HoverHighlightView* container = new HoverHighlightView(this); container->set_fixed_height(kTrayPopupItemHeight); @@ -288,7 +294,16 @@ class NetworkDetailedView : public views::View, GetLocalizedString(IDS_ASH_STATUS_TRAY_MOBILE_VIEW_ACCOUNT), gfx::Font::NORMAL); AddChildView(container); - mobile_account_ = container; + view_mobile_account_ = container; + } + if (!setup_url_.empty()) { + HoverHighlightView* container = new HoverHighlightView(this); + container->set_fixed_height(kTrayPopupItemHeight); + container->AddLabel(ui::ResourceBundle::GetSharedInstance(). + GetLocalizedString(IDS_ASH_STATUS_TRAY_SETUP_MOBILE), + gfx::Font::NORMAL); + AddChildView(container); + setup_mobile_account_ = container; } } } @@ -455,8 +470,10 @@ class NetworkDetailedView : public views::View, if (login_ == user::LOGGED_IN_LOCKED) return; - if (sender == mobile_account_) { - delegate->ShowCellularTopupURL(topup_url_); + if (sender == view_mobile_account_) { + delegate->ShowCellularURL(topup_url_); + } else if (sender == setup_mobile_account_) { + delegate->ShowCellularURL(setup_url_); } else if (sender == airplane_) { delegate->ToggleAirplaneMode(); } else { @@ -471,6 +488,7 @@ class NetworkDetailedView : public views::View, std::string carrier_id_; std::string topup_url_; + std::string setup_url_; user::LoginStatus login_; std::map<views::View*, std::string> network_map_; @@ -481,7 +499,8 @@ class NetworkDetailedView : public views::View, views::ImageButton* info_icon_; views::ToggleImageButton* button_wifi_; views::ToggleImageButton* button_cellular_; - views::View* mobile_account_; + views::View* view_mobile_account_; + views::View* setup_mobile_account_; TrayPopupTextButton* other_wifi_; TrayPopupTextButton* other_mobile_; TrayPopupTextButton* settings_; diff --git a/ash/system/tray/system_tray_delegate.h b/ash/system/tray/system_tray_delegate.h index c399296..3d95d2e 100644 --- a/ash/system/tray/system_tray_delegate.h +++ b/ash/system/tray/system_tray_delegate.h @@ -226,13 +226,15 @@ class SystemTrayDelegate { // Returns whether cellular scanning is supported. virtual bool GetCellularScanSupported() = 0; - // Retrieves information about the carrier. If the information cannot be - // retrieved, returns false. + // Retrieves information about the carrier and locale specific |setup_url|. + // If none of the carrier info/setup URL cannot be retrieved, returns false. + // Note: |setup_url| is returned when carrier is not defined (no SIM card). virtual bool GetCellularCarrierInfo(std::string* carrier_id, - std::string* toup_url) = 0; + std::string* topup_url, + std::string* setup_url) = 0; - // Opens the top up url. - virtual void ShowCellularTopupURL(const std::string& topup_url) = 0; + // Opens the cellular network specific URL. + virtual void ShowCellularURL(const std::string& url) = 0; // Shows UI for changing proxy settings. virtual void ChangeProxySettings() = 0; diff --git a/chrome/browser/chromeos/cros/network_library.h b/chrome/browser/chromeos/cros/network_library.h index f6119b0..f4e9097 100644 --- a/chrome/browser/chromeos/cros/network_library.h +++ b/chrome/browser/chromeos/cros/network_library.h @@ -106,6 +106,12 @@ class NetworkDevice { return sim_lock_state_ == SIM_LOCKED_PIN || sim_lock_state_ == SIM_LOCKED_PUK; } + // Returns true if GSM modem and SIM as absent, otherwise + // returns false: GSM modem and SIM card is present or CDMA modem. + bool is_sim_absent() const { + return technology_family() == TECHNOLOGY_FAMILY_GSM && + !is_sim_locked() && imsi().empty(); + } const int sim_retries_left() const { return sim_retries_left_; } SimPinRequire sim_pin_required() const { return sim_pin_required_; } const std::string& firmware_revision() const { return firmware_revision_; } diff --git a/chrome/browser/chromeos/status/network_menu.cc b/chrome/browser/chromeos/status/network_menu.cc index ab0e818..4293c81 100644 --- a/chrome/browser/chromeos/status/network_menu.cc +++ b/chrome/browser/chromeos/status/network_menu.cc @@ -1064,9 +1064,24 @@ void NetworkMenu::ToggleCellular() { if (!cellular) { LOG(ERROR) << "No cellular device found, it should be available."; cros->EnableCellularNetworkDevice(!cros->cellular_enabled()); - } else if (cellular->sim_lock_state() == SIM_UNLOCKED || - cellular->sim_lock_state() == SIM_UNKNOWN) { - cros->EnableCellularNetworkDevice(!cros->cellular_enabled()); + } else if (!cellular->is_sim_locked()) { + if (cellular->is_sim_absent()) { + std::string setup_url; + MobileConfig* config = MobileConfig::GetInstance(); + if (config->IsReady()) { + const MobileConfig::LocaleConfig* locale_config = + config->GetLocaleConfig(); + if (locale_config) + setup_url = locale_config->setup_url(); + } + if (!setup_url.empty()) { + GetAppropriateBrowser()->ShowSingletonTab(GURL(setup_url)); + } else { + // TODO(nkostylev): Show generic error message. http://crosbug.com/15444 + } + } else { + cros->EnableCellularNetworkDevice(!cros->cellular_enabled()); + } } else { SimDialogDelegate::ShowDialog(delegate()->GetNativeWindow(), SimDialogDelegate::SIM_DIALOG_UNLOCK); @@ -1089,4 +1104,9 @@ bool NetworkMenu::ShouldHighlightNetwork(const Network* network) { return ::ShouldHighlightNetwork(network); } +Browser* NetworkMenu::GetAppropriateBrowser() { + return Browser::GetOrCreateTabbedBrowser( + ProfileManager::GetDefaultProfileOrOffTheRecord()); +} + } // namespace chromeos diff --git a/chrome/browser/chromeos/status/network_menu.h b/chrome/browser/chromeos/status/network_menu.h index 6db277d..57e503a 100644 --- a/chrome/browser/chromeos/status/network_menu.h +++ b/chrome/browser/chromeos/status/network_menu.h @@ -15,6 +15,8 @@ #include "ui/gfx/native_widget_types.h" // gfx::NativeWindow #include "ui/views/controls/button/menu_button_listener.h" +class Browser; + namespace ui { class MenuModel; } @@ -118,6 +120,10 @@ class NetworkMenu { private: friend class NetworkMenuModel; + // Returns the last active browser. If there is no such browser, creates a new + // browser window with an empty tab and returns it. + Browser* GetAppropriateBrowser(); + // Weak ptr to delegate. Delegate* delegate_; diff --git a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc index 1922b4c..eb61bc1 100644 --- a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc +++ b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc @@ -595,25 +595,37 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, } virtual bool GetCellularCarrierInfo(std::string* carrier_id, - std::string* topup_url) OVERRIDE { + std::string* topup_url, + std::string* setup_url) OVERRIDE { + bool result = false; NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); const NetworkDevice* cellular = crosnet->FindCellularDevice(); - if (cellular) { - MobileConfig* config = MobileConfig::GetInstance(); - if (config->IsReady()) { - *carrier_id = crosnet->GetCellularHomeCarrierId(); - const MobileConfig::Carrier* carrier = config->GetCarrier(*carrier_id); - if (carrier) { - *topup_url = carrier->top_up_url(); - return true; + if (!cellular) + return false; + + MobileConfig* config = MobileConfig::GetInstance(); + if (config->IsReady()) { + *carrier_id = crosnet->GetCellularHomeCarrierId(); + const MobileConfig::Carrier* carrier = config->GetCarrier(*carrier_id); + if (carrier) { + *topup_url = carrier->top_up_url(); + result = true; + } + const MobileConfig::LocaleConfig* locale_config = + config->GetLocaleConfig(); + if (locale_config) { + // Only link to setup URL if SIM card is not inserted. + if (cellular->is_sim_absent()) { + *setup_url = locale_config->setup_url(); + result = true; } } } - return false; + return result; } - virtual void ShowCellularTopupURL(const std::string& topup_url) OVERRIDE { - GetAppropriateBrowser()->ShowSingletonTab(GURL(topup_url)); + virtual void ShowCellularURL(const std::string& url) OVERRIDE { + GetAppropriateBrowser()->ShowSingletonTab(GURL(url)); } virtual void ChangeProxySettings() OVERRIDE { diff --git a/chrome/browser/ui/webui/options2/chromeos/internet_options_handler2.cc b/chrome/browser/ui/webui/options2/chromeos/internet_options_handler2.cc index f3440f0..2497c7b 100644 --- a/chrome/browser/ui/webui/options2/chromeos/internet_options_handler2.cc +++ b/chrome/browser/ui/webui/options2/chromeos/internet_options_handler2.cc @@ -37,6 +37,7 @@ #include "chrome/browser/chromeos/status/network_menu_icon.h" #include "chrome/browser/net/pref_proxy_config_tracker.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_window.h" @@ -501,13 +502,29 @@ void InternetOptionsHandler::DisableWifiCallback(const ListValue* args) { } void InternetOptionsHandler::EnableCellularCallback(const ListValue* args) { + // TODO(nkostylev): Code duplication, see NetworkMenu::ToggleCellular(). const chromeos::NetworkDevice* cellular = cros_->FindCellularDevice(); if (!cellular) { LOG(ERROR) << "Didn't find cellular device, it should have been available."; cros_->EnableCellularNetworkDevice(true); - } else if (cellular->sim_lock_state() == chromeos::SIM_UNLOCKED || - cellular->sim_lock_state() == chromeos::SIM_UNKNOWN) { + } else if (!cellular->is_sim_locked()) { + if (cellular->is_sim_absent()) { + std::string setup_url; + chromeos::MobileConfig* config = chromeos::MobileConfig::GetInstance(); + if (config->IsReady()) { + const chromeos::MobileConfig::LocaleConfig* locale_config = + config->GetLocaleConfig(); + if (locale_config) + setup_url = locale_config->setup_url(); + } + if (!setup_url.empty()) { + GetAppropriateBrowser()->ShowSingletonTab(GURL(setup_url)); + } else { + // TODO(nkostylev): Show generic error message. http://crosbug.com/15444 + } + } else { cros_->EnableCellularNetworkDevice(true); + } } else { chromeos::SimDialogDelegate::ShowDialog(GetNativeWindow(), chromeos::SimDialogDelegate::SIM_DIALOG_UNLOCK); @@ -1048,6 +1065,11 @@ gfx::NativeWindow InternetOptionsHandler::GetNativeWindow() const { return browser->window()->GetNativeHandle(); } +Browser* InternetOptionsHandler::GetAppropriateBrowser() { + return Browser::GetOrCreateTabbedBrowser( + ProfileManager::GetDefaultProfileOrOffTheRecord()); +} + void InternetOptionsHandler::ButtonClickCallback(const ListValue* args) { std::string str_type; std::string service_path; diff --git a/chrome/browser/ui/webui/options2/chromeos/internet_options_handler2.h b/chrome/browser/ui/webui/options2/chromeos/internet_options_handler2.h index 4cdcca5..d829d89 100644 --- a/chrome/browser/ui/webui/options2/chromeos/internet_options_handler2.h +++ b/chrome/browser/ui/webui/options2/chromeos/internet_options_handler2.h @@ -14,7 +14,9 @@ #include "content/public/browser/notification_registrar.h" #include "ui/gfx/native_widget_types.h" +class Browser; class SkBitmap; + namespace views { class WidgetDelegate; } @@ -59,6 +61,10 @@ class InternetOptionsHandler void CreateModalPopup(views::WidgetDelegate* view); gfx::NativeWindow GetNativeWindow() const; + // Returns the last active browser. If there is no such browser, creates a new + // browser window with an empty tab and returns it. + Browser* GetAppropriateBrowser(); + // Passes data needed to show details overlay for network. // |args| will be [ network_type, service_path, command ] // And command is one of 'options', 'connect', disconnect', 'activate' or |