Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(618)

Side by Side Diff: chrome/browser/resources/options2/chromeos/internet_detail.js

Issue 9668010: Move proxy handling into network details. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add missing jsdoc. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_;
csilv 2012/03/09 22:30:14 should be 'updateControls'.
kevers 2012/03/12 13:57:13 Done.
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
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
206 this.addEventListener('visibleChange', this.handleVisibleChange_);
csilv 2012/03/09 22:30:14 handleVisibleChange_ is undefined.
kevers 2012/03/12 13:57:13 Done.
207 $('removeHost').addEventListener('click',
208 this.handleRemoveProxyExceptions_);
209 $('addHost').addEventListener('click', this.handleAddProxyException_);
210 $('directProxy').addEventListener('click', this.disableManualProxy_);
211 $('manualProxy').addEventListener('click', this.enableManualProxy_);
212 $('autoProxy').addEventListener('click', this.disableManualProxy_);
213 $('proxyAllProtocols').addEventListener('click',
214 this.toggleSingleProxy_);
215
216 observePrefsUI($('directProxy'));
217 observePrefsUI($('manualProxy'));
218 observePrefsUI($('autoProxy'));
219 observePrefsUI($('proxyAllProtocols'));
220 },
221
222 /**
223 * Handler for "add" event fired from userNameEdit.
224 * @param {Event} e Add event fired from userNameEdit.
225 * @private
226 */
227 handleAddProxyException_: function(e) {
228 var exception = $('newHost').value;
229 $('newHost').value = '';
230
231 exception = exception.trim();
232 if (exception)
233 $('ignoredHostList').addException(exception);
234 },
235
236 /**
237 * Handler for when the remove button is clicked
238 * @param {Event} e The click event.
239 * @private
240 */
241 handleRemoveProxyExceptions_: function(e) {
242 var selectedItems = $('ignoredHostList').selectedItems;
243 for (var x = 0; x < selectedItems.length; x++) {
244 $('ignoredHostList').removeException(selectedItems[x]);
245 }
180 }, 246 },
181 247
182 /** 248 /**
183 * Update details page controls. 249 * Update details page controls.
184 * @private 250 * @private
185 */ 251 */
186 updateControls_: function() { 252 updateControls: function() {
187 // Only show ipconfig section if network is connected OR if nothing on 253 // 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 254 // this device is connected. This is so that you can fix the ip configs
189 // if you can't connect to any network. 255 // if you can't connect to any network.
190 // TODO(chocobo): Once ipconfig is moved to flimflam service objects, 256 // TODO(chocobo): Once ipconfig is moved to flimflam service objects,
191 // we need to redo this logic to allow configuration of all networks. 257 // we need to redo this logic to allow configuration of all networks.
192 $('ipconfigSection').hidden = !this.connected && this.deviceConnected; 258 $('ipconfigSection').hidden = !this.connected && this.deviceConnected;
193 259
194 // Network type related. 260 // Network type related.
195 updateHidden('#detailsInternetPage .cellular-details', !this.cellular); 261 updateHidden('#detailsInternetPage .cellular-details', !this.cellular);
196 updateHidden('#detailsInternetPage .wifi-details', !this.wireless); 262 updateHidden('#detailsInternetPage .wifi-details', !this.wireless);
(...skipping 15 matching lines...) Expand all
212 updateHidden('#detailsInternetPage .apn-list-view', 278 updateHidden('#detailsInternetPage .apn-list-view',
213 !this.cellular || !this.gsm); 279 !this.cellular || !this.gsm);
214 updateHidden('#detailsInternetPage .apn-details-view', true); 280 updateHidden('#detailsInternetPage .apn-details-view', true);
215 281
216 // Password and shared. 282 // Password and shared.
217 updateHidden('#detailsInternetPage .password-details', 283 updateHidden('#detailsInternetPage .password-details',
218 !this.wireless || !this.password); 284 !this.wireless || !this.password);
219 updateHidden('#detailsInternetPage .shared-network', !this.shared); 285 updateHidden('#detailsInternetPage .shared-network', !this.shared);
220 updateHidden('#detailsInternetPage .prefer-network', 286 updateHidden('#detailsInternetPage .prefer-network',
221 !this.showPreferred); 287 !this.showPreferred);
222 } 288
289 // Proxy
290 this.updateProxyBannerVisibility_();
291 this.toggleSingleProxy_();
292 if ($('manualProxy').checked)
293 this.enableManualProxy_();
294 else
295 this.disableManualProxy_();
296 if (!this.proxyListInitialized_ && this.visible) {
297 this.proxyListInitialized_ = true;
298 $('ignoredHostList').redraw();
299 }
300 },
301
302 /**
303 * Updates info banner visibility state. This function shows the banner
304 * if proxy is managed or shared-proxies is off for shared network.
305 * @private
306 */
307 updateProxyBannerVisibility_: function() {
308 var bannerDiv = $('info-banner');
309 // Show banner and determine its message if necessary.
310 var controlledBy = $('directProxy').controlledBy;
311 if (controlledBy == '') {
312 bannerDiv.hidden = true;
313 } else {
314 bannerDiv.hidden = false;
315 // controlledBy must match strings loaded in proxy_handler.cc and
316 // set in proxy_cros_settings_provider.cc.
317 $('banner-text').textContent = localStrings.getString(controlledBy);
318 }
319 },
320
321 /**
322 * Handler for when the user clicks on the checkbox to allow a
323 * single proxy usage.
324 * @private
325 * @param {Event} e Click Event.
326 */
327 toggleSingleProxy_: function(e) {
328 if ($('proxyAllProtocols').checked) {
329 $('multiProxy').style.display = 'none';
330 $('singleProxy').style.display = 'block';
331 } else {
332 $('multiProxy').style.display = 'block';
333 $('singleProxy').style.display = 'none';
334 }
335 },
csilv 2012/03/09 22:30:14 would it be possible to use 'hidden' instead of se
kevers 2012/03/12 13:57:13 Done.
336
337 /**
338 * Handler for selecting a radio button that will disable the manual
339 * controls.
340 * @private
341 * @param {Event} e Click event.
342 */
343 disableManualProxy_: function(e) {
344 $('advancedConfig').hidden = true;
345 $('proxyAllProtocols').disabled = true;
346 $('proxyHostName').disabled = true;
347 $('proxyHostPort').disabled = true;
348 $('proxyHostSingleName').disabled = true;
349 $('proxyHostSinglePort').disabled = true;
350 $('secureProxyHostName').disabled = true;
351 $('secureProxyPort').disabled = true;
352 $('ftpProxy').disabled = true;
353 $('ftpProxyPort').disabled = true;
354 $('socksHost').disabled = true;
355 $('socksPort').disabled = true;
356 $('proxyConfig').disabled = $('autoProxy').disabled ||
357 !$('autoProxy').checked;
358 },
359
360 /**
361 * Handler for selecting a radio button that will enable the manual
362 * controls.
363 * @private
364 * @param {Event} e Click event.
365 */
366 enableManualProxy_: function(e) {
367 $('advancedConfig').hidden = false;
368 $('ignoredHostList').redraw();
369 var all_disabled = $('manualProxy').disabled;
370 $('newHost').disabled = all_disabled;
371 $('removeHost').disabled = all_disabled;
372 $('addHost').disabled = all_disabled;
373 $('proxyAllProtocols').disabled = all_disabled;
374 $('proxyHostName').disabled = all_disabled;
375 $('proxyHostPort').disabled = all_disabled;
376 $('proxyHostSingleName').disabled = all_disabled;
377 $('proxyHostSinglePort').disabled = all_disabled;
378 $('secureProxyHostName').disabled = all_disabled;
379 $('secureProxyPort').disabled = all_disabled;
380 $('ftpProxy').disabled = all_disabled;
381 $('ftpProxyPort').disabled = all_disabled;
382 $('socksHost').disabled = all_disabled;
383 $('socksPort').disabled = all_disabled;
384 $('proxyConfig').disabled = true;
385 },
223 }; 386 };
224 387
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 { 388 return {
324 DetailsInternetPage: DetailsInternetPage 389 DetailsInternetPage: DetailsInternetPage
325 }; 390 };
326 }); 391 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698