Index: chrome/browser/resources/options/chromeos/internet_detail.js |
diff --git a/chrome/browser/resources/options/chromeos/internet_detail.js b/chrome/browser/resources/options/chromeos/internet_detail.js |
index e3574440eaa749b57aee4395019cdb26bac64b82..f24ae5e953690f6869cd133201695966ac961d8e 100644 |
--- a/chrome/browser/resources/options/chromeos/internet_detail.js |
+++ b/chrome/browser/resources/options/chromeos/internet_detail.js |
@@ -11,16 +11,157 @@ |
// networkingPrivate API. See network_config.js. |
// See crbug.com/279351 for more info. |
+/** @typedef {{activationState: (string|undefined), |
+ * carriers: Array, |
+ * currentCarrierIndex; (number|undefined), |
+ * ipAutoConfig: boolean, |
+ * ipconfig: Object, |
+ * nameServerType: string, |
+ * restrictedPool: (string|undefined), |
+ * roamingState: (string|undefined), |
+ * savedIP: Object, |
+ * showActivateButton: (boolean|undefined) |
+ * showViewAccountButton: (boolean|undefined), |
+ * staticIP: Object}} |
+ * Only the keys which had caused problems are declared in this typedef. |
+ * There are many more of them. |
+ * @see chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc |
+ */ |
+var InternetDetailedInfo; |
+ |
cr.define('options.internet', function() { |
var OncData = cr.onc.OncData; |
var Page = cr.ui.pageManager.Page; |
var PageManager = cr.ui.pageManager.PageManager; |
/** @const */ var IPAddressField = options.internet.IPAddressField; |
+ var GetManagedTypes = { |
+ ACTIVE: 0, |
+ TRANSLATED: 1, |
+ RECOMMENDED: 2 |
+ }; |
+ |
+ /** |
+ * Gets the value of a property from a dictionary |data| that includes ONC |
+ * managed properties, e.g. getManagedValue(data, 'Name'). See notes for |
+ * getManagedProperty. |
+ * @param {Object} data The properties dictionary. |
+ * @param {string} key The property key. |
+ * @param {string=} opt_type The type of property to get as defined in |
+ * GetManagedTypes: |
+ * 'ACTIVE' (default) - gets the active value |
+ * 'TRANSLATED' - gets the traslated or active value |
+ * 'RECOMMENDED' - gets the recommended value |
+ * @return {*} The property value or undefined. |
+ */ |
+ function getManagedValue(data, key, opt_type) { |
+ var property = getManagedProperty(data, key); |
+ if (Array.isArray(property) || typeof property != 'object') |
+ return property; |
+ if (opt_type == GetManagedTypes.RECOMMENDED) |
+ return getRecommendedValue(property); |
+ if (opt_type == GetManagedTypes.TRANSLATED && 'Translated' in property) |
+ return property['Translated']; |
+ // Otherwise get the Active value (defalt behavior). |
+ if ('Active' in property) |
+ return property['Active']; |
+ // If no Active value is defined, return the effective value if present. |
+ var effective = getEffectiveValue(property); |
+ if (effective != undefined) |
+ return effective; |
+ // Otherwise this is an Object but not a Managed one. |
+ return property; |
+ } |
+ |
+ /** |
+ * Get the recommended value from a Managed property ONC dictionary. |
+ * @param {Object} property The managed property ONC dictionary. |
+ * @return {*} the effective value or undefined. |
+ */ |
+ function getRecommendedValue(property) { |
+ if (property['UserEditable']) |
+ return property['UserPolicy']; |
+ if (property['DeviceEditable']) |
+ return property['DevicePolicy']; |
+ // No value recommended by policy. |
+ return undefined; |
+ } |
+ |
+ /** |
+ * Get the effective value from a Managed property ONC dictionary. |
+ * @param {Object} property The managed property ONC dictionary. |
+ * @return {*} The effective value or undefined. |
+ */ |
+ function getEffectiveValue(property) { |
+ if ('Effective' in property) { |
+ var effective = property.Effective; |
+ if (effective in property) |
+ return property[effective]; |
+ } |
+ return undefined; |
+ } |
+ |
+ /** |
+ * Gets either a managed property dictionary or an unmanaged value from |
+ * dictionary |data| that includes ONC managed properties. This supports |
+ * nested dictionaries, e.g. getManagedProperty(data, 'VPN.Type'). |
+ * @param {Object} data The properties dictionary. |
+ * @param {string} key The property key. |
+ * @return {*} The property value or dictionary if it exists, otherwise |
+ * undefined. |
+ */ |
+ function getManagedProperty(data, key) { |
+ while (true) { |
+ var index = key.indexOf('.'); |
+ if (index < 0) |
+ break; |
+ var keyComponent = key.substr(0, index); |
+ if (!(keyComponent in data)) |
+ return undefined; |
+ data = data[keyComponent]; |
+ key = key.substr(index + 1); |
+ } |
+ return data[key]; |
+ } |
+ |
+ /** |
+ * Set the value of a property in dictionary |data| that includes ONC |
+ * managed properties, e.g. setManagedValue(data, 'Name', 'MyNetwork'). |
+ * See notes for getManagedProperty. |
+ * @param {Object} data The properties dictionary. |
+ * @param {string} key The property key. |
+ * @param {*} value The property value to set. |
+ */ |
+ function setManagedProperty(data, key, value) { |
+ while (true) { |
+ var index = key.indexOf('.'); |
+ if (index < 0) |
+ break; |
+ var keyComponent = key.substr(0, index); |
+ if (!(keyComponent in data)) |
+ data[keyComponent] = {}; |
+ data = data[keyComponent]; |
+ key = key.substr(index + 1); |
+ } |
+ if (!(key in data) || |
+ (typeof data[key] != 'object') || |
+ (!('Active' in data[key]) && !('Effective' in data[key]))) { |
+ data[key] = value; |
+ } else { |
+ var effective = data[key]['Effective']; |
+ assert(effective != 'UserPolicy' || data[key]['UserEditable']); |
+ assert(effective != 'DevicePolicy' || data[key]['DeviceEditable']); |
+ // For now, just uodare the active value. TODO(stevenjb): Eventually we |
+ // should update the 'UserSetting' and 'Effective' properties correctly |
+ // and send that back to Chrome. |
+ data[key]['Active'] = value; |
+ } |
+ } |
+ |
/** |
* 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. |
+ * @param {boolean} hidden New hidden value. |
*/ |
function updateHidden(selector, hidden) { |
var elements = cr.doc.querySelectorAll(selector); |
@@ -61,7 +202,7 @@ cr.define('options.internet', function() { |
/** |
* Simple helper method for converting a field to a string. It is used to |
* easily assign an empty string from fields that may be unknown or undefined. |
- * @param {object} value that should be converted to a string. |
+ * @param {Object} value that should be converted to a string. |
* @return {string} the result. |
*/ |
function stringFromValue(value) { |
@@ -85,9 +226,10 @@ cr.define('options.internet', function() { |
/** |
* Encapsulated handling of ChromeOS internet details overlay page. |
* @constructor |
+ * @extends {cr.ui.pageManager.Page} |
*/ |
function DetailsInternetPage() { |
- Page.call(this, 'detailsInternetPage', null, 'details-internet-page'); |
+ Page.call(this, 'detailsInternetPage', '', 'details-internet-page'); |
} |
cr.addSingletonGetter(DetailsInternetPage); |
@@ -98,14 +240,14 @@ cr.define('options.internet', function() { |
/** @override */ |
initializePage: function() { |
Page.prototype.initializePage.call(this); |
- var params = parseQueryParams(window.location); |
- this.initializePageContents_(params); |
- this.showNetworkDetails_(params); |
+ this.initializePageContents_(); |
+ this.showNetworkDetails_(parseQueryParams(window.location)); |
}, |
/** |
* Auto-activates the network details dialog if network information |
* is included in the URL. |
+ * @param {Object} params |
*/ |
showNetworkDetails_: function(params) { |
Dan Beam
2014/09/09 02:59:09
remove |params| and instead:
var params = parseQu
Vitaly Pavlenko
2014/09/09 17:54:51
Even "var params" can be inlined, is it ok?
|
var servicePath = params.servicePath; |
@@ -118,7 +260,7 @@ cr.define('options.internet', function() { |
/** |
* Initializes the contents of the page. |
*/ |
- initializePageContents_: function(params) { |
+ initializePageContents_: function() { |
$('details-internet-dismiss').addEventListener('click', function(event) { |
DetailsInternetPage.setDetails(); |
}); |
@@ -166,7 +308,7 @@ cr.define('options.internet', function() { |
data.userApnIndex = -1; |
} |
- var activeApn; |
+ var activeApn = {}; |
var iApn = -1; |
var apnList = onc.getActiveValue('Cellular.APNList'); |
if (apnList != undefined && apnList.length > 0) { |
@@ -536,9 +678,8 @@ cr.define('options.internet', function() { |
* Handler for when the user clicks on the checkbox to allow a |
* single proxy usage. |
* @private |
- * @param {Event} e Click Event. |
*/ |
- toggleSingleProxy_: function(e) { |
+ toggleSingleProxy_: function() { |
if ($('proxy-all-protocols').checked) { |
$('multi-proxy').hidden = true; |
$('single-proxy').hidden = false; |
@@ -552,9 +693,8 @@ cr.define('options.internet', function() { |
* Handler for when the user clicks on the checkbox to enter |
* auto configuration URL. |
* @private |
- * @param {Event} e Click Event. |
*/ |
- handleAutoConfigProxy_: function(e) { |
+ handleAutoConfigProxy_: function() { |
$('proxy-pac-url').disabled = !$('proxy-use-pac-url').checked; |
}, |
@@ -562,9 +702,8 @@ cr.define('options.internet', function() { |
* Handler for selecting a radio button that will disable the manual |
* controls. |
* @private |
- * @param {Event} e Click event. |
*/ |
- disableManualProxy_: function(e) { |
+ disableManualProxy_: function(opt_e) { |
$('ignored-host-list').disabled = true; |
$('new-host').disabled = true; |
$('remove-host').disabled = true; |
@@ -594,9 +733,8 @@ cr.define('options.internet', function() { |
* Handler for selecting a radio button that will enable the manual |
* controls. |
* @private |
- * @param {Event} e Click event. |
*/ |
- enableManualProxy_: function(e) { |
+ enableManualProxy_: function(opt_e) { |
$('ignored-host-list').redraw(); |
var allDisabled = $('manual-proxy').disabled; |
$('ignored-host-list').disabled = allDisabled; |
@@ -769,21 +907,22 @@ cr.define('options.internet', function() { |
var servicePath = data.servicePath; |
if (data.type == 'WiFi') { |
sendCheckedIfEnabled(servicePath, 'setPreferNetwork', |
- $('prefer-network-wifi')); |
+ assertInstanceof($('prefer-network-wifi'), HTMLInputElement)); |
sendCheckedIfEnabled(servicePath, 'setAutoConnect', |
- $('auto-connect-network-wifi')); |
+ assertInstanceof($('auto-connect-network-wifi'), HTMLInputElement)); |
} else if (data.type == 'Wimax') { |
sendCheckedIfEnabled(servicePath, 'setAutoConnect', |
- $('auto-connect-network-wimax')); |
+ assertInstanceof($('auto-connect-network-wimax'), HTMLInputElement)); |
} else if (data.type == 'Cellular') { |
sendCheckedIfEnabled(servicePath, 'setAutoConnect', |
- $('auto-connect-network-cellular')); |
+ assertInstanceof($('auto-connect-network-cellular'), |
+ HTMLInputElement)); |
} else if (data.type == 'VPN') { |
chrome.send('setServerHostname', |
[servicePath, |
$('inet-server-hostname').value]); |
sendCheckedIfEnabled(servicePath, 'setAutoConnect', |
- $('auto-connect-network-vpn')); |
+ assertInstanceof($('auto-connect-network-vpn'), HTMLInputElement)); |
} |
var nameServerTypes = ['automatic', 'google', 'user']; |
@@ -914,7 +1053,7 @@ cr.define('options.internet', function() { |
} else if (onc.type == 'Cellular') { |
$('activation-state').textContent = data.activationState; |
- $('buyplan-details').hidden = !data.showBuyButton; |
+ $('buyplan-details').hidden = true; |
$('view-account-details').hidden = !data.showViewAccountButton; |
$('activate-details').hidden = !data.showActivateButton; |
@@ -933,6 +1072,9 @@ cr.define('options.internet', function() { |
$('connection-state').onc = onc; |
}; |
+ /** |
+ * @param {InternetDetailedInfo} data |
+ */ |
DetailsInternetPage.showDetailedInfo = function(data) { |
var detailsPage = DetailsInternetPage.getInstance(); |
@@ -1277,7 +1419,7 @@ cr.define('options.internet', function() { |
onc.getActiveValue('AutoConnect'); |
$('auto-connect-network-cellular').disabled = false; |
- $('buyplan-details').hidden = !data.showBuyButton; |
+ $('buyplan-details').hidden = true; |
$('view-account-details').hidden = !data.showViewAccountButton; |
$('activate-details').hidden = !data.showActivateButton; |
if (data.showActivateButton) { |