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
= 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() {
142 Type
: CrOnc
.ProxySettingsType
.DIRECT
,
145 HTTPProxy
: { Host
: '', Port
: 80 },
146 SecureHTTPProxy
: { Host
: '', Port
: 80 },
147 FTPProxy
: { Host
: '', Port
: 80 },
148 SOCKS
: { Host
: '', Port
: 1080 }
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',
183 * Event triggered when the selected proxy type changes.
184 * @param {Event} event The select node change event.
187 onTypeChange_: function(event
) {
188 var type
= this.proxyTypes_
[event
.target
.selectedIndex
];
189 this.set('proxy.Type', type
);
190 if (type
!= CrOnc
.ProxySettingsType
.MANUAL
||
192 this.sendProxyChange_();
197 * Event triggered when a proxy value changes.
198 * @param {Event} event The proxy value change event.
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.
210 onAddProxyExclusion_: function(event
) {
211 var value
= this.$.proxyExclusion
.value
;
214 this.push('proxy.ExcludeDomains', value
);
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.
225 onProxyExclusionsChange_: function(event
) {
226 this.sendProxyChange_();
230 * @param {string} proxyType The proxy type.
231 * @return {string} The description for |proxyType|.
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
251 matches_: function(property
, value
) {
252 return property
== value
;