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

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: . 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 2015 The Chromium Authors. All rights reserved.
michaelpg 2017/05/18 21:14:23 2017
stevenjb 2017/05/19 23:35:34 Done.
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 * @type {!chrome.networkingPrivate.NetworkProperties|undefined}
33 * @private
34 */
35 networkProperties_: Object,
36
37 /**
38 * The configuraiton properties for the network. |configProperties_.Type|
39 * will always be defined as the network type being configured.
michaelpg 2017/05/18 21:14:23 "always": including when configuring a new network
stevenjb 2017/05/19 23:35:34 Yes. Done. (It gets set in currentRouteChanged, so
40 * @type {!chrome.networkingPrivate.NetworkConfigProperties|undefined}
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 * Object providing network type values for data binding.
65 * @const
66 * @private
67 */
68 NetworkType_: {
michaelpg 2017/05/18 21:14:23 This isn't really used, apart from passing WI_FI t
stevenjb 2017/05/19 23:35:34 We will definitely have other values in the very s
69 type: Object,
70 value: {
71 CELLULAR: CrOnc.Type.CELLULAR,
72 ETHERNET: CrOnc.Type.ETHERNET,
73 VPN: CrOnc.Type.VPN,
74 WI_FI: CrOnc.Type.WI_FI,
75 WI_MAX: CrOnc.Type.WI_MAX,
76 },
77 readOnly: true
78 },
79
80 /**
81 * Array of values for the WiFi Security dropdown.
82 * @type {!Array<string>}
83 * @const
84 * @private
85 */
86 securityItems_: {
87 type: Array,
88 readOnly: true,
89 value: function() {
michaelpg 2017/05/18 21:14:23 if @const, doesn't really need to be returned via
stevenjb 2017/05/19 23:35:34 Done.
90 return [
91 CrOnc.Security.NONE, CrOnc.Security.WEP_PSK, CrOnc.Security.WPA_PSK,
92 CrOnc.Security.WPA_EAP
93 ];
94 }
95 },
96
97 /**
98 * Array of values for the EAP Method (Outer) dropdown.
99 * @type {!Array<string>}
100 * @const
101 * @private
102 */
103 eapOuterItems_: {
104 type: Array,
105 readOnly: true,
106 value: function() {
107 return ['LEAP', 'PEAP', 'EAP-TLS', 'EAP-TTLS'];
108 }
109 },
110
111 /**
112 * Array of values for the EAP EAP Phase 2 authentication (Inner) dropdown
113 * when the Outer type is PEAP.
114 * @type {!Array<string>}
115 * @const
116 * @private
117 */
118 eapInnerItemsPeap_: {
119 type: Array,
120 readOnly: true,
121 value: function() {
122 return ['Automatic', 'MD5', 'MSCHAPv2'];
123 }
124 },
125
126 /**
127 * Array of values for the EAP EAP Phase 2 authentication (Inner) dropdown
128 * when the Outer type is EAP-TTLS.
129 * @type {!Array<string>}
130 * @const
131 * @private
132 */
133 eapInnerItemsTtls_: {
134 type: Array,
135 readOnly: true,
136 value: function() {
137 return ['Automatic', 'MD5', 'MSCHAP', 'MSCHAPv2', 'PAP', 'CHAP', 'GTC'];
michaelpg 2017/05/18 21:14:23 Suggestion: these constants may be more readable a
stevenjb 2017/05/19 23:35:34 Hmm, the others are used directly in the html so n
138 }
139 },
140 },
141
142 observers: ['updateConfigProperties_(configProperties_.*)'],
143
144 /** @const */
145 MIN_PASSPHRASE_LENGTH: 5,
146
147 /**
148 * settings.RouteObserverBehavior
149 * @param {!settings.Route} route
150 * @protected
151 */
152 currentRouteChanged: function(route) {
153 if (route != settings.Route.NETWORK_CONFIG)
154 return;
155
156 var queryParams = settings.getQueryParameters();
157 this.guid_ = queryParams.get('guid') || '';
158
159 // Set networkProperties for new configurations and for existing
160 // configuraitons until the current properties are loaded.
161 var name = queryParams.get('name') || '';
162 var type = /** @type {!chrome.networkingPrivate.NetworkType} */ (
163 queryParams.get('type')) ||
164 CrOnc.Type.WI_FI;
165 this.networkProperties_ = {
166 GUID: this.guid_,
167 Name: name,
168 Type: type,
169 };
170 var configProperties = {Type: type};
171 if (type == CrOnc.Type.WI_FI) {
172 configProperties.WiFi = {
173 SSID: '',
174 Security: CrOnc.Security.NONE,
175 };
176 }
177 this.configProperties_ = configProperties;
178 if (this.guid_) {
179 this.networkingPrivate.getProperties(
180 this.guid_, this.getPropertiesCallback_.bind(this));
181 } else {
182 this.title_ = this.i18n('OncType' + type);
183 this.shareNetwork_ = true;
184 }
185 },
186
187 /** @private */
188 close_: function() {
189 // Delay navigating to allow other subpages to load first (e.g. when called
michaelpg 2017/05/18 21:14:23 I don't understand why this is necessary -- what h
stevenjb 2017/05/19 23:35:34 It's kind of an edge case, but if a page is left o
190 // from a getPropertiesCallback_ error).
191 requestAnimationFrame(function() {
192 settings.navigateToPreviousRoute();
michaelpg 2017/05/18 21:14:23 verify that we are still on NETWORK_CONFIG so we d
stevenjb 2017/05/19 23:35:34 Done.
193 });
194 },
195
196 /**
197 * networkingPrivate.getProperties callback.
198 * @param {!chrome.networkingPrivate.NetworkProperties} properties
199 * @private
200 */
201 getPropertiesCallback_: function(properties) {
202 if (!properties) {
203 // If |properties| is null, the network no longer exists; close the page.
204 console.error('Network no longer exists: ' + this.guid_);
205 this.close_();
206 return;
207 }
208 this.networkProperties_ = properties;
209 this.title_ = properties.Name || this.i18n('OncType' + properties.Type);
210 this.shareNetwork_ = properties.Source == CrOnc.Source.DEVICE ||
211 properties.Source == CrOnc.Source.DEVICE_POLICY;
212 this.savedSecurity_ = /** @type {string} */ (
213 this.get('WiFi.Security', this.networkProperties_));
214
215 var configProperties =
216 /** @type {chrome.networkingPrivate.NetworkConfigProperties} */ ({
217 Name: properties.Name,
218 Type: properties.Type,
219 });
220 if (properties.WiFi) {
221 configProperties.WiFi = {
222 AutoConnect: properties.WiFi.AutoConnect,
223 EAP: properties.WiFi.EAP,
224 Passphrase: properties.WiFi.Passphrase,
225 SSID: properties.WiFi.SSID,
226 Security: properties.WiFi.Security
227 };
228 }
229 this.configProperties_ = configProperties;
230 },
231
232 /** @private */
233 updateConfigProperties_: function() {
234 if (this.configProperties_.WiFi) {
235 var security = /** @type {string} */ (
236 this.get('WiFi.Security', this.configProperties_));
237 var eapOuter;
238 if (security == CrOnc.Security.WPA_EAP) {
239 this.configProperties_.WiFi.EAP = this.configProperties_.WiFi.EAP || {};
240 eapOuter = this.configProperties_.WiFi.EAP.Outer;
241 if (!eapOuter) {
242 eapOuter = 'LEAP';
243 this.configProperties_.WiFi.EAP.Outer = eapOuter;
244 }
245 if (eapOuter == 'PEAP' || eapOuter == 'EAP-TTLS') {
michaelpg 2017/05/18 21:14:23 I think these strings are used frequently enough t
stevenjb 2017/05/19 23:35:34 Added to OncTypes.
246 if (!this.configProperties_.WiFi.EAP.Inner)
247 this.configProperties_.WiFi.EAP.Inner = 'Automatic';
michaelpg 2017/05/18 21:14:23 please consider splitting this function up -- it h
stevenjb 2017/05/19 23:35:34 Done.
248 } else {
249 delete this.configProperties_.WiFi.EAP.Inner;
250 }
251 } else {
252 delete this.configProperties_.WiFi.EAP;
253 }
254
255 if (security != this.savedSecurity_) {
256 if (!security || security == CrOnc.Security.NONE) {
257 this.shareNetwork_ = true;
258 } else {
259 // TODO: also check login state.
michaelpg 2017/05/18 21:14:23 (stevenjb)
stevenjb 2017/05/19 23:35:34 Done.
260 this.shareNetwork_ = false;
261 }
262 this.savedSecurity_ = security;
263 }
264 }
265 this.setShowEap_();
266 },
267
268 /**
269 * @param {CrOnc.Type} type The type to compare against.
270 * @param {CrOnc.Type} networkType The current network type.
271 * @return {boolean} True if the network type matches 'type'.
272 * @private
273 */
274 isType_: function(type, networkType) {
275 return type == networkType;
276 },
277
278 /**
279 * @return {boolean}
280 * @private
281 */
282 connectIsEnabled_: function() {
283 if (this.configProperties_.Type == CrOnc.Type.WI_FI) {
284 if (!this.get('WiFi.SSID', this.configProperties_))
285 return false;
286 if (this.showWiFiPassphrase_()) {
287 var passphrase = this.get('WiFi.Passphrase', this.configProperties_);
288 if (!passphrase || passphrase.length < this.MIN_PASSPHRASE_LENGTH)
289 return false;
290 }
291 }
292 // TODO(stevenjb): Check certificates.
293 return true;
294 },
295
296 /**
297 * @return {boolean}
298 * @private
299 */
300 shareIsEnabled_: function() {
301 if (this.configProperties_.Type == CrOnc.Type.WI_FI) {
302 var security = this.get('WiFi.Security', this.configProperties_);
303 if (!security || security == CrOnc.Security.NONE) {
304 return false;
305 } else if (security == CrOnc.Security.WPA_EAP) {
306 var outer = this.get('WiFi.EAP.Outer', this.configProperties_);
307 if (outer === 'EAP-TLS')
308 return false;
309 }
310 // TODO(stevenjb): Check certificates.
311 }
312 // TODO(stevenjb): Check login state.
313 return true;
314 },
315
316 /** @private */
317 onSaveTap_: function() {
318 var newConfig = /** @type {boolean} */ (!this.guid_);
319 var propertiesToSet = Object.assign({}, this.configProperties_);
320 if (newConfig) {
321 this.networkingPrivate.createNetwork(
322 this.shareNetwork_, propertiesToSet,
323 this.createNetworkCallback_.bind(this));
324 } else {
325 propertiesToSet.GUID = this.guid_;
326 this.networkingPrivate.setProperties(
327 this.guid_, propertiesToSet, this.setPropertiesCallback_.bind(this));
328 }
329 },
330
331 /**
332 * @param {string} guid
333 * @private
334 */
335 createNetworkCallback_: function(guid) {
336 var error = chrome.runtime.lastError && chrome.runtime.lastError.message;
337 if (error) {
338 // TODO(stevenjb): Display error message.
339 console.error(
340 'Error creating network type: ' + this.networkProperties_.Type +
341 ': ' + error);
342 return;
343 }
344 this.networkProperties_.GUID = guid;
345 this.fire('network-connect', {networkProperties: this.networkProperties_});
346 this.close_();
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 /**
360 * @return boolean
361 * @private
362 */
363 showWiFiPassphrase_: function() {
364 if (this.configProperties_.Type != CrOnc.Type.WI_FI)
365 return false;
366 var security = this.get('WiFi.Security', this.configProperties_);
367 return security == CrOnc.Security.WEP_PSK ||
368 security == CrOnc.Security.WPA_PSK;
369 },
370
371 /** @private */
372 setShowEap_: function() {
373 var showEap = null;
374 if (this.configProperties_.Type == CrOnc.Type.WI_FI) {
375 var security = this.get('WiFi.Security', this.configProperties_);
376 if (security && security == CrOnc.Security.WPA_EAP) {
michaelpg 2017/05/18 21:14:23 maybe consider early returns instead of nested ifs
stevenjb 2017/05/19 23:35:34 Done.
377 var outer = this.get('WiFi.EAP.Outer', this.configProperties_);
378 showEap = {
379 Inner: outer == 'PEAP' || outer == 'EAP-TTLS',
380 ServerCA: outer != 'LEAP',
381 SubjectMatch: outer == 'EAP-TLS',
382 UserCert: outer == 'EAP-TLS',
383 Password: outer != 'EAP-TLS',
384 AnonymousIdentity: outer == 'PEAP' || outer == 'EAP-TTLS',
385 };
386 }
387 }
388 this.showEap_ = showEap;
michaelpg 2017/05/18 21:14:23 er, is this property not declared/documented?
stevenjb 2017/05/19 23:35:34 Done.
389 },
390
391 /**
392 * @param {string} key
393 * @param {string} prefix
394 * @return {string} The text to display for the onc value.
395 * @private
396 */
397 getOncLabel_: function(key, prefix) {
398 var oncKey = 'Onc' + prefix.replace(/\./g, '-') + '_' + key;
399 if (this.i18nExists(oncKey))
400 return this.i18n(oncKey);
401 return key;
michaelpg 2017/05/18 21:14:23 Huh? Do we intentionally translate some strings bu
stevenjb 2017/05/19 23:35:34 Added an assert.
402 },
403
404 /**
405 * @param {string} outer
406 * @return {!Array<string>}
407 * @private
408 */
409 getEapInnerItems_: function(outer) {
410 if (outer == 'PEAP')
411 return this.eapInnerItemsPeap_;
412 else if (outer == 'EAP-TTLS')
michaelpg 2017/05/18 21:14:23 nit: no else after return
stevenjb 2017/05/19 23:35:34 Done.
413 return this.eapInnerItemsTtls_;
414 return ['Automatic'];
415 },
416 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698