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 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 * @param {string} message The message to send to chrome. | 107 * @param {string} message The message to send to chrome. |
108 * @param {HTMLInputElement} checkbox The checkbox storing the value to send. | 108 * @param {HTMLInputElement} checkbox The checkbox storing the value to send. |
109 */ | 109 */ |
110 function sendCheckedIfEnabled(path, message, checkbox) { | 110 function sendCheckedIfEnabled(path, message, checkbox) { |
111 if (!checkbox.hidden && !checkbox.disabled) | 111 if (!checkbox.hidden && !checkbox.disabled) |
112 chrome.send(message, [path, checkbox.checked ? 'true' : 'false']); | 112 chrome.send(message, [path, checkbox.checked ? 'true' : 'false']); |
113 } | 113 } |
114 | 114 |
115 /** | 115 /** |
116 * Returns the netmask as a string for a given prefix length. | 116 * Returns the netmask as a string for a given prefix length. |
117 * @param {string} prefixLength The ONC routing prefix length. | 117 * @param {number} prefixLength The ONC routing prefix length. |
118 * @return {string} The corresponding netmask. | 118 * @return {string} The corresponding netmask. |
119 */ | 119 */ |
120 function prefixLengthToNetmask(prefixLength) { | 120 function prefixLengthToNetmask(prefixLength) { |
121 // Return the empty string for invalid inputs. | 121 // Return the empty string for invalid inputs. |
122 if (prefixLength < 0 || prefixLength > 32) | 122 if (prefixLength < 0 || prefixLength > 32) |
123 return ''; | 123 return ''; |
124 var netmask = ''; | 124 var netmask = ''; |
125 for (var i = 0; i < 4; ++i) { | 125 for (var i = 0; i < 4; ++i) { |
126 var remainder = 8; | 126 var remainder = 8; |
127 if (prefixLength >= 8) { | 127 if (prefixLength >= 8) { |
(...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1177 // Override the "automatic" values with the real saved DHCP values, | 1177 // Override the "automatic" values with the real saved DHCP values, |
1178 // if they are set. | 1178 // if they are set. |
1179 var savedNameServersString; | 1179 var savedNameServersString; |
1180 var savedIpAddress = onc.getActiveValue('SavedIPConfig.IPAddress'); | 1180 var savedIpAddress = onc.getActiveValue('SavedIPConfig.IPAddress'); |
1181 if (savedIpAddress != undefined) { | 1181 if (savedIpAddress != undefined) { |
1182 inetAddress.automatic = savedIpAddress; | 1182 inetAddress.automatic = savedIpAddress; |
1183 inetAddress.value = savedIpAddress; | 1183 inetAddress.value = savedIpAddress; |
1184 } | 1184 } |
1185 var savedPrefix = onc.getActiveValue('SavedIPConfig.RoutingPrefix'); | 1185 var savedPrefix = onc.getActiveValue('SavedIPConfig.RoutingPrefix'); |
1186 if (savedPrefix != undefined) { | 1186 if (savedPrefix != undefined) { |
1187 var savedNetmask = prefixLengthToNetmask(savedPrefix); | 1187 assert(typeof savedPrefix == 'number'); |
| 1188 var savedNetmask = prefixLengthToNetmask( |
| 1189 /** @type {number} */(savedPrefix)); |
1188 inetNetmask.automatic = savedNetmask; | 1190 inetNetmask.automatic = savedNetmask; |
1189 inetNetmask.value = savedNetmask; | 1191 inetNetmask.value = savedNetmask; |
1190 } | 1192 } |
1191 var savedGateway = onc.getActiveValue('SavedIPConfig.Gateway'); | 1193 var savedGateway = onc.getActiveValue('SavedIPConfig.Gateway'); |
1192 if (savedGateway != undefined) { | 1194 if (savedGateway != undefined) { |
1193 inetGateway.automatic = savedGateway; | 1195 inetGateway.automatic = savedGateway; |
1194 inetGateway.value = savedGateway; | 1196 inetGateway.value = savedGateway; |
1195 } | 1197 } |
1196 var savedNameServers = onc.getActiveValue('SavedIPConfig.NameServers'); | 1198 var savedNameServers = onc.getActiveValue('SavedIPConfig.NameServers'); |
1197 if (savedNameServers) { | 1199 if (savedNameServers) { |
1198 savedNameServers = savedNameServers.sort(); | 1200 savedNameServers = savedNameServers.sort(); |
1199 savedNameServersString = savedNameServers.join(','); | 1201 savedNameServersString = savedNameServers.join(','); |
1200 } | 1202 } |
1201 | 1203 |
1202 var ipAutoConfig = 'automatic'; | 1204 var ipAutoConfig = 'automatic'; |
1203 | 1205 |
1204 var staticNameServersString; | 1206 var staticNameServersString; |
1205 var staticIpAddress = onc.getActiveValue('StaticIPConfig.IPAddress'); | 1207 var staticIpAddress = onc.getActiveValue('StaticIPConfig.IPAddress'); |
1206 if (staticIpAddress != undefined) { | 1208 if (staticIpAddress != undefined) { |
1207 ipAutoConfig = 'user'; | 1209 ipAutoConfig = 'user'; |
1208 inetAddress.user = staticIpAddress; | 1210 inetAddress.user = staticIpAddress; |
1209 inetAddress.value = staticIpAddress; | 1211 inetAddress.value = staticIpAddress; |
1210 } | 1212 } |
1211 var staticPrefix = onc.getActiveValue('StaticIPConfig.RoutingPrefix'); | 1213 var staticPrefix = onc.getActiveValue('StaticIPConfig.RoutingPrefix'); |
1212 if (staticPrefix != undefined) { | 1214 if (staticPrefix != undefined) { |
1213 var staticNetmask = prefixLengthToNetmask(staticPrefix); | 1215 assert(typeof staticPrefix == 'number'); |
| 1216 var staticNetmask = prefixLengthToNetmask( |
| 1217 /** @type {number} */(staticPrefix)); |
1214 inetNetmask.user = staticNetmask; | 1218 inetNetmask.user = staticNetmask; |
1215 inetNetmask.value = staticNetmask; | 1219 inetNetmask.value = staticNetmask; |
1216 } | 1220 } |
1217 var staticGateway = onc.getActiveValue('StaticIPConfig.Gateway'); | 1221 var staticGateway = onc.getActiveValue('StaticIPConfig.Gateway'); |
1218 if (staticGateway != undefined) { | 1222 if (staticGateway != undefined) { |
1219 inetGateway.user = staticGateway; | 1223 inetGateway.user = staticGateway; |
1220 inetGateway.value = staticGateway; | 1224 inetGateway.value = staticGateway; |
1221 } | 1225 } |
1222 var staticNameServers = onc.getActiveValue('StaticIPConfig.NameServers'); | 1226 var staticNameServers = onc.getActiveValue('StaticIPConfig.NameServers'); |
1223 if (staticNameServers) { | 1227 if (staticNameServers) { |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1457 | 1461 |
1458 // Don't show page name in address bar and in history to prevent people | 1462 // Don't show page name in address bar and in history to prevent people |
1459 // navigate here by hand and solve issue with page session restore. | 1463 // navigate here by hand and solve issue with page session restore. |
1460 PageManager.showPageByName('detailsInternetPage', false); | 1464 PageManager.showPageByName('detailsInternetPage', false); |
1461 }; | 1465 }; |
1462 | 1466 |
1463 return { | 1467 return { |
1464 DetailsInternetPage: DetailsInternetPage | 1468 DetailsInternetPage: DetailsInternetPage |
1465 }; | 1469 }; |
1466 }); | 1470 }); |
OLD | NEW |