[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
parent 72c40e69
...@@ -240,6 +240,9 @@ This file contains the strings for ash. ...@@ -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."> <message name="IDS_ASH_STATUS_TRAY_DISABLE_MOBILE" desc="The label used for the item to disable cellular networks.">
Disable mobile data Disable mobile data
</message> </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."> <message name="IDS_ASH_STATUS_TRAY_OTHER_MOBILE" desc="The label used for the item to display other cellular networks.">
Mobile ... Mobile ...
</message> </message>
......
...@@ -458,11 +458,12 @@ class DummySystemTrayDelegate : public SystemTrayDelegate { ...@@ -458,11 +458,12 @@ class DummySystemTrayDelegate : public SystemTrayDelegate {
} }
virtual bool GetCellularCarrierInfo(std::string* carrier_id, virtual bool GetCellularCarrierInfo(std::string* carrier_id,
std::string* toup_url) OVERRIDE { std::string* topup_url,
std::string* setup_url) OVERRIDE {
return false; return false;
} }
virtual void ShowCellularTopupURL(const std::string& topup_url) OVERRIDE { virtual void ShowCellularURL(const std::string& url) OVERRIDE {
} }
virtual void ChangeProxySettings() OVERRIDE { virtual void ChangeProxySettings() OVERRIDE {
......
...@@ -168,7 +168,8 @@ class NetworkDetailedView : public views::View, ...@@ -168,7 +168,8 @@ class NetworkDetailedView : public views::View,
info_icon_(NULL), info_icon_(NULL),
button_wifi_(NULL), button_wifi_(NULL),
button_cellular_(NULL), button_cellular_(NULL),
mobile_account_(NULL), view_mobile_account_(NULL),
setup_mobile_account_(NULL),
other_wifi_(NULL), other_wifi_(NULL),
other_mobile_(NULL), other_mobile_(NULL),
settings_(NULL), settings_(NULL),
...@@ -197,7 +198,8 @@ class NetworkDetailedView : public views::View, ...@@ -197,7 +198,8 @@ class NetworkDetailedView : public views::View,
info_icon_ = NULL; info_icon_ = NULL;
button_wifi_ = NULL; button_wifi_ = NULL;
button_cellular_ = NULL; button_cellular_ = NULL;
mobile_account_ = NULL; view_mobile_account_ = NULL;
setup_mobile_account_ = NULL;
other_wifi_ = NULL; other_wifi_ = NULL;
other_mobile_ = NULL; other_mobile_ = NULL;
settings_ = NULL; settings_ = NULL;
...@@ -274,13 +276,17 @@ class NetworkDetailedView : public views::View, ...@@ -274,13 +276,17 @@ class NetworkDetailedView : public views::View,
} }
if (login_ != user::LOGGED_IN_NONE) { if (login_ != user::LOGGED_IN_NONE) {
std::string carrier_id, topup_url; std::string carrier_id, topup_url, setup_url;
if (delegate->GetCellularCarrierInfo(&carrier_id, &topup_url)) { if (delegate->GetCellularCarrierInfo(&carrier_id,
&topup_url,
&setup_url)) {
if (carrier_id != carrier_id_) { if (carrier_id != carrier_id_) {
carrier_id_ = carrier_id; carrier_id_ = carrier_id;
if (!topup_url.empty()) if (!topup_url.empty())
topup_url_ = topup_url; topup_url_ = topup_url;
} }
if (!setup_url.empty())
setup_url_ = setup_url;
if (!topup_url_.empty()) { if (!topup_url_.empty()) {
HoverHighlightView* container = new HoverHighlightView(this); HoverHighlightView* container = new HoverHighlightView(this);
container->set_fixed_height(kTrayPopupItemHeight); container->set_fixed_height(kTrayPopupItemHeight);
...@@ -288,7 +294,16 @@ class NetworkDetailedView : public views::View, ...@@ -288,7 +294,16 @@ class NetworkDetailedView : public views::View,
GetLocalizedString(IDS_ASH_STATUS_TRAY_MOBILE_VIEW_ACCOUNT), GetLocalizedString(IDS_ASH_STATUS_TRAY_MOBILE_VIEW_ACCOUNT),
gfx::Font::NORMAL); gfx::Font::NORMAL);
AddChildView(container); 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, ...@@ -455,8 +470,10 @@ class NetworkDetailedView : public views::View,
if (login_ == user::LOGGED_IN_LOCKED) if (login_ == user::LOGGED_IN_LOCKED)
return; return;
if (sender == mobile_account_) { if (sender == view_mobile_account_) {
delegate->ShowCellularTopupURL(topup_url_); delegate->ShowCellularURL(topup_url_);
} else if (sender == setup_mobile_account_) {
delegate->ShowCellularURL(setup_url_);
} else if (sender == airplane_) { } else if (sender == airplane_) {
delegate->ToggleAirplaneMode(); delegate->ToggleAirplaneMode();
} else { } else {
...@@ -471,6 +488,7 @@ class NetworkDetailedView : public views::View, ...@@ -471,6 +488,7 @@ class NetworkDetailedView : public views::View,
std::string carrier_id_; std::string carrier_id_;
std::string topup_url_; std::string topup_url_;
std::string setup_url_;
user::LoginStatus login_; user::LoginStatus login_;
std::map<views::View*, std::string> network_map_; std::map<views::View*, std::string> network_map_;
...@@ -481,7 +499,8 @@ class NetworkDetailedView : public views::View, ...@@ -481,7 +499,8 @@ class NetworkDetailedView : public views::View,
views::ImageButton* info_icon_; views::ImageButton* info_icon_;
views::ToggleImageButton* button_wifi_; views::ToggleImageButton* button_wifi_;
views::ToggleImageButton* button_cellular_; views::ToggleImageButton* button_cellular_;
views::View* mobile_account_; views::View* view_mobile_account_;
views::View* setup_mobile_account_;
TrayPopupTextButton* other_wifi_; TrayPopupTextButton* other_wifi_;
TrayPopupTextButton* other_mobile_; TrayPopupTextButton* other_mobile_;
TrayPopupTextButton* settings_; TrayPopupTextButton* settings_;
......
...@@ -226,13 +226,15 @@ class SystemTrayDelegate { ...@@ -226,13 +226,15 @@ class SystemTrayDelegate {
// Returns whether cellular scanning is supported. // Returns whether cellular scanning is supported.
virtual bool GetCellularScanSupported() = 0; virtual bool GetCellularScanSupported() = 0;
// Retrieves information about the carrier. If the information cannot be // Retrieves information about the carrier and locale specific |setup_url|.
// retrieved, returns false. // 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, 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. // Opens the cellular network specific URL.
virtual void ShowCellularTopupURL(const std::string& topup_url) = 0; virtual void ShowCellularURL(const std::string& url) = 0;
// Shows UI for changing proxy settings. // Shows UI for changing proxy settings.
virtual void ChangeProxySettings() = 0; virtual void ChangeProxySettings() = 0;
......
...@@ -106,6 +106,12 @@ class NetworkDevice { ...@@ -106,6 +106,12 @@ class NetworkDevice {
return sim_lock_state_ == SIM_LOCKED_PIN || return sim_lock_state_ == SIM_LOCKED_PIN ||
sim_lock_state_ == SIM_LOCKED_PUK; 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_; } const int sim_retries_left() const { return sim_retries_left_; }
SimPinRequire sim_pin_required() const { return sim_pin_required_; } SimPinRequire sim_pin_required() const { return sim_pin_required_; }
const std::string& firmware_revision() const { return firmware_revision_; } const std::string& firmware_revision() const { return firmware_revision_; }
......
...@@ -1064,9 +1064,24 @@ void NetworkMenu::ToggleCellular() { ...@@ -1064,9 +1064,24 @@ void NetworkMenu::ToggleCellular() {
if (!cellular) { if (!cellular) {
LOG(ERROR) << "No cellular device found, it should be available."; LOG(ERROR) << "No cellular device found, it should be available.";
cros->EnableCellularNetworkDevice(!cros->cellular_enabled()); cros->EnableCellularNetworkDevice(!cros->cellular_enabled());
} else if (cellular->sim_lock_state() == SIM_UNLOCKED || } else if (!cellular->is_sim_locked()) {
cellular->sim_lock_state() == SIM_UNKNOWN) { if (cellular->is_sim_absent()) {
cros->EnableCellularNetworkDevice(!cros->cellular_enabled()); 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 { } else {
SimDialogDelegate::ShowDialog(delegate()->GetNativeWindow(), SimDialogDelegate::ShowDialog(delegate()->GetNativeWindow(),
SimDialogDelegate::SIM_DIALOG_UNLOCK); SimDialogDelegate::SIM_DIALOG_UNLOCK);
...@@ -1089,4 +1104,9 @@ bool NetworkMenu::ShouldHighlightNetwork(const Network* network) { ...@@ -1089,4 +1104,9 @@ bool NetworkMenu::ShouldHighlightNetwork(const Network* network) {
return ::ShouldHighlightNetwork(network); return ::ShouldHighlightNetwork(network);
} }
Browser* NetworkMenu::GetAppropriateBrowser() {
return Browser::GetOrCreateTabbedBrowser(
ProfileManager::GetDefaultProfileOrOffTheRecord());
}
} // namespace chromeos } // namespace chromeos
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#include "ui/gfx/native_widget_types.h" // gfx::NativeWindow #include "ui/gfx/native_widget_types.h" // gfx::NativeWindow
#include "ui/views/controls/button/menu_button_listener.h" #include "ui/views/controls/button/menu_button_listener.h"
class Browser;
namespace ui { namespace ui {
class MenuModel; class MenuModel;
} }
...@@ -118,6 +120,10 @@ class NetworkMenu { ...@@ -118,6 +120,10 @@ class NetworkMenu {
private: private:
friend class NetworkMenuModel; 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. // Weak ptr to delegate.
Delegate* delegate_; Delegate* delegate_;
......
...@@ -595,25 +595,37 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, ...@@ -595,25 +595,37 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate,
} }
virtual bool GetCellularCarrierInfo(std::string* carrier_id, 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(); NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary();
const NetworkDevice* cellular = crosnet->FindCellularDevice(); const NetworkDevice* cellular = crosnet->FindCellularDevice();
if (cellular) { if (!cellular)
MobileConfig* config = MobileConfig::GetInstance(); return false;
if (config->IsReady()) {
*carrier_id = crosnet->GetCellularHomeCarrierId(); MobileConfig* config = MobileConfig::GetInstance();
const MobileConfig::Carrier* carrier = config->GetCarrier(*carrier_id); if (config->IsReady()) {
if (carrier) { *carrier_id = crosnet->GetCellularHomeCarrierId();
*topup_url = carrier->top_up_url(); const MobileConfig::Carrier* carrier = config->GetCarrier(*carrier_id);
return true; 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 { virtual void ShowCellularURL(const std::string& url) OVERRIDE {
GetAppropriateBrowser()->ShowSingletonTab(GURL(topup_url)); GetAppropriateBrowser()->ShowSingletonTab(GURL(url));
} }
virtual void ChangeProxySettings() OVERRIDE { virtual void ChangeProxySettings() OVERRIDE {
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "chrome/browser/chromeos/status/network_menu_icon.h" #include "chrome/browser/chromeos/status/network_menu_icon.h"
#include "chrome/browser/net/pref_proxy_config_tracker.h" #include "chrome/browser/net/pref_proxy_config_tracker.h"
#include "chrome/browser/profiles/profile.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.h"
#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
...@@ -501,13 +502,29 @@ void InternetOptionsHandler::DisableWifiCallback(const ListValue* args) { ...@@ -501,13 +502,29 @@ void InternetOptionsHandler::DisableWifiCallback(const ListValue* args) {
} }
void InternetOptionsHandler::EnableCellularCallback(const ListValue* args) { void InternetOptionsHandler::EnableCellularCallback(const ListValue* args) {
// TODO(nkostylev): Code duplication, see NetworkMenu::ToggleCellular().
const chromeos::NetworkDevice* cellular = cros_->FindCellularDevice(); const chromeos::NetworkDevice* cellular = cros_->FindCellularDevice();
if (!cellular) { if (!cellular) {
LOG(ERROR) << "Didn't find cellular device, it should have been available."; LOG(ERROR) << "Didn't find cellular device, it should have been available.";
cros_->EnableCellularNetworkDevice(true); cros_->EnableCellularNetworkDevice(true);
} else if (cellular->sim_lock_state() == chromeos::SIM_UNLOCKED || } else if (!cellular->is_sim_locked()) {
cellular->sim_lock_state() == chromeos::SIM_UNKNOWN) { 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); cros_->EnableCellularNetworkDevice(true);
}
} else { } else {
chromeos::SimDialogDelegate::ShowDialog(GetNativeWindow(), chromeos::SimDialogDelegate::ShowDialog(GetNativeWindow(),
chromeos::SimDialogDelegate::SIM_DIALOG_UNLOCK); chromeos::SimDialogDelegate::SIM_DIALOG_UNLOCK);
...@@ -1048,6 +1065,11 @@ gfx::NativeWindow InternetOptionsHandler::GetNativeWindow() const { ...@@ -1048,6 +1065,11 @@ gfx::NativeWindow InternetOptionsHandler::GetNativeWindow() const {
return browser->window()->GetNativeHandle(); return browser->window()->GetNativeHandle();
} }
Browser* InternetOptionsHandler::GetAppropriateBrowser() {
return Browser::GetOrCreateTabbedBrowser(
ProfileManager::GetDefaultProfileOrOffTheRecord());
}
void InternetOptionsHandler::ButtonClickCallback(const ListValue* args) { void InternetOptionsHandler::ButtonClickCallback(const ListValue* args) {
std::string str_type; std::string str_type;
std::string service_path; std::string service_path;
......
...@@ -14,7 +14,9 @@ ...@@ -14,7 +14,9 @@
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
class Browser;
class SkBitmap; class SkBitmap;
namespace views { namespace views {
class WidgetDelegate; class WidgetDelegate;
} }
...@@ -59,6 +61,10 @@ class InternetOptionsHandler ...@@ -59,6 +61,10 @@ class InternetOptionsHandler
void CreateModalPopup(views::WidgetDelegate* view); void CreateModalPopup(views::WidgetDelegate* view);
gfx::NativeWindow GetNativeWindow() const; 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. // Passes data needed to show details overlay for network.
// |args| will be [ network_type, service_path, command ] // |args| will be [ network_type, service_path, command ]
// And command is one of 'options', 'connect', disconnect', 'activate' or // And command is one of 'options', 'connect', disconnect', 'activate' or
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment