Skip to content

Commit

Permalink
Add ONC 'Source' configuration property
Browse files Browse the repository at this point in the history
This also includes a bit of JS cleanup to use ONC properties directly
where possible.

BUG=279351
R=pneubeck@chromium.org

Review URL: https://codereview.chromium.org/552113002

Cr-Commit-Position: refs/heads/master@{#294462}
  • Loading branch information
stevenjb committed Sep 11, 2014
1 parent 93c37f1 commit b4dd54b
Show file tree
Hide file tree
Showing 22 changed files with 161 additions and 58 deletions.
47 changes: 21 additions & 26 deletions chrome/browser/resources/options/chromeos/internet_detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,14 +379,18 @@ cr.define('options.internet', function() {
* Update details page controls.
*/
updateControls: function() {
var onc = this.onc_;
if (onc == undefined)
return; // May get called from a pref update before initialized.

// Only show ipconfig section if network is connected OR if nothing on
// this device is connected. This is so that you can fix the ip configs
// if you can't connect to any network.
// TODO(chocobo): Once ipconfig is moved to flimflam service objects,
// we need to redo this logic to allow configuration of all networks.
$('ipconfig-section').hidden = !this.connected && this.deviceConnected;
$('ipconfig-dns-section').hidden =
!this.connected && this.deviceConnected;
var connected = onc.getActiveValue('ConnectionState') == 'Connected';
$('ipconfig-section').hidden = !connected && this.deviceConnected;
$('ipconfig-dns-section').hidden = !connected && this.deviceConnected;

// Network type related.
updateHidden('#details-internet-page .cellular-details',
Expand Down Expand Up @@ -414,16 +418,15 @@ cr.define('options.internet', function() {
this.type_ == 'VPN');

// Password and shared.
var source = onc.getSource();
var shared = (source == 'Device' || source == 'DevicePolicy');
updateHidden('#details-internet-page #password-details',
this.type_ != 'WiFi' || !this.hasSecurity);
updateHidden('#details-internet-page #wifi-shared-network',
!this.shared);
updateHidden('#details-internet-page #prefer-network',
!this.showPreferred);
this.type_ != 'WiFi' || onc.getWiFiSecurity() == 'None');
updateHidden('#details-internet-page #wifi-shared-network', !shared);
updateHidden('#details-internet-page #prefer-network', source == 'None');

// WiMAX.
updateHidden('#details-internet-page #wimax-shared-network',
!this.shared);
updateHidden('#details-internet-page #wimax-shared-network', !shared);

// Proxy
this.updateProxyBannerVisibility_();
Expand Down Expand Up @@ -578,7 +581,7 @@ cr.define('options.internet', function() {

var connectable = onc.getActiveValue('Connectable');
if (connectState != 'Connected' &&
(!connectable || this.hasSecurity ||
(!connectable || onc.getWiFiSecurity() != 'None' ||
(this.type_ == 'Wimax' || this.type_ == 'VPN'))) {
$('details-internet-configure').hidden = false;
} else {
Expand All @@ -592,7 +595,6 @@ cr.define('options.internet', function() {
$('network-details-title').textContent = onc.getTranslatedValue('Name');
var connectionState = onc.getActiveValue('ConnectionState');
var connectionStateString = onc.getTranslatedValue('ConnectionState');
this.connected = connectionState == 'Connected';
$('network-details-subtitle-status').textContent = connectionStateString;
var typeKey;
var type = this.type_;
Expand Down Expand Up @@ -1024,7 +1026,6 @@ cr.define('options.internet', function() {
var connectionStateString = onc.getTranslatedValue('ConnectionState');
if ('deviceConnected' in update)
detailsPage.deviceConnected = update.deviceConnected;
detailsPage.connected = connectionState == 'Connected';
$('connection-state').textContent = connectionStateString;

detailsPage.updateConnectionButtonVisibilty_();
Expand Down Expand Up @@ -1071,11 +1072,10 @@ cr.define('options.internet', function() {
$('web-proxy-auto-discovery').hidden = true;

detailsPage.deviceConnected = data.deviceConnected;
detailsPage.connected =
onc.getActiveValue('ConnectionState') == 'Connected';

// Only show proxy for remembered networks.
if (data.remembered) {
var remembered = onc.getSource() != 'None';
if (remembered) {
detailsPage.showProxy = true;
chrome.send('selectNetwork', [detailsPage.servicePath_]);
} else {
Expand Down Expand Up @@ -1231,7 +1231,7 @@ cr.define('options.internet', function() {
}

var setOrHideParent = function(field, property) {
if (property) {
if (property != undefined) {
$(field).textContent = property;
$(field).parentElement.hidden = false;
} else {
Expand All @@ -1253,13 +1253,12 @@ cr.define('options.internet', function() {
if (type == 'WiFi') {
OptionsPage.showTab($('wifi-network-nav-tab'));
detailsPage.gsm = false;
detailsPage.shared = data.shared;
$('wifi-connection-state').textContent = connectionStateString;
$('wifi-restricted-connectivity').textContent = restrictedString;
var ssid = onc.getActiveValue('WiFi.SSID');
$('wifi-ssid').textContent = ssid ? ssid : networkName;
setOrHideParent('wifi-bssid', onc.getActiveValue('WiFi.BSSID'));
var security = onc.getActiveValue('WiFi.Security');
var security = onc.getWiFiSecurity();
if (security == 'None')
security = undefined;
setOrHideParent('wifi-security', security);
Expand All @@ -1273,24 +1272,20 @@ cr.define('options.internet', function() {
$('wifi-signal-strength').textContent = strengthString;
setOrHideParent('wifi-hardware-address',
onc.getActiveValue('MacAddress'));
detailsPage.showPreferred = data.remembered;
var priority = onc.getActiveValue('Priority');
$('prefer-network-wifi').checked = priority > 0;
$('prefer-network-wifi').disabled = !data.remembered;
$('prefer-network-wifi').disabled = !remembered;
$('auto-connect-network-wifi').checked =
onc.getActiveValue('AutoConnect');
$('auto-connect-network-wifi').disabled = !data.remembered;
detailsPage.hasSecurity = security != undefined;
$('auto-connect-network-wifi').disabled = !remembered;
} else if (type == 'Wimax') {
OptionsPage.showTab($('wimax-network-nav-tab'));
detailsPage.gsm = false;
detailsPage.shared = data.shared;
detailsPage.showPreferred = data.remembered;
$('wimax-connection-state').textContent = connectionStateString;
$('wimax-restricted-connectivity').textContent = restrictedString;
$('auto-connect-network-wimax').checked =
onc.getActiveValue('AutoConnect');
$('auto-connect-network-wimax').disabled = !data.remembered;
$('auto-connect-network-wimax').disabled = !remembered;
var identity = onc.getActiveValue('Wimax.EAP.Identity');
setOrHideParent('wimax-eap-identity', identity);
$('wimax-signal-strength').textContent = strengthString;
Expand Down
23 changes: 23 additions & 0 deletions chrome/browser/resources/options/chromeos/onc_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,29 @@ cr.define('cr.onc', function() {
},

/**
* Returns the Source of this configuration. If undefined returns 'None'.
* @return {string} The configuration source: 'None', 'User', 'Device',
* 'UserPolicy', or 'DevicePolicy'.
*/
getSource: function() {
var source = this.getActiveValue('Source');
if (source == undefined)
return 'None';
return source;
},

/**
* Returns the WiFi security type (defaults to 'None').
* @return {string} The security type.
*/
getWiFiSecurity: function() {
var security = this.getActiveValue('WiFi.Security');
if (security == undefined)
return 'None';
return security;
},

/**
* Updates the properties of |data_| from the properties in |update|.
* Note: this only looks at top level entries, so if a dictionary is
* updated the entire dictionary is written over. TODO(stevenjb):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,9 @@ const char kTagDisconnect[] = "disconnect";
const char kTagErrorMessage[] = "errorMessage";
const char kTagForget[] = "forget";
const char kTagOptions[] = "options";
const char kTagRemembered[] = "remembered";
const char kTagRememberedList[] = "rememberedList";
const char kTagCarriers[] = "carriers";
const char kTagCurrentCarrierIndex[] = "currentCarrierIndex";
const char kTagShared[] = "shared";
const char kTagShowActivateButton[] = "showActivateButton";
const char kTagShowViewAccountButton[] = "showViewAccountButton";
const char kTagTrue[] = "true";
Expand Down Expand Up @@ -313,10 +311,6 @@ scoped_ptr<base::DictionaryValue> PopulateConnectionDetails(
kTagErrorMessage,
ash::network_connect::ErrorString(network->error(), network->path()));

dictionary->SetBoolean(kTagRemembered, !network->profile_path().empty());
bool shared = !network->IsPrivate();
dictionary->SetBoolean(kTagShared, shared);

const std::string& type = network->type();

const NetworkState* connected_network =
Expand Down
1 change: 1 addition & 0 deletions chrome/test/data/extensions/api_test/networking/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ var availableTests = [
"Effective": "UserPolicy",
"UserPolicy": "My WiFi Network"
},
"Source": "UserPolicy",
"Type": {
"Active": "WiFi",
"Effective": "UserPolicy",
Expand Down
19 changes: 11 additions & 8 deletions chromeos/network/managed_network_configuration_handler_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,14 @@ void ManagedNetworkConfigurationHandlerImpl::GetManagedProperties(
base::Bind(
&ManagedNetworkConfigurationHandlerImpl::SendManagedProperties,
weak_ptr_factory_.GetWeakPtr(),
userhash,
callback,
error_callback)),
error_callback);
}

void ManagedNetworkConfigurationHandlerImpl::SendManagedProperties(
const std::string& userhash,
const network_handler::DictionaryResultCallback& callback,
const network_handler::ErrorCallback& error_callback,
const std::string& service_path,
Expand All @@ -159,14 +161,14 @@ void ManagedNetworkConfigurationHandlerImpl::SendManagedProperties(
// properties _might_ be user configured.
}

std::string guid;
shill_properties->GetStringWithoutPathExpansion(shill::kGuidProperty, &guid);

::onc::ONCSource onc_source;
FindPolicyByGUID(userhash, guid, &onc_source);
scoped_ptr<base::DictionaryValue> active_settings(
onc::TranslateShillServiceToONCPart(
*shill_properties,
&onc::kNetworkWithStateSignature));

std::string guid;
active_settings->GetStringWithoutPathExpansion(::onc::network_config::kGUID,
&guid);
*shill_properties, onc_source, &onc::kNetworkWithStateSignature));

const base::DictionaryValue* network_policy = NULL;
const base::DictionaryValue* global_policy = NULL;
Expand Down Expand Up @@ -215,8 +217,9 @@ void ManagedNetworkConfigurationHandlerImpl::SendProperties(
const std::string& service_path,
scoped_ptr<base::DictionaryValue> shill_properties) {
scoped_ptr<base::DictionaryValue> onc_network(
onc::TranslateShillServiceToONCPart(*shill_properties,
&onc::kNetworkWithStateSignature));
onc::TranslateShillServiceToONCPart(
*shill_properties, ::onc::ONC_SOURCE_UNKNOWN,
&onc::kNetworkWithStateSignature));
callback.Run(service_path, *onc_network);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class CHROMEOS_EXPORT ManagedNetworkConfigurationHandlerImpl

// Sends the response to the caller of GetManagedProperties.
void SendManagedProperties(
const std::string& userhash,
const network_handler::DictionaryResultCallback& callback,
const network_handler::ErrorCallback& error_callback,
const std::string& service_path,
Expand Down
5 changes: 3 additions & 2 deletions chromeos/network/network_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ scoped_ptr<base::DictionaryValue> TranslateNetworkStateToONC(
network->GetStateProperties(&shill_dictionary);

scoped_ptr<base::DictionaryValue> onc_dictionary =
TranslateShillServiceToONCPart(
shill_dictionary, &onc::kNetworkWithStateSignature);
TranslateShillServiceToONCPart(shill_dictionary,
::onc::ONC_SOURCE_UNKNOWN,
&onc::kNetworkWithStateSignature);
return onc_dictionary.Pass();
}

Expand Down
1 change: 1 addition & 0 deletions chromeos/network/onc/onc_signature.cc
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ const OncFieldSignature network_with_state_fields[] = {
{ ::onc::network_config::kMacAddress, &kStringSignature},
{ ::onc::network_config::kRestrictedConnectivity, &kBoolSignature},
{ ::onc::network_config::kSavedIPConfig, &kSavedIPConfigSignature},
{ ::onc::network_config::kSource, &kStringSignature},
{ ::onc::network_config::kWiFi, &kWiFiWithStateSignature},
{NULL}};

Expand Down
1 change: 1 addition & 0 deletions chromeos/network/onc/onc_translation_tables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ const FieldTranslationEntry network_fields[] = {
// { ::onc::network_config::kConnectionState, shill::kStateProperty },
// { ::onc::network_config::kRestrictedConnectivity,
// shill::kStateProperty },
// { ::onc::network_config::kSource, shill::kProfileProperty },
// { ::onc::network_config::kMacAddress, shill::kAddressProperty },
{NULL}};

Expand Down
6 changes: 5 additions & 1 deletion chromeos/network/onc/onc_translator.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "base/memory/scoped_ptr.h"
#include "chromeos/chromeos_export.h"
#include "components/onc/onc_constants.h"

namespace base {
class DictionaryValue;
Expand Down Expand Up @@ -36,10 +37,13 @@ scoped_ptr<base::DictionaryValue> TranslateONCObjectToShill(
// This function is used to translate network settings coming from Shill to ONC
// before sending them to the UI. The result doesn't have to be valid ONC, but
// only a subset of it and includes only the values that are actually required
// by the UI.
// by the UI. If |onc_source| != ONC_SOURCE_UNKNOWN then the 'Source' property
// of the ONC dictionary will be set accordingly. Note: ONC_SOURCE_USER_IMPORT
// is treated the same as ONC_SOURCE_NONE.
CHROMEOS_EXPORT
scoped_ptr<base::DictionaryValue> TranslateShillServiceToONCPart(
const base::DictionaryValue& shill_dictionary,
::onc::ONCSource onc_source,
const OncValueSignature* onc_signature);

} // namespace onc
Expand Down
Loading

0 comments on commit b4dd54b

Please sign in to comment.