Commit 0064b506 authored by rkc@chromium.org's avatar rkc@chromium.org

Add the ability to activate for carriers that need to be directly activated.

Currently if we try to activate on a carrier like Sprint, which does not use any activation process, we'll not be able to via the UI. In fact, we'll end up using the Verizon activation process which will completely fail. This CL fixes that.
Additionally, this CL also fixes the issue that once the details page is up, the connection state data (and the corresponding state of the various buttons on the page) is not updated as the network updates itself. This affects celluar but also WiFi.

R=gspencer@chromium.org
BUG=chrome-os-partner:14111


Review URL: https://chromiumcodereview.appspot.com/11829015

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175984 0039d316-1c4b-4281-b951-d872f2087c98
parent 84a318a8
...@@ -34,6 +34,19 @@ cr.define('options.internet', function() { ...@@ -34,6 +34,19 @@ cr.define('options.internet', function() {
} }
} }
/*
* Helper function to update the properties of the data object from the
* properties in the update object.
* @param {object} data object to update.
* @param {object} object containing the updated properties.
*/
function updateDataObject(data, update) {
for (prop in update) {
if (prop in data)
data[prop] = update[prop];
}
}
/** /**
* Monitor pref change of given element. * Monitor pref change of given element.
* @param {Element} el Target element. * @param {Element} el Target element.
...@@ -492,7 +505,6 @@ cr.define('options.internet', function() { ...@@ -492,7 +505,6 @@ cr.define('options.internet', function() {
chrome.send('setCarrier', [data.servicePath, carrier]); chrome.send('setCarrier', [data.servicePath, carrier]);
}; };
/** /**
* Performs minimal initialization of the InternetDetails dialog in * Performs minimal initialization of the InternetDetails dialog in
* preparation for showing proxy-setttings. * preparation for showing proxy-setttings.
...@@ -682,6 +694,47 @@ cr.define('options.internet', function() { ...@@ -682,6 +694,47 @@ cr.define('options.internet', function() {
} }
}; };
DetailsInternetPage.updateConnectionData = function(update) {
var detailsPage = DetailsInternetPage.getInstance();
if (!detailsPage.visible)
return;
var data = $('connection-state').data;
if (!data)
return;
// Update our cached data object.
updateDataObject(data, update);
detailsPage.deviceConnected = data.deviceConnected;
detailsPage.connecting = data.connecting;
detailsPage.connected = data.connected;
$('connection-state').textContent = data.connectionState;
$('details-internet-login').hidden = data.connected;
$('details-internet-login').disabled = data.disableConnectButton;
if (data.type == Constants.TYPE_WIFI) {
$('wifi-connection-state').textContent = data.connectionState;
} else if (data.type == Constants.TYPE_WIMAX) {
$('wimax-connection-state').textContent = data.connectionState;
} else if (data.type == Constants.TYPE_CELLULAR) {
$('activation-state').textContent = data.activationState;
$('buyplan-details').hidden = !data.showBuyButton;
$('view-account-details').hidden = !data.showViewAccountButton;
$('activate-details').hidden = !data.showActivateButton;
if (data.showActivateButton)
$('details-internet-login').hidden = true;
}
if (data.type != Constants.TYPE_ETHERNET)
$('details-internet-disconnect').hidden = !data.connected;
$('connection-state').data = data;
}
DetailsInternetPage.showDetailedInfo = function(data) { DetailsInternetPage.showDetailedInfo = function(data) {
var detailsPage = DetailsInternetPage.getInstance(); var detailsPage = DetailsInternetPage.getInstance();
...@@ -728,6 +781,7 @@ cr.define('options.internet', function() { ...@@ -728,6 +781,7 @@ cr.define('options.internet', function() {
$('activate-details').hidden = true; $('activate-details').hidden = true;
$('view-account-details').hidden = true; $('view-account-details').hidden = true;
$('details-internet-login').hidden = data.connected; $('details-internet-login').hidden = data.connected;
$('details-internet-login').disabled = data.disableConnectButton;
if (data.type == Constants.TYPE_ETHERNET) if (data.type == Constants.TYPE_ETHERNET)
$('details-internet-disconnect').hidden = true; $('details-internet-disconnect').hidden = true;
else else
......
...@@ -112,6 +112,8 @@ const char kSetDefaultNetworkIconsFunction[] = ...@@ -112,6 +112,8 @@ const char kSetDefaultNetworkIconsFunction[] =
"options.network.NetworkList.setDefaultNetworkIcons"; "options.network.NetworkList.setDefaultNetworkIcons";
const char kShowDetailedInfoFunction[] = const char kShowDetailedInfoFunction[] =
"options.internet.DetailsInternetPage.showDetailedInfo"; "options.internet.DetailsInternetPage.showDetailedInfo";
const char kUpdateConnectionDataFunction[] =
"options.internet.DetailsInternetPage.updateConnectionData";
const char kUpdateCarrierFunction[] = const char kUpdateCarrierFunction[] =
"options.internet.DetailsInternetPage.updateCarrier"; "options.internet.DetailsInternetPage.updateCarrier";
const char kUpdateSecurityTabFunction[] = const char kUpdateSecurityTabFunction[] =
...@@ -161,6 +163,7 @@ const char kTagConnectionState[] = "connectionState"; ...@@ -161,6 +163,7 @@ const char kTagConnectionState[] = "connectionState";
const char kTagControlledBy[] = "controlledBy"; const char kTagControlledBy[] = "controlledBy";
const char kTagDataRemaining[] = "dataRemaining"; const char kTagDataRemaining[] = "dataRemaining";
const char kTagDeviceConnected[] = "deviceConnected"; const char kTagDeviceConnected[] = "deviceConnected";
const char kTagDisableConnectButton[] = "disableConnectButton";
const char kTagDisconnect[] = "disconnect"; const char kTagDisconnect[] = "disconnect";
const char kTagEncryption[] = "encryption"; const char kTagEncryption[] = "encryption";
const char kTagErrorState[] = "errorState"; const char kTagErrorState[] = "errorState";
...@@ -525,6 +528,30 @@ void PopulateVPNDetails( ...@@ -525,6 +528,30 @@ void PopulateVPNDetails(
hostname_ui_data); hostname_ui_data);
} }
// Activate the cellular device pointed to by the service path.
void Activate(std::string service_path) {
chromeos::Network* network = NULL;
if (!service_path.empty()) {
network = chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
FindNetworkByPath(service_path);
} else {
NOTREACHED();
return;
}
if (network->type() != chromeos::TYPE_CELLULAR)
return;
static_cast<chromeos::CellularNetwork*>(network)->StartActivation();
}
// Check if the current cellular device can be activated by directly calling
// it's activate function instead of going through the activation process.
// Note: Currently Sprint is the only carrier that uses this.
bool UseDirectActivation() {
const chromeos::NetworkDevice* device =
chromeos::CrosLibrary::Get()->GetNetworkLibrary()->FindCellularDevice();
return device && (device->carrier() == shill::kCarrierSprint);
}
// Given a list of supported carrier's by the device, return the index of // Given a list of supported carrier's by the device, return the index of
// the carrier the device is currently using. // the carrier the device is currently using.
int FindCurrentCarrierIndex(const base::ListValue* carriers, int FindCurrentCarrierIndex(const base::ListValue* carriers,
...@@ -991,6 +1018,14 @@ void InternetOptionsHandler::RefreshNetworkData() { ...@@ -991,6 +1018,14 @@ void InternetOptionsHandler::RefreshNetworkData() {
kRefreshNetworkDataFunction, dictionary); kRefreshNetworkDataFunction, dictionary);
} }
void InternetOptionsHandler::UpdateConnectionData(
const chromeos::Network* network) {
DictionaryValue dictionary;
PopulateConnectionDetails(network, &dictionary);
web_ui()->CallJavascriptFunction(
kUpdateConnectionDataFunction, dictionary);
}
void InternetOptionsHandler::UpdateCarrier(bool success) { void InternetOptionsHandler::UpdateCarrier(bool success) {
base::FundamentalValue success_value(success); base::FundamentalValue success_value(success);
web_ui()->CallJavascriptFunction(kUpdateCarrierFunction, success_value); web_ui()->CallJavascriptFunction(kUpdateCarrierFunction, success_value);
...@@ -1007,8 +1042,10 @@ void InternetOptionsHandler::OnNetworkManagerChanged( ...@@ -1007,8 +1042,10 @@ void InternetOptionsHandler::OnNetworkManagerChanged(
void InternetOptionsHandler::OnNetworkChanged( void InternetOptionsHandler::OnNetworkChanged(
chromeos::NetworkLibrary* cros, chromeos::NetworkLibrary* cros,
const chromeos::Network* network) { const chromeos::Network* network) {
if (web_ui()) if (web_ui()) {
RefreshNetworkData(); RefreshNetworkData();
UpdateConnectionData(network);
}
} }
// Monitor wireless networks for changes. It is only necessary // Monitor wireless networks for changes. It is only necessary
...@@ -1282,10 +1319,6 @@ void InternetOptionsHandler::PopulateIPConfigsCallback( ...@@ -1282,10 +1319,6 @@ void InternetOptionsHandler::PopulateIPConfigsCallback(
chromeos::ConnectionType type = network->type(); chromeos::ConnectionType type = network->type();
dictionary.SetInteger(kTagType, type); dictionary.SetInteger(kTagType, type);
dictionary.SetString(kTagServicePath, network->service_path()); dictionary.SetString(kTagServicePath, network->service_path());
dictionary.SetBoolean(kTagConnecting, network->connecting());
dictionary.SetBoolean(kTagConnected, network->connected());
dictionary.SetString(kTagConnectionState, network->GetStateString());
dictionary.SetString(kTagNetworkName, network->name());
dictionary.SetString(kTagNameServerType, name_server_type); dictionary.SetString(kTagNameServerType, name_server_type);
dictionary.SetString(kTagNameServersGoogle, kGoogleNameServers); dictionary.SetString(kTagNameServersGoogle, kGoogleNameServers);
...@@ -1319,31 +1352,43 @@ void InternetOptionsHandler::PopulateIPConfigsCallback( ...@@ -1319,31 +1352,43 @@ void InternetOptionsHandler::PopulateIPConfigsCallback(
new base::FundamentalValue(network->auto_connect()), new base::FundamentalValue(network->auto_connect()),
auto_connect_ui_data); auto_connect_ui_data);
PopulateConnectionDetails(network, &dictionary);
web_ui()->CallJavascriptFunction(
kShowDetailedInfoFunction, dictionary);
}
void InternetOptionsHandler::PopulateConnectionDetails(
const chromeos::Network* network, DictionaryValue* dictionary) {
chromeos::ConnectionType type = network->type();
dictionary->SetBoolean(kTagConnecting, network->connecting());
dictionary->SetBoolean(kTagConnected, network->connected());
dictionary->SetString(kTagConnectionState, network->GetStateString());
dictionary->SetString(kTagNetworkName, network->name());
if (type == chromeos::TYPE_WIFI) { if (type == chromeos::TYPE_WIFI) {
dictionary.SetBoolean(kTagDeviceConnected, cros_->wifi_connected()); dictionary->SetBoolean(kTagDeviceConnected, cros_->wifi_connected());
PopulateWifiDetails(static_cast<const chromeos::WifiNetwork*>(network), PopulateWifiDetails(static_cast<const chromeos::WifiNetwork*>(network),
&dictionary); dictionary);
} else if (type == chromeos::TYPE_WIMAX) { } else if (type == chromeos::TYPE_WIMAX) {
dictionary.SetBoolean(kTagDeviceConnected, cros_->wimax_connected()); dictionary->SetBoolean(kTagDeviceConnected, cros_->wimax_connected());
PopulateWimaxDetails(static_cast<const chromeos::WimaxNetwork*>(network), PopulateWimaxDetails(static_cast<const chromeos::WimaxNetwork*>(network),
&dictionary); dictionary);
} else if (type == chromeos::TYPE_CELLULAR) { } else if (type == chromeos::TYPE_CELLULAR) {
dictionary.SetBoolean(kTagDeviceConnected, cros_->cellular_connected()); dictionary->SetBoolean(kTagDeviceConnected, cros_->cellular_connected());
PopulateCellularDetails( PopulateCellularDetails(
static_cast<const chromeos::CellularNetwork*>(network), static_cast<const chromeos::CellularNetwork*>(network),
&dictionary); dictionary);
} else if (type == chromeos::TYPE_VPN) { } else if (type == chromeos::TYPE_VPN) {
dictionary.SetBoolean(kTagDeviceConnected, dictionary->SetBoolean(kTagDeviceConnected,
cros_->virtual_network_connected()); cros_->virtual_network_connected());
const base::DictionaryValue* onc =
cros_->FindOncForNetwork(network->unique_id());
PopulateVPNDetails(static_cast<const chromeos::VirtualNetwork*>(network), PopulateVPNDetails(static_cast<const chromeos::VirtualNetwork*>(network),
*onc, *onc,
&dictionary); dictionary);
} else if (type == chromeos::TYPE_ETHERNET) { } else if (type == chromeos::TYPE_ETHERNET) {
dictionary.SetBoolean(kTagDeviceConnected, cros_->ethernet_connected()); dictionary->SetBoolean(kTagDeviceConnected, cros_->ethernet_connected());
} }
web_ui()->CallJavascriptFunction(
kShowDetailedInfoFunction, dictionary);
} }
void InternetOptionsHandler::PopulateWifiDetails( void InternetOptionsHandler::PopulateWifiDetails(
...@@ -1475,15 +1520,20 @@ void InternetOptionsHandler::PopulateCellularDetails( ...@@ -1475,15 +1520,20 @@ void InternetOptionsHandler::PopulateCellularDetails(
} }
} }
SetActivationButtonVisibility(cellular, SetCellularButtonsVisibility(cellular,
dictionary, dictionary,
cros_->GetCellularHomeCarrierId()); cros_->GetCellularHomeCarrierId());
} }
void InternetOptionsHandler::SetActivationButtonVisibility( void InternetOptionsHandler::SetCellularButtonsVisibility(
const chromeos::CellularNetwork* cellular, const chromeos::CellularNetwork* cellular,
DictionaryValue* dictionary, DictionaryValue* dictionary,
const std::string& carrier_id) { const std::string& carrier_id) {
dictionary->SetBoolean(
kTagDisableConnectButton,
cellular->activation_state() == chromeos::ACTIVATION_STATE_ACTIVATING ||
cellular->connecting());
if (cellular->activation_state() != chromeos::ACTIVATION_STATE_ACTIVATING && if (cellular->activation_state() != chromeos::ACTIVATION_STATE_ACTIVATING &&
cellular->activation_state() != chromeos::ACTIVATION_STATE_ACTIVATED) { cellular->activation_state() != chromeos::ACTIVATION_STATE_ACTIVATED) {
dictionary->SetBoolean(kTagShowActivateButton, true); dictionary->SetBoolean(kTagShowActivateButton, true);
...@@ -1562,8 +1612,17 @@ void InternetOptionsHandler::NetworkCommandCallback(const ListValue* args) { ...@@ -1562,8 +1612,17 @@ void InternetOptionsHandler::NetworkCommandCallback(const ListValue* args) {
} else if (command == kTagDisconnect && type != chromeos::TYPE_ETHERNET) { } else if (command == kTagDisconnect && type != chromeos::TYPE_ETHERNET) {
cros_->DisconnectFromNetwork(network); cros_->DisconnectFromNetwork(network);
} else if (command == kTagActivate && type == chromeos::TYPE_CELLULAR) { } else if (command == kTagActivate && type == chromeos::TYPE_CELLULAR) {
ash::Shell::GetInstance()->delegate()->OpenMobileSetup( if (!UseDirectActivation()) {
network->service_path()); ash::Shell::GetInstance()->delegate()->OpenMobileSetup(
network->service_path());
} else {
Activate(service_path);
// Update network properties after we start activation. The Activate
// call is a blocking call, which blocks on finishing the "start" of
// the activation, hence when we query for network properties after
// this call is done, we will have the "activating" activation state.
UpdateConnectionData(network);
}
} else { } else {
VLOG(1) << "Unknown command: " << command; VLOG(1) << "Unknown command: " << command;
NOTREACHED(); NOTREACHED();
......
...@@ -80,7 +80,7 @@ class InternetOptionsHandler ...@@ -80,7 +80,7 @@ class InternetOptionsHandler
// be NULL. // be NULL.
void DoConnect(chromeos::Network* network); void DoConnect(chromeos::Network* network);
void SetActivationButtonVisibility( void SetCellularButtonsVisibility(
const chromeos::CellularNetwork* cellular, const chromeos::CellularNetwork* cellular,
base::DictionaryValue* dictionary, base::DictionaryValue* dictionary,
const std::string& carrier_id); const std::string& carrier_id);
...@@ -123,6 +123,8 @@ class InternetOptionsHandler ...@@ -123,6 +123,8 @@ class InternetOptionsHandler
base::DictionaryValue* shill_properties, base::DictionaryValue* shill_properties,
const chromeos::NetworkIPConfigVector& ipconfigs, const chromeos::NetworkIPConfigVector& ipconfigs,
const std::string& hardware_address); const std::string& hardware_address);
void PopulateConnectionDetails(const chromeos::Network* network,
base::DictionaryValue* dictionary);
void PopulateWifiDetails(const chromeos::WifiNetwork* wifi, void PopulateWifiDetails(const chromeos::WifiNetwork* wifi,
base::DictionaryValue* dictionary); base::DictionaryValue* dictionary);
void PopulateWimaxDetails(const chromeos::WimaxNetwork* wimax, void PopulateWimaxDetails(const chromeos::WimaxNetwork* wimax,
...@@ -146,6 +148,9 @@ class InternetOptionsHandler ...@@ -146,6 +148,9 @@ class InternetOptionsHandler
void FillNetworkInfo(base::DictionaryValue* dictionary); void FillNetworkInfo(base::DictionaryValue* dictionary);
// Refreshes the display of network information. // Refreshes the display of network information.
void RefreshNetworkData(); void RefreshNetworkData();
// Updates the display of network connection information for the details page
// if it's up.
void UpdateConnectionData(const chromeos::Network* network);
// Updates the carrier change status. // Updates the carrier change status.
void UpdateCarrier(bool success); void UpdateCarrier(bool success);
// Adds observers for wireless networks, if any, so that we can dynamically // Adds observers for wireless networks, if any, so that we can dynamically
......
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