[sql] Remove _HAS_EXCEPTIONS=0 from build info.
[chromium-blink-merge.git] / chrome / browser / resources / settings / internet_page / network_proxy.js
blob7cabe2d9f277e2959b3095af0772ab5de30ed2cf
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 = this.networkState.ProxySettings || {};
115 // Ensure that all proxy settings object properties are specified.
116 proxy.ExcludeDomains = proxy.ExcludeDomains || this.savedExcludeDomains_ ||
117 defaultProxy.ExcludeDomains;
118 proxy.Manual = proxy.Manual || this.savedManual_ || {};
119 proxy.Manual.HTTPProxy =
120 proxy.Manual.HTTPProxy || defaultProxy.Manual.HTTPProxy;
121 proxy.Manual.SecureHTTPProxy =
122 proxy.Manual.SecureHTTPProxy || defaultProxy.Manual.SecureHTTPProxy;
123 proxy.Manual.FTPProxy =
124 proxy.Manual.FTPProxy || defaultProxy.Manual.FTPProxy;
125 proxy.Manual.SOCKS = proxy.Manual.SOCKS || defaultProxy.Manual.SOCKS;
126 proxy.PAC = proxy.PAC || defaultProxy.PAC;
127 proxy.Type = proxy.Type || defaultProxy.Type;
129 this.set('proxy', proxy);
130 this.$.selectType.value = proxy.Type;
132 // Set the Web Proxy Auto Discovery URL.
133 var ipv4 = CrOnc.getIPConfigForType(this.networkState, CrOnc.IPType.IPV4);
134 this.WPAD = (ipv4 && ipv4.WebProxyAutoDiscoveryUrl) || '';
138 * @return {CrOnc.ProxySettings} An empty/default proxy settings object.
140 createDefaultProxySettings_: function() {
141 return {
142 Type: CrOnc.ProxySettingsType.DIRECT,
143 ExcludeDomains: [],
144 Manual: {
145 HTTPProxy: { Host: '', Port: 80 },
146 SecureHTTPProxy: { Host: '', Port: 80 },
147 FTPProxy: { Host: '', Port: 80 },
148 SOCKS: { Host: '', Port: 1080 }
150 PAC: ''
155 * Polymer useSameProxy changed method.
157 useSameProxyChanged_: function() {
158 this.sendProxyChange_();
162 * Called when the proxy changes in the UI.
164 sendProxyChange_: function() {
165 if (this.proxy.Type == CrOnc.ProxySettingsType.MANUAL) {
166 if (this.useSameProxy) {
167 var defaultProxy = this.proxy.Manual.HTTPProxy;
168 this.set('proxy.Manual.SecureHTTPProxy',
169 Object.assign({}, defaultProxy));
170 this.set('proxy.Manual.FTPProxy', Object.assign({}, defaultProxy));
171 this.set('proxy.Manual.SOCKS', Object.assign({}, defaultProxy));
173 this.savedManual_ = this.proxy.Manual;
174 this.savedExcludeDomains_ = this.proxy.ExcludeDomains;
176 this.fire('proxy-change', {
177 field: 'ProxySettings',
178 value: this.proxy
183 * Event triggered when the selected proxy type changes.
184 * @param {Event} event The select node change event.
185 * @private
187 onTypeChange_: function(event) {
188 var type = this.proxyTypes_[event.target.selectedIndex];
189 this.set('proxy.Type', type);
190 if (type != CrOnc.ProxySettingsType.MANUAL ||
191 this.savedManual_) {
192 this.sendProxyChange_();
197 * Event triggered when a proxy value changes.
198 * @param {Event} event The proxy value change event.
199 * @private
201 onProxyInputChange_: function(event) {
202 this.sendProxyChange_();
206 * Event triggered when a proxy exclusion is added.
207 * @param {Event} event The add proxy exclusion event.
208 * @private
210 onAddProxyExclusion_: function(event) {
211 var value = this.$.proxyExclusion.value;
212 if (!value)
213 return;
214 this.push('proxy.ExcludeDomains', value);
215 // Clear input.
216 this.$.proxyExclusion.value = '';
217 this.sendProxyChange_();
221 * Event triggered when the proxy exclusion list changes.
222 * @param {Event} event The remove proxy exclusions change event.
223 * @private
225 onProxyExclusionsChange_: function(event) {
226 this.sendProxyChange_();
230 * @param {string} proxyType The proxy type.
231 * @return {string} The description for |proxyType|.
232 * @private
234 proxyTypeDesc_: function(proxyType) {
235 // TODO(stevenjb): Translate.
236 if (proxyType == CrOnc.ProxySettingsType.MANUAL)
237 return 'Manual proxy configuration';
238 if (proxyType == CrOnc.ProxySettingsType.PAC)
239 return 'Automatic proxy configuration';
240 if (proxyType == CrOnc.ProxySettingsType.WPAD)
241 return 'Web proxy autodiscovery';
242 return 'Direct Internet connection';
246 * @param {string} property The property to test
247 * @param {string} value The value to test against
248 * @return {boolean} True if property == value
249 * @private
251 matches_: function(property, value) {
252 return property == value;