OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 /** |
| 6 * @fileoverview |
| 7 * 'settings-internet-config' provides configuration of authentication |
| 8 * properties for new and existing networks. |
| 9 */ |
| 10 Polymer({ |
| 11 is: 'settings-internet-config', |
| 12 |
| 13 behaviors: [settings.RouteObserverBehavior, I18nBehavior], |
| 14 |
| 15 properties: { |
| 16 /** |
| 17 * Interface for networkingPrivate calls, passed from internet_page. |
| 18 * @type {NetworkingPrivate} |
| 19 */ |
| 20 networkingPrivate: Object, |
| 21 |
| 22 /** |
| 23 * The current properties if an existing network being configured. |
| 24 * @type {!chrome.networkingPrivate.NetworkProperties|undefined} |
| 25 * @private |
| 26 */ |
| 27 networkProperties_: Object, |
| 28 |
| 29 /** |
| 30 * The configuraiton properties for the network. |configProperties_.Type| |
| 31 * will always be defined as the network type being configured. |
| 32 * @type {!chrome.networkingPrivate.NetworkConfigProperties|undefined} |
| 33 * @private |
| 34 */ |
| 35 configProperties_: Object, |
| 36 |
| 37 /** |
| 38 * The GUID when an existing network is being configured. This will be |
| 39 * empty or undefined for new networks. |
| 40 * @private |
| 41 */ |
| 42 guid_: String, |
| 43 |
| 44 /** |
| 45 * The title to display (network name or type). |
| 46 * @private |
| 47 */ |
| 48 title_: String, |
| 49 |
| 50 /** |
| 51 * Whether this network should be shared. |
| 52 * @private |
| 53 */ |
| 54 shareNetwork_: Boolean, |
| 55 |
| 56 /** |
| 57 * Saved security value, used to detect when Security changes. |
| 58 * @private |
| 59 */ |
| 60 savedSecurity_: String, |
| 61 |
| 62 /** |
| 63 * Object providing network type values for data binding. |
| 64 * @const |
| 65 * @private |
| 66 */ |
| 67 NetworkType_: { |
| 68 type: Object, |
| 69 value: { |
| 70 CELLULAR: CrOnc.Type.CELLULAR, |
| 71 ETHERNET: CrOnc.Type.ETHERNET, |
| 72 VPN: CrOnc.Type.VPN, |
| 73 WI_FI: CrOnc.Type.WI_FI, |
| 74 WI_MAX: CrOnc.Type.WI_MAX, |
| 75 }, |
| 76 readOnly: true |
| 77 }, |
| 78 |
| 79 /** |
| 80 * Array of values for the WiFi Security dropdown. |
| 81 * @type {!Array<string>} |
| 82 * @const |
| 83 * @private |
| 84 */ |
| 85 securityItems_: { |
| 86 type: Array, |
| 87 readOnly: true, |
| 88 value: function() { |
| 89 return [ |
| 90 CrOnc.Security.NONE, CrOnc.Security.WEP_PSK, CrOnc.Security.WPA_PSK, |
| 91 CrOnc.Security.WPA_EAP |
| 92 ]; |
| 93 } |
| 94 }, |
| 95 |
| 96 /** |
| 97 * Array of values for the EAP Method (Outer) dropdown. |
| 98 * @type {!Array<string>} |
| 99 * @const |
| 100 * @private |
| 101 */ |
| 102 eapOuterItems_: { |
| 103 type: Array, |
| 104 readOnly: true, |
| 105 value: function() { |
| 106 return ['LEAP', 'PEAP', 'EAP-TLS', 'EAP-TTLS']; |
| 107 } |
| 108 }, |
| 109 |
| 110 /** |
| 111 * Array of values for the EAP EAP Phase 2 authentication (Inner) dropdown |
| 112 * when the Outer type is PEAP. |
| 113 * @type {!Array<string>} |
| 114 * @const |
| 115 * @private |
| 116 */ |
| 117 eapInnerItemsPeap_: { |
| 118 type: Array, |
| 119 readOnly: true, |
| 120 value: function() { |
| 121 return ['Automatic', 'MD5', 'MSCHAPv2']; |
| 122 } |
| 123 }, |
| 124 |
| 125 /** |
| 126 * Array of values for the EAP EAP Phase 2 authentication (Inner) dropdown |
| 127 * when the Outer type is EAP-TTLS. |
| 128 * @type {!Array<string>} |
| 129 * @const |
| 130 * @private |
| 131 */ |
| 132 eapInnerItemsTtls_: { |
| 133 type: Array, |
| 134 readOnly: true, |
| 135 value: function() { |
| 136 return ['Automatic', 'MD5', 'MSCHAP', 'MSCHAPv2', 'PAP', 'CHAP', 'GTC']; |
| 137 } |
| 138 }, |
| 139 }, |
| 140 |
| 141 observers: ['updateConfigProperties_(configProperties_.*)'], |
| 142 |
| 143 /** @const */ |
| 144 MIN_PASSPHRASE_LENGTH: 5, |
| 145 |
| 146 /** |
| 147 * settings.RouteObserverBehavior |
| 148 * @param {!settings.Route} route |
| 149 * @protected |
| 150 */ |
| 151 currentRouteChanged: function(route) { |
| 152 var queryParams = settings.getQueryParameters(); |
| 153 this.guid_ = queryParams.get('guid') || ''; |
| 154 |
| 155 // Set networkProperties for new configurations and for existing |
| 156 // configuraitons until the current properties are loaded. |
| 157 var name = queryParams.get('name') || ''; |
| 158 var type = /** @type {!chrome.networkingPrivate.NetworkType} */ ( |
| 159 queryParams.get('type')) || |
| 160 CrOnc.Type.WI_FI; |
| 161 this.networkProperties_ = { |
| 162 GUID: this.guid_, |
| 163 Name: name, |
| 164 Type: type, |
| 165 }; |
| 166 var configProperties = {Type: type}; |
| 167 if (type == CrOnc.Type.WI_FI) { |
| 168 configProperties.WiFi = { |
| 169 SSID: '', |
| 170 Security: CrOnc.Security.NONE, |
| 171 }; |
| 172 } |
| 173 this.configProperties_ = configProperties; |
| 174 if (this.guid_) { |
| 175 this.networkingPrivate.getProperties( |
| 176 this.guid_, this.getPropertiesCallback_.bind(this)); |
| 177 } else { |
| 178 this.title_ = this.i18n('OncType' + type); |
| 179 this.shareNetwork_ = true; |
| 180 } |
| 181 }, |
| 182 |
| 183 /** @private */ |
| 184 close_: function() { |
| 185 // Delay navigating to allow other subpages to load first (e.g. when called |
| 186 // from a getPropertiesCallback_ error). |
| 187 requestAnimationFrame(function() { |
| 188 settings.navigateToPreviousRoute(); |
| 189 }); |
| 190 }, |
| 191 |
| 192 /** |
| 193 * networkingPrivate.getProperties callback. |
| 194 * @param {!chrome.networkingPrivate.NetworkProperties} properties |
| 195 * @private |
| 196 */ |
| 197 getPropertiesCallback_: function(properties) { |
| 198 if (!properties) { |
| 199 // If |properties| is null, the network no longer exists; close the page. |
| 200 console.error('Network no longer exists: ' + this.guid_); |
| 201 this.close_(); |
| 202 return; |
| 203 } |
| 204 this.networkProperties_ = properties; |
| 205 this.title_ = properties.Name || this.i18n('OncType' + properties.Type); |
| 206 this.shareNetwork_ = properties.Source == CrOnc.Source.DEVICE || |
| 207 properties.Source == CrOnc.Source.DEVICE_POLICY; |
| 208 this.savedSecurity_ = /** @type {string} */ ( |
| 209 this.get('WiFi.Security', this.networkProperties_)); |
| 210 |
| 211 var configProperties = |
| 212 /** @type {chrome.networkingPrivate.NetworkConfigProperties} */ ({ |
| 213 Name: properties.Name, |
| 214 Type: properties.Type, |
| 215 }); |
| 216 if (properties.WiFi) { |
| 217 configProperties.WiFi = { |
| 218 AutoConnect: properties.WiFi.AutoConnect, |
| 219 EAP: properties.WiFi.EAP, |
| 220 Passphrase: properties.WiFi.Passphrase, |
| 221 SSID: properties.WiFi.SSID, |
| 222 Security: properties.WiFi.Security |
| 223 }; |
| 224 } |
| 225 this.configProperties_ = configProperties; |
| 226 this.updateConfigProperties_(); |
| 227 }, |
| 228 |
| 229 /** @private */ |
| 230 updateConfigProperties_: function() { |
| 231 if (this.configProperties_.WiFi) { |
| 232 var security = /** @type {string} */ ( |
| 233 this.get('WiFi.Security', this.configProperties_)); |
| 234 var eapOuter; |
| 235 if (security == CrOnc.Security.WPA_EAP) { |
| 236 this.configProperties_.WiFi.EAP = this.configProperties_.WiFi.EAP || {}; |
| 237 eapOuter = this.configProperties_.WiFi.EAP.Outer; |
| 238 if (!eapOuter) { |
| 239 eapOuter = 'LEAP'; |
| 240 this.configProperties_.WiFi.EAP.Outer = eapOuter; |
| 241 } |
| 242 if (eapOuter == 'PEAP' || eapOuter == 'EAP-TTLS') { |
| 243 if (!this.configProperties_.WiFi.EAP.Inner) |
| 244 this.configProperties_.WiFi.EAP.Inner = 'Automatic'; |
| 245 } |
| 246 } else { |
| 247 delete this.configProperties_.WiFi.EAP; |
| 248 } |
| 249 |
| 250 if (security != this.savedSecurity_) { |
| 251 if (!security || security == CrOnc.Security.NONE) { |
| 252 this.shareNetwork_ = true; |
| 253 } else { |
| 254 // TODO: also check login state. |
| 255 this.shareNetwork_ = false; |
| 256 } |
| 257 this.savedSecurity_ = security; |
| 258 } |
| 259 } |
| 260 this.setShowEap_(); |
| 261 }, |
| 262 |
| 263 /** |
| 264 * @param {CrOnc.Type} type The type to compare against. |
| 265 * @param {CrOnc.Type} networkType The current network type. |
| 266 * @return {boolean} True if the network type matches 'type'. |
| 267 * @private |
| 268 */ |
| 269 isType_: function(type, networkType) { |
| 270 return type == networkType; |
| 271 }, |
| 272 |
| 273 /** |
| 274 * @return {boolean} |
| 275 * @private |
| 276 */ |
| 277 connectIsEnabled_: function() { |
| 278 if (this.configProperties_.Type == CrOnc.Type.WI_FI) { |
| 279 if (!this.get('WiFi.SSID', this.configProperties_)) |
| 280 return false; |
| 281 if (this.showWiFiPassphrase_()) { |
| 282 var passphrase = this.get('WiFi.Passphrase', this.configProperties_); |
| 283 if (!passphrase || passphrase.length < this.MIN_PASSPHRASE_LENGTH) |
| 284 return false; |
| 285 } |
| 286 } |
| 287 // TODO(stevenjb): Check certificates. |
| 288 return true; |
| 289 }, |
| 290 |
| 291 /** |
| 292 * @return {boolean} |
| 293 * @private |
| 294 */ |
| 295 shareIsEnabled_: function() { |
| 296 if (this.configProperties_.Type == CrOnc.Type.WI_FI) { |
| 297 var security = this.get('WiFi.Security', this.configProperties_); |
| 298 if (!security || security == CrOnc.Security.NONE) { |
| 299 return false; |
| 300 } else if (security == CrOnc.Security.WPA_EAP) { |
| 301 var outer = this.get('WiFi.EAP.Outer', this.configProperties_); |
| 302 if (outer === 'EAP-TLS') |
| 303 return false; |
| 304 } |
| 305 // TODO(stevenjb): Check certificates. |
| 306 } |
| 307 // TODO(stevenjb): Check login state. |
| 308 return true; |
| 309 }, |
| 310 |
| 311 /** @private */ |
| 312 onSaveTap_: function() { |
| 313 var newConfig = /** @type {boolean} */ (!this.guid_); |
| 314 var propertiesToSet = Object.assign({}, this.configProperties_); |
| 315 if (newConfig) { |
| 316 this.networkingPrivate.createNetwork( |
| 317 this.shareNetwork_, propertiesToSet, |
| 318 this.createNetworkCallback_.bind(this)); |
| 319 } else { |
| 320 propertiesToSet.GUID = this.guid_; |
| 321 this.networkingPrivate.setProperties( |
| 322 this.guid_, propertiesToSet, this.setPropertiesCallback_.bind(this)); |
| 323 } |
| 324 }, |
| 325 |
| 326 /** |
| 327 * @param {string} guid |
| 328 * @private |
| 329 */ |
| 330 createNetworkCallback_: function(guid) { |
| 331 var error = chrome.runtime.lastError && chrome.runtime.lastError.message; |
| 332 if (error) { |
| 333 // TODO(stevenjb): Display error message. |
| 334 console.error( |
| 335 'Error creating network type: ' + this.networkProperties_.Type + |
| 336 ': ' + error); |
| 337 return; |
| 338 } |
| 339 this.networkProperties_.GUID = guid; |
| 340 this.fire('network-connect', {networkProperties: this.networkProperties_}); |
| 341 this.close_(); |
| 342 }, |
| 343 |
| 344 /** @private */ |
| 345 setPropertiesCallback_: function() { |
| 346 var error = chrome.runtime.lastError && chrome.runtime.lastError.message; |
| 347 if (error) { |
| 348 console.error( |
| 349 'Error setting network properties: ' + this.guid_ + ': ' + error); |
| 350 } |
| 351 this.close_(); |
| 352 }, |
| 353 |
| 354 /** |
| 355 * @return boolean |
| 356 * @private |
| 357 */ |
| 358 showWiFiPassphrase_() { |
| 359 if (this.configProperties_.Type != CrOnc.Type.WI_FI) |
| 360 return false; |
| 361 var security = this.get('WiFi.Security', this.configProperties_); |
| 362 return !!security && |
| 363 (security == CrOnc.Security.WEP_PSK || |
| 364 security == CrOnc.Security.WPA_PSK); |
| 365 }, |
| 366 |
| 367 /** @private */ |
| 368 setShowEap_() { |
| 369 var showEap = null; |
| 370 if (this.configProperties_.Type == CrOnc.Type.WI_FI) { |
| 371 var security = this.get('WiFi.Security', this.configProperties_); |
| 372 if (security && security == CrOnc.Security.WPA_EAP) { |
| 373 var outer = this.get('WiFi.EAP.Outer', this.configProperties_); |
| 374 showEap = { |
| 375 Inner: outer == 'PEAP' || outer == 'EAP-TTLS', |
| 376 CA: outer != 'LEAP', |
| 377 SubjectMatch: outer == 'EAP-TLS', |
| 378 UserCert: outer == 'EAP-TLS', |
| 379 Password: outer != 'EAP-TLS', |
| 380 AnonymousIdentity: outer == 'PEAP' || outer == 'EAP-TTLS', |
| 381 }; |
| 382 } |
| 383 } |
| 384 this.showEap_ = showEap; |
| 385 }, |
| 386 |
| 387 /** |
| 388 * @param {string} key |
| 389 * @param {string} prefix |
| 390 * @return {string} The text to display for the onc value. |
| 391 * @private |
| 392 */ |
| 393 getOncLabel_: function(key, prefix) { |
| 394 var oncKey = 'Onc' + prefix.replace(/\./g, '-') + '_' + key; |
| 395 if (this.i18nExists(oncKey)) |
| 396 return this.i18n(oncKey); |
| 397 return key; |
| 398 }, |
| 399 |
| 400 /** |
| 401 * @param {string} outer |
| 402 * @return {!Array<string>} |
| 403 * @private |
| 404 */ |
| 405 getEapInnerItems_(outer) { |
| 406 if (outer == 'PEAP') |
| 407 return this.eapInnerItemsPeap_; |
| 408 else if (outer == 'EAP-TTLS') |
| 409 return this.eapInnerItemsTtls_; |
| 410 return ['Automatic']; |
| 411 }, |
| 412 }); |
OLD | NEW |