Elim cr-checkbox
[chromium-blink-merge.git] / chrome / browser / resources / settings / internet_page / network_proxy.js
blobde4a9254dfe0ef95f69e919b159512a090d6421b
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.
5 /**
6 * @fileoverview Polymer element for displaying and editing network proxy
7 * values.
8 */
9 Polymer({
10 is: 'network-proxy',
12 properties: {
13 /**
14 * The current state containing the IP Config properties to display and
15 * modify.
16 * @type {?CrOnc.NetworkStateProperties}
18 networkState: {
19 type: Object,
20 value: null,
21 observer: 'networkStateChanged_'
24 /**
25 * Whether or not the proxy values can be edited.
27 editable: {
28 type: Boolean,
29 value: false
32 /**
33 * UI visible / edited proxy configuration.
34 * @type {!CrOnc.ProxySettings}
36 proxy: {
37 type: Object,
38 value: function() { return this.createDefaultProxySettings_(); }
41 /**
42 * The Web Proxy Auto Discovery URL extracted from networkState.
44 WPAD: {
45 type: String,
46 value: ''
49 /**
50 * Whetner or not to use the same manual proxy for all protocols.
52 useSameProxy: {
53 type: Boolean,
54 value: false,
55 observer: 'useSameProxyChanged_'
58 /**
59 * Array of proxy configuration types.
60 * @type {!Array<string>}
61 * @const
63 proxyTypes_: {
64 type: Array,
65 value: [
66 CrOnc.ProxySettingsType.DIRECT,
67 CrOnc.ProxySettingsType.PAC,
68 CrOnc.ProxySettingsType.WPAD,
69 CrOnc.ProxySettingsType.MANUAL
71 readOnly: true
74 /**
75 * Object providing proxy type values for data binding.
76 * @type {!Object}
77 * @const
79 ProxySettingsType: {
80 type: Object,
81 value: {
82 DIRECT: CrOnc.ProxySettingsType.DIRECT,
83 PAC: CrOnc.ProxySettingsType.PAC,
84 MANUAL: CrOnc.ProxySettingsType.MANUAL,
85 WPAD: CrOnc.ProxySettingsType.WPAD
87 readOnly: true
91 /**
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}
96 savedManual_: null,
98 /**
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)
110 return;
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() {
142 return {
143 Type: CrOnc.ProxySettingsType.DIRECT,
144 ExcludeDomains: [],
145 Manual: {
146 HTTPProxy: {Host: '', Port: 80},
147 SecureHTTPProxy: {Host: '', Port: 80},
148 FTPProxy: {Host: '', Port: 80},
149 SOCKS: {Host: '', Port: 1080}
151 PAC: ''
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',
179 value: this.proxy
184 * Event triggered when the selected proxy type changes.
185 * @param {Event} event The select node change event.
186 * @private
188 onTypeChange_: function(event) {
189 var type = this.proxyTypes_[event.target.selectedIndex];
190 this.set('proxy.Type', type);
191 if (type != CrOnc.ProxySettingsType.MANUAL ||
192 this.savedManual_) {
193 this.sendProxyChange_();
198 * Event triggered when a proxy value changes.
199 * @param {Event} event The proxy value change event.
200 * @private
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.
209 * @private
211 onAddProxyExclusion_: function(event) {
212 var value = this.$.proxyExclusion.value;
213 if (!value)
214 return;
215 this.push('proxy.ExcludeDomains', value);
216 // Clear input.
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.
224 * @private
226 onProxyExclusionsChange_: function(event) {
227 this.sendProxyChange_();
231 * @param {string} proxyType The proxy type.
232 * @return {string} The description for |proxyType|.
233 * @private
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
250 * @private
252 matches_: function(property, value) {
253 return property == value;