Chromium Code Reviews| 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 c9269ca5e4d67be9950ba9ba758004063e545039..95cd01a5accf8b3582fe952f43ccd305400eee89 100644 |
| --- a/chrome/browser/resources/options/chromeos/internet_detail.js |
| +++ b/chrome/browser/resources/options/chromeos/internet_detail.js |
| @@ -17,6 +17,8 @@ cr.define('options.internet', function() { |
| var PageManager = cr.ui.pageManager.PageManager; |
| /** @const */ var IPAddressField = options.internet.IPAddressField; |
| + /** @const */ var GoogleNameServers = '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,33 @@ 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) { |
| + var netmask = ''; |
| + // Return the empty string for invalid inputs. |
| + if (prefixLength < 0 || prefixLength > 32) |
| + return netmask; |
|
pneubeck (no reviews)
2014/09/04 14:54:13
nit: just return '' and move the variable declarat
stevenjb
2014/09/08 18:14:11
Done.
|
| + 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 = |
|
pneubeck (no reviews)
2014/09/04 14:54:13
nit: this term is already a bit long to grasp. may
armansito
2014/09/04 15:41:38
While you're at it, can you also add a short comme
stevenjb
2014/09/08 18:14:11
I added an 'if' instead of a ?, but I don't want t
stevenjb
2014/09/08 18:14:11
I'm not really sure how to explain this better tha
|
| + remainder == 0 ? 0 : ((2 << (remainder - 1)) - 1) << (8 - remainder); |
| + netmask += value; |
| + } |
| + return netmask; |
| + } |
| + |
| ///////////////////////////////////////////////////////////////////////////// |
| // DetailsInternetPage class: |
| @@ -1001,56 +1030,99 @@ cr.define('options.internet', function() { |
| } |
| $('connection-state').textContent = connectionStateString; |
| - var ipAutoConfig = data.ipAutoConfig ? 'automatic' : 'user'; |
| - $('ip-automatic-configuration-checkbox').checked = data.ipAutoConfig; |
| + var ipAutoConfig = 'automatic'; |
| + var staticIpconfig = onc.getActiveValue('StaticIPConfig'); |
| + // If 'StaticIPConfig' is a dictionary with at least one value, set |
| + // ipAutoConfig to 'user'. |
| + if (staticIpconfig && Object.keys(staticIpconfig).length > 0) { |
| + ipAutoConfig = 'user'; |
| + $('ip-automatic-configuration-checkbox').checked = false; |
| + } else { |
| + $('ip-automatic-configuration-checkbox').checked = true; |
| + } |
| 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 inetNameServers = ''; |
| + var nameServerType = 'automatic'; |
| + |
| + 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; |
| + } |
| + inetAddress.automatic = ipconfig['IPAddress']; |
| + inetAddress.value = ipconfig['IPAddress']; |
| + var netmask = PrefixLengthToNetmask(ipconfig['RoutingPrefix']); |
| + inetNetmask.automatic = netmask; |
| + inetNetmask.value = netmask; |
| + inetGateway.automatic = ipconfig['Gateway']; |
| + inetGateway.value = ipconfig['Gateway']; |
| + if ('WebProxyAutoDiscoveryUrl' in ipconfig) { |
| + $('web-proxy-auto-discovery').hidden = false; |
| + $('web-proxy-auto-discovery-url').value = |
| + ipconfig['WebProxyAutoDiscoveryUrl']; |
| + } |
| + if ('NameServers' in ipconfig) |
| + inetNameServers = ipconfig['NameServers']; |
| + 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 savedNameServers; |
| + 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; |
| + } |
| + savedNameServers = onc.getActiveValue('SavedIPConfig.NameServers'); |
| } |
| + var staticNameServers; |
| if (ipAutoConfig == 'user') { |
| - if (data.staticIP.value.address) { |
| - inetAddress.value = data.staticIP.value.address; |
| - inetAddress.user = data.staticIP.value.address; |
| + var staticIpAddress = onc.getActiveValue('StaticIPConfig.IPAddress'); |
| + if (staticIpAddress != undefined) { |
| + inetAddress.user = staticIpAddress; |
| + inetAddress.value = staticIpAddress; |
| } |
| - if (data.staticIP.value.netmask) { |
| - inetNetmask.value = data.staticIP.value.netmask; |
| - inetNetmask.user = data.staticIP.value.netmask; |
| + var staticPrefix = onc.getActiveValue('StaticIPConfig.RoutingPrefix'); |
| + if (staticPrefix != undefined) { |
| + var staticNetmask = PrefixLengthToNetmask(staticPrefix); |
| + inetNetmask.user = staticNetmask; |
| + inetNetmask.value = staticNetmask; |
| } |
| - if (data.staticIP.value.gateway) { |
| - inetGateway.value = data.staticIP.value.gateway; |
| - inetGateway.user = data.staticIP.value.gateway; |
| + var staticGateway = onc.getActiveValue('StaticIPConfig.Gateway'); |
| + if (staticGateway != undefined) { |
| + inetGateway.user = staticGateway; |
| + inetGateway.value = staticGateway; |
| } |
| + staticNameServers = onc.getActiveValue('StaticIPConfig.NameServers'); |
| + if (staticNameServers == inetNameServers) |
| + nameServerType = 'user'; |
| } |
| + if (inetNameServers == GoogleNameServers) |
| + nameServerType = 'google'; |
| + |
| var configureAddressField = function(field, model) { |
| IPAddressField.decorate(field); |
| field.model = model; |
| @@ -1061,33 +1133,28 @@ cr.define('options.internet', function() { |
| configureAddressField($('ip-netmask'), inetNetmask); |
| configureAddressField($('ip-gateway'), inetGateway); |
| - var inetNameServers = ''; |
| - if (data.ipconfig.value && data.ipconfig.value.nameServers) { |
| - inetNameServers = data.ipconfig.value.nameServers; |
| + if (savedNameServers) |
| + $('automatic-dns-display').textContent = savedNameServers; |
| + else |
| $('automatic-dns-display').textContent = inetNameServers; |
| - } |
| - |
| - if (data.savedIP && data.savedIP.nameServers) |
| - $('automatic-dns-display').textContent = data.savedIP.nameServers; |
| - if (data.nameServersGoogle) |
| - $('google-dns-display').textContent = data.nameServersGoogle; |
| + $('google-dns-display').textContent = GoogleNameServers; |
| var nameServersUser = []; |
| - if (data.staticIP.value.nameServers) |
| - nameServersUser = data.staticIP.value.nameServers.split(','); |
| + if (staticNameServers != undefined) |
| + nameServersUser = staticNameServers.split(','); |
| 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) { |
| @@ -1238,8 +1305,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]; |
| @@ -1252,24 +1326,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; |