Commit 24e0812a authored by stevenjb@chromium.org's avatar stevenjb@chromium.org

Support Managed NetworkState format dictionaries for controlled settings.

BUG=279351

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288145 0039d316-1c4b-4281-b951-d872f2087c98
parent 40a16f97
......@@ -92,7 +92,7 @@
i18n-content="inetAutoConnectNetwork">
</label>
<span class="controlled-setting-indicator"
data="autoConnect" for="auto-connect-network-wifi">
managed="AutoConnect" for="auto-connect-network-wifi">
</span>
</span>
</span>
......@@ -114,22 +114,6 @@
<td class="option-name" i18n-content="inetBssid"></td>
<td id="wifi-bssid" class="option-value"></td>
</tr>
<tr class="wifi-network-setting">
<td class="option-name" i18n-content="inetAddress"></td>
<td id="wifi-ip-address" class="option-value"></td>
</tr>
<tr class="wifi-network-setting">
<td class="option-name" i18n-content="inetNetmask"></td>
<td id="wifi-netmask" class="option-value"></td>
</tr>
<tr class="wifi-network-setting">
<td class="option-name" i18n-content="inetGateway"></td>
<td id="wifi-gateway" class="option-value"></td>
</tr>
<tr class="wifi-network-setting">
<td class="option-name" i18n-content="inetNameServers"></td>
<td id="wifi-name-servers" class="option-value"></td>
</tr>
<tr id="wifi-security-entry">
<td class="options-name" i18n-content="inetEncryption"></td>
<td id="wifi-security" class="option-value"></td>
......@@ -176,7 +160,7 @@
i18n-content="inetAutoConnectNetwork">
</label>
<span class="controlled-setting-indicator"
data="autoConnect" for="auto-connect-network-wimax">
managed="AutoConnect" for="auto-connect-network-wimax">
</span>
</span>
</span>
......@@ -224,7 +208,7 @@
i18n-content="inetAutoConnectNetwork">
</label>
<span class="controlled-setting-indicator"
data="autoConnect" for="auto-connect-network-vpn">
managed="AutoConnect" for="auto-connect-network-vpn">
</span>
</span>
</span>
......@@ -344,7 +328,8 @@
i18n-content="inetAutoConnectNetwork">
</label>
<span class="controlled-setting-indicator"
data="autoConnect" for="auto-connect-network-cellular">
managed="AutoConnect"
for="auto-connect-network-cellular">
</span>
</span>
</span>
......
......@@ -16,7 +16,43 @@ cr.define('options.internet', function() {
/** @const */ var IPAddressField = options.internet.IPAddressField;
/**
/*
* Helper function to get the "Active" value of a property from a dictionary
* that includes ONC managed properties, e.g. getActiveValue(data, 'Name').
* We use (data, key) instead of getActiveValue(data[key]) so that we can
* (possibly) add ONC key validation once all properties use ONC.
* @param {object} data The properties dictionary.
* @param {string} key The property key.
* @return {*} the property value or undefined.
*/
function getActiveValue(data, key) {
if (!(key in data))
return undefined;
var property = data[key];
if (typeof property != 'object')
return property;
if ('Active' in property)
return property['Active'];
if ('Effective' in property) {
var effective = property.Effective;
if (effective in property)
return property[effective];
}
return undefined;
}
/**
* Helper function for nested ONC properties, e.g. data[WiFi][Strength].
* @param {object|string} property The property which must ether be
* a dictionary object or not be present.
* @return {*} the property value or undefined.
*/
function getActiveDictionaryValue(data, dict, key) {
if (!(dict in data))
return undefined;
return getActiveValue(data[dict], key);
}
/**
* Helper function to set hidden attribute for elements matching a selector.
* @param {string} selector CSS selector for extracting a list of elements.
* @param {bool} hidden New hidden value.
......@@ -97,17 +133,9 @@ cr.define('options.internet', function() {
* @param {Object} data The network ONC dictionary.
*/
function getNetworkName(data) {
if (data.Type == 'Ethernet')
if (data.type == 'Ethernet')
return loadTimeData.getString('ethernetName');
return data.Name;
}
/**
* Returns True if the network represented by 'data' is a secure WiFi network.
* @param {Object} data The network ONC dictionary.
*/
function isSecureWiFiNetwork(data) {
return data.WiFi && data.WiFi.Security && data.WiFi.Security != 'None';
return getActiveValue(data, 'Name');
}
/////////////////////////////////////////////////////////////////////////////
......@@ -146,7 +174,6 @@ cr.define('options.internet', function() {
chrome.send('networkCommand', [networkType, servicePath, 'options']);
},
/**
* Initializes the contents of the page.
*/
......@@ -411,9 +438,64 @@ cr.define('options.internet', function() {
},
/**
* Update details page controls.
* Creates an indicator event for controlled properties using
* the same dictionary format as CoreOptionsHandler::CreateValueForPref.
* @param {string} name The name for the Event.
* @param {Object} data Property dictionary with |value|, |controlledBy|,
* and |recommendedValue| properties set.
* @private
*/
createControlledEvent_: function(name, propData) {
var event = new Event(name);
event.value = {
value: propData.value,
controlledBy: propData.controlledBy,
recommendedValue: propData.recommendedValue
};
return event;
},
/**
* Creates an indicator event for controlled properties using
* the ONC getManagedProperties dictionary format.
* @param {string} name The name for the Event.
* @param {Object} data ONC managed network property dictionary.
* @private
*/
createManagedEvent_: function(name, propData) {
var event = new Event(name);
event.value = {};
// Set the current value and recommended value.
var activeValue = propData['Active'];
var effective = propData['Effective'];
if (activeValue == undefined)
activeValue = propData[effective];
event.value.value = activeValue;
// If a property is editable then it is not enforced, and 'controlledBy'
// is set to 'recommended' unless effective == {User|Shared}Setting, in
// which case the value was modifed from the recommended value.
// Otherwise if 'Effective' is set to 'UserPolicy' or 'DevicePolicy' then
// the set value is mandated by the policy.
if (propData['UserEditable']) {
if (effective == 'UserPolicy')
event.value.controlledBy = 'recommended';
event.value.recommendedValue = propData['UserPolicy'];
} else if (propData['DeviceEditable']) {
if (effective == 'DevicePolicy')
event.value.controlledBy = 'recommended';
event.value.recommendedValue = propData['DevicePolicy'];
} else if (effective == 'UserPolicy' || effective == 'DevicePolicy') {
event.value.controlledBy = 'policy';
}
return event;
},
/**
* Update details page controls.
*/
updateControls: function() {
// 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
......@@ -425,10 +507,13 @@ cr.define('options.internet', function() {
!this.connected && this.deviceConnected;
// Network type related.
updateHidden('#details-internet-page .cellular-details', !this.cellular);
updateHidden('#details-internet-page .wifi-details', !this.wireless);
updateHidden('#details-internet-page .wimax-details', !this.wimax);
updateHidden('#details-internet-page .vpn-details', !this.vpn);
updateHidden('#details-internet-page .cellular-details',
this.type != 'Cellular');
updateHidden('#details-internet-page .wifi-details',
this.type != 'WiFi');
updateHidden('#details-internet-page .wimax-details',
this.type != 'Wimax');
updateHidden('#details-internet-page .vpn-details', this.type != 'VPN');
updateHidden('#details-internet-page .proxy-details', !this.showProxy);
// Cellular
......@@ -442,16 +527,13 @@ cr.define('options.internet', function() {
// Wifi
// Network information merged into the Wifi tab for wireless networks
// unless the option is set for enabling a static IP configuration.
// Hide network tab for VPN.
updateHidden('#details-internet-page .network-details',
(this.wireless && !this.showStaticIPConfig) || this.vpn);
updateHidden('#details-internet-page .wifi-network-setting',
this.showStaticIPConfig);
this.type == 'VPN');
// Password and shared.
updateHidden('#details-internet-page #password-details',
!this.wireless || !this.hasSecurity);
this.type != 'WiFi' || !this.hasSecurity);
updateHidden('#details-internet-page #wifi-shared-network',
!this.shared);
updateHidden('#details-internet-page #prefer-network',
......@@ -459,7 +541,7 @@ cr.define('options.internet', function() {
// WiMAX.
updateHidden('#details-internet-page #wimax-shared-network',
!this.shared);
!this.shared);
// Proxy
this.updateProxyBannerVisibility_();
......@@ -586,7 +668,7 @@ cr.define('options.internet', function() {
$('manual-proxy-parms').hidden = !$('manual-proxy').checked;
chrome.send('coreOptionsUserMetricsAction',
['Options_NetworkManualProxy_Enable']);
},
}
};
/**
......@@ -647,9 +729,6 @@ cr.define('options.internet', function() {
$('activate-details').hidden = true;
$('view-account-details').hidden = true;
$('web-proxy-auto-discovery').hidden = true;
detailsPage.cellular = false;
detailsPage.wireless = false;
detailsPage.vpn = false;
detailsPage.showProxy = true;
updateHidden('#internet-tab', true);
updateHidden('#details-tab-strip', true);
......@@ -707,21 +786,21 @@ cr.define('options.internet', function() {
DetailsInternetPage.loginFromDetails = function() {
var data = $('connection-state').data;
var servicePath = data.servicePath;
chrome.send('networkCommand', [data.Type, servicePath, 'connect']);
chrome.send('networkCommand', [data.type, servicePath, 'connect']);
PageManager.closeOverlay();
};
DetailsInternetPage.disconnectNetwork = function() {
var data = $('connection-state').data;
var servicePath = data.servicePath;
chrome.send('networkCommand', [data.Type, servicePath, 'disconnect']);
chrome.send('networkCommand', [data.type, servicePath, 'disconnect']);
PageManager.closeOverlay();
};
DetailsInternetPage.configureNetwork = function() {
var data = $('connection-state').data;
var servicePath = data.servicePath;
chrome.send('networkCommand', [data.Type, servicePath, 'configure']);
chrome.send('networkCommand', [data.type, servicePath, 'configure']);
PageManager.closeOverlay();
};
......@@ -729,25 +808,25 @@ cr.define('options.internet', function() {
var data = $('connection-state').data;
var servicePath = data.servicePath;
if (data.Type == 'Cellular')
chrome.send('networkCommand', [data.Type, servicePath, 'activate']);
chrome.send('networkCommand', [data.type, servicePath, 'activate']);
PageManager.closeOverlay();
};
DetailsInternetPage.setDetails = function() {
var data = $('connection-state').data;
var servicePath = data.servicePath;
if (data.Type == 'WiFi') {
if (data.type == 'WiFi') {
sendCheckedIfEnabled(servicePath, 'setPreferNetwork',
$('prefer-network-wifi'));
sendCheckedIfEnabled(servicePath, 'setAutoConnect',
$('auto-connect-network-wifi'));
} else if (data.Type == 'Wimax') {
} else if (data.type == 'Wimax') {
sendCheckedIfEnabled(servicePath, 'setAutoConnect',
$('auto-connect-network-wimax'));
} else if (data.Type == 'Cellular') {
} else if (data.type == 'Cellular') {
sendCheckedIfEnabled(servicePath, 'setAutoConnect',
$('auto-connect-network-cellular'));
} else if (data.Type == 'VPN') {
} else if (data.type == 'VPN') {
chrome.send('setServerHostname',
[servicePath,
$('inet-server-hostname').value]);
......@@ -829,7 +908,7 @@ cr.define('options.internet', function() {
return;
}
var connectState = data.ConnectionState;
var connectState = getActiveValue(data, 'ConnectionState');
if (connectState == 'NotConnected') {
$('details-internet-login').hidden = false;
// Connecting to an unconfigured network might trigger certificate
......@@ -842,10 +921,10 @@ cr.define('options.internet', function() {
$('details-internet-disconnect').hidden = false;
}
var connectable = data.Connectable;
var connectable = getActiveValue(data, 'Connectable');
if (connectState != 'Connected' &&
(!connectable || isSecureWiFiNetwork(data) ||
(data.Type == 'Wimax' || data.Type == 'VPN'))) {
(!connectable || this.hasSecurity ||
(data.type == 'Wimax' || data.type == 'VPN'))) {
$('details-internet-configure').hidden = false;
} else {
$('details-internet-configure').hidden = true;
......@@ -867,19 +946,19 @@ cr.define('options.internet', function() {
// Update our cached data object.
updateDataObject(data, update);
var connectionState = getActiveValue(data, 'ConnectionState');
var connectionStateString = networkOncStateString(connectionState);
detailsPage.deviceConnected = data.deviceConnected;
detailsPage.connecting = data.ConnectionState == 'Connecting';
detailsPage.connected = data.ConnectionState == 'Connected';
var connectionStateString = networkOncStateString(data.ConnectionState);
detailsPage.connected = connectionState == 'Connected';
$('connection-state').textContent = connectionStateString;
this.updateConnectionButtonVisibilty(data);
if (data.Type == 'WiFi') {
if (data.type == 'WiFi') {
$('wifi-connection-state').textContent = connectionStateString;
} else if (data.Type == 'Wimax') {
} else if (data.type == 'Wimax') {
$('wimax-connection-state').textContent = connectionStateString;
} else if (data.Type == 'Cellular') {
} else if (data.type == 'Cellular') {
$('activation-state').textContent = data.activationState;
$('buyplan-details').hidden = !data.showBuyButton;
......@@ -903,27 +982,31 @@ cr.define('options.internet', function() {
DetailsInternetPage.showDetailedInfo = function(data) {
var detailsPage = DetailsInternetPage.getInstance();
data.type = getActiveValue(data, 'Type'); // Get Active Type value.
// Populate header
$('network-details-title').textContent = getNetworkName(data);
var connectionStateString = networkOncStateString(data.ConnectionState);
var connectionState = getActiveValue(data, 'ConnectionState');
var connectionStateString = networkOncStateString(connectionState);
detailsPage.connected = connectionState == 'Connected';
$('network-details-subtitle-status').textContent = connectionStateString;
var typeKey = null;
switch (data.Type) {
case 'Ethernet':
typeKey = 'ethernetTitle';
break;
case 'WiFi':
typeKey = 'wifiTitle';
break;
case 'Wimax':
typeKey = 'wimaxTitle';
break;
case 'Cellular':
typeKey = 'cellularTitle';
break;
case 'VPN':
typeKey = 'vpnTitle';
break;
switch (data.type) {
case 'Ethernet':
typeKey = 'ethernetTitle';
break;
case 'WiFi':
typeKey = 'wifiTitle';
break;
case 'Wimax':
typeKey = 'wimaxTitle';
break;
case 'Cellular':
typeKey = 'cellularTitle';
break;
case 'VPN':
typeKey = 'vpnTitle';
break;
}
var typeLabel = $('network-details-subtitle-type');
var typeSeparator = $('network-details-subtitle-separator');
......@@ -936,8 +1019,7 @@ cr.define('options.internet', function() {
typeSeparator.hidden = true;
}
// TODO(chocobo): Is this hack to cache the data here reasonable?
// TODO(kevers): Find more appropriate place to cache data.
// TODO(stevenjb): Find a more appropriate place to cache data.
$('connection-state').data = data;
$('buyplan-details').hidden = true;
......@@ -949,8 +1031,7 @@ cr.define('options.internet', function() {
$('web-proxy-auto-discovery').hidden = true;
detailsPage.deviceConnected = data.deviceConnected;
detailsPage.connecting = data.ConnectionState == 'Connecting';
detailsPage.connected = data.ConnectionState == 'Connected';
detailsPage.connected = connectionState == 'Connected';
// Only show proxy for remembered networks.
if (data.remembered) {
......@@ -959,7 +1040,6 @@ cr.define('options.internet', function() {
} else {
detailsPage.showProxy = false;
}
detailsPage.showStaticIPConfig = data.showStaticIPConfig;
$('connection-state').textContent = connectionStateString;
var ipAutoConfig = data.ipAutoConfig ? 'automatic' : 'user';
......@@ -1050,94 +1130,88 @@ cr.define('options.internet', function() {
DetailsInternetPage.updateNameServerDisplay(data.nameServerType);
if (data.MacAddress) {
$('hardware-address').textContent = data.MacAddress;
var macAddress = getActiveValue(data, 'MacAddress');
if (macAddress) {
$('hardware-address').textContent = macAddress;
$('hardware-address-row').style.display = 'table-row';
} else {
// This is most likely a device without a hardware address.
$('hardware-address-row').style.display = 'none';
}
var setOrHideParent = function(field, property) {
if (property) {
$(field).textContent = property;
$(field).parentElement.hidden = false;
} else {
$(field).parentElement.hidden = true;
}
};
var networkName = getNetworkName(data);
// Signal strength as percentage (for WiFi and Wimax).
var signalStrength =
(data.WiFi && data.WiFi.SignalStrength) ? data.WiFi.SignalStrength : 0;
var signalStrength;
if (data.type == 'WiFi' || data.type == 'Wimax') {
signalStrength =
getActiveDictionaryValue(data, data.type, 'SignalStrength');
}
if (!signalStrength)
signalStrength = 0;
var strengthFormat = loadTimeData.getString('inetSignalStrengthFormat');
strengthFormat = strengthFormat.replace('$1', signalStrength);
var strengthString = strengthFormat.replace('$1', signalStrength);
if (data.Type == 'WiFi') {
detailsPage.type = data.type;
if (data.type == 'WiFi') {
assert(data.WiFi, 'WiFi network has no WiFi object' + networkName);
OptionsPage.showTab($('wifi-network-nav-tab'));
detailsPage.wireless = true;
detailsPage.vpn = false;
detailsPage.ethernet = false;
detailsPage.cellular = false;
detailsPage.gsm = false;
detailsPage.wimax = false;
detailsPage.shared = data.shared;
$('wifi-connection-state').textContent = connectionStateString;
$('wifi-ssid').textContent = data.WiFi ? data.WiFi.SSID : data.Name;
if (data.WiFi && data.WiFi.BSSID) {
$('wifi-bssid').textContent = data.WiFi.BSSID;
$('wifi-bssid-entry').hidden = false;
} else {
$('wifi-bssid-entry').hidden = true;
}
$('wifi-ip-address').textContent = inetAddress.value;
$('wifi-netmask').textContent = inetNetmask.value;
$('wifi-gateway').textContent = inetGateway.value;
$('wifi-name-servers').textContent = inetNameServers;
var hasSecurity = isSecureWiFiNetwork(data);
if (hasSecurity) {
$('wifi-security').textContent = data.WiFi.Security;
$('wifi-security-entry').hidden = false;
} else {
$('wifi-security-entry').hidden = true;
}
var ssid = getActiveDictionaryValue(data, 'WiFi', 'SSID');
$('wifi-ssid').textContent = ssid ? ssid : networkName;
setOrHideParent('wifi-bssid',
getActiveDictionaryValue(data, 'WiFi', 'BSSID'));
var security = getActiveDictionaryValue(data, 'WiFi', 'Security');
if (security == 'None')
security = undefined;
setOrHideParent('wifi-security', security);
// Frequency is in MHz.
var frequency =
data.WiFi && data.WiFi.Frequency ? data.WiFi.Frequency : 0;
var frequency = getActiveDictionaryValue(data, 'WiFi', 'Frequency');
if (!frequency)
frequency = 0;
var frequencyFormat = loadTimeData.getString('inetFrequencyFormat');
frequencyFormat = frequencyFormat.replace('$1', frequency);
$('wifi-frequency').textContent = frequencyFormat;
$('wifi-signal-strength').textContent = strengthFormat;
if (data.MacAddress) {
$('wifi-hardware-address').textContent = data.MacAddress;
$('wifi-hardware-address-entry').hidden = false;
} else {
$('wifi-hardware-address-entry').hidden = true;
}
$('wifi-signal-strength').textContent = strengthString;
setOrHideParent('wifi-hardware-address',
getActiveValue(data, 'MacAddress'));
detailsPage.showPreferred = data.remembered;
$('prefer-network-wifi').checked = data.preferred.value;
$('prefer-network-wifi').disabled = !data.remembered;
$('auto-connect-network-wifi').checked = data.autoConnect.value;
$('auto-connect-network-wifi').checked =
getActiveValue(data, 'AutoConnect');
$('auto-connect-network-wifi').disabled = !data.remembered;
detailsPage.hasSecurity = hasSecurity;
} else if (data.Type == 'Wimax') {
detailsPage.hasSecurity = security != undefined;
} else if (data.type == 'Wimax') {
assert(data.Wimax, 'Wimax network has no Wimax object' + networkName);
OptionsPage.showTab($('wimax-network-nav-tab'));
detailsPage.wimax = true;
detailsPage.wireless = false;
detailsPage.vpn = false;
detailsPage.ethernet = false;
detailsPage.cellular = false;
detailsPage.gsm = false;
detailsPage.shared = data.shared;
detailsPage.showPreferred = data.remembered;
$('wimax-connection-state').textContent = connectionStateString;
$('auto-connect-network-wimax').checked = data.autoConnect.value;
$('auto-connect-network-wimax').checked =
getActiveValue(data, 'AutoConnect');
$('auto-connect-network-wimax').disabled = !data.remembered;
if (data.identity) {
$('wimax-eap-identity').textContent = data.identity;
$('wimax-eap-identity-entry').hidden = false;
} else {
$('wimax-eap-identity-entry').hidden = true;
}
$('wimax-signal-strength').textContent = strengthFormat;
} else if (data.Type == 'Cellular') {
var identity;
if (data.Wimax.EAP)
identity = getActiveValue(data.Wimax.EAP, 'Identity');
setOrHideParent('wimax-eap-identity', identity);
$('wimax-signal-strength').textContent = strengthString;
} else if (data.type == 'Cellular') {
assert(data.Cellular,
'Cellular network has no Cellular object' + networkName);
OptionsPage.showTab($('cellular-conn-nav-tab'));
detailsPage.ethernet = false;
detailsPage.wireless = false;
detailsPage.wimax = false;
detailsPage.vpn = false;
detailsPage.cellular = true;
if (data.showCarrierSelect && data.currentCarrierIndex != -1) {
var carrierSelector = $('select-carrier');
carrierSelector.onchange = DetailsInternetPage.handleCarrierChanged;
......@@ -1149,24 +1223,31 @@ cr.define('options.internet', function() {
}
carrierSelector.selectedIndex = data.currentCarrierIndex;
} else {
$('service-name').textContent = getNetworkName(data);
$('service-name').textContent = networkName;
}
$('network-technology').textContent = data.Cellular.NetworkTechnology;
$('network-technology').textContent =
getActiveDictionaryValue(data, 'Cellular', 'NetworkTechnology');
$('activation-state').textContent = data.activationState;
$('roaming-state').textContent = data.roamingState;
$('restricted-pool').textContent = data.restrictedPool;
$('error-state').textContent = data.errorState;
$('manufacturer').textContent = data.Cellular.Manufacturer;
$('model-id').textContent = data.Cellular.ModelID;
$('firmware-revision').textContent = data.Cellular.FirmwareRevision;
$('hardware-revision').textContent = data.Cellular.HardwareRevision;
$('mdn').textContent = data.Cellular.MDN;
$('error-state').textContent = data.errorMessage;
$('manufacturer').textContent =
getActiveDictionaryValue(data, 'Cellular', 'Manufacturer');
$('model-id').textContent =
getActiveDictionaryValue(data, 'Cellular', 'ModelID');
$('firmware-revision').textContent =
getActiveDictionaryValue(data, 'Cellular', 'FirmwareRevision');
$('hardware-revision').textContent =
getActiveDictionaryValue(data, 'Cellular', 'HardwareRevision');
$('mdn').textContent = getActiveDictionaryValue(data, 'Cellular', 'MDN');
// Show ServingOperator properties only if available.
if (data.Cellular.ServingOperator) {
$('operator-name').textContent = data.Cellular.ServingOperator.Name;
$('operator-code').textContent = data.Cellular.ServingOperator.Code;
$('operator-name').textContent =
getActiveValue(data.Cellular.ServingOperator, 'Name');
$('operator-code').textContent =
getActiveValue(data.Cellular.ServingOperator, 'Code');
} else {
$('operator-name').parentElement.hidden = true;
$('operator-code').parentElement.hidden = true;
......@@ -1177,23 +1258,23 @@ cr.define('options.internet', function() {
updateHidden('#details-internet-page .cdma-only', false);
// Show IMEI/ESN/MEID/MIN/PRL only if they are available.
(function() {
var setContentOrHide = function(field, value) {
if (value)
$(field).textContent = value;
else
$(field).parentElement.hidden = true;
};
setContentOrHide('esn', data.Cellular.ESN);
setContentOrHide('imei', data.Cellular.IMEI);
setContentOrHide('meid', data.Cellular.MEID);
setContentOrHide('min', data.Cellular.MIN);
setContentOrHide('prl-version', data.Cellular.PRLVersion);
})();
detailsPage.gsm = data.Cellular.Family == 'GSM';
setOrHideParent('esn', getActiveDictionaryValue(data, 'Cellular', 'ESN'));
setOrHideParent(
'imei', getActiveDictionaryValue(data, 'Cellular', 'IMEI'));
setOrHideParent(
'meid', getActiveDictionaryValue(data, 'Cellular', 'MEID'));
setOrHideParent('min', getActiveDictionaryValue(data, 'Cellular', 'MIN'));
setOrHideParent(
'prl-version',
getActiveDictionaryValue(data, 'Cellular', 'PRLVersion'));
var family = getActiveDictionaryValue(data, 'Cellular', 'GSM');
detailsPage.gsm = family == 'GSM';
if (detailsPage.gsm) {
$('iccid').textContent = data.Cellular.ICCID;
$('imsi').textContent = data.Cellular.IMSI;
$('iccid').textContent =
getActiveDictionaryValue(data, 'Cellular', 'ICCID');
$('imsi').textContent =
getActiveDictionaryValue(data, 'Cellular', 'IMSI');
var apnSelector = $('select-apn');
// Clear APN lists, keep only last element that "other".
......@@ -1242,7 +1323,8 @@ cr.define('options.internet', function() {
$('sim-card-lock-enabled').checked = lockEnabled;
$('change-pin').hidden = !lockEnabled;
}
$('auto-connect-network-cellular').checked = data.autoConnect.value;
$('auto-connect-network-cellular').checked =
getActiveValue(data, 'AutoConnect');
$('auto-connect-network-cellular').disabled = false;
$('buyplan-details').hidden = !data.showBuyButton;
......@@ -1251,15 +1333,10 @@ cr.define('options.internet', function() {
if (data.showActivateButton) {
$('details-internet-login').hidden = true;
}
} else if (data.Type == 'VPN') {
} else if (data.type == 'VPN') {
OptionsPage.showTab($('vpn-nav-tab'));
detailsPage.wireless = false;
detailsPage.wimax = false;
detailsPage.vpn = true;
detailsPage.ethernet = false;
detailsPage.cellular = false;
detailsPage.gsm = false;
$('inet-service-name').textContent = getNetworkName(data);
$('inet-service-name').textContent = networkName;
$('inet-provider-type').textContent = data.providerType;
$('inet-username').textContent = data.username;
var inetServerHostname = $('inet-server-hostname');
......@@ -1268,38 +1345,31 @@ cr.define('options.internet', function() {
PageManager.hideBubble();
inetServerHostname.value = data.serverHostname.recommendedValue;
};
$('auto-connect-network-vpn').checked = data.autoConnect.value;
$('auto-connect-network-vpn').checked =
getActiveValue(data, 'AutoConnect');
$('auto-connect-network-vpn').disabled = false;
} else {
OptionsPage.showTab($('internet-nav-tab'));
detailsPage.ethernet = true;
detailsPage.wireless = false;
detailsPage.wimax = false;
detailsPage.vpn = false;
detailsPage.cellular = false;
detailsPage.gsm = false;
}
// Update controlled option indicators.
indicators = cr.doc.querySelectorAll(
var indicators = cr.doc.querySelectorAll(
'#details-internet-page .controlled-setting-indicator');
for (var i = 0; i < indicators.length; i++) {
var propName = indicators[i].getAttribute('data');
var attributeName =
indicators[i].hasAttribute('managed') ? 'managed' : 'data';
var propName = indicators[i].getAttribute(attributeName);
if (!propName || !data[propName])
continue;
var propData = data[propName];
// Create a synthetic pref change event decorated as
// CoreOptionsHandler::CreateValueForPref() does.
var event = new Event(name);
event.value = {
value: propData.value,
controlledBy: propData.controlledBy,
recommendedValue: propData.recommendedValue
};
var event;
if (attributeName == 'managed')
event = detailsPage.createManagedEvent_(propName, data[propName]);
else
event = detailsPage.createControlledEvent_(propName, data[propName]);
indicators[i].handlePrefChange(event);
var forElement = $(indicators[i].getAttribute('for'));
if (forElement) {
if (propData.controlledBy == 'policy')
if (event.value.controlledBy == 'policy')
forElement.disabled = true;
if (forElement.resetHandler)
indicators[i].resetHandler = forElement.resetHandler;
......
......@@ -44,6 +44,7 @@
#include "chromeos/network/network_util.h"
#include "chromeos/network/onc/onc_signature.h"
#include "chromeos/network/onc/onc_translator.h"
#include "chromeos/network/onc/onc_utils.h"
#include "components/onc/onc_constants.h"
#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents.h"
......@@ -126,7 +127,6 @@ const char kTagActivate[] = "activate";
const char kTagActivationState[] = "activationState";
const char kTagAddConnection[] = "add";
const char kTagApn[] = "apn";
const char kTagAutoConnect[] = "autoConnect";
const char kTagCarrierSelectFlag[] = "showCarrierSelect";
const char kTagCarrierUrl[] = "carrierUrl";
const char kTagCellularAvailable[] = "cellularAvailable";
......@@ -137,9 +137,8 @@ const char kTagConnect[] = "connect";
const char kTagControlledBy[] = "controlledBy";
const char kTagDeviceConnected[] = "deviceConnected";
const char kTagDisconnect[] = "disconnect";
const char kTagErrorState[] = "errorState";
const char kTagErrorMessage[] = "errorMessage";
const char kTagForget[] = "forget";
const char kTagIdentity[] = "identity";
const char kTagLanguage[] = "language";
const char kTagLastGoodApn[] = "lastGoodApn";
const char kTagLocalizedName[] = "localizedName";
......@@ -164,7 +163,6 @@ const char kTagCarriers[] = "carriers";
const char kTagCurrentCarrierIndex[] = "currentCarrierIndex";
const char kTagShared[] = "shared";
const char kTagShowActivateButton[] = "showActivateButton";
const char kTagShowStaticIPConfig[] = "showStaticIPConfig";
const char kTagShowViewAccountButton[] = "showViewAccountButton";
const char kTagSimCardLockEnabled[] = "simCardLockEnabled";
const char kTagSupportUrl[] = "supportUrl";
......@@ -295,57 +293,81 @@ base::DictionaryValue* BuildIPInfoDictionary(
return ip_info_dict.release();
}
// Decorate dictionary |value_dict| with policy information from |ui_data|.
void DecorateValueDictionary(const NetworkPropertyUIData& ui_data,
const base::Value& value,
base::DictionaryValue* value_dict) {
const base::Value* recommended_value = ui_data.default_value();
if (ui_data.IsManaged())
value_dict->SetString(kTagControlledBy, kTagPolicy);
else if (recommended_value && recommended_value->Equals(&value))
value_dict->SetString(kTagControlledBy, kTagRecommended);
if (recommended_value)
value_dict->Set(kTagRecommendedValue, recommended_value->DeepCopy());
}
// Decorate pref value as CoreOptionsHandler::CreateValueForPref() does and
// store it under |key| in |settings|. Takes ownership of |value|.
void SetValueDictionary(base::DictionaryValue* settings,
const char* key,
void SetValueDictionary(const char* key,
base::Value* value,
const NetworkPropertyUIData& ui_data) {
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);
DecorateValueDictionary(ui_data, *value, 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;
}
// Creates a decorated dictionary like SetValueDictionary does, but extended for
// the Autoconnect property, which respects additionally global network policy.
void SetAutoconnectValueDictionary(bool network_is_private,
::onc::ONCSource onc_source,
bool current_autoconnect,
const NetworkPropertyUIData& ui_data,
base::DictionaryValue* settings) {
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.
// Note(stevenjb): This is bridge code until we use GetManagedProperties to
// retrieve Shill properties.
void SetManagedValueDictionary(const char* key,
const base::Value* value,
::onc::ONCSource onc_source,
bool recommended,
const base::Value* default_value,
base::DictionaryValue* settings) {
base::DictionaryValue* dict = new base::DictionaryValue();
base::Value* value = new base::FundamentalValue(current_autoconnect);
// DictionaryValue::Set() takes ownership of |value|.
dict->Set(kTagValue, value);
settings->Set(kTagAutoConnect, dict);
if (onc_source != ::onc::ONC_SOURCE_USER_POLICY &&
onc_source != ::onc::ONC_SOURCE_DEVICE_POLICY) {
// Autoconnect can be controlled by the GlobalNetworkConfiguration of the
// ONC policy.
bool only_policy_autoconnect =
onc::PolicyAllowsOnlyPolicyNetworksToAutoconnect(network_is_private);
if (only_policy_autoconnect) {
dict->SetString(kTagControlledBy, kTagPolicy);
return;
settings->Set(key, dict);
DCHECK(value);
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);
}
}
DecorateValueDictionary(ui_data, *value, dict);
}
std::string CopyStringFromDictionary(const base::DictionaryValue& source,
......@@ -401,9 +423,10 @@ void PopulateVPNDetails(const NetworkState* vpn,
std::string provider_host;
provider_properties->GetStringWithoutPathExpansion(
shill::kHostProperty, &provider_host);
SetValueDictionary(dictionary, kTagServerHostname,
SetValueDictionary(kTagServerHostname,
new base::StringValue(provider_host),
hostname_ui_data);
hostname_ui_data,
dictionary);
}
// Given a list of supported carrier's by the device, return the index of
......@@ -430,13 +453,6 @@ int FindCurrentCarrierIndex(const base::ListValue* carriers,
return -1;
}
void PopulateWimaxDetails(const NetworkState* wimax,
const base::DictionaryValue& shill_properties,
base::DictionaryValue* dictionary) {
CopyStringFromDictionary(
shill_properties, shill::kEapIdentityProperty, kTagIdentity, dictionary);
}
void CreateDictionaryFromCellularApn(const base::DictionaryValue* apn,
base::DictionaryValue* dictionary) {
CopyStringFromDictionary(*apn, shill::kApnProperty, kTagApn, dictionary);
......@@ -508,10 +524,10 @@ void PopulateCellularDetails(const NetworkState* cellular,
FindPolicyByGUID(LoginState::Get()->primary_user_hash(),
cellular->guid(), &onc_source);
const NetworkPropertyUIData cellular_property_ui_data(onc_source);
SetValueDictionary(dictionary,
kTagSimCardLockEnabled,
SetValueDictionary(kTagSimCardLockEnabled,
new base::FundamentalValue(device->sim_lock_enabled()),
cellular_property_ui_data);
cellular_property_ui_data,
dictionary);
carrier_id = device->home_provider_id();
device_properties.GetStringWithoutPathExpansion(shill::kMdnProperty, &mdn);
......@@ -538,10 +554,10 @@ void PopulateCellularDetails(const NetworkState* cellular,
}
}
}
SetValueDictionary(dictionary,
kTagProviderApnList,
SetValueDictionary(kTagProviderApnList,
apn_list_value,
cellular_property_ui_data);
cellular_property_ui_data,
dictionary);
const base::ListValue* supported_carriers;
if (device_properties.GetListWithoutPathExpansion(
shill::kSupportedCarriersProperty, &supported_carriers)) {
......@@ -621,8 +637,15 @@ scoped_ptr<base::DictionaryValue> PopulateConnectionDetails(
NetworkHandler::Get()->network_state_handler()->GetDeviceState(
network->device_path());
if (device) {
shill_properties_with_device->Set(shill::kDeviceProperty,
device->properties().DeepCopy());
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(
......@@ -630,7 +653,7 @@ scoped_ptr<base::DictionaryValue> PopulateConnectionDetails(
dictionary->SetString(kNetworkInfoKeyServicePath, network->path());
dictionary->SetString(
kTagErrorState,
kTagErrorMessage,
ash::network_connect::ErrorString(network->error(), network->path()));
dictionary->SetBoolean(kTagRemembered, !network->profile_path().empty());
......@@ -644,9 +667,7 @@ scoped_ptr<base::DictionaryValue> PopulateConnectionDetails(
NetworkTypePattern::Primitive(type));
dictionary->SetBoolean(kTagDeviceConnected, connected_network != NULL);
if (type == shill::kTypeWimax)
PopulateWimaxDetails(network, shill_properties, dictionary.get());
else if (type == shill::kTypeCellular)
if (type == shill::kTypeCellular)
PopulateCellularDetails(network, shill_properties, dictionary.get());
else if (type == shill::kTypeVPN)
PopulateVPNDetails(network, shill_properties, dictionary.get());
......@@ -1272,10 +1293,10 @@ void InternetOptionsHandler::PopulateDictionaryDetailsCallback(
ipconfig_dhcp->SetString(kIpConfigNameServers, ipconfig_name_servers);
ipconfig_dhcp->SetString(kIpConfigWebProxyAutoDiscoveryUrl,
network->web_proxy_auto_discovery_url().spec());
SetValueDictionary(dictionary.get(),
kDictionaryIpConfig,
SetValueDictionary(kDictionaryIpConfig,
ipconfig_dhcp.release(),
property_ui_data);
property_ui_data,
dictionary.get());
std::string name_server_type = kNameServerTypeAutomatic;
int automatic_ip_config = 0;
......@@ -1300,28 +1321,23 @@ void InternetOptionsHandler::PopulateDictionaryDetailsCallback(
if (ipconfig_name_servers == kGoogleNameServers) {
name_server_type = kNameServerTypeGoogle;
}
SetValueDictionary(dictionary.get(),
kDictionaryStaticIp,
SetValueDictionary(kDictionaryStaticIp,
static_ip_dict.release(),
property_ui_data);
property_ui_data,
dictionary.get());
dictionary->SetString(kTagNameServerType, name_server_type);
dictionary->SetString(kTagNameServersGoogle, kGoogleNameServers);
// Enable static ip config for Ethernet or WiFi.
bool staticIPConfig = network->Matches(NetworkTypePattern::Ethernet()) ||
network->Matches(NetworkTypePattern::WiFi());
dictionary->SetBoolean(kTagShowStaticIPConfig, staticIPConfig);
int priority = 0;
shill_properties.GetIntegerWithoutPathExpansion(
shill::kPriorityProperty, &priority);
bool preferred = priority > 0;
SetValueDictionary(dictionary.get(), kTagPreferred,
SetValueDictionary(kTagPreferred,
new base::FundamentalValue(preferred),
property_ui_data);
property_ui_data,
dictionary.get());
NetworkPropertyUIData auto_connect_ui_data(onc_source);
std::string onc_path_to_auto_connect;
if (network->Matches(NetworkTypePattern::WiFi())) {
content::RecordAction(
......@@ -1349,18 +1365,44 @@ void InternetOptionsHandler::PopulateDictionaryDetailsCallback(
"Options_NetworkShowDetailsCellularConnected"));
}
}
if (!onc_path_to_auto_connect.empty()) {
auto_connect_ui_data.ParseOncProperty(
onc_source, onc, onc_path_to_auto_connect);
bool auto_connect = false;
shill_properties.GetBooleanWithoutPathExpansion(
shill::kAutoConnectProperty, &auto_connect);
scoped_ptr<base::Value> auto_connect_value(
new base::FundamentalValue(auto_connect));
::onc::ONCSource auto_connect_onc_source = onc_source;
bool auto_connect_recommended =
auto_connect_onc_source != ::onc::ONC_SOURCE_NONE &&
onc::IsRecommendedValue(onc, onc_path_to_auto_connect);
// |auto_connect_default_value| will contain either a recommended value
// if |auto_connect_recommended| is true, or an enforced value otherwise.
const base::Value* auto_connect_default_value = NULL;
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.reset(new base::FundamentalValue(false));
}
}
SetManagedValueDictionary(shill::kAutoConnectProperty,
auto_connect_value.get(),
auto_connect_onc_source,
auto_connect_recommended,
auto_connect_default_value,
dictionary.get());
}
bool auto_connect = false;
shill_properties.GetBooleanWithoutPathExpansion(
shill::kAutoConnectProperty, &auto_connect);
SetAutoconnectValueDictionary(network->IsPrivate(),
onc_source,
auto_connect,
auto_connect_ui_data,
dictionary.get());
// Show details dialog
web_ui()->CallJavascriptFunction(kShowDetailedInfoFunction, *dictionary);
......
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