Chromium Code Reviews| Index: chrome/browser/resources/settings/internet_page/network_proxy.js |
| diff --git a/chrome/browser/resources/settings/internet_page/network_proxy.js b/chrome/browser/resources/settings/internet_page/network_proxy.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1792387cf18bf007a4c9bf302251e9d284ae1c0c |
| --- /dev/null |
| +++ b/chrome/browser/resources/settings/internet_page/network_proxy.js |
| @@ -0,0 +1,180 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +/** |
| + * @fileoverview Polymer element for displaying and editing network proxy |
| + * values. |
| + */ |
| +Polymer({ |
| + is: 'network-proxy', |
| + |
| + properties: { |
| + /** |
| + * The current state containing the IP Config properties to display and |
| + * modify. |
| + * @type {?CrOnc.NetworkStateProperties} |
| + */ |
| + networkState: { |
| + type: Object, |
| + value: null, |
| + observer: 'networkStateChanged_' |
| + }, |
| + |
| + /** |
| + * Whether or not the proxy values can be edited. |
| + */ |
| + editable: { |
| + type: Boolean, |
| + value: false |
| + }, |
| + |
| + /** |
| + * UI visible / edited proxy configuration. |
| + * @type {!CrOnc.ProxySettings} |
| + */ |
| + proxy: { |
| + type: Object, |
| + value: function() { return this.createDefaultProxyObject_(); } |
| + }, |
| + |
| + /** |
| + * The Web Proxy Auto Discovery URL extracted from networkState. |
| + */ |
| + WPAD: { |
| + type: String, |
| + value: '' |
| + }, |
| + |
| + /** |
| + * Whetner or not to use the same manual proxy for all protocols. |
| + */ |
| + useSameProxy: { |
| + type: Boolean, |
| + value: false |
| + }, |
| + |
| + /** |
| + * Array of proxy configuration types. |
| + * @type {!Array<string>} |
| + * @const |
| + */ |
| + proxyTypes_: { |
| + type: Array, |
| + value: [ |
| + CrOnc.ProxySettingsType.DIRECT, |
| + CrOnc.ProxySettingsType.PAC, |
| + CrOnc.ProxySettingsType.WPAD, |
| + CrOnc.ProxySettingsType.MANUAL |
| + ], |
| + readOnly: true |
| + }, |
| + |
| + /** |
| + * Object providing proxy type values for data binding. |
| + * @type {!Object} |
| + * @const |
| + */ |
| + ProxySettingsType: { |
| + type: Object, |
| + value: { |
| + DIRECT: CrOnc.ProxySettingsType.DIRECT, |
| + PAC: CrOnc.ProxySettingsType.PAC, |
| + MANUAL: CrOnc.ProxySettingsType.MANUAL, |
| + WPAD: CrOnc.ProxySettingsType.WPAD |
| + }, |
| + readOnly: true |
| + }, |
| + }, |
| + |
| + networkStateChanged_: function() { |
| + console.log('NetworkProxy.networkStateChanged_'); |
| + if (!this.networkState) |
| + return; |
| + var proxy = this.networkState.ProxySettings || {}; |
| + proxy.Type = proxy.Type || CrOnc.ProxySettingsType.DIRECT; |
| + this.$$('#selectType').value = proxy.Type; |
|
stevenjb
2015/07/08 01:59:25
comment
|
| + proxy.Manual = proxy.Manual || {}; |
| + var defaultProxy = this.createDefaultProxyObject_(); |
| + proxy.Manual.HTTPProxy = proxy.Manual.HTTPProxy || defaultProxy.HTTPProxy; |
| + proxy.Manual.SecureHTTPProxy = |
| + proxy.Manual.SecureHTTPProxy || defaultProxy.SecureHTTPProxy; |
| + proxy.Manual.FTPProxy = proxy.Manual.FTPProxy || defaultProxy.FTPProxy; |
| + proxy.Manual.SOCKS = proxy.Manual.SOCKS || defaultProxy.SOCKS; |
| + this.set('proxy', proxy); |
| + }, |
| + |
|
stevenjb
2015/07/08 01:59:25
comment
|
| + createDefaultProxyObject_: function() { |
| + return { |
| + HTTPProxy: { Host: '', Port: 80 }, |
| + SecureHTTPProxy: { Host: '', Port: 80 }, |
| + FTPProxy: { Host: '', Port: 80 }, |
| + SOCKS: { Host: '', Port: 80 } |
| + }; |
| + }, |
| + |
| + /** |
| + * Called when the proxy is changed in the UI. |
| + */ |
| + sendProxyChanged_: function() { |
| + this.fire('changed', { |
| + field: 'ProxySettings', |
| + value: this.proxy |
| + }); |
| + }, |
| + |
| + /** |
| + * Event triggered when the selected proxy type changes. |
| + * @param {Event} event The select node changed event. |
| + * @private |
| + */ |
| + onTypeChange_: function(event) { |
| + var type = this.proxyTypes_[event.target.selectedIndex]; |
| + console.debug('Proxy type changed: ' + type); |
| + this.set('proxy.Type', type); |
| + if (type != CrOnc.ProxySettingsType.MANUAL) |
| + this.sendProxyChanged_(); |
| + }, |
| + |
| + /** |
| + * Event triggered when a proxy value changes. |
| + * @param {Event} event The proxy value changed event. |
| + * @private |
| + */ |
| + onProxyInputChanged_: function(event) { |
| + console.debug('Proxy input changed'); |
| + console.debug(this.proxy); |
| + if (this.useSameProxy) { |
| + var defaultProxy = this.proxy.Manual.HTTPProxy; |
| + this.copyProxy_(defaultProxy, this.proxy.Manual.SecureHTTPProxy); |
| + this.copyProxy_(defaultProxy, this.proxy.Manual.FTPProxy); |
| + this.copyProxy_(defaultProxy, this.proxy.Manual.SOCKS); |
| + } |
| + this.sendProxyChanged_(); |
| + }, |
| + |
|
stevenjb
2015/07/08 01:59:25
comment
|
| + copyProxy_: function(proxyToCopy, proxyToSet) { |
| + proxyToSet.Host = proxyToCopy.Host; |
| + proxyToSet.Port = proxyToCopy.Port; |
| + }, |
| + |
| + /** |
| + * @param {string} proxyType The proxy type. |
| + * @return {string} The description for |proxyType|. |
| + * @private |
| + */ |
| + proxyTypeDesc_: function(proxyType) { |
| + // TODO(stevenjb): Translate. |
| + if (proxyType == CrOnc.ProxySettingsType.MANUAL) |
| + return 'Manual proxy configuration'; |
| + if (proxyType == CrOnc.ProxySettingsType.PAC) |
| + return 'Automatic proxy configuration'; |
| + if (proxyType == CrOnc.ProxySettingsType.WPAD) |
| + return 'Web proxy autodiscovery'; |
| + return 'Direct Internet connection'; |
| + }, |
| + |
|
stevenjb
2015/07/08 01:59:25
comment
|
| + matches_: function(property, value) { |
| + return property == value; |
| + } |
| +}); |