OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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 GUID when an existing network is being configured. This will be | |
24 * empty when configuring a new network. | |
25 * @private | |
tbarzic
2017/05/22 19:29:02
@private {string}, or does type not have to specif
michaelpg
2017/05/22 20:01:53
Yep, Closure has a Polymer pass that detects simpl
| |
26 */ | |
27 guid_: String, | |
28 | |
29 /** | |
30 * The current properties if an existing network being configured. | |
31 * This will be undefined when configuring a new network. | |
32 * @type {!chrome.networkingPrivate.NetworkProperties|undefined} | |
tbarzic
2017/05/22 19:29:02
I think you can merge @private and @type into:
@pr
stevenjb
2017/05/22 20:36:36
Done.
| |
33 * @private | |
34 */ | |
35 networkProperties_: Object, | |
36 | |
37 /** | |
38 * The configuraiton properties for the network. |configProperties_.Type| | |
tbarzic
2017/05/22 19:29:02
typo: configuraiton
stevenjb
2017/05/22 20:36:36
Done.
| |
39 * will always be defined as the network type being configured. | |
40 * @type {!chrome.networkingPrivate.NetworkConfigProperties} | |
41 * @private | |
42 */ | |
43 configProperties_: Object, | |
44 | |
45 /** | |
46 * The title to display (network name or type). | |
47 * @private | |
48 */ | |
49 title_: String, | |
50 | |
51 /** | |
52 * Whether this network should be shared with other users of the device. | |
53 * @private | |
54 */ | |
55 shareNetwork_: Boolean, | |
56 | |
57 /** | |
58 * Saved security value, used to detect when Security changes. | |
59 * @private | |
60 */ | |
61 savedSecurity_: String, | |
62 | |
63 /** | |
64 * Dictionary of boolean values determining which EAP properties to show. | |
tbarzic
2017/05/22 19:29:02
nit: comment on the meaning of null value
stevenjb
2017/05/22 20:36:36
Done.
| |
65 * @type {?{ | |
66 * Inner: boolean, | |
67 * ServerCA: boolean, | |
68 * SubjectMatch: boolean, | |
69 * UserCert: boolean, | |
70 * Password: boolean, | |
71 * AnonymousIdentity: boolean, | |
72 * }} | |
73 * @private | |
74 */ | |
75 showEap_: { | |
76 type: Object, | |
77 value: null, | |
78 }, | |
79 | |
80 /** | |
81 * Object providing network type values for data binding. Note: Currently | |
82 * we only support WiFi, but support for other types will be following | |
83 * shortly. | |
84 * @const | |
85 * @private | |
86 */ | |
87 NetworkType_: { | |
88 type: Object, | |
89 value: { | |
90 ETHERNET: CrOnc.Type.ETHERNET, | |
91 VPN: CrOnc.Type.VPN, | |
92 WI_FI: CrOnc.Type.WI_FI, | |
93 WI_MAX: CrOnc.Type.WI_MAX, | |
94 }, | |
95 readOnly: true | |
96 }, | |
97 | |
98 /** | |
99 * Array of values for the WiFi Security dropdown. | |
100 * @type {!Array<string>} | |
101 * @const | |
102 * @private | |
103 */ | |
104 securityItems_: { | |
105 type: Array, | |
106 readOnly: true, | |
107 value: [ | |
108 CrOnc.Security.NONE, CrOnc.Security.WEP_PSK, CrOnc.Security.WPA_PSK, | |
109 CrOnc.Security.WPA_EAP | |
110 ], | |
111 }, | |
112 | |
113 /** | |
114 * Array of values for the EAP Method (Outer) dropdown. | |
115 * @type {!Array<string>} | |
116 * @const | |
117 * @private | |
118 */ | |
119 eapOuterItems_: { | |
120 type: Array, | |
121 readOnly: true, | |
122 value: [ | |
123 CrOnc.EAPType.LEAP, CrOnc.EAPType.PEAP, CrOnc.EAPType.EAP_TLS, | |
124 CrOnc.EAPType.EAP_TTLS | |
125 ], | |
126 }, | |
127 | |
128 /** | |
129 * Array of values for the EAP EAP Phase 2 authentication (Inner) dropdown | |
130 * when the Outer type is PEAP. | |
131 * @type {!Array<string>} | |
132 * @const | |
133 * @private | |
134 */ | |
135 eapInnerItemsPeap_: { | |
136 type: Array, | |
137 readOnly: true, | |
138 value: ['Automatic', 'MD5', 'MSCHAPv2'], | |
139 }, | |
140 | |
141 /** | |
142 * Array of values for the EAP EAP Phase 2 authentication (Inner) dropdown | |
143 * when the Outer type is EAP-TTLS. | |
144 * @type {!Array<string>} | |
145 * @const | |
146 * @private | |
147 */ | |
148 eapInnerItemsTtls_: { | |
149 type: Array, | |
150 readOnly: true, | |
151 value: ['Automatic', 'MD5', 'MSCHAP', 'MSCHAPv2', 'PAP', 'CHAP', 'GTC'], | |
152 }, | |
153 }, | |
154 | |
155 observers: [ | |
156 'updateWiFiSecurity_(configProperties_.WiFi.Security)', | |
157 'updateWiFiEapOuter_(configProperties_.WiFi.EAP.Outer)', | |
158 ], | |
159 | |
160 /** @const */ | |
161 MIN_PASSPHRASE_LENGTH: 5, | |
162 | |
163 /** | |
164 * settings.RouteObserverBehavior | |
165 * @param {!settings.Route} route | |
166 * @protected | |
167 */ | |
168 currentRouteChanged: function(route) { | |
169 if (route != settings.Route.NETWORK_CONFIG) | |
170 return; | |
171 | |
172 var queryParams = settings.getQueryParameters(); | |
173 this.guid_ = queryParams.get('guid') || ''; | |
174 | |
175 // Set networkProperties for new configurations and for existing | |
176 // configuraitons until the current properties are loaded. | |
177 var name = queryParams.get('name') || ''; | |
178 var type = /** @type {!chrome.networkingPrivate.NetworkType} */ ( | |
tbarzic
2017/05/22 19:29:02
should we believe the type param is really chrome.
stevenjb
2017/05/22 20:36:36
Re-factored a bit.
| |
179 queryParams.get('type')) || | |
180 CrOnc.Type.WI_FI; | |
181 this.networkProperties_ = { | |
182 GUID: this.guid_, | |
183 Name: name, | |
184 Type: type, | |
185 }; | |
186 var configProperties = {Type: type}; | |
187 if (type == CrOnc.Type.WI_FI) { | |
188 configProperties.WiFi = { | |
189 SSID: '', | |
190 Security: CrOnc.Security.NONE, | |
191 }; | |
192 } | |
193 this.configProperties_ = configProperties; | |
194 if (this.guid_) { | |
195 this.networkingPrivate.getProperties( | |
196 this.guid_, this.getPropertiesCallback_.bind(this)); | |
197 } else { | |
198 this.title_ = this.i18n('OncType' + type); | |
199 this.shareNetwork_ = true; | |
200 } | |
201 }, | |
202 | |
203 /** @private */ | |
204 close_: function() { | |
205 if (settings.getCurrentRoute() == settings.Route.NETWORK_CONFIG) | |
206 settings.navigateToPreviousRoute(); | |
207 }, | |
208 | |
209 /** | |
210 * networkingPrivate.getProperties callback. | |
211 * @param {!chrome.networkingPrivate.NetworkProperties} properties | |
212 * @private | |
213 */ | |
214 getPropertiesCallback_: function(properties) { | |
215 if (!properties) { | |
216 // If |properties| is null, the network no longer exists; close the page. | |
217 console.error('Network no longer exists: ' + this.guid_); | |
218 this.close_(); | |
219 return; | |
220 } | |
221 this.networkProperties_ = properties; | |
222 this.title_ = properties.Name || this.i18n('OncType' + properties.Type); | |
tbarzic
2017/05/22 19:29:02
It looks like you're missing OncType* strings (or
stevenjb
2017/05/22 20:36:36
These are set here:
https://cs.chromium.org/chromi
| |
223 this.shareNetwork_ = properties.Source == CrOnc.Source.DEVICE || | |
224 properties.Source == CrOnc.Source.DEVICE_POLICY; | |
tbarzic
2017/05/22 19:29:02
should shareNetwork button be disabled if the conf
stevenjb
2017/05/22 20:36:38
Added to shareIsEnabled_.
| |
225 | |
226 var configProperties = | |
227 /** @type {chrome.networkingPrivate.NetworkConfigProperties} */ ({ | |
228 Name: properties.Name, | |
229 Type: properties.Type, | |
230 }); | |
231 if (properties.WiFi) { | |
232 configProperties.WiFi = { | |
233 AutoConnect: properties.WiFi.AutoConnect, | |
234 EAP: properties.WiFi.EAP, | |
235 Passphrase: properties.WiFi.Passphrase, | |
236 SSID: properties.WiFi.SSID, | |
237 Security: properties.WiFi.Security | |
238 }; | |
239 this.savedSecurity_ = properties.WiFi.Security || ''; | |
240 } | |
241 this.configProperties_ = configProperties; | |
242 }, | |
243 | |
244 /** | |
245 * Ensures that the appropriate properties are set or deleted when the | |
246 * Security type changes. | |
247 * @private | |
248 */ | |
249 updateWiFiSecurity_: function() { | |
250 assert(this.configProperties_.WiFi); | |
251 var security = this.configProperties_.WiFi.Security || CrOnc.Security.NONE; | |
252 if (security == this.savedSecurity_) | |
253 return; | |
254 this.savedSecurity_ = security || ''; | |
255 | |
256 if (!this.guid_) { | |
257 // Set the default share state for new configurations. | |
258 // TODO(stevenjb): also check login state. | |
259 this.shareNetwork_ = security == CrOnc.Security.NONE; | |
260 } | |
261 | |
262 if (security == CrOnc.Security.WPA_EAP) | |
263 this.set('configProperties_.WiFi.EAP', {Outer: CrOnc.EAPType.LEAP}); | |
264 else | |
265 delete this.configProperties_.WiFi.EAP; | |
266 }, | |
267 | |
268 /** | |
269 * Ensures that the appropriate EAP properties are created(or deleted when the | |
tbarzic
2017/05/22 19:29:02
nit: space before (
stevenjb
2017/05/22 20:36:36
Done.
| |
270 * EAP.Outer property changes. | |
271 * @private | |
272 */ | |
273 updateWiFiEapOuter_: function() { | |
274 var eap = this.configProperties_.WiFi.EAP; | |
275 if (!eap || !eap.Outer) | |
276 return; | |
277 var innerItems = this.getEapInnerItems_(eap.Outer); | |
278 if (innerItems.length > 0) { | |
279 if (!eap.Inner || innerItems.indexOf(eap.Inner) < 0) | |
280 this.set('configProperties_.WiFi.EAP.Inner', innerItems[0]); | |
281 } else { | |
282 delete eap.Inner; | |
283 } | |
284 this.setShowEap_(this.configProperties_.WiFi.EAP); | |
285 }, | |
286 | |
287 /** | |
288 * @param {CrOnc.Type} type The type to compare against. | |
289 * @param {CrOnc.Type} networkType The current network type. | |
290 * @return {boolean} True if the network type matches 'type'. | |
291 * @private | |
292 */ | |
293 isType_: function(type, networkType) { | |
294 return type == networkType; | |
295 }, | |
296 | |
297 /** | |
298 * @return {boolean} | |
299 * @private | |
300 */ | |
301 connectIsEnabled_: function() { | |
302 if (this.configProperties_.Type == CrOnc.Type.WI_FI) { | |
303 if (!this.get('WiFi.SSID', this.configProperties_)) | |
304 return false; | |
305 if (this.showWiFiPassphrase_()) { | |
306 var passphrase = this.get('WiFi.Passphrase', this.configProperties_); | |
307 if (!passphrase || passphrase.length < this.MIN_PASSPHRASE_LENGTH) | |
308 return false; | |
309 } | |
310 } | |
311 // TODO(stevenjb): Check certificates. | |
312 return true; | |
313 }, | |
314 | |
315 /** | |
316 * @return {boolean} | |
317 * @private | |
318 */ | |
319 shareIsEnabled_: function() { | |
320 if (this.configProperties_.Type == CrOnc.Type.WI_FI) { | |
321 var security = this.get('WiFi.Security', this.configProperties_); | |
322 if (!security || security == CrOnc.Security.NONE) { | |
323 return false; | |
324 } else if (security == CrOnc.Security.WPA_EAP) { | |
325 var outer = this.get('WiFi.EAP.Outer', this.configProperties_); | |
326 if (outer == CrOnc.EAPType.EAP_TLS) | |
327 return false; | |
328 } | |
329 // TODO(stevenjb): Check certificates. | |
330 } | |
331 // TODO(stevenjb): Check login state. | |
332 return true; | |
333 }, | |
334 | |
335 /** @private */ | |
336 onSaveTap_: function() { | |
tbarzic
2017/05/22 19:29:02
Can you split this into two methods:
* onSaveTap_
stevenjb
2017/05/22 20:36:36
Done.
| |
337 var newConfig = /** @type {boolean} */ (!this.guid_); | |
tbarzic
2017/05/22 19:29:02
afaik, cast to boolean should not be needed
stevenjb
2017/05/22 20:36:36
Acknowledged.
| |
338 var propertiesToSet = Object.assign({}, this.configProperties_); | |
339 if (newConfig) { | |
340 this.networkingPrivate.createNetwork( | |
341 this.shareNetwork_, propertiesToSet, | |
342 this.createNetworkCallback_.bind(this)); | |
343 } else { | |
344 propertiesToSet.GUID = this.guid_; | |
345 this.networkingPrivate.setProperties( | |
346 this.guid_, propertiesToSet, this.setPropertiesCallback_.bind(this)); | |
347 } | |
348 }, | |
349 | |
350 /** | |
351 * @param {string} guid | |
352 * @private | |
353 */ | |
354 createNetworkCallback_: function(guid) { | |
355 var error = chrome.runtime.lastError && chrome.runtime.lastError.message; | |
356 if (error) { | |
357 // TODO(stevenjb): Display error message. | |
358 console.error( | |
359 'Error creating network type: ' + this.networkProperties_.Type + | |
360 ': ' + error); | |
361 return; | |
362 } | |
363 this.networkProperties_.GUID = guid; | |
364 this.fire('network-connect', {networkProperties: this.networkProperties_}); | |
365 this.close_(); | |
366 }, | |
367 | |
368 /** @private */ | |
369 setPropertiesCallback_: function() { | |
370 var error = chrome.runtime.lastError && chrome.runtime.lastError.message; | |
371 if (error) { | |
372 console.error( | |
373 'Error setting network properties: ' + this.guid_ + ': ' + error); | |
374 } | |
375 this.close_(); | |
376 }, | |
377 | |
378 /** | |
379 * @return boolean | |
380 * @private | |
381 */ | |
382 showWiFiPassphrase_: function() { | |
tbarzic
2017/05/22 19:29:02
nit: wdyt about "configRequiresPassphrase_"
stevenjb
2017/05/22 20:36:38
Done.
| |
383 if (this.configProperties_.Type != CrOnc.Type.WI_FI) | |
384 return false; | |
385 var security = this.get('WiFi.Security', this.configProperties_); | |
386 return security == CrOnc.Security.WEP_PSK || | |
387 security == CrOnc.Security.WPA_PSK; | |
388 }, | |
389 | |
390 /** | |
391 * Sets the EAP properties for |eap|, which may be WiFi.EAP, Etherent.EAP etc. | |
392 * @private | |
393 */ | |
394 setShowEap_: function(eap) { | |
395 var outer = eap.Outer; | |
396 this.showEap_ = { | |
397 Inner: outer == CrOnc.EAPType.PEAP || outer == CrOnc.EAPType.EAP_TTLS, | |
398 ServerCA: outer != CrOnc.EAPType.LEAP, | |
399 SubjectMatch: outer == CrOnc.EAPType.EAP_TLS, | |
400 UserCert: outer == CrOnc.EAPType.EAP_TLS, | |
401 Password: outer != CrOnc.EAPType.EAP_TLS, | |
402 AnonymousIdentity: | |
403 outer == CrOnc.EAPType.PEAP || outer == CrOnc.EAPType.EAP_TTLS, | |
404 }; | |
405 }, | |
406 | |
407 /** | |
408 * @param {string} outer | |
409 * @return {!Array<string>} | |
410 * @private | |
411 */ | |
412 getEapInnerItems_: function(outer) { | |
413 if (outer == CrOnc.EAPType.PEAP) | |
414 return this.eapInnerItemsPeap_; | |
415 if (outer == CrOnc.EAPType.EAP_TTLS) | |
416 return this.eapInnerItemsTtls_; | |
417 return []; | |
418 }, | |
419 }); | |
OLD | NEW |