Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Side by Side Diff: chrome/browser/resources/settings/internet_page/internet_config.js

Issue 2848683003: MD Settings: Add settings-internet-config (WiFi only, no certs) (Closed)
Patch Set: Rebase + Feedback Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
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 * @private {!chrome.networkingPrivate.NetworkProperties|undefined}
33 */
34 networkProperties_: Object,
35
36 /**
37 * The configuration properties for the network. |configProperties_.Type|
38 * will always be defined as the network type being configured.
39 * @private {!chrome.networkingPrivate.NetworkConfigProperties}
40 */
41 configProperties_: Object,
42
43 /**
44 * The title to display (network name or type).
45 * @private
46 */
47 title_: String,
48
49 /**
50 * Whether this network should be shared with other users of the device.
51 * @private
52 */
53 shareNetwork_: Boolean,
54
55 /**
56 * Saved security value, used to detect when Security changes.
57 * @private
58 */
59 savedSecurity_: String,
60
61 /**
62 * Dictionary of boolean values determining which EAP properties to show,
63 * or null to hide all EAP settings.
64 * @type {?{
65 * Inner: boolean,
66 * ServerCA: boolean,
67 * SubjectMatch: boolean,
68 * UserCert: boolean,
69 * Password: boolean,
70 * AnonymousIdentity: boolean,
71 * }}
72 * @private
73 */
74 showEap_: {
75 type: Object,
76 value: null,
77 },
78
79 /**
80 * Object providing network type values for data binding. Note: Currently
81 * we only support WiFi, but support for other types will be following
82 * shortly.
83 * @const
84 * @private
85 */
86 NetworkType_: {
87 type: Object,
88 value: {
89 ETHERNET: CrOnc.Type.ETHERNET,
90 VPN: CrOnc.Type.VPN,
91 WI_FI: CrOnc.Type.WI_FI,
92 WI_MAX: CrOnc.Type.WI_MAX,
93 },
94 readOnly: true
95 },
96
97 /**
98 * Array of values for the WiFi Security dropdown.
99 * @type {!Array<string>}
100 * @const
101 * @private
102 */
103 securityItems_: {
104 type: Array,
105 readOnly: true,
106 value: [
107 CrOnc.Security.NONE, CrOnc.Security.WEP_PSK, CrOnc.Security.WPA_PSK,
108 CrOnc.Security.WPA_EAP
109 ],
110 },
111
112 /**
113 * Array of values for the EAP Method (Outer) dropdown.
114 * @type {!Array<string>}
115 * @const
116 * @private
117 */
118 eapOuterItems_: {
119 type: Array,
120 readOnly: true,
121 value: [
122 CrOnc.EAPType.LEAP, CrOnc.EAPType.PEAP, CrOnc.EAPType.EAP_TLS,
123 CrOnc.EAPType.EAP_TTLS
124 ],
125 },
126
127 /**
128 * Array of values for the EAP EAP Phase 2 authentication (Inner) dropdown
129 * when the Outer type is PEAP.
130 * @type {!Array<string>}
131 * @const
132 * @private
133 */
134 eapInnerItemsPeap_: {
135 type: Array,
136 readOnly: true,
137 value: ['Automatic', 'MD5', 'MSCHAPv2'],
138 },
139
140 /**
141 * Array of values for the EAP EAP Phase 2 authentication (Inner) dropdown
142 * when the Outer type is EAP-TTLS.
143 * @type {!Array<string>}
144 * @const
145 * @private
146 */
147 eapInnerItemsTtls_: {
148 type: Array,
149 readOnly: true,
150 value: ['Automatic', 'MD5', 'MSCHAP', 'MSCHAPv2', 'PAP', 'CHAP', 'GTC'],
151 },
152 },
153
154 observers: [
155 'updateWiFiSecurity_(configProperties_.WiFi.Security)',
156 'updateWiFiEapOuter_(configProperties_.WiFi.EAP.Outer)',
157 ],
158
159 /** @const */
160 MIN_PASSPHRASE_LENGTH: 5,
161
162 /**
163 * settings.RouteObserverBehavior
164 * @param {!settings.Route} route
165 * @protected
166 */
167 currentRouteChanged: function(route) {
168 if (route != settings.Route.NETWORK_CONFIG)
169 return;
170
171 var queryParams = settings.getQueryParameters();
172 this.guid_ = queryParams.get('guid') || '';
173
174 // Set networkProperties for new configurations and for existing
175 // configurations until the current properties are loaded.
176 var name = queryParams.get('name') || '';
177 var typeParam = queryParams.get('type');
178 var type = typeParam ?
tbarzic 2017/05/23 18:36:38 afaik, type param could still be set to something
stevenjb 2017/05/23 20:05:22 I guess I'll add a helper method to CrOnc and add
179 /** @type {!chrome.networkingPrivate.NetworkType} */ (typeParam) :
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(
tbarzic 2017/05/23 18:36:38 should we disable 'Save' until trusted network pro
stevenjb 2017/05/23 20:05:22 Yes. Done.
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) {
michaelpg 2017/05/23 17:05:56 this function doesn't have a clear purpose. i'd su
stevenjb 2017/05/23 20:05:22 Acknowledged.
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);
michaelpg 2017/05/23 17:05:56 might make more sense as a computed property keyed
stevenjb 2017/05/23 20:05:21 Done.
223 this.shareNetwork_ = properties.Source == CrOnc.Source.DEVICE ||
224 properties.Source == CrOnc.Source.DEVICE_POLICY;
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 || '';
michaelpg 2017/05/23 17:05:56 also might make more sense as a computed property
stevenjb 2017/05/23 20:05:22 A computed property would be confusing since this
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
270 * the 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.configRequiresPassphrase_()) {
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.networkProperties_.Source == CrOnc.Source.DEVICE ||
321 this.networkProperties_.Source == CrOnc.Source.DEVICE_POLICY) {
322 return false;
323 }
324 // TODO(stevenjb): Check login state.
325
326 if (this.configProperties_.Type == CrOnc.Type.WI_FI) {
327 var security = this.get('WiFi.Security', this.configProperties_);
328 if (!security || security == CrOnc.Security.NONE) {
329 return false;
330 } else if (security == CrOnc.Security.WPA_EAP) {
331 var outer = this.get('WiFi.EAP.Outer', this.configProperties_);
332 if (outer == CrOnc.EAPType.EAP_TLS)
333 return false;
334 }
335 // TODO(stevenjb): Check certificates.
336 }
337 return true;
338 },
339
340 /** @private */
341 onSaveTap_: function() {
342 assert(this.guid_);
343 var propertiesToSet = Object.assign({}, this.configProperties_);
344 propertiesToSet.GUID = this.guid_;
345 this.networkingPrivate.setProperties(
346 this.guid_, propertiesToSet, this.setPropertiesCallback_.bind(this));
347 },
348
349 /** @private */
350 setPropertiesCallback_: function() {
351 var error = chrome.runtime.lastError && chrome.runtime.lastError.message;
352 if (error) {
353 console.error(
354 'Error setting network properties: ' + this.guid_ + ': ' + error);
355 }
356 this.close_();
357 },
358
359 /** @private */
360 onConnectTap_: function() {
361 assert(!this.guid_);
tbarzic 2017/05/23 18:36:38 I'd consider disabling connect button at this poin
stevenjb 2017/05/23 20:05:22 Done.
362 var propertiesToSet = Object.assign({}, this.configProperties_);
michaelpg 2017/05/23 17:05:56 this looks unnecessary
stevenjb 2017/05/23 20:05:22 Done.
363 // Create the configuration, then connect to it in the callback.
364 this.networkingPrivate.createNetwork(
365 this.shareNetwork_, propertiesToSet,
366 this.createNetworkCallback_.bind(this));
367 },
368
369 /**
370 * @param {string} guid
371 * @private
372 */
373 createNetworkCallback_: function(guid) {
374 var error = chrome.runtime.lastError && chrome.runtime.lastError.message;
375 if (error) {
376 // TODO(stevenjb): Display error message.
377 console.error(
378 'Error creating network type: ' + this.networkProperties_.Type +
379 ': ' + error);
380 return;
381 }
382 this.networkProperties_.GUID = guid;
383 this.fire('network-connect', {networkProperties: this.networkProperties_});
384 this.close_();
385 },
386
387 /**
388 * @return boolean
389 * @private
390 */
391 configRequiresPassphrase_: function() {
392 if (this.configProperties_.Type != CrOnc.Type.WI_FI)
393 return false;
394 var security = this.get('WiFi.Security', this.configProperties_);
395 return security == CrOnc.Security.WEP_PSK ||
396 security == CrOnc.Security.WPA_PSK;
397 },
398
399 /**
400 * Sets the EAP properties for |eap|, which may be WiFi.EAP, Ethernet.EAP etc.
401 * @private
402 */
403 setShowEap_: function(eap) {
404 var outer = eap.Outer;
405 this.showEap_ = {
406 Inner: outer == CrOnc.EAPType.PEAP || outer == CrOnc.EAPType.EAP_TTLS,
407 ServerCA: outer != CrOnc.EAPType.LEAP,
408 SubjectMatch: outer == CrOnc.EAPType.EAP_TLS,
409 UserCert: outer == CrOnc.EAPType.EAP_TLS,
410 Password: outer != CrOnc.EAPType.EAP_TLS,
411 AnonymousIdentity:
412 outer == CrOnc.EAPType.PEAP || outer == CrOnc.EAPType.EAP_TTLS,
413 };
414 },
415
416 /**
417 * @param {string} outer
418 * @return {!Array<string>}
419 * @private
420 */
421 getEapInnerItems_: function(outer) {
422 if (outer == CrOnc.EAPType.PEAP)
423 return this.eapInnerItemsPeap_;
424 if (outer == CrOnc.EAPType.EAP_TTLS)
425 return this.eapInnerItemsTtls_;
426 return [];
427 },
428 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698