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
3 // found in the LICENSE file.
6 * @fileoverview Polymer element for displaying and editing network proxy
14 * The current state containing the IP Config properties to display and
16 * @type {?CrOnc.NetworkStateProperties}
21 observer: 'networkStateChanged_'
25 * Whether or not the proxy values can be edited.
33 * UI visible / edited proxy configuration.
34 * @type {!CrOnc.ProxySettings}
38 value: function() { return this.createDefaultProxySettings_(); }
42 * The Web Proxy Auto Discovery URL extracted from networkState.
50 * Whetner or not to use the same manual proxy for all protocols.
55 observer: 'useSameProxyChanged_'
59 * Array of proxy configuration types.
60 * @type {!Array<string>}
66 CrOnc.ProxySettingsType.DIRECT,
67 CrOnc.ProxySettingsType.PAC,
68 CrOnc.ProxySettingsType.WPAD,
69 CrOnc.ProxySettingsType.MANUAL
75 * Object providing proxy type values for data binding.
82 DIRECT: CrOnc.ProxySettingsType.DIRECT,
83 PAC: CrOnc.ProxySettingsType.PAC,
84 MANUAL: CrOnc.ProxySettingsType.MANUAL,
85 WPAD: CrOnc.ProxySettingsType.WPAD
92 * Saved Manual properties so that switching to another type does not loose
93 * any set properties while the UI is open.
94 * @type {?CrOnc.ManualProxySettings}
99 * Saved ExcludeDomains properties so that switching to a non-Manual type does
100 * not loose any set exclusions while the UI is open.
101 * @type {?Array<string>}
103 savedExcludeDomains_: null,
106 * Polymer networkState changed method.
108 networkStateChanged_: function() {
109 if (!this.networkState)
112 var defaultProxy = this.createDefaultProxySettings_();
113 var proxy = /** @type {CrOnc.ProxySettings|undefined} */(
114 CrOnc.getActiveValue(this.networkState, 'ProxySettings')) || {};
116 // Ensure that all proxy settings object properties are specified.
117 proxy.ExcludeDomains = proxy.ExcludeDomains || this.savedExcludeDomains_ ||
118 defaultProxy.ExcludeDomains;
119 proxy.Manual = proxy.Manual || this.savedManual_ || {};
120 proxy.Manual.HTTPProxy =
121 proxy.Manual.HTTPProxy || defaultProxy.Manual.HTTPProxy;
122 proxy.Manual.SecureHTTPProxy =
123 proxy.Manual.SecureHTTPProxy || defaultProxy.Manual.SecureHTTPProxy;
124 proxy.Manual.FTPProxy =
125 proxy.Manual.FTPProxy || defaultProxy.Manual.FTPProxy;
126 proxy.Manual.SOCKS = proxy.Manual.SOCKS || defaultProxy.Manual.SOCKS;
127 proxy.PAC = proxy.PAC || defaultProxy.PAC;
128 proxy.Type = proxy.Type || defaultProxy.Type;
130 this.set('proxy', proxy);
131 this.$.selectType.value = proxy.Type;
133 // Set the Web Proxy Auto Discovery URL.
134 var ipv4 = CrOnc.getIPConfigForType(this.networkState, CrOnc.IPType.IPV4);
135 this.WPAD = (ipv4 && ipv4.WebProxyAutoDiscoveryUrl) || '';
139 * @return {CrOnc.ProxySettings} An empty/default proxy settings object.
141 createDefaultProxySettings_: function() {
143 Type: CrOnc.ProxySettingsType.DIRECT,
146 HTTPProxy: {Host: '', Port: 80},
147 SecureHTTPProxy: {Host: '', Port: 80},
148 FTPProxy: {Host: '', Port: 80},
149 SOCKS: {Host: '', Port: 1080}
156 * Polymer useSameProxy changed method.
158 useSameProxyChanged_: function() {
159 this.sendProxyChange_();
163 * Called when the proxy changes in the UI.
165 sendProxyChange_: function() {
166 if (this.proxy.Type == CrOnc.ProxySettingsType.MANUAL) {
167 if (this.useSameProxy) {
168 var defaultProxy = this.proxy.Manual.HTTPProxy;
169 this.set('proxy.Manual.SecureHTTPProxy',
170 Object.assign({}, defaultProxy));
171 this.set('proxy.Manual.FTPProxy', Object.assign({}, defaultProxy));
172 this.set('proxy.Manual.SOCKS', Object.assign({}, defaultProxy));
174 this.savedManual_ = this.proxy.Manual || null;
175 this.savedExcludeDomains_ = this.proxy.ExcludeDomains || null;
177 this.fire('proxy-change', {
178 field: 'ProxySettings',
184 * Event triggered when the selected proxy type changes.
185 * @param {Event} event The select node change event.
188 onTypeChange_: function(event) {
189 var type = this.proxyTypes_[event.target.selectedIndex];
190 this.set('proxy.Type', type);
191 if (type != CrOnc.ProxySettingsType.MANUAL ||
193 this.sendProxyChange_();
198 * Event triggered when a proxy value changes.
199 * @param {Event} event The proxy value change event.
202 onProxyInputChange_: function(event) {
203 this.sendProxyChange_();
207 * Event triggered when a proxy exclusion is added.
208 * @param {Event} event The add proxy exclusion event.
211 onAddProxyExclusion_: function(event) {
212 var value = this.$.proxyExclusion.value;
215 this.push('proxy.ExcludeDomains', value);
217 this.$.proxyExclusion.value = '';
218 this.sendProxyChange_();
222 * Event triggered when the proxy exclusion list changes.
223 * @param {Event} event The remove proxy exclusions change event.
226 onProxyExclusionsChange_: function(event) {
227 this.sendProxyChange_();
231 * @param {string} proxyType The proxy type.
232 * @return {string} The description for |proxyType|.
235 proxyTypeDesc_: function(proxyType) {
236 // TODO(stevenjb): Translate.
237 if (proxyType == CrOnc.ProxySettingsType.MANUAL)
238 return 'Manual proxy configuration';
239 if (proxyType == CrOnc.ProxySettingsType.PAC)
240 return 'Automatic proxy configuration';
241 if (proxyType == CrOnc.ProxySettingsType.WPAD)
242 return 'Web proxy autodiscovery';
243 return 'Direct Internet connection';
247 * @param {string} property The property to test
248 * @param {string} value The value to test against
249 * @return {boolean} True if property == value
252 matches_: function(property, value) {
253 return property == value;