| 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', |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 * Whether or not to use the same manual proxy for all protocols. | 49 * Whether or not to use the same manual proxy for all protocols. |
| 50 * @private | 50 * @private |
| 51 */ | 51 */ |
| 52 useSameProxy_: { | 52 useSameProxy_: { |
| 53 type: Boolean, | 53 type: Boolean, |
| 54 value: false, | 54 value: false, |
| 55 observer: 'useSameProxyChanged_', | 55 observer: 'useSameProxyChanged_', |
| 56 }, | 56 }, |
| 57 | 57 |
| 58 /** | 58 /** |
| 59 * Reflects prefs.settings.use_shared_proxies for data binding. |
| 60 * @private |
| 61 */ |
| 62 useSharedProxies_: Boolean, |
| 63 |
| 64 /** |
| 59 * Array of proxy configuration types. | 65 * Array of proxy configuration types. |
| 60 * @private {!Array<string>} | 66 * @private {!Array<string>} |
| 61 * @const | 67 * @const |
| 62 */ | 68 */ |
| 63 proxyTypes_: { | 69 proxyTypes_: { |
| 64 type: Array, | 70 type: Array, |
| 65 value: [ | 71 value: [ |
| 66 CrOnc.ProxySettingsType.DIRECT, | 72 CrOnc.ProxySettingsType.DIRECT, |
| 67 CrOnc.ProxySettingsType.PAC, | 73 CrOnc.ProxySettingsType.PAC, |
| 68 CrOnc.ProxySettingsType.WPAD, | 74 CrOnc.ProxySettingsType.WPAD, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 81 value: { | 87 value: { |
| 82 DIRECT: CrOnc.ProxySettingsType.DIRECT, | 88 DIRECT: CrOnc.ProxySettingsType.DIRECT, |
| 83 PAC: CrOnc.ProxySettingsType.PAC, | 89 PAC: CrOnc.ProxySettingsType.PAC, |
| 84 MANUAL: CrOnc.ProxySettingsType.MANUAL, | 90 MANUAL: CrOnc.ProxySettingsType.MANUAL, |
| 85 WPAD: CrOnc.ProxySettingsType.WPAD, | 91 WPAD: CrOnc.ProxySettingsType.WPAD, |
| 86 }, | 92 }, |
| 87 readOnly: true, | 93 readOnly: true, |
| 88 }, | 94 }, |
| 89 }, | 95 }, |
| 90 | 96 |
| 97 observers: [ |
| 98 'useSharedProxiesChanged_(prefs.settings.use_shared_proxies.value)', |
| 99 ], |
| 100 |
| 91 /** | 101 /** |
| 92 * Saved Manual properties so that switching to another type does not loose | 102 * Saved Manual properties so that switching to another type does not loose |
| 93 * any set properties while the UI is open. | 103 * any set properties while the UI is open. |
| 94 * @private {!CrOnc.ManualProxySettings|undefined} | 104 * @private {!CrOnc.ManualProxySettings|undefined} |
| 95 */ | 105 */ |
| 96 savedManual_: undefined, | 106 savedManual_: undefined, |
| 97 | 107 |
| 98 /** | 108 /** |
| 99 * Saved ExcludeDomains properties so that switching to a non-Manual type does | 109 * Saved ExcludeDomains properties so that switching to a non-Manual type does |
| 100 * not loose any set exclusions while the UI is open. | 110 * not loose any set exclusions while the UI is open. |
| 101 * @private {!Array<string>|undefined} | 111 * @private {!Array<string>|undefined} |
| 102 */ | 112 */ |
| 103 savedExcludeDomains_: undefined, | 113 savedExcludeDomains_: undefined, |
| 104 | 114 |
| 105 /** | 115 /** |
| 106 * Set to true the first time we receive a manual proxy. Used to set the | 116 * Set to true the first time we receive a manual proxy. Used to set the |
| 107 * initial |useSameProxy_| value. | 117 * initial |useSameProxy_| value. |
| 108 * @private {boolean} | 118 * @private {boolean} |
| 109 */ | 119 */ |
| 110 receivedManualProxy_: false, | 120 receivedManualProxy_: false, |
| 111 | 121 |
| 112 /** @private */ | 122 /** @private */ |
| 113 networkPropertiesChanged_: function() { | 123 networkPropertiesChanged_: function() { |
| 124 this.updateProxy_(); |
| 125 }, |
| 126 |
| 127 /** @private */ |
| 128 updateProxy_: function() { |
| 114 if (!this.networkProperties) | 129 if (!this.networkProperties) |
| 115 return; | 130 return; |
| 116 | 131 |
| 117 /** @type {!CrOnc.ProxySettings} */ | 132 /** @type {!CrOnc.ProxySettings} */ |
| 118 var proxy = this.createDefaultProxySettings_(); | 133 var proxy = this.createDefaultProxySettings_(); |
| 134 |
| 135 // For shared networks with unmanaged proxy settings, ignore any saved |
| 136 // proxy settings (use the default values). |
| 137 if (this.isShared_()) { |
| 138 let property = this.getProxySettingsTypeProperty_(); |
| 139 if (!this.isControlled(property) && !this.useSharedProxies_) { |
| 140 this.setProxyAsync_(proxy); |
| 141 return; // Proxy settings will be ignored. |
| 142 } |
| 143 } |
| 144 |
| 119 /** @type {!chrome.networkingPrivate.ManagedProxySettings|undefined} */ | 145 /** @type {!chrome.networkingPrivate.ManagedProxySettings|undefined} */ |
| 120 var proxySettings = this.networkProperties.ProxySettings; | 146 var proxySettings = this.networkProperties.ProxySettings; |
| 121 if (proxySettings) { | 147 if (proxySettings) { |
| 122 proxy.Type = /** @type {!CrOnc.ProxySettingsType} */ ( | 148 proxy.Type = /** @type {!CrOnc.ProxySettingsType} */ ( |
| 123 CrOnc.getActiveValue(proxySettings.Type)); | 149 CrOnc.getActiveValue(proxySettings.Type)); |
| 124 if (proxySettings.Manual) { | 150 if (proxySettings.Manual) { |
| 125 proxy.Manual.HTTPProxy = /** @type {!CrOnc.ProxyLocation|undefined} */ ( | 151 proxy.Manual.HTTPProxy = /** @type {!CrOnc.ProxyLocation|undefined} */ ( |
| 126 CrOnc.getSimpleActiveProperties(proxySettings.Manual.HTTPProxy)); | 152 CrOnc.getSimpleActiveProperties(proxySettings.Manual.HTTPProxy)); |
| 127 proxy.Manual.SecureHTTPProxy = | 153 proxy.Manual.SecureHTTPProxy = |
| 128 /** @type {!CrOnc.ProxyLocation|undefined} */ ( | 154 /** @type {!CrOnc.ProxyLocation|undefined} */ ( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 145 proxy.ExcludeDomains = /** @type {!Array<string>|undefined} */ ( | 171 proxy.ExcludeDomains = /** @type {!Array<string>|undefined} */ ( |
| 146 CrOnc.getActiveValue(proxySettings.ExcludeDomains)); | 172 CrOnc.getActiveValue(proxySettings.ExcludeDomains)); |
| 147 } | 173 } |
| 148 proxy.PAC = /** @type {string|undefined} */ ( | 174 proxy.PAC = /** @type {string|undefined} */ ( |
| 149 CrOnc.getActiveValue(proxySettings.PAC)); | 175 CrOnc.getActiveValue(proxySettings.PAC)); |
| 150 } | 176 } |
| 151 // Use saved ExcludeDomanains and Manual if not defined. | 177 // Use saved ExcludeDomanains and Manual if not defined. |
| 152 proxy.ExcludeDomains = proxy.ExcludeDomains || this.savedExcludeDomains_; | 178 proxy.ExcludeDomains = proxy.ExcludeDomains || this.savedExcludeDomains_; |
| 153 proxy.Manual = proxy.Manual || this.savedManual_; | 179 proxy.Manual = proxy.Manual || this.savedManual_; |
| 154 | 180 |
| 155 // Set this.proxy after dom-repeat has been stamped. | |
| 156 this.async(function() { | |
| 157 this.proxy = proxy; | |
| 158 }.bind(this)); | |
| 159 | |
| 160 // Set the Web Proxy Auto Discovery URL. | 181 // Set the Web Proxy Auto Discovery URL. |
| 161 var ipv4 = | 182 var ipv4 = |
| 162 CrOnc.getIPConfigForType(this.networkProperties, CrOnc.IPType.IPV4); | 183 CrOnc.getIPConfigForType(this.networkProperties, CrOnc.IPType.IPV4); |
| 163 this.WPAD = (ipv4 && ipv4.WebProxyAutoDiscoveryUrl) || ''; | 184 this.WPAD = (ipv4 && ipv4.WebProxyAutoDiscoveryUrl) || ''; |
| 185 |
| 186 this.setProxyAsync_(proxy); |
| 187 }, |
| 188 |
| 189 /** |
| 190 * @param {!CrOnc.ProxySettings} proxy |
| 191 * @private |
| 192 */ |
| 193 setProxyAsync_: function(proxy) { |
| 194 // Set this.proxy after dom-repeat has been stamped. |
| 195 this.async(function() { |
| 196 this.proxy = proxy; |
| 197 }.bind(this)); |
| 164 }, | 198 }, |
| 165 | 199 |
| 166 /** @private */ | 200 /** @private */ |
| 167 useSameProxyChanged_: function() { | 201 useSameProxyChanged_: function() { |
| 168 if (!this.receivedManualProxy_) | 202 if (!this.receivedManualProxy_) |
| 169 return; | 203 return; |
| 170 this.sendProxyChange_(); | 204 this.sendProxyChange_(); |
| 171 }, | 205 }, |
| 172 | 206 |
| 207 /** @private */ |
| 208 useSharedProxiesChanged_: function() { |
| 209 let pref = this.getPref('settings.use_shared_proxies'); |
| 210 this.useSharedProxies_ = !!pref && !!pref.value; |
| 211 this.updateProxy_(); |
| 212 }, |
| 213 |
| 173 /** | 214 /** |
| 174 * @return {CrOnc.ProxySettings} An empty/default proxy settings object. | 215 * @return {CrOnc.ProxySettings} An empty/default proxy settings object. |
| 175 * @private | 216 * @private |
| 176 */ | 217 */ |
| 177 createDefaultProxySettings_: function() { | 218 createDefaultProxySettings_: function() { |
| 178 return { | 219 return { |
| 179 Type: CrOnc.ProxySettingsType.DIRECT, | 220 Type: CrOnc.ProxySettingsType.DIRECT, |
| 180 ExcludeDomains: [], | 221 ExcludeDomains: [], |
| 181 Manual: { | 222 Manual: { |
| 182 HTTPProxy: {Host: '', Port: 80}, | 223 HTTPProxy: {Host: '', Port: 80}, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 if (proxyType == CrOnc.ProxySettingsType.MANUAL) | 317 if (proxyType == CrOnc.ProxySettingsType.MANUAL) |
| 277 return this.i18n('networkProxyTypeManual'); | 318 return this.i18n('networkProxyTypeManual'); |
| 278 if (proxyType == CrOnc.ProxySettingsType.PAC) | 319 if (proxyType == CrOnc.ProxySettingsType.PAC) |
| 279 return this.i18n('networkProxyTypePac'); | 320 return this.i18n('networkProxyTypePac'); |
| 280 if (proxyType == CrOnc.ProxySettingsType.WPAD) | 321 if (proxyType == CrOnc.ProxySettingsType.WPAD) |
| 281 return this.i18n('networkProxyTypeWpad'); | 322 return this.i18n('networkProxyTypeWpad'); |
| 282 return this.i18n('networkProxyTypeDirect'); | 323 return this.i18n('networkProxyTypeDirect'); |
| 283 }, | 324 }, |
| 284 | 325 |
| 285 /** | 326 /** |
| 327 * @return {!CrOnc.ManagedProperty|undefined} |
| 328 * @private |
| 329 */ |
| 330 getProxySettingsTypeProperty_: function() { |
| 331 return /** @type {!CrOnc.ManagedProperty|undefined} */ ( |
| 332 this.get('ProxySettings.Type', this.networkProperties)); |
| 333 }, |
| 334 |
| 335 /** |
| 286 * @return {boolean} | 336 * @return {boolean} |
| 287 * @private | 337 * @private |
| 288 */ | 338 */ |
| 289 getShowNetworkPolicyIndicator_: function() { | 339 getShowNetworkPolicyIndicator_: function() { |
| 290 let property = /** @type {!CrOnc.ManagedProperty|undefined}*/ ( | 340 let property = this.getProxySettingsTypeProperty_(); |
| 291 this.get('ProxySettings.Type', this.networkProperties)); | |
| 292 return !!property && !this.isExtensionControlled(property) && | 341 return !!property && !this.isExtensionControlled(property) && |
| 293 this.isNetworkPolicyEnforced(property); | 342 this.isNetworkPolicyEnforced(property); |
| 294 }, | 343 }, |
| 295 | 344 |
| 296 /** | 345 /** |
| 297 * @return {boolean} | 346 * @return {boolean} |
| 298 * @private | 347 * @private |
| 299 */ | 348 */ |
| 300 getShowPrefPolicyIndicator_: function() { | 349 getShowPrefPolicyIndicator_: function() { |
| 301 let property = /** @type {!CrOnc.ManagedProperty|undefined}*/ ( | 350 let property = this.getProxySettingsTypeProperty_(); |
| 302 this.get('ProxySettings.Type', this.networkProperties)); | |
| 303 return !!property && this.isExtensionControlled(property); | 351 return !!property && this.isExtensionControlled(property); |
| 304 }, | 352 }, |
| 305 | 353 |
| 306 /** | 354 /** |
| 355 * @param {!CrOnc.ManagedProperty} property |
| 356 * @return {boolean} |
| 357 * @private |
| 358 */ |
| 359 getShowAllowShared_: function(property) { |
| 360 return !this.isControlled(property) && this.isShared_(); |
| 361 }, |
| 362 |
| 363 /** |
| 307 * @param {!CrOnc.ManagedProperty|undefined} property | 364 * @param {!CrOnc.ManagedProperty|undefined} property |
| 308 * @return {boolean} Whether the property setting is enforced. | 365 * @return {boolean} Whether the property setting is enforced. |
| 309 * @private | 366 * @private |
| 310 */ | 367 */ |
| 311 isEditable_: function(property) { | 368 isEditable_: function(property) { |
| 312 return this.editable && !this.isNetworkPolicyEnforced(property) && | 369 return this.editable && !this.isNetworkPolicyEnforced(property) && |
| 313 !this.isExtensionControlled(property); | 370 !this.isExtensionControlled(property) && |
| 371 (!this.isShared_() || this.useSharedProxies_); |
| 314 }, | 372 }, |
| 315 | 373 |
| 316 /** | 374 /** |
| 375 * @return {boolean} |
| 376 * @private |
| 377 */ |
| 378 isShared_: function() { |
| 379 return this.networkProperties.Source == 'Device' || |
| 380 this.networkProperties.Source == 'DevicePolicy'; |
| 381 }, |
| 382 |
| 383 /** |
| 317 * Used to check the editable state for proxy related UI that may or may | 384 * Used to check the editable state for proxy related UI that may or may |
| 318 * not be directly controlled by a policy. We use the enforced state of the | 385 * not be directly controlled by a policy. We use the enforced state of the |
| 319 * 'ProxySettings.Type' property for these controls. | 386 * 'ProxySettings.Type' property for these controls. |
| 320 * @return {boolean} Whether the proxy control is editable. | 387 * @return {boolean} Whether the proxy control is editable. |
| 321 * @private | 388 * @private |
| 322 */ | 389 */ |
| 323 isProxyEditable_: function() { | 390 isProxyEditable_: function() { |
| 324 let property = /** @type {!CrOnc.ManagedProperty|undefined}*/ ( | 391 let property = this.getProxySettingsTypeProperty_(); |
| 325 this.get('ProxySettings.Type', this.networkProperties)); | |
| 326 return !!property && this.isEditable_(property); | 392 return !!property && this.isEditable_(property); |
| 327 }, | 393 }, |
| 328 | 394 |
| 329 /** | 395 /** |
| 330 * @param {string} property The property to test | 396 * @param {string} property The property to test |
| 331 * @param {string} value The value to test against | 397 * @param {string} value The value to test against |
| 332 * @return {boolean} True if property == value | 398 * @return {boolean} True if property == value |
| 333 * @private | 399 * @private |
| 334 */ | 400 */ |
| 335 matches_: function(property, value) { | 401 matches_: function(property, value) { |
| 336 return property == value; | 402 return property == value; |
| 337 } | 403 }, |
| 404 |
| 405 /** |
| 406 * Handles the change event for the shared proxy checkbox. Shows a |
| 407 * confirmation dialog. |
| 408 * @param {Event} event |
| 409 * @private |
| 410 */ |
| 411 onAllowSharedProxiesChange_: function(event) { |
| 412 this.$.confirmAllowSharedDialog.showModal(); |
| 413 }, |
| 414 |
| 415 /** |
| 416 * Handles the shared proxy confirmation dialog 'Confirm' button. |
| 417 * @private |
| 418 */ |
| 419 onAllowSharedDialogConfirm_: function() { |
| 420 /** @type {!SettingsCheckboxElement} */ (this.$.allowShared) |
| 421 .sendPrefChange(); |
| 422 this.$.confirmAllowSharedDialog.close(); |
| 423 }, |
| 424 |
| 425 /** |
| 426 * Handles the shared proxy confirmation dialog 'Cancel' button or a cancel |
| 427 * event. |
| 428 * @private |
| 429 */ |
| 430 onAllowSharedDialogCancel_: function() { |
| 431 /** @type {!SettingsCheckboxElement} */ (this.$.allowShared) |
| 432 .resetToPrefValue(); |
| 433 this.$.confirmAllowSharedDialog.close(); |
| 434 }, |
| 338 }); | 435 }); |
| OLD | NEW |