Index: chrome/browser/resources/settings/internet_page/internet_config.js |
diff --git a/chrome/browser/resources/settings/internet_page/internet_config.js b/chrome/browser/resources/settings/internet_page/internet_config.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..113d93fe657934d37e91bcb1a7cbef59def503fa |
--- /dev/null |
+++ b/chrome/browser/resources/settings/internet_page/internet_config.js |
@@ -0,0 +1,270 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+/** |
+ * @fileoverview |
+ * 'settings-internet-config' provides configuration of authentication |
+ * properties for new and existing networks. |
+ */ |
+Polymer({ |
+ is: 'settings-internet-config', |
+ |
+ behaviors: [settings.RouteObserverBehavior, I18nBehavior], |
+ |
+ properties: { |
+ /** |
+ * Interface for networkingPrivate calls, passed from internet_page. |
+ * @type {NetworkingPrivate} |
+ */ |
+ networkingPrivate: Object, |
+ |
+ /** |
+ * The properties for the network being configured. |
stevenjb
2017/05/02 00:17:45
current properties (if any)
|
+ * @type {!chrome.networkingPrivate.NetworkProperties|undefined} |
+ * @private |
+ */ |
+ networkProperties_: Object, |
+ |
+ /** |
+ * The configuraiton properties for the network. |
+ * @type {!chrome.networkingPrivate.NetworkConfigProperties|undefined} |
+ * @private |
+ */ |
+ configProperties_: Object, |
+ |
+ /** @private */ |
stevenjb
2017/05/02 00:17:45
Document
|
+ guid_: String, |
+ |
+ /** @private */ |
stevenjb
2017/05/02 00:17:45
Document
|
+ title_: String, |
+ |
+ /** @private */ |
stevenjb
2017/05/02 00:17:45
Document
|
+ shareNetwork_: Boolean, |
+ |
+ /** |
+ * Object providing network type values for data binding. |
+ * @const |
+ * @private |
+ */ |
+ NetworkType_: { |
+ type: Object, |
+ value: { |
+ CELLULAR: CrOnc.Type.CELLULAR, |
+ ETHERNET: CrOnc.Type.ETHERNET, |
+ VPN: CrOnc.Type.VPN, |
+ WI_FI: CrOnc.Type.WI_FI, |
+ WI_MAX: CrOnc.Type.WI_MAX, |
+ }, |
+ readOnly: true |
+ }, |
+ |
+ /** |
+ * @type {!Array<{value: string, label: string}>} |
stevenjb
2017/05/02 00:17:45
Document all of these
|
+ * @private |
+ */ |
+ securityItems_: { |
+ type: Array, |
+ readOnly: true, |
+ value: function() { |
+ return [ |
+ CrOnc.Security.NONE, CrOnc.Security.WEP_PSK, CrOnc.Security.WPA_PSK, |
+ CrOnc.Security.WPA_EAP |
+ ]; |
+ } |
+ }, |
+ |
+ /** |
+ * @type {!Array<string>} |
+ * @private |
+ */ |
+ eapOuterItems_: { |
+ type: Array, |
+ readOnly: true, |
+ value: function() { |
+ return ['LEAP', 'PEAP', 'EAP-TLS', 'EAP-TTLS']; |
+ } |
+ }, |
+ |
+ /** |
+ * @type {!Array<string>} |
+ * @private |
+ */ |
+ eapInnerItems_: { |
+ type: Array, |
+ readOnly: true, |
+ value: function() { |
+ return ['Automatic', 'MD5', 'MSCHAP', 'MSCHAPv2', 'PAP', 'CHAP', 'GTC']; |
+ } |
+ }, |
+ }, |
+ |
+ observers: ['updateConfigProperties_(configProperties_.*)'], |
stevenjb
2017/05/02 00:17:45
Elim
|
+ |
+ /** |
+ * settings.RouteObserverBehavior |
+ * @param {!settings.Route} route |
+ * @protected |
+ */ |
+ currentRouteChanged: function(route) { |
+ var queryParams = settings.getQueryParameters(); |
+ this.guid_ = queryParams.get('guid') || ''; |
+ |
+ // Set placeholder networkProperties until they are loaded. |
stevenjb
2017/05/02 00:17:45
Update comment (not a placeholder of guid is empty
|
+ var name = queryParams.get('name') || ''; |
+ var type = /** @type {!chrome.networkingPrivate.NetworkType} */ ( |
+ queryParams.get('type')) || |
+ CrOnc.Type.WI_FI; |
+ this.networkProperties_ = { |
+ GUID: this.guid_, |
+ Name: name, |
+ Type: type, |
+ }; |
+ var configProperties = {Type: type}; |
+ if (type == CrOnc.Type.WI_FI) { |
+ configProperties.WiFi = { |
+ SSID: '', |
+ Security: CrOnc.Security.NONE, |
+ }; |
+ } |
+ this.configProperties_ = configProperties; |
+ if (this.guid_) { |
+ this.networkingPrivate.getProperties( |
+ this.guid_, this.getPropertiesCallback_.bind(this)); |
+ } else { |
+ this.title_ = this.i18n('OncType' + type); |
+ this.shareNetwork_ = false; |
+ } |
+ }, |
+ |
+ /** @private */ |
+ onCancelTap_: function() { |
+ this.close_(); |
+ }, |
+ |
+ /** @private */ |
+ onSaveTap_: function() { |
+ var newConfig = /** @type {boolean} */ (!!this.guid_); |
+ var id = newConfig ? this.networkProperties_.Type : this.guid_; |
+ var handleError = function() { |
+ var error = chrome.runtime.lastError; |
+ if (error && error.message) { |
+ console.error('Error configuring: ' + id + ': ' + error.message); |
+ this.close_(); |
+ } |
+ }.bind(this); |
+ |
+ var propertiesToSet = Object.assign({}, this.configProperties_); |
+ if (newConfig) { |
+ this.networkingPrivate.createNetwork( |
+ this.shareNetwork_, propertiesToSet, handleError); |
+ } else { |
+ propertiesToSet.GUID = this.guid_; |
+ this.networkingPrivate.setProperties( |
+ this.guid_, propertiesToSet, handleError); |
+ } |
+ }, |
+ |
+ /** @private */ |
+ close_: function() { |
+ // Delay navigating to allow other subpages to load first. |
stevenjb
2017/05/02 00:17:45
when called from a getPropertiesCallback_ error.
|
+ requestAnimationFrame(function() { |
+ settings.navigateToPreviousRoute(); |
+ }); |
+ }, |
+ |
+ /** |
+ * networkingPrivate.getProperties callback. |
+ * @param {!chrome.networkingPrivate.NetworkProperties} properties |
+ * @private |
+ */ |
+ getPropertiesCallback_: function(properties) { |
+ if (!properties) { |
stevenjb
2017/05/02 00:17:45
Test lastError
|
+ // If |properties| is null, the network no longer exists; close the page. |
+ console.error('Network no longer exists: ' + this.guid_); |
+ this.close_(); |
+ return; |
+ } |
+ this.networkProperties_ = properties; |
+ this.title_ = properties.Name || this.i18n('OncType' + properties.Type); |
+ this.shareNetwork_ = properties.Source == CrOnc.Source.DEVICE || |
+ properties.Source == CrOnc.Source.DEVICE_POLICY; |
+ |
+ var configProperties = |
+ /** @type {chrome.networkingPrivate.NetworkConfigProperties} */ ({ |
+ Name: properties.Name, |
+ Type: properties.Type, |
+ }); |
+ if (properties.WiFi) { |
+ configProperties.WiFi = { |
+ AutoConnect: properties.WiFi.AutoConnect, |
+ EAP: properties.WiFi.EAP, |
+ Passphrase: properties.WiFi.Passphrase, |
+ SSID: properties.WiFi.SSID, |
+ Security: properties.WiFi.Security |
+ }; |
+ } |
+ this.configProperties_ = configProperties; |
+ this.updateConfigProperties_(); |
+ }, |
+ |
+ /** @private */ |
+ updateConfigProperties_: function() { |
stevenjb
2017/05/02 00:17:45
Elim (merge with above)
|
+ if (this.configProperties_.WiFi) { |
+ if (this.configProperties_.WiFi.Security == CrOnc.Security.WPA_EAP) { |
+ this.configProperties_.WiFi.EAP = this.configProperties_.WiFi.EAP || { |
+ Outer: 'LEAP', |
+ }; |
+ } else { |
+ delete this.configProperties_.WiFi.EAP; |
+ } |
+ } |
+ }, |
+ |
+ /** |
+ * @param {string} type The network type. |
+ * @param {!CrOnc.NetworkProperties} networkProperties |
+ * @return {boolean} True if the network type matches 'type'. |
+ * @private |
+ */ |
+ isType_: function(type, networkProperties) { |
+ return networkProperties.Type == type; |
+ }, |
+ |
+ /** |
+ * @return boolean |
+ * @private |
+ */ |
+ showPassphrase_() { |
+ if (this.configProperties_.Type != CrOnc.Type.WI_FI) |
+ return false; |
+ var security = this.get('Security', this.configProperties_.WiFi); |
+ return !!security && |
+ (security == CrOnc.Security.WEP_PSK || |
+ security == CrOnc.Security.WPA_PSK); |
+ }, |
+ |
+ /** |
+ * @return boolean |
+ * @private |
+ */ |
+ showEap_() { |
+ if (this.configProperties_.Type != CrOnc.Type.WI_FI) |
+ return false; |
+ var security = this.get('Security', this.configProperties_.WiFi); |
+ return !!security && security == CrOnc.Security.WPA_EAP; |
+ }, |
+ |
+ /** |
+ * @param {string} key |
+ * @param {string} prefix |
+ * @return {string} The text to display for the onc value. |
+ * @private |
+ */ |
+ getOncLabel_: function(key, prefix) { |
+ var oncKey = 'Onc' + prefix.replace(/\./g, '-') + '_' + key; |
+ if (this.i18nExists(oncKey)) |
+ return this.i18n(oncKey); |
+ return key; |
+ } |
+}); |