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 cr.define('options.internet', function() { | 5 cr.define('options.internet', function() { |
6 var OptionsPage = options.OptionsPage; | 6 var OptionsPage = options.OptionsPage; |
7 | 7 |
8 /* | 8 /* |
9 * Helper function to set hidden attribute for elements matching a selector. | 9 * Helper function to set hidden attribute for elements matching a selector. |
10 * @param {string} selector CSS selector for extracting a list of elements. | 10 * @param {string} selector CSS selector for extracting a list of elements. |
11 * @param {bool} hidden New hidden value. | 11 * @param {bool} hidden New hidden value. |
12 */ | 12 */ |
13 function updateHidden(selector, hidden) { | 13 function updateHidden(selector, hidden) { |
14 var elements = cr.doc.querySelectorAll(selector); | 14 var elements = cr.doc.querySelectorAll(selector); |
15 for (var i = 0, el; el = elements[i]; i++) { | 15 for (var i = 0, el; el = elements[i]; i++) { |
16 el.hidden = hidden; | 16 el.hidden = hidden; |
17 } | 17 } |
18 } | 18 } |
19 | 19 |
| 20 /** |
| 21 * Monitor pref change of given element. |
| 22 * @param {Element} el Target element. |
| 23 */ |
| 24 function observePrefsUI(el) { |
| 25 Preferences.getInstance().addEventListener(el.pref, handlePrefUpdate); |
| 26 } |
| 27 |
| 28 /** |
| 29 * UI pref change handler. |
| 30 * @param {Event} e The update event. |
| 31 */ |
| 32 function handlePrefUpdate(e) { |
| 33 DetailsInternetPage.prototype.updateControls; |
| 34 } |
| 35 |
20 ///////////////////////////////////////////////////////////////////////////// | 36 ///////////////////////////////////////////////////////////////////////////// |
21 // DetailsInternetPage class: | 37 // DetailsInternetPage class: |
22 | 38 |
23 /** | 39 /** |
24 * Encapsulated handling of ChromeOS internet details overlay page. | 40 * Encapsulated handling of ChromeOS internet details overlay page. |
25 * @constructor | 41 * @constructor |
26 */ | 42 */ |
27 function DetailsInternetPage() { | 43 function DetailsInternetPage() { |
28 OptionsPage.call(this, 'detailsInternetPage', null, 'detailsInternetPage'); | 44 OptionsPage.call(this, 'detailsInternetPage', null, 'detailsInternetPage'); |
29 } | 45 } |
30 | 46 |
31 cr.addSingletonGetter(DetailsInternetPage); | 47 cr.addSingletonGetter(DetailsInternetPage); |
32 | 48 |
33 DetailsInternetPage.prototype = { | 49 DetailsInternetPage.prototype = { |
34 __proto__: OptionsPage.prototype, | 50 __proto__: OptionsPage.prototype, |
35 | 51 |
36 /** | 52 /** |
| 53 * Indicates if the list of proxy exceptions has been initialized. |
| 54 * @type {boolean} |
| 55 */ |
| 56 proxyListInitialized_: false, |
| 57 |
| 58 /** |
37 * Initializes DetailsInternetPage page. | 59 * Initializes DetailsInternetPage page. |
38 * Calls base class implementation to starts preference initialization. | 60 * Calls base class implementation to starts preference initialization. |
39 */ | 61 */ |
40 initializePage: function() { | 62 initializePage: function() { |
41 OptionsPage.prototype.initializePage.call(this); | 63 OptionsPage.prototype.initializePage.call(this); |
42 | 64 |
43 options.internet.CellularPlanElement.decorate($('planList')); | 65 options.internet.CellularPlanElement.decorate($('planList')); |
44 | 66 |
45 $('detailsInternetDismiss').addEventListener('click', function(event) { | 67 $('detailsInternetDismiss').addEventListener('click', function(event) { |
46 InternetOptions.setDetails(); | 68 InternetOptions.setDetails(); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 var newValue = $('sim-card-lock-enabled').checked; | 192 var newValue = $('sim-card-lock-enabled').checked; |
171 // Leave value as is because user needs to enter PIN code first. | 193 // Leave value as is because user needs to enter PIN code first. |
172 // When PIN will be entered and value changed, | 194 // When PIN will be entered and value changed, |
173 // we'll update UI to reflect that change. | 195 // we'll update UI to reflect that change. |
174 $('sim-card-lock-enabled').checked = !newValue; | 196 $('sim-card-lock-enabled').checked = !newValue; |
175 chrome.send('setSimCardLock', [newValue]); | 197 chrome.send('setSimCardLock', [newValue]); |
176 }); | 198 }); |
177 $('change-pin').addEventListener('click', function(event) { | 199 $('change-pin').addEventListener('click', function(event) { |
178 chrome.send('changePin'); | 200 chrome.send('changePin'); |
179 }); | 201 }); |
| 202 |
| 203 // Proxy |
| 204 options.proxyexceptions.ProxyExceptions.decorate($('ignoredHostList')); |
| 205 $('removeHost').addEventListener('click', |
| 206 this.handleRemoveProxyExceptions_); |
| 207 $('addHost').addEventListener('click', this.handleAddProxyException_); |
| 208 $('directProxy').addEventListener('click', this.disableManualProxy_); |
| 209 $('manualProxy').addEventListener('click', this.enableManualProxy_); |
| 210 $('autoProxy').addEventListener('click', this.disableManualProxy_); |
| 211 $('proxyAllProtocols').addEventListener('click', |
| 212 this.toggleSingleProxy_); |
| 213 observePrefsUI($('directProxy')); |
| 214 observePrefsUI($('manualProxy')); |
| 215 observePrefsUI($('autoProxy')); |
| 216 observePrefsUI($('proxyAllProtocols')); |
| 217 }, |
| 218 |
| 219 /** |
| 220 * Handler for "add" event fired from userNameEdit. |
| 221 * @param {Event} e Add event fired from userNameEdit. |
| 222 * @private |
| 223 */ |
| 224 handleAddProxyException_: function(e) { |
| 225 var exception = $('newHost').value; |
| 226 $('newHost').value = ''; |
| 227 |
| 228 exception = exception.trim(); |
| 229 if (exception) |
| 230 $('ignoredHostList').addException(exception); |
| 231 }, |
| 232 |
| 233 /** |
| 234 * Handler for when the remove button is clicked |
| 235 * @param {Event} e The click event. |
| 236 * @private |
| 237 */ |
| 238 handleRemoveProxyExceptions_: function(e) { |
| 239 var selectedItems = $('ignoredHostList').selectedItems; |
| 240 for (var x = 0; x < selectedItems.length; x++) { |
| 241 $('ignoredHostList').removeException(selectedItems[x]); |
| 242 } |
180 }, | 243 }, |
181 | 244 |
182 /** | 245 /** |
183 * Update details page controls. | 246 * Update details page controls. |
184 * @private | 247 * @private |
185 */ | 248 */ |
186 updateControls_: function() { | 249 updateControls: function() { |
187 // Only show ipconfig section if network is connected OR if nothing on | 250 // Only show ipconfig section if network is connected OR if nothing on |
188 // this device is connected. This is so that you can fix the ip configs | 251 // this device is connected. This is so that you can fix the ip configs |
189 // if you can't connect to any network. | 252 // if you can't connect to any network. |
190 // TODO(chocobo): Once ipconfig is moved to flimflam service objects, | 253 // TODO(chocobo): Once ipconfig is moved to flimflam service objects, |
191 // we need to redo this logic to allow configuration of all networks. | 254 // we need to redo this logic to allow configuration of all networks. |
192 $('ipconfigSection').hidden = !this.connected && this.deviceConnected; | 255 $('ipconfigSection').hidden = !this.connected && this.deviceConnected; |
193 | 256 |
194 // Network type related. | 257 // Network type related. |
195 updateHidden('#detailsInternetPage .cellular-details', !this.cellular); | 258 updateHidden('#detailsInternetPage .cellular-details', !this.cellular); |
196 updateHidden('#detailsInternetPage .wifi-details', !this.wireless); | 259 updateHidden('#detailsInternetPage .wifi-details', !this.wireless); |
(...skipping 15 matching lines...) Expand all Loading... |
212 updateHidden('#detailsInternetPage .apn-list-view', | 275 updateHidden('#detailsInternetPage .apn-list-view', |
213 !this.cellular || !this.gsm); | 276 !this.cellular || !this.gsm); |
214 updateHidden('#detailsInternetPage .apn-details-view', true); | 277 updateHidden('#detailsInternetPage .apn-details-view', true); |
215 | 278 |
216 // Password and shared. | 279 // Password and shared. |
217 updateHidden('#detailsInternetPage .password-details', | 280 updateHidden('#detailsInternetPage .password-details', |
218 !this.wireless || !this.password); | 281 !this.wireless || !this.password); |
219 updateHidden('#detailsInternetPage .shared-network', !this.shared); | 282 updateHidden('#detailsInternetPage .shared-network', !this.shared); |
220 updateHidden('#detailsInternetPage .prefer-network', | 283 updateHidden('#detailsInternetPage .prefer-network', |
221 !this.showPreferred); | 284 !this.showPreferred); |
222 } | 285 |
| 286 // Proxy |
| 287 this.updateProxyBannerVisibility_(); |
| 288 this.toggleSingleProxy_(); |
| 289 if ($('manualProxy').checked) |
| 290 this.enableManualProxy_(); |
| 291 else |
| 292 this.disableManualProxy_(); |
| 293 if (!this.proxyListInitialized_ && this.visible) { |
| 294 this.proxyListInitialized_ = true; |
| 295 $('ignoredHostList').redraw(); |
| 296 } |
| 297 }, |
| 298 |
| 299 /** |
| 300 * Updates info banner visibility state. This function shows the banner |
| 301 * if proxy is managed or shared-proxies is off for shared network. |
| 302 * @private |
| 303 */ |
| 304 updateProxyBannerVisibility_: function() { |
| 305 var bannerDiv = $('info-banner'); |
| 306 // Show banner and determine its message if necessary. |
| 307 var controlledBy = $('directProxy').controlledBy; |
| 308 if (controlledBy == '') { |
| 309 bannerDiv.hidden = true; |
| 310 } else { |
| 311 bannerDiv.hidden = false; |
| 312 // controlledBy must match strings loaded in proxy_handler.cc and |
| 313 // set in proxy_cros_settings_provider.cc. |
| 314 $('banner-text').textContent = localStrings.getString(controlledBy); |
| 315 } |
| 316 }, |
| 317 |
| 318 /** |
| 319 * Handler for when the user clicks on the checkbox to allow a |
| 320 * single proxy usage. |
| 321 * @private |
| 322 * @param {Event} e Click Event. |
| 323 */ |
| 324 toggleSingleProxy_: function(e) { |
| 325 if ($('proxyAllProtocols').checked) { |
| 326 $('multiProxy').hidden = true; |
| 327 $('singleProxy').hidden = false; |
| 328 } else { |
| 329 $('multiProxy').hidden = false; |
| 330 $('singleProxy').hidden = true; |
| 331 } |
| 332 }, |
| 333 |
| 334 /** |
| 335 * Handler for selecting a radio button that will disable the manual |
| 336 * controls. |
| 337 * @private |
| 338 * @param {Event} e Click event. |
| 339 */ |
| 340 disableManualProxy_: function(e) { |
| 341 $('advancedConfig').hidden = true; |
| 342 $('proxyAllProtocols').disabled = true; |
| 343 $('proxyHostName').disabled = true; |
| 344 $('proxyHostPort').disabled = true; |
| 345 $('proxyHostSingleName').disabled = true; |
| 346 $('proxyHostSinglePort').disabled = true; |
| 347 $('secureProxyHostName').disabled = true; |
| 348 $('secureProxyPort').disabled = true; |
| 349 $('ftpProxy').disabled = true; |
| 350 $('ftpProxyPort').disabled = true; |
| 351 $('socksHost').disabled = true; |
| 352 $('socksPort').disabled = true; |
| 353 $('proxyConfig').disabled = $('autoProxy').disabled || |
| 354 !$('autoProxy').checked; |
| 355 }, |
| 356 |
| 357 /** |
| 358 * Handler for selecting a radio button that will enable the manual |
| 359 * controls. |
| 360 * @private |
| 361 * @param {Event} e Click event. |
| 362 */ |
| 363 enableManualProxy_: function(e) { |
| 364 $('advancedConfig').hidden = false; |
| 365 $('ignoredHostList').redraw(); |
| 366 var all_disabled = $('manualProxy').disabled; |
| 367 $('newHost').disabled = all_disabled; |
| 368 $('removeHost').disabled = all_disabled; |
| 369 $('addHost').disabled = all_disabled; |
| 370 $('proxyAllProtocols').disabled = all_disabled; |
| 371 $('proxyHostName').disabled = all_disabled; |
| 372 $('proxyHostPort').disabled = all_disabled; |
| 373 $('proxyHostSingleName').disabled = all_disabled; |
| 374 $('proxyHostSinglePort').disabled = all_disabled; |
| 375 $('secureProxyHostName').disabled = all_disabled; |
| 376 $('secureProxyPort').disabled = all_disabled; |
| 377 $('ftpProxy').disabled = all_disabled; |
| 378 $('ftpProxyPort').disabled = all_disabled; |
| 379 $('socksHost').disabled = all_disabled; |
| 380 $('socksPort').disabled = all_disabled; |
| 381 $('proxyConfig').disabled = true; |
| 382 }, |
223 }; | 383 }; |
224 | 384 |
225 /** | |
226 * Whether the underlying network is connected. Only used for display purpose. | |
227 * @type {boolean} | |
228 */ | |
229 cr.defineProperty(DetailsInternetPage, 'connected', | |
230 cr.PropertyKind.JS, | |
231 DetailsInternetPage.prototype.updateControls_); | |
232 | |
233 /** | |
234 * Whether the underlying network is wifi. Only used for display purpose. | |
235 * @type {boolean} | |
236 */ | |
237 cr.defineProperty(DetailsInternetPage, 'wireless', | |
238 cr.PropertyKind.JS, | |
239 DetailsInternetPage.prototype.updateControls_); | |
240 | |
241 /** | |
242 * Whether the underlying network shared wifi. Only used for display purpose. | |
243 * @type {boolean} | |
244 */ | |
245 cr.defineProperty(DetailsInternetPage, 'shared', | |
246 cr.PropertyKind.JS, | |
247 DetailsInternetPage.prototype.updateControls_); | |
248 | |
249 /** | |
250 * Whether the underlying network is a vpn. Only used for display purpose. | |
251 * @type {boolean} | |
252 */ | |
253 cr.defineProperty(DetailsInternetPage, 'vpn', | |
254 cr.PropertyKind.JS, | |
255 DetailsInternetPage.prototype.updateControls_); | |
256 | |
257 /** | |
258 * Whether the underlying network is ethernet. Only used for display purpose. | |
259 * @type {boolean} | |
260 */ | |
261 cr.defineProperty(DetailsInternetPage, 'ethernet', | |
262 cr.PropertyKind.JS, | |
263 DetailsInternetPage.prototype.updateControls_); | |
264 | |
265 /** | |
266 * Whether the underlying network is cellular. Only used for display purpose. | |
267 * @type {boolean} | |
268 */ | |
269 cr.defineProperty(DetailsInternetPage, 'cellular', | |
270 cr.PropertyKind.JS, | |
271 DetailsInternetPage.prototype.updateControls_); | |
272 | |
273 /** | |
274 * Whether the network is loading cell plan. Only used for display purpose. | |
275 * @type {boolean} | |
276 */ | |
277 cr.defineProperty(DetailsInternetPage, 'cellplanloading', | |
278 cr.PropertyKind.JS, | |
279 DetailsInternetPage.prototype.updateControls_); | |
280 | |
281 /** | |
282 * Whether the network has cell plan(s). Only used for display purpose. | |
283 * @type {boolean} | |
284 */ | |
285 cr.defineProperty(DetailsInternetPage, 'hascellplan', | |
286 cr.PropertyKind.JS, | |
287 DetailsInternetPage.prototype.updateControls_); | |
288 | |
289 /** | |
290 * Whether the network has no cell plan. Only used for display purpose. | |
291 * @type {boolean} | |
292 */ | |
293 cr.defineProperty(DetailsInternetPage, 'nocellplan', | |
294 cr.PropertyKind.JS, | |
295 DetailsInternetPage.prototype.updateControls_); | |
296 | |
297 /** | |
298 * Whether the network is gsm. Only used for display purpose. | |
299 * @type {boolean} | |
300 */ | |
301 cr.defineProperty(DetailsInternetPage, 'gsm', | |
302 cr.PropertyKind.JS, | |
303 DetailsInternetPage.prototype.updateControls_); | |
304 | |
305 /** | |
306 * Whether show password details for network. Only used for display purpose. | |
307 * @type {boolean} | |
308 */ | |
309 cr.defineProperty(DetailsInternetPage, 'password', | |
310 cr.PropertyKind.JS, | |
311 DetailsInternetPage.prototype.updateControls_); | |
312 | |
313 // TODO(xiyuan): Check to see if it is safe to remove these attributes. | |
314 cr.defineProperty(DetailsInternetPage, 'hasactiveplan', | |
315 cr.PropertyKind.JS); | |
316 cr.defineProperty(DetailsInternetPage, 'activated', | |
317 cr.PropertyKind.JS); | |
318 cr.defineProperty(DetailsInternetPage, 'connecting', | |
319 cr.PropertyKind.JS); | |
320 cr.defineProperty(DetailsInternetPage, 'connected', | |
321 cr.PropertyKind.JS); | |
322 | |
323 return { | 385 return { |
324 DetailsInternetPage: DetailsInternetPage | 386 DetailsInternetPage: DetailsInternetPage |
325 }; | 387 }; |
326 }); | 388 }); |
OLD | NEW |