OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // require: onc_data.js | 5 // require: onc_data.js |
6 | 6 |
7 // NOTE(stevenjb): This code is in the process of being converted to be | 7 // NOTE(stevenjb): This code is in the process of being converted to be |
8 // compatible with the networkingPrivate extension API: | 8 // compatible with the networkingPrivate extension API: |
9 // * The network property dictionaries are being converted to use ONC values. | 9 // * The network property dictionaries are being converted to use ONC values. |
10 // * chrome.send calls will be replaced with an API object that simulates the | 10 // * chrome.send calls will be replaced with an API object that simulates the |
11 // networkingPrivate API. See network_config.js. | 11 // networkingPrivate API. See network_config.js. |
12 // See crbug.com/279351 for more info. | 12 // See crbug.com/279351 for more info. |
13 | 13 |
14 cr.define('options.internet', function() { | 14 cr.define('options.internet', function() { |
15 var OncData = cr.onc.OncData; | 15 var OncData = cr.onc.OncData; |
16 var Page = cr.ui.pageManager.Page; | 16 var Page = cr.ui.pageManager.Page; |
17 var PageManager = cr.ui.pageManager.PageManager; | 17 var PageManager = cr.ui.pageManager.PageManager; |
18 /** @const */ var IPAddressField = options.internet.IPAddressField; | 18 /** @const */ var IPAddressField = options.internet.IPAddressField; |
19 | 19 |
20 /** @const */ var GoogleNameServers = '8.8.4.4,8.8.8.8'; | |
21 | |
20 /** | 22 /** |
21 * Helper function to set hidden attribute for elements matching a selector. | 23 * Helper function to set hidden attribute for elements matching a selector. |
22 * @param {string} selector CSS selector for extracting a list of elements. | 24 * @param {string} selector CSS selector for extracting a list of elements. |
23 * @param {bool} hidden New hidden value. | 25 * @param {bool} hidden New hidden value. |
24 */ | 26 */ |
25 function updateHidden(selector, hidden) { | 27 function updateHidden(selector, hidden) { |
26 var elements = cr.doc.querySelectorAll(selector); | 28 var elements = cr.doc.querySelectorAll(selector); |
27 for (var i = 0, el; el = elements[i]; i++) { | 29 for (var i = 0, el; el = elements[i]; i++) { |
28 el.hidden = hidden; | 30 el.hidden = hidden; |
29 } | 31 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 * Sends the 'checked' state of a control to chrome for a network. | 74 * Sends the 'checked' state of a control to chrome for a network. |
73 * @param {string} path The service path of the network. | 75 * @param {string} path The service path of the network. |
74 * @param {string} message The message to send to chrome. | 76 * @param {string} message The message to send to chrome. |
75 * @param {HTMLInputElement} checkbox The checkbox storing the value to send. | 77 * @param {HTMLInputElement} checkbox The checkbox storing the value to send. |
76 */ | 78 */ |
77 function sendCheckedIfEnabled(path, message, checkbox) { | 79 function sendCheckedIfEnabled(path, message, checkbox) { |
78 if (!checkbox.hidden && !checkbox.disabled) | 80 if (!checkbox.hidden && !checkbox.disabled) |
79 chrome.send(message, [path, checkbox.checked ? 'true' : 'false']); | 81 chrome.send(message, [path, checkbox.checked ? 'true' : 'false']); |
80 } | 82 } |
81 | 83 |
84 /** | |
85 * Returns the netmask as a string for a given prefix length. | |
86 * @param {string} prefixLength The ONC routing prefix length. | |
87 * @return {string} The corresponding netmask. | |
88 */ | |
89 function PrefixLengthToNetmask(prefixLength) { | |
90 var netmask = ''; | |
91 // Return the empty string for invalid inputs. | |
92 if (prefixLength < 0 || prefixLength > 32) | |
93 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.
| |
94 for (var i = 0; i < 4; ++i) { | |
95 var remainder = 8; | |
96 if (prefixLength >= 8) { | |
97 prefixLength -= 8; | |
98 } else { | |
99 remainder = prefixLength; | |
100 prefixLength = 0; | |
101 } | |
102 if (i > 0) | |
103 netmask += '.'; | |
104 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
| |
105 remainder == 0 ? 0 : ((2 << (remainder - 1)) - 1) << (8 - remainder); | |
106 netmask += value; | |
107 } | |
108 return netmask; | |
109 } | |
110 | |
82 ///////////////////////////////////////////////////////////////////////////// | 111 ///////////////////////////////////////////////////////////////////////////// |
83 // DetailsInternetPage class: | 112 // DetailsInternetPage class: |
84 | 113 |
85 /** | 114 /** |
86 * Encapsulated handling of ChromeOS internet details overlay page. | 115 * Encapsulated handling of ChromeOS internet details overlay page. |
87 * @constructor | 116 * @constructor |
88 */ | 117 */ |
89 function DetailsInternetPage() { | 118 function DetailsInternetPage() { |
90 Page.call(this, 'detailsInternetPage', null, 'details-internet-page'); | 119 Page.call(this, 'detailsInternetPage', null, 'details-internet-page'); |
91 } | 120 } |
(...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
994 | 1023 |
995 // Only show proxy for remembered networks. | 1024 // Only show proxy for remembered networks. |
996 if (data.remembered) { | 1025 if (data.remembered) { |
997 detailsPage.showProxy = true; | 1026 detailsPage.showProxy = true; |
998 chrome.send('selectNetwork', [data.servicePath]); | 1027 chrome.send('selectNetwork', [data.servicePath]); |
999 } else { | 1028 } else { |
1000 detailsPage.showProxy = false; | 1029 detailsPage.showProxy = false; |
1001 } | 1030 } |
1002 $('connection-state').textContent = connectionStateString; | 1031 $('connection-state').textContent = connectionStateString; |
1003 | 1032 |
1004 var ipAutoConfig = data.ipAutoConfig ? 'automatic' : 'user'; | 1033 var ipAutoConfig = 'automatic'; |
1005 $('ip-automatic-configuration-checkbox').checked = data.ipAutoConfig; | 1034 var staticIpconfig = onc.getActiveValue('StaticIPConfig'); |
1035 // If 'StaticIPConfig' is a dictionary with at least one value, set | |
1036 // ipAutoConfig to 'user'. | |
1037 if (staticIpconfig && Object.keys(staticIpconfig).length > 0) { | |
1038 ipAutoConfig = 'user'; | |
1039 $('ip-automatic-configuration-checkbox').checked = false; | |
1040 } else { | |
1041 $('ip-automatic-configuration-checkbox').checked = true; | |
1042 } | |
1006 var inetAddress = {autoConfig: ipAutoConfig}; | 1043 var inetAddress = {autoConfig: ipAutoConfig}; |
1007 var inetNetmask = {autoConfig: ipAutoConfig}; | 1044 var inetNetmask = {autoConfig: ipAutoConfig}; |
1008 var inetGateway = {autoConfig: ipAutoConfig}; | 1045 var inetGateway = {autoConfig: ipAutoConfig}; |
1009 | 1046 |
1010 if (data.ipconfig.value) { | 1047 var inetNameServers = ''; |
1011 inetAddress.automatic = data.ipconfig.value.address; | 1048 var nameServerType = 'automatic'; |
1012 inetAddress.value = data.ipconfig.value.address; | 1049 |
1013 inetNetmask.automatic = data.ipconfig.value.netmask; | 1050 if ('IPConfigs' in data) { |
1014 inetNetmask.value = data.ipconfig.value.netmask; | 1051 var ipconfigList = onc.getActiveValue('IPConfigs'); |
1015 inetGateway.automatic = data.ipconfig.value.gateway; | 1052 for (var i = 0; i < ipconfigList.length; ++i) { |
1016 inetGateway.value = data.ipconfig.value.gateway; | 1053 var ipconfig = ipconfigList[i]; |
1017 if (data.ipconfig.value.webProxyAutoDiscoveryUrl) { | 1054 var type = ipconfig['Type']; |
1018 $('web-proxy-auto-discovery').hidden = false; | 1055 if (type != 'IPv4') { |
1019 $('web-proxy-auto-discovery-url').value = | 1056 // TODO(stevenjb): Handle IPv6 properties. |
1020 data.ipconfig.value.webProxyAutoDiscoveryUrl; | 1057 continue; |
1058 } | |
1059 inetAddress.automatic = ipconfig['IPAddress']; | |
1060 inetAddress.value = ipconfig['IPAddress']; | |
1061 var netmask = PrefixLengthToNetmask(ipconfig['RoutingPrefix']); | |
1062 inetNetmask.automatic = netmask; | |
1063 inetNetmask.value = netmask; | |
1064 inetGateway.automatic = ipconfig['Gateway']; | |
1065 inetGateway.value = ipconfig['Gateway']; | |
1066 if ('WebProxyAutoDiscoveryUrl' in ipconfig) { | |
1067 $('web-proxy-auto-discovery').hidden = false; | |
1068 $('web-proxy-auto-discovery-url').value = | |
1069 ipconfig['WebProxyAutoDiscoveryUrl']; | |
1070 } | |
1071 if ('NameServers' in ipconfig) | |
1072 inetNameServers = ipconfig['NameServers']; | |
1073 break; // Use the first IPv4 entry. | |
1021 } | 1074 } |
1022 } | 1075 } |
1023 | 1076 |
1024 // Override the "automatic" values with the real saved DHCP values, | 1077 // Override the "automatic" values with the real saved DHCP values, |
1025 // if they are set. | 1078 // if they are set. |
1026 if (data.savedIP.address) { | 1079 var savedNameServers; |
1027 inetAddress.automatic = data.savedIP.address; | 1080 if ('SavedIPConfig' in data) { |
1028 inetAddress.value = data.savedIP.address; | 1081 var savedIpAddress = onc.getActiveValue('SavedIPConfig.IPAddress'); |
1029 } | 1082 if (savedIpAddress != undefined) { |
1030 if (data.savedIP.netmask) { | 1083 inetAddress.automatic = savedIpAddress; |
1031 inetNetmask.automatic = data.savedIP.netmask; | 1084 inetAddress.value = savedIpAddress; |
1032 inetNetmask.value = data.savedIP.netmask; | 1085 } |
1033 } | 1086 var savedPrefix = onc.getActiveValue('SavedIPConfig.RoutingPrefix'); |
1034 if (data.savedIP.gateway) { | 1087 if (savedPrefix != undefined) { |
1035 inetGateway.automatic = data.savedIP.gateway; | 1088 var savedNetmask = PrefixLengthToNetmask(savedPrefix); |
1036 inetGateway.value = data.savedIP.gateway; | 1089 inetNetmask.automatic = savedNetmask; |
1090 inetNetmask.value = savedNetmask; | |
1091 } | |
1092 var savedGateway = onc.getActiveValue('SavedIPConfig.Gateway'); | |
1093 if (savedGateway != undefined) { | |
1094 inetGateway.automatic = savedGateway; | |
1095 inetGateway.value = savedGateway; | |
1096 } | |
1097 savedNameServers = onc.getActiveValue('SavedIPConfig.NameServers'); | |
1037 } | 1098 } |
1038 | 1099 |
1100 var staticNameServers; | |
1039 if (ipAutoConfig == 'user') { | 1101 if (ipAutoConfig == 'user') { |
1040 if (data.staticIP.value.address) { | 1102 var staticIpAddress = onc.getActiveValue('StaticIPConfig.IPAddress'); |
1041 inetAddress.value = data.staticIP.value.address; | 1103 if (staticIpAddress != undefined) { |
1042 inetAddress.user = data.staticIP.value.address; | 1104 inetAddress.user = staticIpAddress; |
1105 inetAddress.value = staticIpAddress; | |
1043 } | 1106 } |
1044 if (data.staticIP.value.netmask) { | 1107 var staticPrefix = onc.getActiveValue('StaticIPConfig.RoutingPrefix'); |
1045 inetNetmask.value = data.staticIP.value.netmask; | 1108 if (staticPrefix != undefined) { |
1046 inetNetmask.user = data.staticIP.value.netmask; | 1109 var staticNetmask = PrefixLengthToNetmask(staticPrefix); |
1110 inetNetmask.user = staticNetmask; | |
1111 inetNetmask.value = staticNetmask; | |
1047 } | 1112 } |
1048 if (data.staticIP.value.gateway) { | 1113 var staticGateway = onc.getActiveValue('StaticIPConfig.Gateway'); |
1049 inetGateway.value = data.staticIP.value.gateway; | 1114 if (staticGateway != undefined) { |
1050 inetGateway.user = data.staticIP.value.gateway; | 1115 inetGateway.user = staticGateway; |
1116 inetGateway.value = staticGateway; | |
1051 } | 1117 } |
1118 staticNameServers = onc.getActiveValue('StaticIPConfig.NameServers'); | |
1119 if (staticNameServers == inetNameServers) | |
1120 nameServerType = 'user'; | |
1052 } | 1121 } |
1053 | 1122 |
1123 if (inetNameServers == GoogleNameServers) | |
1124 nameServerType = 'google'; | |
1125 | |
1054 var configureAddressField = function(field, model) { | 1126 var configureAddressField = function(field, model) { |
1055 IPAddressField.decorate(field); | 1127 IPAddressField.decorate(field); |
1056 field.model = model; | 1128 field.model = model; |
1057 field.editable = model.autoConfig == 'user'; | 1129 field.editable = model.autoConfig == 'user'; |
1058 }; | 1130 }; |
1059 | 1131 |
1060 configureAddressField($('ip-address'), inetAddress); | 1132 configureAddressField($('ip-address'), inetAddress); |
1061 configureAddressField($('ip-netmask'), inetNetmask); | 1133 configureAddressField($('ip-netmask'), inetNetmask); |
1062 configureAddressField($('ip-gateway'), inetGateway); | 1134 configureAddressField($('ip-gateway'), inetGateway); |
1063 | 1135 |
1064 var inetNameServers = ''; | 1136 if (savedNameServers) |
1065 if (data.ipconfig.value && data.ipconfig.value.nameServers) { | 1137 $('automatic-dns-display').textContent = savedNameServers; |
1066 inetNameServers = data.ipconfig.value.nameServers; | 1138 else |
1067 $('automatic-dns-display').textContent = inetNameServers; | 1139 $('automatic-dns-display').textContent = inetNameServers; |
1068 } | |
1069 | 1140 |
1070 if (data.savedIP && data.savedIP.nameServers) | 1141 $('google-dns-display').textContent = GoogleNameServers; |
1071 $('automatic-dns-display').textContent = data.savedIP.nameServers; | |
1072 | |
1073 if (data.nameServersGoogle) | |
1074 $('google-dns-display').textContent = data.nameServersGoogle; | |
1075 | 1142 |
1076 var nameServersUser = []; | 1143 var nameServersUser = []; |
1077 if (data.staticIP.value.nameServers) | 1144 if (staticNameServers != undefined) |
1078 nameServersUser = data.staticIP.value.nameServers.split(','); | 1145 nameServersUser = staticNameServers.split(','); |
1079 | 1146 |
1080 var nameServerModels = []; | 1147 var nameServerModels = []; |
1081 for (var i = 0; i < 4; ++i) | 1148 for (var i = 0; i < 4; ++i) |
1082 nameServerModels.push({value: nameServersUser[i] || ''}); | 1149 nameServerModels.push({value: nameServersUser[i] || ''}); |
1083 | 1150 |
1084 $(data.nameServerType + '-dns-radio').checked = true; | 1151 $(nameServerType + '-dns-radio').checked = true; |
1085 configureAddressField($('ipconfig-dns1'), nameServerModels[0]); | 1152 configureAddressField($('ipconfig-dns1'), nameServerModels[0]); |
1086 configureAddressField($('ipconfig-dns2'), nameServerModels[1]); | 1153 configureAddressField($('ipconfig-dns2'), nameServerModels[1]); |
1087 configureAddressField($('ipconfig-dns3'), nameServerModels[2]); | 1154 configureAddressField($('ipconfig-dns3'), nameServerModels[2]); |
1088 configureAddressField($('ipconfig-dns4'), nameServerModels[3]); | 1155 configureAddressField($('ipconfig-dns4'), nameServerModels[3]); |
1089 | 1156 |
1090 DetailsInternetPage.updateNameServerDisplay(data.nameServerType); | 1157 DetailsInternetPage.updateNameServerDisplay(nameServerType); |
1091 | 1158 |
1092 var macAddress = onc.getActiveValue('MacAddress'); | 1159 var macAddress = onc.getActiveValue('MacAddress'); |
1093 if (macAddress) { | 1160 if (macAddress) { |
1094 $('hardware-address').textContent = macAddress; | 1161 $('hardware-address').textContent = macAddress; |
1095 $('hardware-address-row').style.display = 'table-row'; | 1162 $('hardware-address-row').style.display = 'table-row'; |
1096 } else { | 1163 } else { |
1097 // This is most likely a device without a hardware address. | 1164 // This is most likely a device without a hardware address. |
1098 $('hardware-address-row').style.display = 'none'; | 1165 $('hardware-address-row').style.display = 'none'; |
1099 } | 1166 } |
1100 | 1167 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1231 $('iccid').textContent = onc.getActiveValue('Cellular.ICCID'); | 1298 $('iccid').textContent = onc.getActiveValue('Cellular.ICCID'); |
1232 $('imsi').textContent = onc.getActiveValue('Cellular.IMSI'); | 1299 $('imsi').textContent = onc.getActiveValue('Cellular.IMSI'); |
1233 | 1300 |
1234 var apnSelector = $('select-apn'); | 1301 var apnSelector = $('select-apn'); |
1235 // Clear APN lists, keep only last element that "other". | 1302 // Clear APN lists, keep only last element that "other". |
1236 while (apnSelector.length != 1) | 1303 while (apnSelector.length != 1) |
1237 apnSelector.remove(0); | 1304 apnSelector.remove(0); |
1238 var otherOption = apnSelector[0]; | 1305 var otherOption = apnSelector[0]; |
1239 data.selectedApn = -1; | 1306 data.selectedApn = -1; |
1240 data.userApnIndex = -1; | 1307 data.userApnIndex = -1; |
1241 var activeApn = onc.getActiveValue('Cellular.APN'); | 1308 var activeApn = onc.getActiveValue('Cellular.APN.AccessPointName'); |
1242 var lastGoodApn = onc.getActiveValue('Cellular.LastGoodAPN'); | 1309 var activeUsername = onc.getActiveValue('Cellular.APN.Username'); |
1310 var activePassword = onc.getActiveValue('Cellular.APN.Password'); | |
1311 var lastGoodApn = | |
1312 onc.getActiveValue('Cellular.LastGoodAPN.AccessPointName'); | |
1313 var lastGoodUsername = | |
1314 onc.getActiveValue('Cellular.LastGoodAPN.Username'); | |
1315 var lastGoodPassword = | |
1316 onc.getActiveValue('Cellular.LastGoodAPN.Password'); | |
1243 var apnList = onc.getActiveValue('Cellular.APNList'); | 1317 var apnList = onc.getActiveValue('Cellular.APNList'); |
1244 for (var i = 0; i < apnList.length; i++) { | 1318 for (var i = 0; i < apnList.length; i++) { |
1245 var apnDict = apnList[i]; | 1319 var apnDict = apnList[i]; |
1246 var option = document.createElement('option'); | 1320 var option = document.createElement('option'); |
1247 var localizedName = apnDict['LocalizedName']; | 1321 var localizedName = apnDict['LocalizedName']; |
1248 var name = localizedName ? localizedName : apnDict['Name']; | 1322 var name = localizedName ? localizedName : apnDict['Name']; |
1249 var accessPointName = apnDict['AccessPointName']; | 1323 var accessPointName = apnDict['AccessPointName']; |
1250 option.textContent = | 1324 option.textContent = |
1251 name ? (name + ' (' + accessPointName + ')') : accessPointName; | 1325 name ? (name + ' (' + accessPointName + ')') : accessPointName; |
1252 option.value = i; | 1326 option.value = i; |
1253 // If this matches the active Apn, or LastGoodApn, set it as the | 1327 // If this matches the active Apn, or LastGoodApn, set it as the |
1254 // selected Apn. | 1328 // selected Apn. |
1255 if ((activeApn != undefined && | 1329 if ((activeApn == accessPointName && |
1256 activeApn['AccessPointName'] == accessPointName && | 1330 activeUsername == apnDict['Username'] && |
1257 activeApn['Username'] == apnDict['Username'] && | 1331 activePassword == apnDict['Password']) || |
1258 activeApn['Password'] == apnDict['Password']) || | 1332 (!activeApn && |
1259 ((activeApn == undefined || !activeApn['AccessPointName']) && | 1333 lastGoodApn == accessPointName && |
1260 lastGoodApn != undefined && | 1334 lastGoodUsername == apnDict['Username'] && |
1261 lastGoodApn['AccessPointName'] == accessPointName && | 1335 lastGoodPassword == apnDict['Password'])) { |
1262 lastGoodApn['Username'] == apnDict['Username'] && | |
1263 lastGoodApn['Password'] == apnDict['Password'])) { | |
1264 data.selectedApn = i; | 1336 data.selectedApn = i; |
1265 } | 1337 } |
1266 // Insert new option before "other" option. | 1338 // Insert new option before "other" option. |
1267 apnSelector.add(option, otherOption); | 1339 apnSelector.add(option, otherOption); |
1268 } | 1340 } |
1269 if (data.selectedApn == -1 && | 1341 if (data.selectedApn == -1 && activeApn) { |
1270 activeApn != undefined && activeApn['AccessPointName']) { | |
1271 var option = document.createElement('option'); | 1342 var option = document.createElement('option'); |
1272 option.textContent = activeApn['AccessPointName']; | 1343 option.textContent = activeApn; |
1273 option.value = -1; | 1344 option.value = -1; |
1274 apnSelector.add(option, otherOption); | 1345 apnSelector.add(option, otherOption); |
1275 data.selectedApn = apnSelector.length - 2; | 1346 data.selectedApn = apnSelector.length - 2; |
1276 data.userApnIndex = data.selectedApn; | 1347 data.userApnIndex = data.selectedApn; |
1277 } | 1348 } |
1278 apnSelector.selectedIndex = data.selectedApn; | 1349 apnSelector.selectedIndex = data.selectedApn; |
1279 updateHidden('.apn-list-view', false); | 1350 updateHidden('.apn-list-view', false); |
1280 updateHidden('.apn-details-view', true); | 1351 updateHidden('.apn-details-view', true); |
1281 var lockEnabled = | 1352 var lockEnabled = |
1282 onc.getActiveValue('Cellular.SIMLockStatus.LockEnabled'); | 1353 onc.getActiveValue('Cellular.SIMLockStatus.LockEnabled'); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1351 | 1422 |
1352 // Don't show page name in address bar and in history to prevent people | 1423 // Don't show page name in address bar and in history to prevent people |
1353 // navigate here by hand and solve issue with page session restore. | 1424 // navigate here by hand and solve issue with page session restore. |
1354 PageManager.showPageByName('detailsInternetPage', false); | 1425 PageManager.showPageByName('detailsInternetPage', false); |
1355 }; | 1426 }; |
1356 | 1427 |
1357 return { | 1428 return { |
1358 DetailsInternetPage: DetailsInternetPage | 1429 DetailsInternetPage: DetailsInternetPage |
1359 }; | 1430 }; |
1360 }); | 1431 }); |
OLD | NEW |