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

Side by Side Diff: chrome/browser/resources/settings/internet_page/network_proxy.js

Issue 2467123003: Settings: Internet: Update proxy controlled indicator and fields. (Closed)
Patch Set: Rebase Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 Polymer element for displaying and editing network proxy 6 * @fileoverview Polymer element for displaying and editing network proxy
7 * values. 7 * values.
8 */ 8 */
9 Polymer({ 9 Polymer({
10 is: 'network-proxy', 10 is: 'network-proxy',
11 11
12 behaviors: [CrPolicyNetworkBehavior], 12 behaviors: [CrPolicyNetworkBehavior, I18nBehavior, PrefsBehavior],
13 13
14 properties: { 14 properties: {
15 /** 15 /**
16 * The network properties dictionary containing the proxy properties to 16 * The network properties dictionary containing the proxy properties to
17 * display and modify. 17 * display and modify.
18 * @type {!CrOnc.NetworkProperties|undefined} 18 * @type {!CrOnc.NetworkProperties|undefined}
19 */ 19 */
20 networkProperties: { 20 networkProperties: {
21 type: Object, 21 type: Object,
22 observer: 'networkPropertiesChanged_', 22 observer: 'networkPropertiesChanged_',
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 */ 95 */
96 savedManual_: undefined, 96 savedManual_: undefined,
97 97
98 /** 98 /**
99 * Saved ExcludeDomains properties so that switching to a non-Manual type does 99 * Saved ExcludeDomains properties so that switching to a non-Manual type does
100 * not loose any set exclusions while the UI is open. 100 * not loose any set exclusions while the UI is open.
101 * @private {!Array<string>|undefined} 101 * @private {!Array<string>|undefined}
102 */ 102 */
103 savedExcludeDomains_: undefined, 103 savedExcludeDomains_: undefined,
104 104
105 /**
106 * Set to true the first time we receive a manual proxy. Used to set the
107 * initial |useSameProxy_| value.
108 * @private {boolean}
109 */
110 receivedManualProxy_: false,
111
105 /** @private */ 112 /** @private */
106 networkPropertiesChanged_: function() { 113 networkPropertiesChanged_: function() {
107 if (!this.networkProperties) 114 if (!this.networkProperties)
108 return; 115 return;
109 116
110 /** @type {!CrOnc.ProxySettings} */ 117 /** @type {!CrOnc.ProxySettings} */
111 var proxy = this.createDefaultProxySettings_(); 118 var proxy = this.createDefaultProxySettings_();
112 /** @type {!chrome.networkingPrivate.ManagedProxySettings|undefined} */ 119 /** @type {!chrome.networkingPrivate.ManagedProxySettings|undefined} */
113 var proxySettings = this.networkProperties.ProxySettings; 120 var proxySettings = this.networkProperties.ProxySettings;
114 if (proxySettings) { 121 if (proxySettings) {
115 proxy.Type = /** @type {!CrOnc.ProxySettingsType} */ ( 122 proxy.Type = /** @type {!CrOnc.ProxySettingsType} */ (
116 CrOnc.getActiveValue(proxySettings.Type)); 123 CrOnc.getActiveValue(proxySettings.Type));
117 if (proxySettings.Manual) { 124 if (proxySettings.Manual) {
118 proxy.Manual.HTTPProxy = /** @type {!CrOnc.ProxyLocation|undefined} */ ( 125 proxy.Manual.HTTPProxy = /** @type {!CrOnc.ProxyLocation|undefined} */ (
119 CrOnc.getSimpleActiveProperties(proxySettings.Manual.HTTPProxy)); 126 CrOnc.getSimpleActiveProperties(proxySettings.Manual.HTTPProxy));
120 proxy.Manual.SecureHTTPProxy = 127 proxy.Manual.SecureHTTPProxy =
121 /** @type {!CrOnc.ProxyLocation|undefined} */ ( 128 /** @type {!CrOnc.ProxyLocation|undefined} */ (
122 CrOnc.getSimpleActiveProperties( 129 CrOnc.getSimpleActiveProperties(
123 proxySettings.Manual.SecureHTTPProxy)); 130 proxySettings.Manual.SecureHTTPProxy));
124 proxy.Manual.FTPProxy = /** @type {!CrOnc.ProxyLocation|undefined} */ ( 131 proxy.Manual.FTPProxy = /** @type {!CrOnc.ProxyLocation|undefined} */ (
125 CrOnc.getSimpleActiveProperties(proxySettings.Manual.FTPProxy)); 132 CrOnc.getSimpleActiveProperties(proxySettings.Manual.FTPProxy));
126 proxy.Manual.SOCKS = /** @type {!CrOnc.ProxyLocation|undefined} */ ( 133 proxy.Manual.SOCKS = /** @type {!CrOnc.ProxyLocation|undefined} */ (
127 CrOnc.getSimpleActiveProperties(proxySettings.Manual.SOCKS)); 134 CrOnc.getSimpleActiveProperties(proxySettings.Manual.SOCKS));
135 if (!this.receivedManualProxy_) {
136 let json_http = JSON.stringify(proxy.Manual.HTTPProxy);
137 this.useSameProxy_ =
138 json_http == JSON.stringify(proxy.Manual.SecureHTTPProxy) &&
139 json_http == JSON.stringify(proxy.Manual.FTPProxy) &&
140 json_http == JSON.stringify(proxy.Manual.SOCKS);
141 this.receivedManualProxy_ = true;
142 }
128 } 143 }
129 if (proxySettings.ExcludeDomains) { 144 if (proxySettings.ExcludeDomains) {
130 proxy.ExcludeDomains = /** @type {!Array<string>|undefined} */ ( 145 proxy.ExcludeDomains = /** @type {!Array<string>|undefined} */ (
131 CrOnc.getActiveValue(proxySettings.ExcludeDomains)); 146 CrOnc.getActiveValue(proxySettings.ExcludeDomains));
132 } 147 }
133 proxy.PAC = /** @type {string|undefined} */ ( 148 proxy.PAC = /** @type {string|undefined} */ (
134 CrOnc.getActiveValue(proxySettings.PAC)); 149 CrOnc.getActiveValue(proxySettings.PAC));
135 } 150 }
136 // Use saved ExcludeDomanains and Manual if not defined. 151 // Use saved ExcludeDomanains and Manual if not defined.
137 proxy.ExcludeDomains = proxy.ExcludeDomains || this.savedExcludeDomains_; 152 proxy.ExcludeDomains = proxy.ExcludeDomains || this.savedExcludeDomains_;
138 proxy.Manual = proxy.Manual || this.savedManual_; 153 proxy.Manual = proxy.Manual || this.savedManual_;
139 154
140 // Set this.proxy after dom-repeat has been stamped. 155 // Set this.proxy after dom-repeat has been stamped.
141 this.async(function() { 156 this.async(function() {
142 this.proxy = proxy; 157 this.proxy = proxy;
143 }.bind(this)); 158 }.bind(this));
144 159
145 // Set the Web Proxy Auto Discovery URL. 160 // Set the Web Proxy Auto Discovery URL.
146 var ipv4 = 161 var ipv4 =
147 CrOnc.getIPConfigForType(this.networkProperties, CrOnc.IPType.IPV4); 162 CrOnc.getIPConfigForType(this.networkProperties, CrOnc.IPType.IPV4);
148 this.WPAD = (ipv4 && ipv4.WebProxyAutoDiscoveryUrl) || ''; 163 this.WPAD = (ipv4 && ipv4.WebProxyAutoDiscoveryUrl) || '';
149 }, 164 },
150 165
151 /** @private */ 166 /** @private */
152 useSameProxyChanged_: function() { 167 useSameProxyChanged_: function() {
168 if (!this.receivedManualProxy_)
169 return;
153 this.sendProxyChange_(); 170 this.sendProxyChange_();
154 }, 171 },
155 172
156 /** 173 /**
157 * @return {CrOnc.ProxySettings} An empty/default proxy settings object. 174 * @return {CrOnc.ProxySettings} An empty/default proxy settings object.
158 * @private 175 * @private
159 */ 176 */
160 createDefaultProxySettings_: function() { 177 createDefaultProxySettings_: function() {
161 return { 178 return {
162 Type: CrOnc.ProxySettingsType.DIRECT, 179 Type: CrOnc.ProxySettingsType.DIRECT,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 */ 265 */
249 onProxyExclusionsChange_: function(event) { 266 onProxyExclusionsChange_: function(event) {
250 this.sendProxyChange_(); 267 this.sendProxyChange_();
251 }, 268 },
252 269
253 /** 270 /**
254 * @param {string} proxyType The proxy type. 271 * @param {string} proxyType The proxy type.
255 * @return {string} The description for |proxyType|. 272 * @return {string} The description for |proxyType|.
256 * @private 273 * @private
257 */ 274 */
258 proxyTypeDesc_: function(proxyType) { 275 getProxyTypeDesc_: function(proxyType) {
259 // TODO(stevenjb): Translate.
260 if (proxyType == CrOnc.ProxySettingsType.MANUAL) 276 if (proxyType == CrOnc.ProxySettingsType.MANUAL)
261 return 'Manual proxy configuration'; 277 return this.i18n('networkProxyTypeManual');
262 if (proxyType == CrOnc.ProxySettingsType.PAC) 278 if (proxyType == CrOnc.ProxySettingsType.PAC)
263 return 'Automatic proxy configuration'; 279 return this.i18n('networkProxyTypePac');
264 if (proxyType == CrOnc.ProxySettingsType.WPAD) 280 if (proxyType == CrOnc.ProxySettingsType.WPAD)
265 return 'Web proxy autodiscovery'; 281 return this.i18n('networkProxyTypeWpad');
266 return 'Direct Internet connection'; 282 return this.i18n('networkProxyTypeDirect');
267 }, 283 },
268 284
269 /** 285 /**
270 * @param {boolean} editable 286 * @return {boolean}
271 * @param {!CrOnc.NetworkProperties} networkProperties
272 * @param {string} key
273 * @return {boolean} Whether the property is editable.
274 * @private 287 * @private
275 */ 288 */
276 isPropertyEditable_: function(editable, networkProperties, key) { 289 getShowNetworkPolicyIndicator_: function() {
277 if (!editable) 290 let property = /** @type {!CrOnc.ManagedProperty|undefined}*/ (
278 return false; 291 this.get('ProxySettings.Type', this.networkProperties));
279 var property = /** @type {!CrOnc.ManagedProperty|undefined} */ ( 292 return !!property && !this.isExtensionControlled(property) &&
280 this.get(key, networkProperties)); 293 this.isNetworkPolicyEnforced(property);
281 return !this.isNetworkPolicyEnforced(property);
282 }, 294 },
283 295
284 /** 296 /**
297 * @return {boolean}
298 * @private
299 */
300 getShowPrefPolicyIndicator_: function() {
301 let property = /** @type {!CrOnc.ManagedProperty|undefined}*/ (
302 this.get('ProxySettings.Type', this.networkProperties));
303 return !!property && this.isExtensionControlled(property);
304 },
305
306 /**
307 * @param {!CrOnc.ManagedProperty|undefined} property
308 * @return {boolean} Whether the property setting is enforced.
309 * @private
310 */
311 isEditable_: function(property) {
312 return this.editable && !this.isNetworkPolicyEnforced(property) &&
313 !this.isExtensionControlled(property);
314 },
315
316 /**
317 * Used to check the editable state for proxy related UI that may or may
318 * not be directly controlled by a policy. We use the enforced state of the
319 * 'ProxySettings.Type' property for these controls.
320 * @return {boolean} Whether the proxy control is editable.
321 * @private
322 */
323 isProxyEditable_: function() {
324 let property = /** @type {!CrOnc.ManagedProperty|undefined}*/ (
325 this.get('ProxySettings.Type', this.networkProperties));
326 return !!property && this.isEditable_(property);
327 },
328
329 /**
285 * @param {string} property The property to test 330 * @param {string} property The property to test
286 * @param {string} value The value to test against 331 * @param {string} value The value to test against
287 * @return {boolean} True if property == value 332 * @return {boolean} True if property == value
288 * @private 333 * @private
289 */ 334 */
290 matches_: function(property, value) { 335 matches_: function(property, value) {
291 return property == value; 336 return property == value;
292 } 337 }
293 }); 338 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698