| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview Polymer element for displaying and editing network proxy | 6 * @fileoverview Polymer element for displaying and editing network proxy |
| 7 * values. | 7 * values. |
| 8 */ | 8 */ |
| 9 Polymer({ | 9 Polymer({ |
| 10 is: 'network-proxy', | 10 is: 'network-proxy', |
| 11 | 11 |
| 12 behaviors: [CrPolicyNetworkBehavior], | 12 behaviors: [CrPolicyNetworkBehavior], |
| 13 | 13 |
| 14 properties: { | 14 properties: { |
| 15 /** | 15 /** |
| 16 * The network properties dictionary containing the proxy properties to | 16 * The network properties dictionary containing the proxy properties to |
| 17 * display and modify. | 17 * display and modify. |
| 18 * @type {!CrOnc.NetworkProperties|undefined} | 18 * @type {!CrOnc.NetworkProperties|undefined} |
| 19 */ | 19 */ |
| 20 networkProperties: { | 20 networkProperties: { |
| 21 type: Object, | 21 type: Object, |
| 22 observer: 'networkPropertiesChanged_' | 22 observer: 'networkPropertiesChanged_', |
| 23 }, | 23 }, |
| 24 | 24 |
| 25 /** | 25 /** |
| 26 * Whether or not the proxy values can be edited. | 26 * Whether or not the proxy values can be edited. |
| 27 */ | 27 */ |
| 28 editable: { | 28 editable: { |
| 29 type: Boolean, | 29 type: Boolean, |
| 30 value: false | 30 value: false, |
| 31 }, | 31 }, |
| 32 | 32 |
| 33 /** | 33 /** |
| 34 * UI visible / edited proxy configuration. | 34 * UI visible / edited proxy configuration. |
| 35 * @type {!CrOnc.ProxySettings} | 35 * @type {!CrOnc.ProxySettings} |
| 36 */ | 36 */ |
| 37 proxy: { | 37 proxy: { |
| 38 type: Object, | 38 type: Object, |
| 39 value: function() { return this.createDefaultProxySettings_(); } | 39 value: function() { |
| 40 return this.createDefaultProxySettings_(); |
| 41 }, |
| 40 }, | 42 }, |
| 41 | 43 |
| 42 /** | 44 /** |
| 43 * The Web Proxy Auto Discovery URL extracted from networkProperties. | 45 * The Web Proxy Auto Discovery URL extracted from networkProperties. |
| 44 */ | 46 */ |
| 45 WPAD: { | 47 WPAD: { |
| 46 type: String, | 48 type: String, |
| 47 value: '' | 49 value: '', |
| 48 }, | 50 }, |
| 49 | 51 |
| 50 /** | 52 /** |
| 51 * Whetner or not to use the same manual proxy for all protocols. | 53 * Whetner or not to use the same manual proxy for all protocols. |
| 52 */ | 54 */ |
| 53 useSameProxy: { | 55 useSameProxy: { |
| 54 type: Boolean, | 56 type: Boolean, |
| 55 value: false, | 57 value: false, |
| 56 observer: 'useSameProxyChanged_' | 58 observer: 'useSameProxyChanged_', |
| 57 }, | 59 }, |
| 58 | 60 |
| 59 /** | 61 /** |
| 60 * Array of proxy configuration types. | 62 * Array of proxy configuration types. |
| 61 * @type {!Array<string>} | 63 * @type {!Array<string>} |
| 62 * @const | 64 * @const |
| 63 */ | 65 */ |
| 64 proxyTypes_: { | 66 proxyTypes_: { |
| 65 type: Array, | 67 type: Array, |
| 66 value: [ | 68 value: [ |
| 67 CrOnc.ProxySettingsType.DIRECT, | 69 CrOnc.ProxySettingsType.DIRECT, |
| 68 CrOnc.ProxySettingsType.PAC, | 70 CrOnc.ProxySettingsType.PAC, |
| 69 CrOnc.ProxySettingsType.WPAD, | 71 CrOnc.ProxySettingsType.WPAD, |
| 70 CrOnc.ProxySettingsType.MANUAL | 72 CrOnc.ProxySettingsType.MANUAL, |
| 71 ], | 73 ], |
| 72 readOnly: true | 74 readOnly: true |
| 73 }, | 75 }, |
| 74 | 76 |
| 75 /** | 77 /** |
| 76 * Object providing proxy type values for data binding. | 78 * Object providing proxy type values for data binding. |
| 77 * @type {!Object} | 79 * @type {!Object} |
| 78 * @const | 80 * @const |
| 79 */ | 81 */ |
| 80 ProxySettingsType: { | 82 ProxySettingsType: { |
| 81 type: Object, | 83 type: Object, |
| 82 value: { | 84 value: { |
| 83 DIRECT: CrOnc.ProxySettingsType.DIRECT, | 85 DIRECT: CrOnc.ProxySettingsType.DIRECT, |
| 84 PAC: CrOnc.ProxySettingsType.PAC, | 86 PAC: CrOnc.ProxySettingsType.PAC, |
| 85 MANUAL: CrOnc.ProxySettingsType.MANUAL, | 87 MANUAL: CrOnc.ProxySettingsType.MANUAL, |
| 86 WPAD: CrOnc.ProxySettingsType.WPAD | 88 WPAD: CrOnc.ProxySettingsType.WPAD, |
| 87 }, | 89 }, |
| 88 readOnly: true | 90 readOnly: true, |
| 89 }, | 91 }, |
| 90 }, | 92 }, |
| 91 | 93 |
| 92 /** | 94 /** |
| 93 * Saved Manual properties so that switching to another type does not loose | 95 * Saved Manual properties so that switching to another type does not loose |
| 94 * any set properties while the UI is open. | 96 * any set properties while the UI is open. |
| 95 * @type {!CrOnc.ManualProxySettings|undefined} | 97 * @type {!CrOnc.ManualProxySettings|undefined} |
| 96 */ | 98 */ |
| 97 savedManual_: undefined, | 99 savedManual_: undefined, |
| 98 | 100 |
| 99 /** | 101 /** |
| 100 * Saved ExcludeDomains properties so that switching to a non-Manual type does | 102 * Saved ExcludeDomains properties so that switching to a non-Manual type does |
| 101 * not loose any set exclusions while the UI is open. | 103 * not loose any set exclusions while the UI is open. |
| 102 * @type {!Array<string>|undefined} | 104 * @type {!Array<string>|undefined} |
| 103 */ | 105 */ |
| 104 savedExcludeDomains_: undefined, | 106 savedExcludeDomains_: undefined, |
| 105 | 107 |
| 106 /** | 108 /** |
| 107 * Polymer networkProperties changed method. | 109 * Polymer networkProperties changed method. |
| 108 */ | 110 */ |
| 109 networkPropertiesChanged_: function() { | 111 networkPropertiesChanged_: function() { |
| 110 if (!this.networkProperties) | 112 if (!this.networkProperties) |
| 111 return; | 113 return; |
| 112 | 114 |
| 113 /** @type {!CrOnc.ProxySettings} */ | 115 /** @type {!CrOnc.ProxySettings} */ |
| 114 var proxy = this.createDefaultProxySettings_(); | 116 var proxy = this.createDefaultProxySettings_(); |
| 115 /** @type {!chrome.networkingPrivate.ManagedProxySettings|undefined} */ | 117 /** @type {!chrome.networkingPrivate.ManagedProxySettings|undefined} */ |
| 116 var proxySettings = this.networkProperties.ProxySettings; | 118 var proxySettings = this.networkProperties.ProxySettings; |
| 117 if (proxySettings) { | 119 if (proxySettings) { |
| 118 proxy.Type = /** @type {!CrOnc.ProxySettingsType} */( | 120 proxy.Type = /** @type {!CrOnc.ProxySettingsType} */ ( |
| 119 CrOnc.getActiveValue(proxySettings.Type)); | 121 CrOnc.getActiveValue(proxySettings.Type)); |
| 120 if (proxySettings.Manual) { | 122 if (proxySettings.Manual) { |
| 121 proxy.Manual.HTTPProxy = /** @type {!CrOnc.ProxyLocation|undefined} */( | 123 proxy.Manual.HTTPProxy = /** @type {!CrOnc.ProxyLocation|undefined} */ ( |
| 122 CrOnc.getSimpleActiveProperties(proxySettings.Manual.HTTPProxy)); | 124 CrOnc.getSimpleActiveProperties(proxySettings.Manual.HTTPProxy)); |
| 123 proxy.Manual.SecureHTTPProxy = | 125 proxy.Manual.SecureHTTPProxy = |
| 124 /** @type {!CrOnc.ProxyLocation|undefined} */( | 126 /** @type {!CrOnc.ProxyLocation|undefined} */ ( |
| 125 CrOnc.getSimpleActiveProperties( | 127 CrOnc.getSimpleActiveProperties( |
| 126 proxySettings.Manual.SecureHTTPProxy)); | 128 proxySettings.Manual.SecureHTTPProxy)); |
| 127 proxy.Manual.FTPProxy = /** @type {!CrOnc.ProxyLocation|undefined} */( | 129 proxy.Manual.FTPProxy = /** @type {!CrOnc.ProxyLocation|undefined} */ ( |
| 128 CrOnc.getSimpleActiveProperties(proxySettings.Manual.FTPProxy)); | 130 CrOnc.getSimpleActiveProperties(proxySettings.Manual.FTPProxy)); |
| 129 proxy.Manual.SOCKS = /** @type {!CrOnc.ProxyLocation|undefined} */( | 131 proxy.Manual.SOCKS = /** @type {!CrOnc.ProxyLocation|undefined} */ ( |
| 130 CrOnc.getSimpleActiveProperties(proxySettings.Manual.SOCKS)); | 132 CrOnc.getSimpleActiveProperties(proxySettings.Manual.SOCKS)); |
| 131 } | 133 } |
| 132 if (proxySettings.ExcludeDomains) { | 134 if (proxySettings.ExcludeDomains) { |
| 133 proxy.ExcludeDomains = /** @type {!Array<string>|undefined} */( | 135 proxy.ExcludeDomains = /** @type {!Array<string>|undefined} */ ( |
| 134 CrOnc.getActiveValue(proxySettings.ExcludeDomains)); | 136 CrOnc.getActiveValue(proxySettings.ExcludeDomains)); |
| 135 } | 137 } |
| 136 proxy.PAC = /** @type {string|undefined} */( | 138 proxy.PAC = /** @type {string|undefined} */ ( |
| 137 CrOnc.getActiveValue(proxySettings.PAC)); | 139 CrOnc.getActiveValue(proxySettings.PAC)); |
| 138 } | 140 } |
| 139 // Use saved ExcludeDomanains and Manual if not defined. | 141 // Use saved ExcludeDomanains and Manual if not defined. |
| 140 proxy.ExcludeDomains = proxy.ExcludeDomains || this.savedExcludeDomains_; | 142 proxy.ExcludeDomains = proxy.ExcludeDomains || this.savedExcludeDomains_; |
| 141 proxy.Manual = proxy.Manual || this.savedManual_; | 143 proxy.Manual = proxy.Manual || this.savedManual_; |
| 142 | 144 |
| 143 this.set('proxy', proxy); | 145 this.proxy = proxy; |
| 144 this.$.selectType.value = proxy.Type; | |
| 145 | 146 |
| 146 // Set the Web Proxy Auto Discovery URL. | 147 // Set the Web Proxy Auto Discovery URL. |
| 147 var ipv4 = | 148 var ipv4 = |
| 148 CrOnc.getIPConfigForType(this.networkProperties, CrOnc.IPType.IPV4); | 149 CrOnc.getIPConfigForType(this.networkProperties, CrOnc.IPType.IPV4); |
| 149 this.WPAD = (ipv4 && ipv4.WebProxyAutoDiscoveryUrl) || ''; | 150 this.WPAD = (ipv4 && ipv4.WebProxyAutoDiscoveryUrl) || ''; |
| 150 }, | 151 }, |
| 151 | 152 |
| 152 /** | 153 /** |
| 153 * @return {CrOnc.ProxySettings} An empty/default proxy settings object. | 154 * @return {CrOnc.ProxySettings} An empty/default proxy settings object. |
| 154 */ | 155 */ |
| (...skipping 16 matching lines...) Expand all Loading... |
| 171 */ | 172 */ |
| 172 useSameProxyChanged_: function() { | 173 useSameProxyChanged_: function() { |
| 173 this.sendProxyChange_(); | 174 this.sendProxyChange_(); |
| 174 }, | 175 }, |
| 175 | 176 |
| 176 /** | 177 /** |
| 177 * Called when the proxy changes in the UI. | 178 * Called when the proxy changes in the UI. |
| 178 */ | 179 */ |
| 179 sendProxyChange_: function() { | 180 sendProxyChange_: function() { |
| 180 if (this.proxy.Type == CrOnc.ProxySettingsType.MANUAL) { | 181 if (this.proxy.Type == CrOnc.ProxySettingsType.MANUAL) { |
| 181 if (this.useSameProxy) { | 182 var proxy = |
| 182 var defaultProxy = this.proxy.Manual.HTTPProxy; | 183 /** @type {!CrOnc.ProxySettings} */ (Object.assign({}, this.proxy)); |
| 183 this.set('proxy.Manual.SecureHTTPProxy', | 184 var defaultProxy = proxy.Manual.HTTPProxy; |
| 184 Object.assign({}, defaultProxy)); | 185 if (!defaultProxy || !defaultProxy.Host) |
| 185 this.set('proxy.Manual.FTPProxy', Object.assign({}, defaultProxy)); | 186 return; |
| 186 this.set('proxy.Manual.SOCKS', Object.assign({}, defaultProxy)); | 187 if (this.useSameProxy || !proxy.Manual.SecureHTTPProxy) { |
| 188 proxy.Manual.SecureHTTPProxy = /** @type {!CrOnc.ProxyLocation} */ ( |
| 189 Object.assign({}, defaultProxy)); |
| 187 } | 190 } |
| 188 this.savedManual_ = this.proxy.Manual; | 191 if (this.useSameProxy || !proxy.Manual.FTPProxy) { |
| 189 this.savedExcludeDomains_ = this.proxy.ExcludeDomains; | 192 proxy.Manual.FTPProxy = /** @type {!CrOnc.ProxyLocation} */ ( |
| 193 Object.assign({}, defaultProxy)); |
| 194 } |
| 195 if (this.useSameProxy || !proxy.Manual.SOCKS) { |
| 196 proxy.Manual.SOCKS = /** @type {!CrOnc.ProxyLocation} */ ( |
| 197 Object.assign({}, defaultProxy)); |
| 198 } |
| 199 this.savedManual_ = Object.assign({}, proxy.Manual); |
| 200 this.savedExcludeDomains_ = proxy.ExcludeDomains; |
| 201 this.proxy = proxy; |
| 202 } else if (this.proxy.Type == CrOnc.ProxySettingsType.PAC) { |
| 203 if (!this.proxy.PAC) |
| 204 return; |
| 190 } | 205 } |
| 191 this.fire('proxy-change', { | 206 this.fire('proxy-change', {field: 'ProxySettings', value: this.proxy}); |
| 192 field: 'ProxySettings', | |
| 193 value: this.proxy | |
| 194 }); | |
| 195 }, | 207 }, |
| 196 | 208 |
| 197 /** | 209 /** |
| 198 * Event triggered when the selected proxy type changes. | 210 * Event triggered when the selected proxy type changes. |
| 199 * @param {Event} event The select node change event. | 211 * @param {!{detail: !{selected: string}}} e |
| 200 * @private | 212 * @private |
| 201 */ | 213 */ |
| 202 onTypeChange_: function(event) { | 214 onTypeChange_: function(e) { |
| 203 var type = this.proxyTypes_[event.target.selectedIndex]; | 215 var type = /** @type {chrome.networkingPrivate.ProxySettingsType} */ ( |
| 216 e.detail.selected); |
| 204 this.set('proxy.Type', type); | 217 this.set('proxy.Type', type); |
| 205 if (type != CrOnc.ProxySettingsType.MANUAL || | 218 this.sendProxyChange_(); |
| 206 this.savedManual_) { | |
| 207 this.sendProxyChange_(); | |
| 208 } | |
| 209 }, | 219 }, |
| 210 | 220 |
| 211 /** | 221 /** |
| 212 * Event triggered when a proxy value changes. | 222 * Event triggered when a proxy value changes. |
| 213 * @param {Event} event The proxy value change event. | 223 * @param {Event} event The proxy value change event. |
| 214 * @private | 224 * @private |
| 215 */ | 225 */ |
| 216 onProxyInputChange_: function(event) { | 226 onProxyInputChange_: function(event) { |
| 217 this.sendProxyChange_(); | 227 this.sendProxyChange_(); |
| 218 }, | 228 }, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 /** | 270 /** |
| 261 * @param {boolean} editable | 271 * @param {boolean} editable |
| 262 * @param {!CrOnc.NetworkProperties} networkProperties | 272 * @param {!CrOnc.NetworkProperties} networkProperties |
| 263 * @param {string} key | 273 * @param {string} key |
| 264 * @return {boolean} Whether the property is editable. | 274 * @return {boolean} Whether the property is editable. |
| 265 * @private | 275 * @private |
| 266 */ | 276 */ |
| 267 isPropertyEditable_: function(editable, networkProperties, key) { | 277 isPropertyEditable_: function(editable, networkProperties, key) { |
| 268 if (!editable) | 278 if (!editable) |
| 269 return false; | 279 return false; |
| 270 var property = /** @type {!CrOnc.ManagedProperty|undefined} */( | 280 var property = /** @type {!CrOnc.ManagedProperty|undefined} */ ( |
| 271 this.get(key, networkProperties)); | 281 this.get(key, networkProperties)); |
| 272 return !this.isNetworkPolicyEnforced(property); | 282 return !this.isNetworkPolicyEnforced(property); |
| 273 }, | 283 }, |
| 274 | 284 |
| 275 /** | 285 /** |
| 276 * @param {string} property The property to test | 286 * @param {string} property The property to test |
| 277 * @param {string} value The value to test against | 287 * @param {string} value The value to test against |
| 278 * @return {boolean} True if property == value | 288 * @return {boolean} True if property == value |
| 279 * @private | 289 * @private |
| 280 */ | 290 */ |
| 281 matches_: function(property, value) { | 291 matches_: function(property, value) { |
| 282 return property == value; | 292 return property == value; |
| 283 } | 293 } |
| 284 }); | 294 }); |
| OLD | NEW |