Commit 9f86a541 authored by stevenjb's avatar stevenjb Committed by Commit bot

Use GetManagedProperties in InternetOptionsHandler

This CL does the following:
* Eliminates auto connect glue code
* Elim SetManaged* helpers
* Converts StaticIPConfig, SavedIPConfig, and WebProxyAutoDiscoveryUrl
  properties from Shill to ONC
* Uses ManagedNetworkConfigurationHandler::GetManagedProperties in
  internet_options_handler.cc to get (almost) all properites. The
  remaining properties will require additional translation and/or design

BUG=279351

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

Cr-Commit-Position: refs/heads/master@{#293816}
parent 8a5b0eec
......@@ -17,6 +17,8 @@ cr.define('options.internet', function() {
var PageManager = cr.ui.pageManager.PageManager;
/** @const */ var IPAddressField = options.internet.IPAddressField;
/** @const */ var GoogleNameServersString = '8.8.4.4,8.8.8.8';
/**
* Helper function to set hidden attribute for elements matching a selector.
* @param {string} selector CSS selector for extracting a list of elements.
......@@ -79,6 +81,34 @@ cr.define('options.internet', function() {
chrome.send(message, [path, checkbox.checked ? 'true' : 'false']);
}
/**
* Returns the netmask as a string for a given prefix length.
* @param {string} prefixLength The ONC routing prefix length.
* @return {string} The corresponding netmask.
*/
function PrefixLengthToNetmask(prefixLength) {
// Return the empty string for invalid inputs.
if (prefixLength < 0 || prefixLength > 32)
return '';
var netmask = '';
for (var i = 0; i < 4; ++i) {
var remainder = 8;
if (prefixLength >= 8) {
prefixLength -= 8;
} else {
remainder = prefixLength;
prefixLength = 0;
}
if (i > 0)
netmask += '.';
var value = 0;
if (remainder != 0)
value = ((2 << (remainder - 1)) - 1) << (8 - remainder);
netmask += value.toString();
}
return netmask;
}
/////////////////////////////////////////////////////////////////////////////
// DetailsInternetPage class:
......@@ -329,7 +359,7 @@ cr.define('options.internet', function() {
// page is fixed. http://crbug.com/242865
if (loadTimeData.data_) {
$('google-dns-label').innerHTML =
loadTimeData.getString('googleNameServers');
loadTimeData.getString('googleNameServers');
}
},
......@@ -805,8 +835,7 @@ cr.define('options.internet', function() {
}
}
userNameServers = userNameServers.join(',');
userNameServers = userNameServers.sort();
chrome.send('setIPConfig',
[servicePath,
Boolean($('ip-automatic-configuration-checkbox').checked),
......@@ -814,7 +843,7 @@ cr.define('options.internet', function() {
$('ip-netmask').model.value || '',
$('ip-gateway').model.value || '',
nameServerType,
userNameServers]);
userNameServers.join(',')]);
PageManager.closeOverlay();
};
......@@ -1003,93 +1032,143 @@ cr.define('options.internet', function() {
var restricted = onc.getActiveValue('RestrictedConnectivity');
var restrictedString = loadTimeData.getString(
restricted ? 'restrictedYes' : 'restrictedNo');
var ipAutoConfig = data.ipAutoConfig ? 'automatic' : 'user';
$('ip-automatic-configuration-checkbox').checked = data.ipAutoConfig;
var inetAddress = {autoConfig: ipAutoConfig};
var inetNetmask = {autoConfig: ipAutoConfig};
var inetGateway = {autoConfig: ipAutoConfig};
if (data.ipconfig.value) {
inetAddress.automatic = data.ipconfig.value.address;
inetAddress.value = data.ipconfig.value.address;
inetNetmask.automatic = data.ipconfig.value.netmask;
inetNetmask.value = data.ipconfig.value.netmask;
inetGateway.automatic = data.ipconfig.value.gateway;
inetGateway.value = data.ipconfig.value.gateway;
if (data.ipconfig.value.webProxyAutoDiscoveryUrl) {
$('web-proxy-auto-discovery').hidden = false;
$('web-proxy-auto-discovery-url').value =
data.ipconfig.value.webProxyAutoDiscoveryUrl;
var inetAddress = {};
var inetNetmask = {};
var inetGateway = {};
var inetNameServersString;
if ('IPConfigs' in data) {
var ipconfigList = onc.getActiveValue('IPConfigs');
for (var i = 0; i < ipconfigList.length; ++i) {
var ipconfig = ipconfigList[i];
var type = ipconfig['Type'];
if (type != 'IPv4') {
// TODO(stevenjb): Handle IPv6 properties.
continue;
}
var address = ipconfig['IPAddress'];
inetAddress.automatic = address;
inetAddress.value = address;
var netmask = PrefixLengthToNetmask(ipconfig['RoutingPrefix']);
inetNetmask.automatic = netmask;
inetNetmask.value = netmask;
var gateway = ipconfig['Gateway'];
inetGateway.automatic = gateway;
inetGateway.value = gateway;
if ('WebProxyAutoDiscoveryUrl' in ipconfig) {
$('web-proxy-auto-discovery').hidden = false;
$('web-proxy-auto-discovery-url').value =
ipconfig['WebProxyAutoDiscoveryUrl'];
}
if ('NameServers' in ipconfig) {
var inetNameServers = ipconfig['NameServers'];
inetNameServers = inetNameServers.sort();
inetNameServersString = inetNameServers.join(',');
}
break; // Use the first IPv4 entry.
}
}
// Override the "automatic" values with the real saved DHCP values,
// if they are set.
if (data.savedIP.address) {
inetAddress.automatic = data.savedIP.address;
inetAddress.value = data.savedIP.address;
}
if (data.savedIP.netmask) {
inetNetmask.automatic = data.savedIP.netmask;
inetNetmask.value = data.savedIP.netmask;
}
if (data.savedIP.gateway) {
inetGateway.automatic = data.savedIP.gateway;
inetGateway.value = data.savedIP.gateway;
var savedNameServersString;
if ('SavedIPConfig' in data) {
var savedIpAddress = onc.getActiveValue('SavedIPConfig.IPAddress');
if (savedIpAddress != undefined) {
inetAddress.automatic = savedIpAddress;
inetAddress.value = savedIpAddress;
}
var savedPrefix = onc.getActiveValue('SavedIPConfig.RoutingPrefix');
if (savedPrefix != undefined) {
var savedNetmask = PrefixLengthToNetmask(savedPrefix);
inetNetmask.automatic = savedNetmask;
inetNetmask.value = savedNetmask;
}
var savedGateway = onc.getActiveValue('SavedIPConfig.Gateway');
if (savedGateway != undefined) {
inetGateway.automatic = savedGateway;
inetGateway.value = savedGateway;
}
var savedNameServers = onc.getActiveValue('SavedIPConfig.NameServers');
if (savedNameServers) {
savedNameServers = savedNameServers.sort();
savedNameServersString = savedNameServers.join(',');
}
}
if (ipAutoConfig == 'user') {
if (data.staticIP.value.address) {
inetAddress.value = data.staticIP.value.address;
inetAddress.user = data.staticIP.value.address;
var ipAutoConfig = 'automatic';
var staticNameServersString;
if ('StaticIPConfig' in data) {
var staticIpAddress = onc.getActiveValue('StaticIPConfig.IPAddress');
if (staticIpAddress != undefined) {
ipAutoConfig = 'user';
inetAddress.user = staticIpAddress;
inetAddress.value = staticIpAddress;
}
var staticPrefix = onc.getActiveValue('StaticIPConfig.RoutingPrefix');
if (staticPrefix != undefined) {
var staticNetmask = PrefixLengthToNetmask(staticPrefix);
inetNetmask.user = staticNetmask;
inetNetmask.value = staticNetmask;
}
if (data.staticIP.value.netmask) {
inetNetmask.value = data.staticIP.value.netmask;
inetNetmask.user = data.staticIP.value.netmask;
var staticGateway = onc.getActiveValue('StaticIPConfig.Gateway');
if (staticGateway != undefined) {
inetGateway.user = staticGateway;
inetGateway.value = staticGateway;
}
if (data.staticIP.value.gateway) {
inetGateway.value = data.staticIP.value.gateway;
inetGateway.user = data.staticIP.value.gateway;
var staticNameServers = onc.getActiveValue('StaticIPConfig.NameServers');
if (staticNameServers) {
staticNameServers = staticNameServers.sort();
staticNameServersString = staticNameServers.join(',');
}
}
$('ip-automatic-configuration-checkbox').checked =
ipAutoConfig == 'automatic';
inetAddress.autoConfig = ipAutoConfig;
inetNetmask.autoConfig = ipAutoConfig;
inetGateway.autoConfig = ipAutoConfig;
var configureAddressField = function(field, model) {
IPAddressField.decorate(field);
field.model = model;
field.editable = model.autoConfig == 'user';
};
configureAddressField($('ip-address'), inetAddress);
configureAddressField($('ip-netmask'), inetNetmask);
configureAddressField($('ip-gateway'), inetGateway);
var inetNameServers = '';
if (data.ipconfig.value && data.ipconfig.value.nameServers) {
inetNameServers = data.ipconfig.value.nameServers;
$('automatic-dns-display').textContent = inetNameServers;
// Set Nameserver fields.
var nameServerType = 'automatic';
if (staticNameServersString &&
staticNameServersString == inetNameServersString) {
nameServerType = 'user';
}
if (inetNameServersString == GoogleNameServersString)
nameServerType = 'google';
if (data.savedIP && data.savedIP.nameServers)
$('automatic-dns-display').textContent = data.savedIP.nameServers;
if (data.nameServersGoogle)
$('google-dns-display').textContent = data.nameServersGoogle;
$('automatic-dns-display').textContent = inetNameServersString;
$('google-dns-display').textContent = GoogleNameServersString;
var nameServersUser = [];
if (data.staticIP.value.nameServers)
nameServersUser = data.staticIP.value.nameServers.split(',');
if (staticNameServers)
nameServersUser = staticNameServers;
var nameServerModels = [];
for (var i = 0; i < 4; ++i)
nameServerModels.push({value: nameServersUser[i] || ''});
$(data.nameServerType + '-dns-radio').checked = true;
$(nameServerType + '-dns-radio').checked = true;
configureAddressField($('ipconfig-dns1'), nameServerModels[0]);
configureAddressField($('ipconfig-dns2'), nameServerModels[1]);
configureAddressField($('ipconfig-dns3'), nameServerModels[2]);
configureAddressField($('ipconfig-dns4'), nameServerModels[3]);
DetailsInternetPage.updateNameServerDisplay(data.nameServerType);
DetailsInternetPage.updateNameServerDisplay(nameServerType);
var macAddress = onc.getActiveValue('MacAddress');
if (macAddress) {
......@@ -1237,8 +1316,15 @@ cr.define('options.internet', function() {
var otherOption = apnSelector[0];
data.selectedApn = -1;
data.userApnIndex = -1;
var activeApn = onc.getActiveValue('Cellular.APN');
var lastGoodApn = onc.getActiveValue('Cellular.LastGoodAPN');
var activeApn = onc.getActiveValue('Cellular.APN.AccessPointName');
var activeUsername = onc.getActiveValue('Cellular.APN.Username');
var activePassword = onc.getActiveValue('Cellular.APN.Password');
var lastGoodApn =
onc.getActiveValue('Cellular.LastGoodAPN.AccessPointName');
var lastGoodUsername =
onc.getActiveValue('Cellular.LastGoodAPN.Username');
var lastGoodPassword =
onc.getActiveValue('Cellular.LastGoodAPN.Password');
var apnList = onc.getActiveValue('Cellular.APNList');
for (var i = 0; i < apnList.length; i++) {
var apnDict = apnList[i];
......@@ -1251,24 +1337,21 @@ cr.define('options.internet', function() {
option.value = i;
// If this matches the active Apn, or LastGoodApn, set it as the
// selected Apn.
if ((activeApn != undefined &&
activeApn['AccessPointName'] == accessPointName &&
activeApn['Username'] == apnDict['Username'] &&
activeApn['Password'] == apnDict['Password']) ||
((activeApn == undefined || !activeApn['AccessPointName']) &&
lastGoodApn != undefined &&
lastGoodApn['AccessPointName'] == accessPointName &&
lastGoodApn['Username'] == apnDict['Username'] &&
lastGoodApn['Password'] == apnDict['Password'])) {
if ((activeApn == accessPointName &&
activeUsername == apnDict['Username'] &&
activePassword == apnDict['Password']) ||
(!activeApn &&
lastGoodApn == accessPointName &&
lastGoodUsername == apnDict['Username'] &&
lastGoodPassword == apnDict['Password'])) {
data.selectedApn = i;
}
// Insert new option before "other" option.
apnSelector.add(option, otherOption);
}
if (data.selectedApn == -1 &&
activeApn != undefined && activeApn['AccessPointName']) {
if (data.selectedApn == -1 && activeApn) {
var option = document.createElement('option');
option.textContent = activeApn['AccessPointName'];
option.textContent = activeApn;
option.value = -1;
apnSelector.add(option, otherOption);
data.selectedApn = apnSelector.length - 2;
......
......@@ -31,6 +31,7 @@
#include "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h"
#include "chrome/browser/ui/webui/options/chromeos/internet_options_handler_strings.h"
#include "chromeos/chromeos_switches.h"
#include "chromeos/login/login_state.h"
#include "chromeos/network/device_state.h"
#include "chromeos/network/managed_network_configuration_handler.h"
#include "chromeos/network/network_configuration_handler.h"
......@@ -69,24 +70,9 @@ const char kNetworkInfoKeyIconURL[] = "iconURL";
const char kNetworkInfoKeyServicePath[] = "servicePath";
const char kNetworkInfoKeyPolicyManaged[] = "policyManaged";
// These are keys for getting IP information from the web ui.
const char kIpConfigAddress[] = "address";
const char kIpConfigPrefixLength[] = "prefixLength";
const char kIpConfigNetmask[] = "netmask";
const char kIpConfigGateway[] = "gateway";
const char kIpConfigNameServers[] = "nameServers";
const char kIpConfigAutoConfig[] = "ipAutoConfig";
const char kIpConfigWebProxyAutoDiscoveryUrl[] = "webProxyAutoDiscoveryUrl";
// These are types of name server selections from the web ui.
const char kNameServerTypeAutomatic[] = "automatic";
const char kNameServerTypeGoogle[] = "google";
const char kNameServerTypeUser[] = "user";
// These are dictionary names used to send data to the web ui.
const char kDictionaryIpConfig[] = "ipconfig";
const char kDictionaryStaticIp[] = "staticIP";
const char kDictionarySavedIp[] = "savedIP";
// Google public name servers (DNS).
const char kGoogleNameServers[] = "8.8.4.4,8.8.8.8";
......@@ -133,17 +119,11 @@ const char kTagCellularEnabled[] = "cellularEnabled";
const char kTagCellularSupportsScan[] = "cellularSupportsScan";
const char kTagConfigure[] = "configure";
const char kTagConnect[] = "connect";
const char kTagControlledBy[] = "controlledBy";
const char kTagDeviceConnected[] = "deviceConnected";
const char kTagDisconnect[] = "disconnect";
const char kTagErrorMessage[] = "errorMessage";
const char kTagForget[] = "forget";
const char kTagNameServersGoogle[] = "nameServersGoogle";
const char kTagNameServerType[] = "nameServerType";
const char kTagOptions[] = "options";
const char kTagPolicy[] = "policy";
const char kTagRecommended[] = "recommended";
const char kTagRecommendedValue[] = "recommendedValue";
const char kTagRemembered[] = "remembered";
const char kTagRememberedList[] = "rememberedList";
const char kTagCarriers[] = "carriers";
......@@ -152,7 +132,6 @@ const char kTagShared[] = "shared";
const char kTagShowActivateButton[] = "showActivateButton";
const char kTagShowViewAccountButton[] = "showViewAccountButton";
const char kTagTrue[] = "true";
const char kTagValue[] = "value";
const char kTagVpnList[] = "vpnList";
const char kTagWifiAvailable[] = "wifiAvailable";
const char kTagWifiEnabled[] = "wifiEnabled";
......@@ -215,230 +194,6 @@ base::DictionaryValue* BuildNetworkDictionary(
return network_info.release();
}
// Pulls IP information out of a shill service properties dictionary. If
// |static_ip| is true, then it fetches "StaticIP.*" properties. If not, then it
// fetches "SavedIP.*" properties. Caller must take ownership of returned
// dictionary. If non-NULL, |ip_parameters_set| returns a count of the number
// of IP routing parameters that get set.
base::DictionaryValue* BuildIPInfoDictionary(
const base::DictionaryValue& shill_properties,
bool static_ip,
int* routing_parameters_set) {
std::string address_key;
std::string prefix_len_key;
std::string gateway_key;
std::string name_servers_key;
if (static_ip) {
address_key = shill::kStaticIPAddressProperty;
prefix_len_key = shill::kStaticIPPrefixlenProperty;
gateway_key = shill::kStaticIPGatewayProperty;
name_servers_key = shill::kStaticIPNameServersProperty;
} else {
address_key = shill::kSavedIPAddressProperty;
prefix_len_key = shill::kSavedIPPrefixlenProperty;
gateway_key = shill::kSavedIPGatewayProperty;
name_servers_key = shill::kSavedIPNameServersProperty;
}
scoped_ptr<base::DictionaryValue> ip_info_dict(new base::DictionaryValue);
std::string address;
int routing_parameters = 0;
if (shill_properties.GetStringWithoutPathExpansion(address_key, &address)) {
ip_info_dict->SetString(kIpConfigAddress, address);
VLOG(2) << "Found " << address_key << ": " << address;
routing_parameters++;
}
int prefix_len = -1;
if (shill_properties.GetIntegerWithoutPathExpansion(
prefix_len_key, &prefix_len)) {
ip_info_dict->SetInteger(kIpConfigPrefixLength, prefix_len);
std::string netmask = network_util::PrefixLengthToNetmask(prefix_len);
ip_info_dict->SetString(kIpConfigNetmask, netmask);
VLOG(2) << "Found " << prefix_len_key << ": "
<< prefix_len << " (" << netmask << ")";
routing_parameters++;
}
std::string gateway;
if (shill_properties.GetStringWithoutPathExpansion(gateway_key, &gateway)) {
ip_info_dict->SetString(kIpConfigGateway, gateway);
VLOG(2) << "Found " << gateway_key << ": " << gateway;
routing_parameters++;
}
if (routing_parameters_set)
*routing_parameters_set = routing_parameters;
std::string name_servers;
if (shill_properties.GetStringWithoutPathExpansion(
name_servers_key, &name_servers)) {
ip_info_dict->SetString(kIpConfigNameServers, name_servers);
VLOG(2) << "Found " << name_servers_key << ": " << name_servers;
}
return ip_info_dict.release();
}
// Decorate pref value as CoreOptionsHandler::CreateValueForPref() does and
// store it under |key| in |settings|. Takes ownership of |value|.
void SetValueDictionary(const char* key,
base::Value* value,
const NetworkPropertyUIData& ui_data,
base::DictionaryValue* settings) {
base::DictionaryValue* dict = new base::DictionaryValue();
// DictionaryValue::Set() takes ownership of |value|.
dict->Set(kTagValue, value);
settings->Set(key, dict);
const base::Value* recommended_value = ui_data.default_value();
if (ui_data.IsManaged())
dict->SetString(kTagControlledBy, kTagPolicy);
else if (recommended_value && recommended_value->Equals(value))
dict->SetString(kTagControlledBy, kTagRecommended);
if (recommended_value)
dict->Set(kTagRecommendedValue, recommended_value->DeepCopy());
}
const char* GetOncPolicyString(::onc::ONCSource onc_source) {
if (onc_source == ::onc::ONC_SOURCE_DEVICE_POLICY)
return ::onc::kAugmentationDevicePolicy;
return ::onc::kAugmentationUserPolicy;
}
const char* GetOncEditableString(::onc::ONCSource onc_source) {
if (onc_source == ::onc::ONC_SOURCE_DEVICE_POLICY)
return ::onc::kAugmentationDeviceEditable;
return ::onc::kAugmentationUserEditable;
}
const char* GetOncSettingString(::onc::ONCSource onc_source) {
if (onc_source == ::onc::ONC_SOURCE_DEVICE_POLICY)
return ::onc::kAugmentationSharedSetting;
return ::onc::kAugmentationUserSetting;
}
// Creates a GetManagedProperties style dictionary and adds it to |settings|.
// |default_value| represents either the recommended value if |recommended|
// is true, or the enforced value if |recommended| is false. |settings_dict_key|
// is expected to be an ONC key with no '.' in it.
// Note(stevenjb): This is bridge code until we use GetManagedProperties to
// retrieve Shill properties.
void SetManagedValueDictionaryEx(const char* settings_dict_key,
const base::Value& value,
::onc::ONCSource onc_source,
bool recommended,
const base::Value* default_value,
base::DictionaryValue* settings_dict) {
base::DictionaryValue* dict = new base::DictionaryValue();
settings_dict->SetWithoutPathExpansion(settings_dict_key, dict);
dict->Set(::onc::kAugmentationActiveSetting, value.DeepCopy());
if (onc_source == ::onc::ONC_SOURCE_NONE)
return;
if (recommended) {
// If an ONC property is 'Recommended' it can be edited by the user.
std::string editable = GetOncEditableString(onc_source);
dict->Set(editable, new base::FundamentalValue(true));
}
if (default_value) {
std::string policy_source = GetOncPolicyString(onc_source);
dict->Set(policy_source, default_value->DeepCopy());
if (recommended && !value.Equals(default_value)) {
std::string setting_source = GetOncSettingString(onc_source);
dict->Set(setting_source, value.DeepCopy());
dict->SetString(::onc::kAugmentationEffectiveSetting, setting_source);
} else {
dict->SetString(::onc::kAugmentationEffectiveSetting, policy_source);
}
}
}
// Wrapper for SetManagedValueDictionaryEx that does the policy lookup.
// Note: We have to pass |onc_key| separately from |settings_dict_key| since
// we might be populating a sub-dictionary in which case |onc_key| will be the
// complete path (e.g. 'VPN.Host') and |settings_dict_key| is the dictionary key
// (e.g. 'Host').
void SetManagedValueDictionary(const std::string& guid,
const char* settings_dict_key,
const base::Value& value,
const std::string& onc_key,
base::DictionaryValue* settings_dict) {
::onc::ONCSource onc_source = ::onc::ONC_SOURCE_NONE;
const base::DictionaryValue* onc =
onc::FindPolicyForActiveUser(guid, &onc_source);
DCHECK_EQ(onc == NULL, onc_source == ::onc::ONC_SOURCE_NONE);
const base::Value* default_value = NULL;
bool recommended = false;
if (onc) {
onc->Get(onc_key, &default_value);
recommended = onc::IsRecommendedValue(onc, onc_key);
}
SetManagedValueDictionaryEx(settings_dict_key,
value,
onc_source,
recommended,
default_value,
settings_dict);
}
// Fills |dictionary| with the configuration details of |vpn|. |onc| is required
// for augmenting the policy-managed information.
void PopulateVPNDetails(const NetworkState* vpn,
const base::DictionaryValue& shill_properties,
base::DictionaryValue* dictionary) {
// Name and Remembered are set in PopulateConnectionDetails().
// Provider properties are stored in the "Provider" dictionary.
const base::DictionaryValue* shill_provider_properties = NULL;
if (!shill_properties.GetDictionaryWithoutPathExpansion(
shill::kProviderProperty, &shill_provider_properties)) {
LOG(ERROR) << "No provider properties for VPN: " << vpn->path();
return;
}
base::DictionaryValue* vpn_dictionary;
if (!dictionary->GetDictionary(
::onc::network_config::kVPN, &vpn_dictionary)) {
vpn_dictionary = new base::DictionaryValue;
dictionary->Set(::onc::network_config::kVPN, vpn_dictionary);
}
std::string shill_provider_type;
if (!shill_provider_properties->GetStringWithoutPathExpansion(
shill::kTypeProperty, &shill_provider_type)) {
LOG(ERROR) << "Shill VPN has no Provider.Type: " << vpn->path();
return;
}
std::string onc_provider_type;
onc::TranslateStringToONC(
onc::kVPNTypeTable, shill_provider_type, &onc_provider_type);
vpn_dictionary->SetString(::onc::vpn::kType, onc_provider_type);
std::string provider_type_key;
std::string username;
if (shill_provider_type == shill::kProviderOpenVpn) {
provider_type_key = ::onc::vpn::kOpenVPN;
shill_provider_properties->GetStringWithoutPathExpansion(
shill::kOpenVPNUserProperty, &username);
} else {
provider_type_key = ::onc::vpn::kL2TP;
shill_provider_properties->GetStringWithoutPathExpansion(
shill::kL2tpIpsecUserProperty, &username);
}
base::DictionaryValue* provider_type_dictionary = new base::DictionaryValue;
vpn_dictionary->Set(provider_type_key, provider_type_dictionary);
provider_type_dictionary->SetString(::onc::vpn::kUsername, username);
std::string provider_host;
shill_provider_properties->GetStringWithoutPathExpansion(
shill::kHostProperty, &provider_host);
SetManagedValueDictionary(
vpn->guid(),
::onc::vpn::kHost,
base::StringValue(provider_host),
::onc::network_config::VpnProperty(::onc::vpn::kHost),
vpn_dictionary);
}
// Given a list of supported carrier's by the device, return the index of
// the carrier the device is currently using.
int FindCurrentCarrierIndex(const base::ListValue* carriers,
......@@ -551,30 +306,8 @@ void PopulateCellularDetails(const NetworkState* cellular,
scoped_ptr<base::DictionaryValue> PopulateConnectionDetails(
const NetworkState* network,
const base::DictionaryValue& shill_properties) {
// TODO(stevenjb): Once we eliminate all references to Shill properties,
// we can switch to using managed_network_configuration_handler which
// includes Device properties for Cellular (and skip the call to
// onc::TranslateShillServiceToONCPart). For now we copy them over here.
scoped_ptr<base::DictionaryValue> shill_properties_with_device(
shill_properties.DeepCopy());
const DeviceState* device =
NetworkHandler::Get()->network_state_handler()->GetDeviceState(
network->device_path());
if (device) {
shill_properties_with_device->SetWithoutPathExpansion(
shill::kDeviceProperty, device->properties().DeepCopy());
// Get the hardware MAC address from the DeviceState.
// (Note: this is done in ManagedNetworkConfigurationHandler but not
// in NetworkConfigurationHandler).
if (!device->mac_address().empty()) {
shill_properties_with_device->SetStringWithoutPathExpansion(
shill::kAddressProperty, device->mac_address());
}
}
scoped_ptr<base::DictionaryValue> dictionary =
onc::TranslateShillServiceToONCPart(
*shill_properties_with_device, &onc::kNetworkWithStateSignature);
const base::DictionaryValue& onc_properties) {
scoped_ptr<base::DictionaryValue> dictionary(onc_properties.DeepCopy());
dictionary->SetString(kNetworkInfoKeyServicePath, network->path());
dictionary->SetString(
......@@ -594,8 +327,6 @@ scoped_ptr<base::DictionaryValue> PopulateConnectionDetails(
if (type == shill::kTypeCellular)
PopulateCellularDetails(network, dictionary.get());
else if (type == shill::kTypeVPN)
PopulateVPNDetails(network, shill_properties, dictionary.get());
return dictionary.Pass();
}
......@@ -978,21 +709,24 @@ void InternetOptionsHandler::RefreshNetworkData() {
void InternetOptionsHandler::UpdateConnectionData(
const std::string& service_path) {
NetworkHandler::Get()->network_configuration_handler()->GetProperties(
service_path,
base::Bind(&InternetOptionsHandler::UpdateConnectionDataCallback,
weak_factory_.GetWeakPtr()),
base::Bind(&ShillError, "UpdateConnectionData"));
NetworkHandler::Get()
->managed_network_configuration_handler()
->GetManagedProperties(
LoginState::Get()->primary_user_hash(),
service_path,
base::Bind(&InternetOptionsHandler::UpdateConnectionDataCallback,
weak_factory_.GetWeakPtr()),
base::Bind(&ShillError, "UpdateConnectionData"));
}
void InternetOptionsHandler::UpdateConnectionDataCallback(
const std::string& service_path,
const base::DictionaryValue& shill_properties) {
const base::DictionaryValue& onc_properties) {
const NetworkState* network = GetNetworkState(service_path);
if (!network)
return;
scoped_ptr<base::DictionaryValue> dictionary =
PopulateConnectionDetails(network, shill_properties);
PopulateConnectionDetails(network, onc_properties);
web_ui()->CallJavascriptFunction(kUpdateConnectionDataFunction, *dictionary);
}
......@@ -1192,7 +926,7 @@ void InternetOptionsHandler::SetIPConfigProperties(
void InternetOptionsHandler::PopulateDictionaryDetailsCallback(
const std::string& service_path,
const base::DictionaryValue& shill_properties) {
const base::DictionaryValue& onc_properties) {
const NetworkState* network = GetNetworkState(service_path);
if (!network) {
LOG(ERROR) << "Network properties not found: " << service_path;
......@@ -1202,68 +936,8 @@ void InternetOptionsHandler::PopulateDictionaryDetailsCallback(
details_path_ = service_path;
scoped_ptr<base::DictionaryValue> dictionary =
PopulateConnectionDetails(network, shill_properties);
::onc::ONCSource onc_source = ::onc::ONC_SOURCE_NONE;
const base::DictionaryValue* onc =
onc::FindPolicyForActiveUser(network->guid(), &onc_source);
const NetworkPropertyUIData property_ui_data(onc_source);
// IP config
scoped_ptr<base::DictionaryValue> ipconfig_dhcp(new base::DictionaryValue);
ipconfig_dhcp->SetString(kIpConfigAddress, network->ip_address());
ipconfig_dhcp->SetString(kIpConfigNetmask, network->GetNetmask());
ipconfig_dhcp->SetString(kIpConfigGateway, network->gateway());
std::string ipconfig_name_servers = network->GetDnsServersAsString();
ipconfig_dhcp->SetString(kIpConfigNameServers, ipconfig_name_servers);
ipconfig_dhcp->SetString(kIpConfigWebProxyAutoDiscoveryUrl,
network->web_proxy_auto_discovery_url().spec());
SetValueDictionary(kDictionaryIpConfig,
ipconfig_dhcp.release(),
property_ui_data,
dictionary.get());
std::string name_server_type = kNameServerTypeAutomatic;
int automatic_ip_config = 0;
scoped_ptr<base::DictionaryValue> static_ip_dict(
BuildIPInfoDictionary(shill_properties, true, &automatic_ip_config));
dictionary->SetBoolean(kIpConfigAutoConfig, automatic_ip_config == 0);
DCHECK(automatic_ip_config == 3 || automatic_ip_config == 0)
<< "UI doesn't support automatic specification of individual "
<< "static IP parameters.";
scoped_ptr<base::DictionaryValue> saved_ip_dict(
BuildIPInfoDictionary(shill_properties, false, NULL));
dictionary->Set(kDictionarySavedIp, saved_ip_dict.release());
// Determine what kind of name server setting we have by comparing the
// StaticIP and Google values with the ipconfig values.
std::string static_ip_nameservers;
static_ip_dict->GetString(kIpConfigNameServers, &static_ip_nameservers);
if (!static_ip_nameservers.empty() &&
static_ip_nameservers == ipconfig_name_servers) {
name_server_type = kNameServerTypeUser;
}
if (ipconfig_name_servers == kGoogleNameServers) {
name_server_type = kNameServerTypeGoogle;
}
SetValueDictionary(kDictionaryStaticIp,
static_ip_dict.release(),
property_ui_data,
dictionary.get());
dictionary->SetString(kTagNameServerType, name_server_type);
dictionary->SetString(kTagNameServersGoogle, kGoogleNameServers);
int priority = 0;
shill_properties.GetIntegerWithoutPathExpansion(
shill::kPriorityProperty, &priority);
SetManagedValueDictionary(network->guid(),
::onc::network_config::kPriority,
base::FundamentalValue(priority),
::onc::network_config::kPriority,
dictionary.get());
std::string onc_path_to_auto_connect;
PopulateConnectionDetails(network, onc_properties);
if (network->Matches(NetworkTypePattern::WiFi())) {
content::RecordAction(
base::UserMetricsAction("Options_NetworkShowDetailsWifi"));
......@@ -1271,8 +945,6 @@ void InternetOptionsHandler::PopulateDictionaryDetailsCallback(
content::RecordAction(
base::UserMetricsAction("Options_NetworkShowDetailsWifiConnected"));
}
onc_path_to_auto_connect =
::onc::network_config::WifiProperty(::onc::wifi::kAutoConnect);
} else if (network->Matches(NetworkTypePattern::VPN())) {
content::RecordAction(
base::UserMetricsAction("Options_NetworkShowDetailsVPN"));
......@@ -1280,8 +952,6 @@ void InternetOptionsHandler::PopulateDictionaryDetailsCallback(
content::RecordAction(
base::UserMetricsAction("Options_NetworkShowDetailsVPNConnected"));
}
onc_path_to_auto_connect = ::onc::network_config::VpnProperty(
::onc::vpn::kAutoConnect);
} else if (network->Matches(NetworkTypePattern::Cellular())) {
content::RecordAction(
base::UserMetricsAction("Options_NetworkShowDetailsCellular"));
......@@ -1291,47 +961,6 @@ void InternetOptionsHandler::PopulateDictionaryDetailsCallback(
}
}
if (!onc_path_to_auto_connect.empty()) {
bool auto_connect = false;
shill_properties.GetBooleanWithoutPathExpansion(
shill::kAutoConnectProperty, &auto_connect);
base::FundamentalValue auto_connect_value(auto_connect);
::onc::ONCSource auto_connect_onc_source = onc_source;
DCHECK_EQ(onc == NULL, onc_source == ::onc::ONC_SOURCE_NONE);
bool auto_connect_recommended =
auto_connect_onc_source != ::onc::ONC_SOURCE_NONE &&
onc::IsRecommendedValue(onc, onc_path_to_auto_connect);
// If a policy exists, |auto_connect_default_value| will contain either a
// recommended value (if |auto_connect_recommended| is true) or an enforced
// value (if |auto_connect_recommended| is false).
const base::Value* auto_connect_default_value = NULL;
if (onc)
onc->Get(onc_path_to_auto_connect, &auto_connect_default_value);
// Autoconnect can be controlled by the GlobalNetworkConfiguration of the
// ONC policy.
if (auto_connect_onc_source == ::onc::ONC_SOURCE_NONE &&
onc::PolicyAllowsOnlyPolicyNetworksToAutoconnect(
network->IsPrivate())) {
auto_connect_recommended = false;
auto_connect_onc_source = network->IsPrivate()
? ::onc::ONC_SOURCE_USER_POLICY
: ::onc::ONC_SOURCE_DEVICE_POLICY;
if (auto_connect) {
LOG(WARNING) << "Policy prevents autoconnect, but value is True.";
auto_connect_value = base::FundamentalValue(false);
}
}
SetManagedValueDictionaryEx(shill::kAutoConnectProperty,
auto_connect_value,
auto_connect_onc_source,
auto_connect_recommended,
auto_connect_default_value,
dictionary.get());
}
// Show details dialog
web_ui()->CallJavascriptFunction(kShowDetailedInfoFunction, *dictionary);
}
......@@ -1376,11 +1005,15 @@ void InternetOptionsHandler::NetworkCommandCallback(
base::Bind(&base::DoNothing),
base::Bind(&ShillError, "NetworkCommand: " + command));
} else if (command == kTagOptions) {
NetworkHandler::Get()->network_configuration_handler()->GetProperties(
service_path,
base::Bind(&InternetOptionsHandler::PopulateDictionaryDetailsCallback,
weak_factory_.GetWeakPtr()),
base::Bind(&ShillError, "NetworkCommand: " + command));
NetworkHandler::Get()
->managed_network_configuration_handler()
->GetManagedProperties(
LoginState::Get()->primary_user_hash(),
service_path,
base::Bind(
&InternetOptionsHandler::PopulateDictionaryDetailsCallback,
weak_factory_.GetWeakPtr()),
base::Bind(&ShillError, "NetworkCommand: " + command));
} else if (command == kTagConnect) {
const NetworkState* network = GetNetworkState(service_path);
if (network && network->type() == shill::kTypeWifi)
......
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