| 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..5bf1f7cf71e4e4027eeb8f0d17a60648990c4b6c
|
| --- /dev/null
|
| +++ b/chrome/browser/resources/settings/internet_page/internet_config.js
|
| @@ -0,0 +1,412 @@
|
| +// 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 current properties if an existing network being configured.
|
| + * @type {!chrome.networkingPrivate.NetworkProperties|undefined}
|
| + * @private
|
| + */
|
| + networkProperties_: Object,
|
| +
|
| + /**
|
| + * The configuraiton properties for the network. |configProperties_.Type|
|
| + * will always be defined as the network type being configured.
|
| + * @type {!chrome.networkingPrivate.NetworkConfigProperties|undefined}
|
| + * @private
|
| + */
|
| + configProperties_: Object,
|
| +
|
| + /**
|
| + * The GUID when an existing network is being configured. This will be
|
| + * empty or undefined for new networks.
|
| + * @private
|
| + */
|
| + guid_: String,
|
| +
|
| + /**
|
| + * The title to display (network name or type).
|
| + * @private
|
| + */
|
| + title_: String,
|
| +
|
| + /**
|
| + * Whether this network should be shared.
|
| + * @private
|
| + */
|
| + shareNetwork_: Boolean,
|
| +
|
| + /**
|
| + * Saved security value, used to detect when Security changes.
|
| + * @private
|
| + */
|
| + savedSecurity_: String,
|
| +
|
| + /**
|
| + * 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
|
| + },
|
| +
|
| + /**
|
| + * Array of values for the WiFi Security dropdown.
|
| + * @type {!Array<string>}
|
| + * @const
|
| + * @private
|
| + */
|
| + securityItems_: {
|
| + type: Array,
|
| + readOnly: true,
|
| + value: function() {
|
| + return [
|
| + CrOnc.Security.NONE, CrOnc.Security.WEP_PSK, CrOnc.Security.WPA_PSK,
|
| + CrOnc.Security.WPA_EAP
|
| + ];
|
| + }
|
| + },
|
| +
|
| + /**
|
| + * Array of values for the EAP Method (Outer) dropdown.
|
| + * @type {!Array<string>}
|
| + * @const
|
| + * @private
|
| + */
|
| + eapOuterItems_: {
|
| + type: Array,
|
| + readOnly: true,
|
| + value: function() {
|
| + return ['LEAP', 'PEAP', 'EAP-TLS', 'EAP-TTLS'];
|
| + }
|
| + },
|
| +
|
| + /**
|
| + * Array of values for the EAP EAP Phase 2 authentication (Inner) dropdown
|
| + * when the Outer type is PEAP.
|
| + * @type {!Array<string>}
|
| + * @const
|
| + * @private
|
| + */
|
| + eapInnerItemsPeap_: {
|
| + type: Array,
|
| + readOnly: true,
|
| + value: function() {
|
| + return ['Automatic', 'MD5', 'MSCHAPv2'];
|
| + }
|
| + },
|
| +
|
| + /**
|
| + * Array of values for the EAP EAP Phase 2 authentication (Inner) dropdown
|
| + * when the Outer type is EAP-TTLS.
|
| + * @type {!Array<string>}
|
| + * @const
|
| + * @private
|
| + */
|
| + eapInnerItemsTtls_: {
|
| + type: Array,
|
| + readOnly: true,
|
| + value: function() {
|
| + return ['Automatic', 'MD5', 'MSCHAP', 'MSCHAPv2', 'PAP', 'CHAP', 'GTC'];
|
| + }
|
| + },
|
| + },
|
| +
|
| + observers: ['updateConfigProperties_(configProperties_.*)'],
|
| +
|
| + /** @const */
|
| + MIN_PASSPHRASE_LENGTH: 5,
|
| +
|
| + /**
|
| + * settings.RouteObserverBehavior
|
| + * @param {!settings.Route} route
|
| + * @protected
|
| + */
|
| + currentRouteChanged: function(route) {
|
| + var queryParams = settings.getQueryParameters();
|
| + this.guid_ = queryParams.get('guid') || '';
|
| +
|
| + // Set networkProperties for new configurations and for existing
|
| + // configuraitons until the current properties are loaded.
|
| + 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_ = true;
|
| + }
|
| + },
|
| +
|
| + /** @private */
|
| + close_: function() {
|
| + // Delay navigating to allow other subpages to load first (e.g. when called
|
| + // from a getPropertiesCallback_ error).
|
| + requestAnimationFrame(function() {
|
| + settings.navigateToPreviousRoute();
|
| + });
|
| + },
|
| +
|
| + /**
|
| + * networkingPrivate.getProperties callback.
|
| + * @param {!chrome.networkingPrivate.NetworkProperties} properties
|
| + * @private
|
| + */
|
| + getPropertiesCallback_: function(properties) {
|
| + if (!properties) {
|
| + // 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;
|
| + this.savedSecurity_ = /** @type {string} */ (
|
| + this.get('WiFi.Security', this.networkProperties_));
|
| +
|
| + 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() {
|
| + if (this.configProperties_.WiFi) {
|
| + var security = /** @type {string} */ (
|
| + this.get('WiFi.Security', this.configProperties_));
|
| + var eapOuter;
|
| + if (security == CrOnc.Security.WPA_EAP) {
|
| + this.configProperties_.WiFi.EAP = this.configProperties_.WiFi.EAP || {};
|
| + eapOuter = this.configProperties_.WiFi.EAP.Outer;
|
| + if (!eapOuter) {
|
| + eapOuter = 'LEAP';
|
| + this.configProperties_.WiFi.EAP.Outer = eapOuter;
|
| + }
|
| + if (eapOuter == 'PEAP' || eapOuter == 'EAP-TTLS') {
|
| + if (!this.configProperties_.WiFi.EAP.Inner)
|
| + this.configProperties_.WiFi.EAP.Inner = 'Automatic';
|
| + }
|
| + } else {
|
| + delete this.configProperties_.WiFi.EAP;
|
| + }
|
| +
|
| + if (security != this.savedSecurity_) {
|
| + if (!security || security == CrOnc.Security.NONE) {
|
| + this.shareNetwork_ = true;
|
| + } else {
|
| + // TODO: also check login state.
|
| + this.shareNetwork_ = false;
|
| + }
|
| + this.savedSecurity_ = security;
|
| + }
|
| + }
|
| + this.setShowEap_();
|
| + },
|
| +
|
| + /**
|
| + * @param {CrOnc.Type} type The type to compare against.
|
| + * @param {CrOnc.Type} networkType The current network type.
|
| + * @return {boolean} True if the network type matches 'type'.
|
| + * @private
|
| + */
|
| + isType_: function(type, networkType) {
|
| + return type == networkType;
|
| + },
|
| +
|
| + /**
|
| + * @return {boolean}
|
| + * @private
|
| + */
|
| + connectIsEnabled_: function() {
|
| + if (this.configProperties_.Type == CrOnc.Type.WI_FI) {
|
| + if (!this.get('WiFi.SSID', this.configProperties_))
|
| + return false;
|
| + if (this.showWiFiPassphrase_()) {
|
| + var passphrase = this.get('WiFi.Passphrase', this.configProperties_);
|
| + if (!passphrase || passphrase.length < this.MIN_PASSPHRASE_LENGTH)
|
| + return false;
|
| + }
|
| + }
|
| + // TODO(stevenjb): Check certificates.
|
| + return true;
|
| + },
|
| +
|
| + /**
|
| + * @return {boolean}
|
| + * @private
|
| + */
|
| + shareIsEnabled_: function() {
|
| + if (this.configProperties_.Type == CrOnc.Type.WI_FI) {
|
| + var security = this.get('WiFi.Security', this.configProperties_);
|
| + if (!security || security == CrOnc.Security.NONE) {
|
| + return false;
|
| + } else if (security == CrOnc.Security.WPA_EAP) {
|
| + var outer = this.get('WiFi.EAP.Outer', this.configProperties_);
|
| + if (outer === 'EAP-TLS')
|
| + return false;
|
| + }
|
| + // TODO(stevenjb): Check certificates.
|
| + }
|
| + // TODO(stevenjb): Check login state.
|
| + return true;
|
| + },
|
| +
|
| + /** @private */
|
| + onSaveTap_: function() {
|
| + var newConfig = /** @type {boolean} */ (!this.guid_);
|
| + var propertiesToSet = Object.assign({}, this.configProperties_);
|
| + if (newConfig) {
|
| + this.networkingPrivate.createNetwork(
|
| + this.shareNetwork_, propertiesToSet,
|
| + this.createNetworkCallback_.bind(this));
|
| + } else {
|
| + propertiesToSet.GUID = this.guid_;
|
| + this.networkingPrivate.setProperties(
|
| + this.guid_, propertiesToSet, this.setPropertiesCallback_.bind(this));
|
| + }
|
| + },
|
| +
|
| + /**
|
| + * @param {string} guid
|
| + * @private
|
| + */
|
| + createNetworkCallback_: function(guid) {
|
| + var error = chrome.runtime.lastError && chrome.runtime.lastError.message;
|
| + if (error) {
|
| + // TODO(stevenjb): Display error message.
|
| + console.error(
|
| + 'Error creating network type: ' + this.networkProperties_.Type +
|
| + ': ' + error);
|
| + return;
|
| + }
|
| + this.networkProperties_.GUID = guid;
|
| + this.fire('network-connect', {networkProperties: this.networkProperties_});
|
| + this.close_();
|
| + },
|
| +
|
| + /** @private */
|
| + setPropertiesCallback_: function() {
|
| + var error = chrome.runtime.lastError && chrome.runtime.lastError.message;
|
| + if (error) {
|
| + console.error(
|
| + 'Error setting network properties: ' + this.guid_ + ': ' + error);
|
| + }
|
| + this.close_();
|
| + },
|
| +
|
| + /**
|
| + * @return boolean
|
| + * @private
|
| + */
|
| + showWiFiPassphrase_() {
|
| + if (this.configProperties_.Type != CrOnc.Type.WI_FI)
|
| + return false;
|
| + var security = this.get('WiFi.Security', this.configProperties_);
|
| + return !!security &&
|
| + (security == CrOnc.Security.WEP_PSK ||
|
| + security == CrOnc.Security.WPA_PSK);
|
| + },
|
| +
|
| + /** @private */
|
| + setShowEap_() {
|
| + var showEap = null;
|
| + if (this.configProperties_.Type == CrOnc.Type.WI_FI) {
|
| + var security = this.get('WiFi.Security', this.configProperties_);
|
| + if (security && security == CrOnc.Security.WPA_EAP) {
|
| + var outer = this.get('WiFi.EAP.Outer', this.configProperties_);
|
| + showEap = {
|
| + Inner: outer == 'PEAP' || outer == 'EAP-TTLS',
|
| + CA: outer != 'LEAP',
|
| + SubjectMatch: outer == 'EAP-TLS',
|
| + UserCert: outer == 'EAP-TLS',
|
| + Password: outer != 'EAP-TLS',
|
| + AnonymousIdentity: outer == 'PEAP' || outer == 'EAP-TTLS',
|
| + };
|
| + }
|
| + }
|
| + this.showEap_ = showEap;
|
| + },
|
| +
|
| + /**
|
| + * @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;
|
| + },
|
| +
|
| + /**
|
| + * @param {string} outer
|
| + * @return {!Array<string>}
|
| + * @private
|
| + */
|
| + getEapInnerItems_(outer) {
|
| + if (outer == 'PEAP')
|
| + return this.eapInnerItemsPeap_;
|
| + else if (outer == 'EAP-TTLS')
|
| + return this.eapInnerItemsTtls_;
|
| + return ['Automatic'];
|
| + },
|
| +});
|
|
|