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

Side by Side Diff: chrome/common/extensions/docs/examples/extensions/proxy_configuration/proxy_form_controller.js

Issue 6677108: `extension.isAllowed???Access` samples (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 /** 5 /**
6 * @fileoverview This file implements the ProxyFormController class, which 6 * @fileoverview This file implements the ProxyFormController class, which
7 * wraps a form element with logic that enables implementation of proxy 7 * wraps a form element with logic that enables implementation of proxy
8 * settings. 8 * settings.
9 * 9 *
10 * @author mkwst@google.com (Mike West) 10 * @author mkwst@google.com (Mike West)
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 /////////////////////////////////////////////////////////////////////////////// 118 ///////////////////////////////////////////////////////////////////////////////
119 119
120 ProxyFormController.prototype = { 120 ProxyFormController.prototype = {
121 /** 121 /**
122 * The form's current state. 122 * The form's current state.
123 * @type {regular: ?ProxyConfig, incognito: ?ProxyConfig} 123 * @type {regular: ?ProxyConfig, incognito: ?ProxyConfig}
124 * @private 124 * @private
125 */ 125 */
126 config_: {regular: null, incognito: null}, 126 config_: {regular: null, incognito: null},
127 127
128 /**
129 * Do we have access to incognito mode?
130 * @type {boolean}
131 * @private
132 */
133 isAllowedIncognitoAccess_: false,
128 134
129 /** 135 /**
130 * @return {string} The PAC file URL (or an empty string). 136 * @return {string} The PAC file URL (or an empty string).
131 */ 137 */
132 get pacURL() { 138 get pacURL() {
133 return document.getElementById('autoconfigURL').value; 139 return document.getElementById('autoconfigURL').value;
134 }, 140 },
135 141
136 142
137 /** 143 /**
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 322
317 /////////////////////////////////////////////////////////////////////////////// 323 ///////////////////////////////////////////////////////////////////////////////
318 324
319 /** 325 /**
320 * Calls the proxy API to read the current settings, and populates the form 326 * Calls the proxy API to read the current settings, and populates the form
321 * accordingly. 327 * accordingly.
322 * 328 *
323 * @private 329 * @private
324 */ 330 */
325 readCurrentState_: function() { 331 readCurrentState_: function() {
326 chrome.experimental.proxy.settings.get({incognito: false}, 332 chrome.extension.isAllowedIncognitoAccess(
327 this.handleRegularState_.bind(this)); 333 this.handleIncognitoAccessResponse_.bind(this));
328 chrome.experimental.proxy.settings.get({incognito: true},
329 this.handleIncognitoState_.bind(this));
330 }, 334 },
331 335
332 /** 336 /**
337 * Handles the respnse from `chrome.extension.isAllowedIncognitoAccess`
338 * We can't render the form until we know what our access level is, so
339 * we wait until we have confirmed incognito access levels before
340 * asking for the proxy state.
341 *
342 * @param {boolean} state The state of incognito access.
343 * @private
344 */
345 handleIncognitoAccessResponse_: function(state) {
346 this.isAllowedIncognitoAccess_ = state;
347 chrome.experimental.proxy.settings.get({incognito: false},
348 this.handleRegularState_.bind(this));
349 if (this.isAllowedIncognitoAccess_) {
350 chrome.experimental.proxy.settings.get({incognito: true},
351 this.handleIncognitoState_.bind(this));
352 }
353 },
354
355 /**
333 * Handles the response from 'proxy.settings.get' for regular settings. 356 * Handles the response from 'proxy.settings.get' for regular settings.
334 * 357 *
335 * @param {ProxyFormController.WrappedProxyConfig} c The proxy data and 358 * @param {ProxyFormController.WrappedProxyConfig} c The proxy data and
336 * extension's level of control thereof. 359 * extension's level of control thereof.
337 * @private 360 * @private
338 */ 361 */
339 handleRegularState_: function(c) { 362 handleRegularState_: function(c) {
340 if (c.levelOfControl === ProxyFormController.LevelOfControl.AVAILABLE || 363 if (c.levelOfControl === ProxyFormController.LevelOfControl.AVAILABLE ||
341 c.levelOfControl === ProxyFormController.LevelOfControl.CONTROLLING) { 364 c.levelOfControl === ProxyFormController.LevelOfControl.CONTROLLING) {
342 this.recalcFormValues_(c.value); 365 this.recalcFormValues_(c.value);
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 }, 674 },
652 675
653 676
654 /** 677 /**
655 * Sets the form's values based on a ProxyConfig. 678 * Sets the form's values based on a ProxyConfig.
656 * 679 *
657 * @param {!ProxyConfig} c The ProxyConfig object. 680 * @param {!ProxyConfig} c The ProxyConfig object.
658 * @private 681 * @private
659 */ 682 */
660 recalcFormValues_: function(c) { 683 recalcFormValues_: function(c) {
684 var button = document.getElementsByTagName('button')[0];
685 button.style.display = this.isAllowedIncognitoAccess_ ? 'block' : 'none';
kurrik.chromium 2011/03/21 22:13:02 This button now wraps to another line. I think I
Mike West 2011/03/22 08:44:56 Done.
686
kurrik.chromium 2011/03/21 22:13:02 I think you could also add some UI indicating how
Mike West 2011/03/22 08:44:56 Fair enough. I've reworked this section entirely;
661 // Normalize `auto_detect` 687 // Normalize `auto_detect`
662 if (c.mode === 'auto_detect') 688 if (c.mode === 'auto_detect')
663 c.mode = 'pac_script'; 689 c.mode = 'pac_script';
664 // Activate one of the groups, based on `mode`. 690 // Activate one of the groups, based on `mode`.
665 this.changeActive_(document.getElementById(c.mode)); 691 this.changeActive_(document.getElementById(c.mode));
666 // Populate the PAC script 692 // Populate the PAC script
667 if (c.pacScript) { 693 if (c.pacScript) {
668 if (c.pacScript.url) 694 if (c.pacScript.url)
669 this.pacURL = c.pacScript.url; 695 this.pacURL = c.pacScript.url;
670 } else { 696 } else {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 if (response.result !== null) { 761 if (response.result !== null) {
736 var error = response.result; 762 var error = response.result;
737 console.error(error); // TODO(mkwst): Do something more interesting 763 console.error(error); // TODO(mkwst): Do something more interesting
738 this.generateAlert_( 764 this.generateAlert_(
739 chrome.i18n.getMessage('errorProxyError', error.error), 765 chrome.i18n.getMessage('errorProxyError', error.error),
740 false); 766 false);
741 } 767 }
742 chrome.extension.sendRequest({type: 'clearError'}); 768 chrome.extension.sendRequest({type: 'clearError'});
743 } 769 }
744 }; 770 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698