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

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.
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 properties for the network being configured.
stevenjb 2017/05/02 00:17:45 current properties (if any)
24 * @type {!chrome.networkingPrivate.NetworkProperties|undefined}
25 * @private
26 */
27 networkProperties_: Object,
28
29 /**
30 * The configuraiton properties for the network.
31 * @type {!chrome.networkingPrivate.NetworkConfigProperties|undefined}
32 * @private
33 */
34 configProperties_: Object,
35
36 /** @private */
stevenjb 2017/05/02 00:17:45 Document
37 guid_: String,
38
39 /** @private */
stevenjb 2017/05/02 00:17:45 Document
40 title_: String,
41
42 /** @private */
stevenjb 2017/05/02 00:17:45 Document
43 shareNetwork_: Boolean,
44
45 /**
46 * Object providing network type values for data binding.
47 * @const
48 * @private
49 */
50 NetworkType_: {
51 type: Object,
52 value: {
53 CELLULAR: CrOnc.Type.CELLULAR,
54 ETHERNET: CrOnc.Type.ETHERNET,
55 VPN: CrOnc.Type.VPN,
56 WI_FI: CrOnc.Type.WI_FI,
57 WI_MAX: CrOnc.Type.WI_MAX,
58 },
59 readOnly: true
60 },
61
62 /**
63 * @type {!Array<{value: string, label: string}>}
stevenjb 2017/05/02 00:17:45 Document all of these
64 * @private
65 */
66 securityItems_: {
67 type: Array,
68 readOnly: true,
69 value: function() {
70 return [
71 CrOnc.Security.NONE, CrOnc.Security.WEP_PSK, CrOnc.Security.WPA_PSK,
72 CrOnc.Security.WPA_EAP
73 ];
74 }
75 },
76
77 /**
78 * @type {!Array<string>}
79 * @private
80 */
81 eapOuterItems_: {
82 type: Array,
83 readOnly: true,
84 value: function() {
85 return ['LEAP', 'PEAP', 'EAP-TLS', 'EAP-TTLS'];
86 }
87 },
88
89 /**
90 * @type {!Array<string>}
91 * @private
92 */
93 eapInnerItems_: {
94 type: Array,
95 readOnly: true,
96 value: function() {
97 return ['Automatic', 'MD5', 'MSCHAP', 'MSCHAPv2', 'PAP', 'CHAP', 'GTC'];
98 }
99 },
100 },
101
102 observers: ['updateConfigProperties_(configProperties_.*)'],
stevenjb 2017/05/02 00:17:45 Elim
103
104 /**
105 * settings.RouteObserverBehavior
106 * @param {!settings.Route} route
107 * @protected
108 */
109 currentRouteChanged: function(route) {
110 var queryParams = settings.getQueryParameters();
111 this.guid_ = queryParams.get('guid') || '';
112
113 // Set placeholder networkProperties until they are loaded.
stevenjb 2017/05/02 00:17:45 Update comment (not a placeholder of guid is empty
114 var name = queryParams.get('name') || '';
115 var type = /** @type {!chrome.networkingPrivate.NetworkType} */ (
116 queryParams.get('type')) ||
117 CrOnc.Type.WI_FI;
118 this.networkProperties_ = {
119 GUID: this.guid_,
120 Name: name,
121 Type: type,
122 };
123 var configProperties = {Type: type};
124 if (type == CrOnc.Type.WI_FI) {
125 configProperties.WiFi = {
126 SSID: '',
127 Security: CrOnc.Security.NONE,
128 };
129 }
130 this.configProperties_ = configProperties;
131 if (this.guid_) {
132 this.networkingPrivate.getProperties(
133 this.guid_, this.getPropertiesCallback_.bind(this));
134 } else {
135 this.title_ = this.i18n('OncType' + type);
136 this.shareNetwork_ = false;
137 }
138 },
139
140 /** @private */
141 onCancelTap_: function() {
142 this.close_();
143 },
144
145 /** @private */
146 onSaveTap_: function() {
147 var newConfig = /** @type {boolean} */ (!!this.guid_);
148 var id = newConfig ? this.networkProperties_.Type : this.guid_;
149 var handleError = function() {
150 var error = chrome.runtime.lastError;
151 if (error && error.message) {
152 console.error('Error configuring: ' + id + ': ' + error.message);
153 this.close_();
154 }
155 }.bind(this);
156
157 var propertiesToSet = Object.assign({}, this.configProperties_);
158 if (newConfig) {
159 this.networkingPrivate.createNetwork(
160 this.shareNetwork_, propertiesToSet, handleError);
161 } else {
162 propertiesToSet.GUID = this.guid_;
163 this.networkingPrivate.setProperties(
164 this.guid_, propertiesToSet, handleError);
165 }
166 },
167
168 /** @private */
169 close_: function() {
170 // Delay navigating to allow other subpages to load first.
stevenjb 2017/05/02 00:17:45 when called from a getPropertiesCallback_ error.
171 requestAnimationFrame(function() {
172 settings.navigateToPreviousRoute();
173 });
174 },
175
176 /**
177 * networkingPrivate.getProperties callback.
178 * @param {!chrome.networkingPrivate.NetworkProperties} properties
179 * @private
180 */
181 getPropertiesCallback_: function(properties) {
182 if (!properties) {
stevenjb 2017/05/02 00:17:45 Test lastError
183 // If |properties| is null, the network no longer exists; close the page.
184 console.error('Network no longer exists: ' + this.guid_);
185 this.close_();
186 return;
187 }
188 this.networkProperties_ = properties;
189 this.title_ = properties.Name || this.i18n('OncType' + properties.Type);
190 this.shareNetwork_ = properties.Source == CrOnc.Source.DEVICE ||
191 properties.Source == CrOnc.Source.DEVICE_POLICY;
192
193 var configProperties =
194 /** @type {chrome.networkingPrivate.NetworkConfigProperties} */ ({
195 Name: properties.Name,
196 Type: properties.Type,
197 });
198 if (properties.WiFi) {
199 configProperties.WiFi = {
200 AutoConnect: properties.WiFi.AutoConnect,
201 EAP: properties.WiFi.EAP,
202 Passphrase: properties.WiFi.Passphrase,
203 SSID: properties.WiFi.SSID,
204 Security: properties.WiFi.Security
205 };
206 }
207 this.configProperties_ = configProperties;
208 this.updateConfigProperties_();
209 },
210
211 /** @private */
212 updateConfigProperties_: function() {
stevenjb 2017/05/02 00:17:45 Elim (merge with above)
213 if (this.configProperties_.WiFi) {
214 if (this.configProperties_.WiFi.Security == CrOnc.Security.WPA_EAP) {
215 this.configProperties_.WiFi.EAP = this.configProperties_.WiFi.EAP || {
216 Outer: 'LEAP',
217 };
218 } else {
219 delete this.configProperties_.WiFi.EAP;
220 }
221 }
222 },
223
224 /**
225 * @param {string} type The network type.
226 * @param {!CrOnc.NetworkProperties} networkProperties
227 * @return {boolean} True if the network type matches 'type'.
228 * @private
229 */
230 isType_: function(type, networkProperties) {
231 return networkProperties.Type == type;
232 },
233
234 /**
235 * @return boolean
236 * @private
237 */
238 showPassphrase_() {
239 if (this.configProperties_.Type != CrOnc.Type.WI_FI)
240 return false;
241 var security = this.get('Security', this.configProperties_.WiFi);
242 return !!security &&
243 (security == CrOnc.Security.WEP_PSK ||
244 security == CrOnc.Security.WPA_PSK);
245 },
246
247 /**
248 * @return boolean
249 * @private
250 */
251 showEap_() {
252 if (this.configProperties_.Type != CrOnc.Type.WI_FI)
253 return false;
254 var security = this.get('Security', this.configProperties_.WiFi);
255 return !!security && security == CrOnc.Security.WPA_EAP;
256 },
257
258 /**
259 * @param {string} key
260 * @param {string} prefix
261 * @return {string} The text to display for the onc value.
262 * @private
263 */
264 getOncLabel_: function(key, prefix) {
265 var oncKey = 'Onc' + prefix.replace(/\./g, '-') + '_' + key;
266 if (this.i18nExists(oncKey))
267 return this.i18n(oncKey);
268 return key;
269 }
270 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698