OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview | 6 * @fileoverview |
7 * 'settings-internet-detail' is the settings subpage containing details | 7 * 'settings-internet-detail' is the settings subpage containing details |
8 * for a network. | 8 * for a network. |
9 */ | 9 */ |
10 (function() { | 10 (function() { |
(...skipping 14 matching lines...) Expand all Loading... | |
25 type: String, | 25 type: String, |
26 value: '', | 26 value: '', |
27 }, | 27 }, |
28 | 28 |
29 /** | 29 /** |
30 * The current properties for the network matching |guid|. | 30 * The current properties for the network matching |guid|. |
31 * @type {!CrOnc.NetworkProperties|undefined} | 31 * @type {!CrOnc.NetworkProperties|undefined} |
32 */ | 32 */ |
33 networkProperties: { | 33 networkProperties: { |
34 type: Object, | 34 type: Object, |
35 observer: 'networkPropertiesChanged_' | 35 observer: 'networkPropertiesChanged_', |
36 }, | 36 }, |
37 | 37 |
38 /** | 38 /** |
39 * The network AutoConnect state. | 39 * The network AutoConnect state. |
40 */ | 40 */ |
41 autoConnect: { | 41 autoConnect: { |
42 type: Boolean, | 42 type: Boolean, |
43 value: false, | 43 value: false, |
44 observer: 'autoConnectChanged_' | 44 observer: 'autoConnectChanged_', |
45 }, | 45 }, |
46 | 46 |
47 /** | 47 /** |
48 * The network preferred state. | 48 * The network preferred state. |
49 */ | 49 */ |
50 preferNetwork: { | 50 preferNetwork: { |
51 type: Boolean, | 51 type: Boolean, |
52 value: false, | 52 value: false, |
53 observer: 'preferNetworkChanged_' | 53 observer: 'preferNetworkChanged_', |
54 }, | 54 }, |
55 | 55 |
56 /** | 56 /** |
57 * The network IP Address. | 57 * The network IP Address. |
58 */ | 58 */ |
59 IPAddress: { | 59 IPAddress: { |
60 type: String, | 60 type: String, |
61 value: '' | 61 value: '', |
62 }, | 62 }, |
63 | 63 |
64 /** | 64 /** |
65 * Highest priority connected network or null. | 65 * Highest priority connected network or null. |
66 * @type {?CrOnc.NetworkStateProperties} | 66 * @type {?CrOnc.NetworkStateProperties} |
67 */ | 67 */ |
68 defaultNetwork: { | 68 defaultNetwork: { |
69 type: Object, | 69 type: Object, |
70 value: null | 70 value: null, |
71 }, | 71 }, |
72 | 72 |
73 advancedExpanded: { type: Boolean }, | |
74 | |
73 /** | 75 /** |
74 * Object providing network type values for data binding. | 76 * Object providing network type values for data binding. |
75 * @const | 77 * @const |
76 */ | 78 */ |
77 NetworkType: { | 79 NetworkType: { |
78 type: Object, | 80 type: Object, |
79 value: { | 81 value: { |
80 CELLULAR: CrOnc.Type.CELLULAR, | 82 CELLULAR: CrOnc.Type.CELLULAR, |
81 ETHERNET: CrOnc.Type.ETHERNET, | 83 ETHERNET: CrOnc.Type.ETHERNET, |
82 VPN: CrOnc.Type.VPN, | 84 VPN: CrOnc.Type.VPN, |
83 WIFI: CrOnc.Type.WI_FI, | 85 WIFI: CrOnc.Type.WI_FI, |
84 WIMAX: CrOnc.Type.WI_MAX, | 86 WIMAX: CrOnc.Type.WI_MAX, |
85 }, | 87 }, |
86 readOnly: true | 88 readOnly: true |
87 }, | 89 }, |
88 | 90 |
89 /** | 91 /** |
90 * Interface for networkingPrivate calls, passed from internet_page. | 92 * Interface for networkingPrivate calls, passed from internet_page. |
91 * @type {NetworkingPrivate} | 93 * @type {NetworkingPrivate} |
92 */ | 94 */ |
93 networkingPrivate: { | 95 networkingPrivate: {type: Object}, |
94 type: Object, | |
95 }, | |
96 }, | 96 }, |
97 | 97 |
98 observers: [ | 98 observers: [ |
99 'guidChanged_(guid, networkingPrivate)', | 99 'guidChanged_(guid, networkingPrivate)', |
100 ], | 100 ], |
101 | 101 |
102 /** | 102 /** |
103 * Listener function for chrome.networkingPrivate.onNetworksChanged event. | 103 * Listener function for chrome.networkingPrivate.onNetworksChanged event. |
104 * @type {function(!Array<string>)} | 104 * @type {function(!Array<string>)} |
105 * @private | 105 * @private |
106 */ | 106 */ |
107 networksChangedListener_: function() {}, | 107 networksChangedListener_: function() {}, |
108 | 108 |
109 /** @override */ | 109 /** @override */ |
110 attached: function() { | 110 attached: function() { |
111 this.networksChangedListener_ = this.onNetworksChangedEvent_.bind(this); | 111 this.networksChangedListener_ = this.onNetworksChangedEvent_.bind(this); |
112 this.networkingPrivate.onNetworksChanged.addListener( | 112 this.networkingPrivate.onNetworksChanged.addListener( |
113 this.networksChangedListener_); | 113 this.networksChangedListener_); |
114 }, | 114 }, |
115 | 115 |
116 /** @override */ | 116 /** @override */ |
117 detached: function() { | 117 detached: function() { |
118 this.networkingPrivate.onNetworksChanged.removeListener( | 118 this.networkingPrivate.onNetworksChanged.removeListener( |
119 this.networksChangedListener_); | 119 this.networksChangedListener_); |
120 }, | 120 }, |
121 | 121 |
122 /** | 122 /** @private */ |
123 * Polymer guid changed method. | |
124 */ | |
125 guidChanged_: function() { | 123 guidChanged_: function() { |
126 if (!this.guid) | 124 if (!this.guid) |
127 return; | 125 return; |
128 this.getNetworkDetails_(); | 126 this.getNetworkDetails_(); |
129 }, | 127 }, |
130 | 128 |
131 /** | 129 /** @private */ |
132 * Polymer networkProperties changed method. | |
133 */ | |
134 networkPropertiesChanged_: function() { | 130 networkPropertiesChanged_: function() { |
135 if (!this.networkProperties) | 131 if (!this.networkProperties) |
136 return; | 132 return; |
137 | 133 |
138 // Update autoConnect if it has changed. Default value is false. | 134 // Update autoConnect if it has changed. Default value is false. |
139 var autoConnect = CrOnc.getAutoConnect(this.networkProperties); | 135 var autoConnect = CrOnc.getAutoConnect(this.networkProperties); |
140 if (autoConnect != this.autoConnect) | 136 if (autoConnect != this.autoConnect) |
141 this.autoConnect = autoConnect; | 137 this.autoConnect = autoConnect; |
142 | 138 |
143 // Update preferNetwork if it has changed. Default value is false. | 139 // Update preferNetwork if it has changed. Default value is false. |
144 var priority = /** @type {number} */(CrOnc.getActiveValue( | 140 var priority = /** @type {number} */ ( |
145 this.networkProperties.Priority) || 0); | 141 CrOnc.getActiveValue(this.networkProperties.Priority) || 0); |
146 var preferNetwork = priority > 0; | 142 var preferNetwork = priority > 0; |
147 if (preferNetwork != this.preferNetwork) | 143 if (preferNetwork != this.preferNetwork) |
148 this.preferNetwork = preferNetwork; | 144 this.preferNetwork = preferNetwork; |
149 | 145 |
150 // Set the IPAddress property to the IPV4 Address. | 146 // Set the IPAddress property to the IPV4 Address. |
151 var ipv4 = | 147 var ipv4 = |
152 CrOnc.getIPConfigForType(this.networkProperties, CrOnc.IPType.IPV4); | 148 CrOnc.getIPConfigForType(this.networkProperties, CrOnc.IPType.IPV4); |
153 this.IPAddress = (ipv4 && ipv4.IPAddress) || ''; | 149 this.IPAddress = (ipv4 && ipv4.IPAddress) || ''; |
154 }, | 150 }, |
155 | 151 |
156 /** | 152 /** @private */ |
157 * Polymer autoConnect changed method. | |
158 */ | |
159 autoConnectChanged_: function() { | 153 autoConnectChanged_: function() { |
160 if (!this.networkProperties || !this.guid) | 154 if (!this.networkProperties || !this.guid) |
161 return; | 155 return; |
162 var onc = this.getEmptyNetworkProperties_(); | 156 var onc = this.getEmptyNetworkProperties_(); |
163 CrOnc.setTypeProperty(onc, 'AutoConnect', this.autoConnect); | 157 CrOnc.setTypeProperty(onc, 'AutoConnect', this.autoConnect); |
164 this.setNetworkProperties_(onc); | 158 this.setNetworkProperties_(onc); |
165 }, | 159 }, |
166 | 160 |
167 /** | 161 /** @private */ |
168 * Polymer preferNetwork changed method. | |
169 */ | |
170 preferNetworkChanged_: function() { | 162 preferNetworkChanged_: function() { |
171 if (!this.networkProperties || !this.guid) | 163 if (!this.networkProperties || !this.guid) |
172 return; | 164 return; |
173 var onc = this.getEmptyNetworkProperties_(); | 165 var onc = this.getEmptyNetworkProperties_(); |
174 onc.Priority = this.preferNetwork ? 1 : 0; | 166 onc.Priority = this.preferNetwork ? 1 : 0; |
175 this.setNetworkProperties_(onc); | 167 this.setNetworkProperties_(onc); |
176 }, | 168 }, |
177 | 169 |
178 /** | 170 /** |
179 * networkingPrivate.onNetworksChanged event callback. | 171 * networkingPrivate.onNetworksChanged event callback. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 getEmptyNetworkProperties_: function() { | 228 getEmptyNetworkProperties_: function() { |
237 return {Type: this.networkProperties.Type}; | 229 return {Type: this.networkProperties.Type}; |
238 }, | 230 }, |
239 | 231 |
240 /** | 232 /** |
241 * @param {!CrOnc.NetworkProperties} properties | 233 * @param {!CrOnc.NetworkProperties} properties |
242 * @return {string} The text to display for the network name. | 234 * @return {string} The text to display for the network name. |
243 * @private | 235 * @private |
244 */ | 236 */ |
245 getStateName_: function(properties) { | 237 getStateName_: function(properties) { |
246 return /** @type {string} */(CrOnc.getActiveValue( | 238 return /** @type {string} */ ( |
247 this.networkProperties.Name) || ''); | 239 CrOnc.getActiveValue(this.networkProperties.Name) || ''); |
248 }, | 240 }, |
249 | 241 |
250 /** | 242 /** |
251 * @param {!CrOnc.NetworkProperties} properties | 243 * @param {!CrOnc.NetworkProperties} properties |
252 * @return {string} The text to display for the network connection state. | 244 * @return {string} The text to display for the network connection state. |
253 * @private | 245 * @private |
254 */ | 246 */ |
255 getStateText_: function(properties) { | 247 getStateText_: function(properties) { |
256 // TODO(stevenjb): Localize. | 248 // TODO(stevenjb): Localize. |
257 return (properties && properties.ConnectionState) || ''; | 249 return (properties && properties.ConnectionState) || ''; |
258 }, | 250 }, |
259 | 251 |
260 /** | 252 /** |
261 * @param {!CrOnc.NetworkProperties} properties | 253 * @param {!CrOnc.NetworkProperties} properties |
262 * @return {boolean} True if the network is connected. | 254 * @return {boolean} True if the network is connected. |
263 * @private | 255 * @private |
264 */ | 256 */ |
265 isConnectedState_: function(properties) { | 257 isConnectedState_: function(properties) { |
266 return properties.ConnectionState == CrOnc.ConnectionState.CONNECTED; | 258 return properties.ConnectionState == CrOnc.ConnectionState.CONNECTED; |
267 }, | 259 }, |
268 | 260 |
269 /** | 261 /** |
270 * @param {!CrOnc.NetworkProperties} properties | 262 * @param {!CrOnc.NetworkProperties} properties |
271 * @return {boolean} Whether or not to show the 'Connect' button. | 263 * @return {boolean} |
272 * @private | 264 * @private |
273 */ | 265 */ |
274 showConnect_: function(properties) { | 266 showConnect_: function(properties) { |
275 return properties.Type != CrOnc.Type.ETHERNET && | 267 return properties.Type != CrOnc.Type.ETHERNET && |
276 properties.ConnectionState == CrOnc.ConnectionState.NOT_CONNECTED; | 268 properties.ConnectionState == CrOnc.ConnectionState.NOT_CONNECTED; |
277 }, | 269 }, |
278 | 270 |
279 /** | 271 /** |
280 * @param {!CrOnc.NetworkProperties} properties | 272 * @param {!CrOnc.NetworkProperties} properties |
281 * @return {boolean} Whether or not to show the 'Activate' button. | 273 * @return {boolean} |
282 * @private | 274 * @private |
283 */ | 275 */ |
284 showActivate_: function(properties) { | 276 showActivate_: function(properties) { |
285 if (!properties || properties.Type != CrOnc.Type.CELLULAR) | 277 if (!properties || properties.Type != CrOnc.Type.CELLULAR) |
286 return false; | 278 return false; |
287 var activation = properties.Cellular.ActivationState; | 279 var activation = properties.Cellular.ActivationState; |
288 return activation == CrOnc.ActivationState.NOT_ACTIVATED || | 280 return activation == CrOnc.ActivationState.NOT_ACTIVATED || |
289 activation == CrOnc.ActivationState.PARTIALLY_ACTIVATED; | 281 activation == CrOnc.ActivationState.PARTIALLY_ACTIVATED; |
290 }, | 282 }, |
291 | 283 |
292 /** | 284 /** |
293 * @param {!CrOnc.NetworkProperties} properties | 285 * @param {!CrOnc.NetworkProperties} properties |
294 * @return {boolean} Whether or not to show the 'View Account' button. | 286 * @return {boolean} |
295 * @private | 287 * @private |
296 */ | 288 */ |
297 showViewAccount_: function(properties) { | 289 showViewAccount_: function(properties) { |
298 // Show either the 'Activate' or the 'View Account' button. | 290 // Show either the 'Activate' or the 'View Account' button. |
299 if (this.showActivate_(properties)) | 291 if (this.showActivate_(properties)) |
300 return false; | 292 return false; |
301 | 293 |
302 if (!properties || properties.Type != CrOnc.Type.CELLULAR || | 294 if (!properties || properties.Type != CrOnc.Type.CELLULAR || |
303 !properties.Cellular) { | 295 !properties.Cellular) { |
304 return false; | 296 return false; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
337 return false; | 329 return false; |
338 if (properties.Type == CrOnc.Type.CELLULAR && CrOnc.isSimLocked(properties)) | 330 if (properties.Type == CrOnc.Type.CELLULAR && CrOnc.isSimLocked(properties)) |
339 return false; | 331 return false; |
340 if (properties.Type == CrOnc.Type.VPN && !defaultNetwork) | 332 if (properties.Type == CrOnc.Type.VPN && !defaultNetwork) |
341 return false; | 333 return false; |
342 return true; | 334 return true; |
343 }, | 335 }, |
344 | 336 |
345 /** | 337 /** |
346 * @param {!CrOnc.NetworkProperties} properties | 338 * @param {!CrOnc.NetworkProperties} properties |
347 * @return {boolean} Whether or not to show the 'Disconnect' button. | 339 * @return {boolean} |
348 * @private | 340 * @private |
349 */ | 341 */ |
350 showDisconnect_: function(properties) { | 342 showDisconnect_: function(properties) { |
351 return properties.Type != CrOnc.Type.ETHERNET && | 343 return properties.Type != CrOnc.Type.ETHERNET && |
352 properties.ConnectionState != CrOnc.ConnectionState.NOT_CONNECTED; | 344 properties.ConnectionState != CrOnc.ConnectionState.NOT_CONNECTED; |
353 }, | 345 }, |
354 | 346 |
355 /** | 347 /** @private */ |
356 * Callback when the Connect button is tapped. | 348 onConnectTap_: function() { this.networkingPrivate.startConnect(this.guid); }, |
357 * @private | |
358 */ | |
359 onConnectTap_: function() { | |
360 this.networkingPrivate.startConnect(this.guid); | |
361 }, | |
362 | 349 |
363 /** | 350 /** @private */ |
364 * Callback when the Disconnect button is tapped. | |
365 * @private | |
366 */ | |
367 onDisconnectTap_: function() { | 351 onDisconnectTap_: function() { |
368 this.networkingPrivate.startDisconnect(this.guid); | 352 this.networkingPrivate.startDisconnect(this.guid); |
369 }, | 353 }, |
370 | 354 |
371 /** | 355 /** @private */ |
372 * Callback when the Activate button is tapped. | |
373 * @private | |
374 */ | |
375 onActivateTap_: function() { | 356 onActivateTap_: function() { |
376 this.networkingPrivate.startActivate(this.guid); | 357 this.networkingPrivate.startActivate(this.guid); |
377 }, | 358 }, |
378 | 359 |
379 /** | 360 /** @private */ |
380 * Callback when the View Account button is tapped. | |
381 * @private | |
382 */ | |
383 onViewAccountTap_: function() { | 361 onViewAccountTap_: function() { |
384 // startActivate() will show the account page for activated networks. | 362 // startActivate() will show the account page for activated networks. |
385 this.networkingPrivate.startActivate(this.guid); | 363 this.networkingPrivate.startActivate(this.guid); |
386 }, | 364 }, |
387 | 365 |
388 /** | 366 /** |
367 * @param {Event} event | |
368 * @private | |
369 */ | |
370 toggleAdvancedExpanded_: function(event) { | |
371 if (event.target.id == 'expandButton') | |
372 return; // Already handled. | |
373 this.advancedExpanded = !this.advancedExpanded; | |
374 }, | |
375 | |
376 /** | |
389 * Event triggered for elements associated with network properties. | 377 * Event triggered for elements associated with network properties. |
390 * @param {!{detail: !{field: string, value: (string|!Object)}}} event | 378 * @param {!{detail: !{field: string, value: (string|!Object)}}} event |
391 * @private | 379 * @private |
392 */ | 380 */ |
393 onNetworkPropertyChange_: function(event) { | 381 onNetworkPropertyChange_: function(event) { |
394 if (!this.networkProperties) | 382 if (!this.networkProperties) |
395 return; | 383 return; |
396 var field = event.detail.field; | 384 var field = event.detail.field; |
397 var value = event.detail.value; | 385 var value = event.detail.value; |
398 var onc = this.getEmptyNetworkProperties_(); | 386 var onc = this.getEmptyNetworkProperties_(); |
(...skipping 18 matching lines...) Expand all Loading... | |
417 */ | 405 */ |
418 onIPConfigChange_: function(event) { | 406 onIPConfigChange_: function(event) { |
419 if (!this.networkProperties) | 407 if (!this.networkProperties) |
420 return; | 408 return; |
421 var field = event.detail.field; | 409 var field = event.detail.field; |
422 var value = event.detail.value; | 410 var value = event.detail.value; |
423 // Get an empty ONC dictionary and set just the IP Config properties that | 411 // Get an empty ONC dictionary and set just the IP Config properties that |
424 // need to change. | 412 // need to change. |
425 var onc = this.getEmptyNetworkProperties_(); | 413 var onc = this.getEmptyNetworkProperties_(); |
426 var ipConfigType = | 414 var ipConfigType = |
427 /** @type {chrome.networkingPrivate.IPConfigType|undefined} */( | 415 /** @type {chrome.networkingPrivate.IPConfigType|undefined} */ ( |
428 CrOnc.getActiveValue(this.networkProperties.IPAddressConfigType)); | 416 CrOnc.getActiveValue(this.networkProperties.IPAddressConfigType)); |
429 if (field == 'IPAddressConfigType') { | 417 if (field == 'IPAddressConfigType') { |
430 var newIpConfigType = | 418 var newIpConfigType = |
431 /** @type {chrome.networkingPrivate.IPConfigType} */(value); | 419 /** @type {chrome.networkingPrivate.IPConfigType} */ (value); |
432 if (newIpConfigType == ipConfigType) | 420 if (newIpConfigType == ipConfigType) |
433 return; | 421 return; |
434 onc.IPAddressConfigType = newIpConfigType; | 422 onc.IPAddressConfigType = newIpConfigType; |
435 } else if (field == 'NameServersConfigType') { | 423 } else if (field == 'NameServersConfigType') { |
436 var nsConfigType = | 424 var nsConfigType = |
437 /** @type {chrome.networkingPrivate.IPConfigType|undefined} */( | 425 /** @type {chrome.networkingPrivate.IPConfigType|undefined} */ ( |
438 CrOnc.getActiveValue( | 426 CrOnc.getActiveValue( |
439 this.networkProperties.NameServersConfigType)); | 427 this.networkProperties.NameServersConfigType)); |
440 var newNsConfigType = | 428 var newNsConfigType = |
441 /** @type {chrome.networkingPrivate.IPConfigType} */(value); | 429 /** @type {chrome.networkingPrivate.IPConfigType} */ (value); |
442 if (newNsConfigType == nsConfigType) | 430 if (newNsConfigType == nsConfigType) |
443 return; | 431 return; |
444 onc.NameServersConfigType = newNsConfigType; | 432 onc.NameServersConfigType = newNsConfigType; |
445 } else if (field == 'StaticIPConfig') { | 433 } else if (field == 'StaticIPConfig') { |
446 if (ipConfigType == CrOnc.IPConfigType.STATIC) { | 434 if (ipConfigType == CrOnc.IPConfigType.STATIC) { |
447 var staticIpConfig = this.networkProperties.StaticIPConfig; | 435 let staticIpConfig = this.networkProperties.StaticIPConfig; |
436 let ipConfigValue = /** @type {!Object} */ (value); | |
448 if (staticIpConfig && | 437 if (staticIpConfig && |
449 this.allPropertiesMatch_(staticIpConfig, | 438 this.allPropertiesMatch_(staticIpConfig, ipConfigValue)) { |
450 /** @type {!Object} */(value))) { | |
451 return; | 439 return; |
452 } | 440 } |
453 } | 441 } |
454 onc.IPAddressConfigType = CrOnc.IPConfigType.STATIC; | 442 onc.IPAddressConfigType = CrOnc.IPConfigType.STATIC; |
455 if (!onc.StaticIPConfig) { | 443 if (!onc.StaticIPConfig) { |
456 onc.StaticIPConfig = | 444 onc.StaticIPConfig = |
457 /** @type {!chrome.networkingPrivate.IPConfigProperties} */({}); | 445 /** @type {!chrome.networkingPrivate.IPConfigProperties} */ ({}); |
458 } | 446 } |
459 for (let key in value) | 447 for (let key in value) |
460 onc.StaticIPConfig[key] = value[key]; | 448 onc.StaticIPConfig[key] = value[key]; |
461 } else if (field == 'NameServers') { | 449 } else if (field == 'NameServers') { |
462 // If a StaticIPConfig property is specified and its NameServers value | 450 // If a StaticIPConfig property is specified and its NameServers value |
463 // matches the new value, no need to set anything. | 451 // matches the new value, no need to set anything. |
464 var nameServers = /** @type {!Array<string>} */(value); | 452 let nameServers = /** @type {!Array<string>} */ (value); |
465 if (onc.NameServersConfigType == CrOnc.IPConfigType.STATIC && | 453 if (onc.NameServersConfigType == CrOnc.IPConfigType.STATIC && |
466 onc.StaticIPConfig && | 454 onc.StaticIPConfig && onc.StaticIPConfig.NameServers == nameServers) { |
467 onc.StaticIPConfig.NameServers == nameServers) { | |
468 return; | 455 return; |
469 } | 456 } |
470 onc.NameServersConfigType = CrOnc.IPConfigType.STATIC; | 457 onc.NameServersConfigType = CrOnc.IPConfigType.STATIC; |
471 if (!onc.StaticIPConfig) { | 458 if (!onc.StaticIPConfig) { |
472 onc.StaticIPConfig = | 459 onc.StaticIPConfig = |
473 /** @type {!chrome.networkingPrivate.IPConfigProperties} */({}); | 460 /** @type {!chrome.networkingPrivate.IPConfigProperties} */ ({}); |
474 } | 461 } |
475 onc.StaticIPConfig.NameServers = nameServers; | 462 onc.StaticIPConfig.NameServers = nameServers; |
476 } else { | 463 } else { |
477 console.error('Unexpected change field: ' + field); | 464 console.error('Unexpected change field: ' + field); |
478 return; | 465 return; |
479 } | 466 } |
480 // setValidStaticIPConfig will fill in any other properties from | 467 // setValidStaticIPConfig will fill in any other properties from |
481 // networkProperties. This is necessary since we update IP Address and | 468 // networkProperties. This is necessary since we update IP Address and |
482 // NameServers independently. | 469 // NameServers independently. |
483 CrOnc.setValidStaticIPConfig(onc, this.networkProperties); | 470 CrOnc.setValidStaticIPConfig(onc, this.networkProperties); |
484 this.setNetworkProperties_(onc); | 471 this.setNetworkProperties_(onc); |
485 }, | 472 }, |
486 | 473 |
487 /** | 474 /** |
488 * Event triggered when the Proxy configuration element changes. | 475 * Event triggered when the Proxy configuration element changes. |
489 * @param {!{detail: {field: string, value: !CrOnc.ProxySettings}}} event | 476 * @param {!{detail: {field: string, value: !CrOnc.ProxySettings}}} event |
490 * The network-proxy change event. | 477 * The network-proxy change event. |
491 * @private | 478 * @private |
492 */ | 479 */ |
493 onProxyChange_: function(event) { | 480 onProxyChange_: function(event) { |
494 if (!this.networkProperties) | 481 if (!this.networkProperties) |
495 return; | 482 return; |
496 var field = event.detail.field; | 483 var field = event.detail.field; |
497 var value = event.detail.value; | 484 var value = event.detail.value; |
498 if (field != 'ProxySettings') | 485 if (field != 'ProxySettings') |
499 return; | 486 return; |
500 var onc = this.getEmptyNetworkProperties_(); | 487 var onc = this.getEmptyNetworkProperties_(); |
501 CrOnc.setProperty(onc, 'ProxySettings', /** @type {!Object} */(value)); | 488 CrOnc.setProperty(onc, 'ProxySettings', /** @type {!Object} */ (value)); |
502 this.setNetworkProperties_(onc); | 489 this.setNetworkProperties_(onc); |
503 }, | 490 }, |
504 | 491 |
505 /** | 492 /** |
506 * @param {!CrOnc.NetworkProperties} properties | 493 * @param {!CrOnc.NetworkProperties} properties |
507 * @return {boolean} True if the shared message should be shown. | 494 * @return {boolean} True if the shared message should be shown. |
508 * @private | 495 * @private |
509 */ | 496 */ |
510 showShared_: function(properties) { | 497 showShared_: function(properties) { |
511 return properties.Source == 'Device' || properties.Source == 'DevicePolicy'; | 498 return properties.Source == 'Device' || properties.Source == 'DevicePolicy'; |
512 }, | 499 }, |
513 | 500 |
514 /** | 501 /** |
515 * @param {!CrOnc.NetworkProperties} properties | 502 * @param {!CrOnc.NetworkProperties} properties |
516 * @return {boolean} True if the AutoConnect checkbox should be shown. | 503 * @return {boolean} True if the AutoConnect checkbox should be shown. |
517 * @private | 504 * @private |
518 */ | 505 */ |
519 showAutoConnect_: function(properties) { | 506 showAutoConnect_: function(properties) { |
520 return properties.Type != CrOnc.Type.ETHERNET && | 507 return properties.Type != CrOnc.Type.ETHERNET && |
521 properties.Source != CrOnc.Source.NONE; | 508 properties.Source != CrOnc.Source.NONE; |
522 }, | 509 }, |
523 | 510 |
524 /** | 511 /** |
525 * @param {!CrOnc.NetworkProperties} properties | 512 * @param {!CrOnc.NetworkProperties} properties |
526 * @return {!CrOnc.ManagedProperty|undefined} Managed AutoConnect property. | 513 * @return {!CrOnc.ManagedProperty|undefined} Managed AutoConnect property. |
527 * @private | 514 * @private |
528 */ | 515 */ |
529 getManagedAutoConnect_: function(properties) { | 516 getManagedAutoConnect_: function(properties) { |
530 return CrOnc.getManagedAutoConnect(properties); | 517 return CrOnc.getManagedAutoConnect(properties); |
531 }, | 518 }, |
532 | 519 |
533 /** | 520 /** |
534 * @param {!CrOnc.NetworkProperties} properties | 521 * @param {!CrOnc.NetworkProperties} properties |
535 * @return {boolean} True if the prefer network checkbox should be shown. | 522 * @return {boolean} True if the prefer network checkbox should be shown. |
536 * @private | 523 * @private |
537 */ | 524 */ |
538 showPreferNetwork_: function(properties) { | 525 showPreferNetwork_: function(properties) { |
539 // TODO(stevenjb): Resolve whether or not we want to allow "preferred" for | 526 // TODO(stevenjb): Resolve whether or not we want to allow "preferred" for |
540 // properties.Type == CrOnc.Type.ETHERNET. | 527 // properties.Type == CrOnc.Type.ETHERNET. |
541 return properties.Source != CrOnc.Source.NONE; | 528 return properties.Source != CrOnc.Source.NONE; |
542 }, | 529 }, |
543 | 530 |
544 /** | 531 /** |
545 * @param {boolean} preferNetwork | 532 * @param {!Array<string>} fields |
546 * @return {string} The icon to use for the preferred button. | 533 * @return {boolean} |
547 * @private | 534 * @private |
548 */ | 535 */ |
549 getPreferredIcon_: function(preferNetwork) { | 536 hasVisibleFields_: function(fields) { |
550 return preferNetwork ? 'cr:star' : 'cr:star-border'; | 537 for (let key of fields) { |
538 let value = this.get(key, this.networkProperties); | |
539 if (value !== undefined && value !== '') | |
540 return true; | |
541 } | |
542 return false; | |
551 }, | 543 }, |
552 | 544 |
553 /** | 545 /** |
546 * @param {!CrOnc.NetworkProperties} properties | |
547 * @return {boolean} | |
548 * @private | |
549 */ | |
550 hasInfoFields_: function(properties) { | |
551 return this.hasVisibleFields_(this.getInfoFields_(properties)); | |
552 }, | |
553 | |
554 /** | |
554 * @param {!CrOnc.NetworkProperties} properties | 555 * @param {!CrOnc.NetworkProperties} properties |
555 * @return {!Array<string>} The fields to display in the info section. | 556 * @return {!Array<string>} The fields to display in the info section. |
556 * @private | 557 * @private |
557 */ | 558 */ |
558 getInfoFields_: function(properties) { | 559 getInfoFields_: function(properties) { |
559 /** @type {!Array<string>} */ var fields = []; | 560 /** @type {!Array<string>} */ var fields = []; |
560 if (!properties) | 561 if (!properties) |
561 return fields; | 562 return fields; |
562 | 563 |
563 if (properties.Type == CrOnc.Type.CELLULAR) { | 564 if (properties.Type == CrOnc.Type.CELLULAR) { |
564 fields.push('Cellular.ActivationState', | 565 fields.push( |
565 'Cellular.RoamingState', | 566 'Cellular.ActivationState', 'Cellular.RoamingState', |
566 'RestrictedConnectivity', | 567 'RestrictedConnectivity', 'Cellular.ServingOperator.Name'); |
567 'Cellular.ServingOperator.Name'); | |
568 } | 568 } |
569 if (properties.Type == CrOnc.Type.VPN) { | 569 if (properties.Type == CrOnc.Type.VPN) { |
570 fields.push('VPN.Host', 'VPN.Type'); | 570 fields.push('VPN.Host', 'VPN.Type'); |
571 if (properties.VPN.Type == 'OpenVPN') | 571 if (properties.VPN.Type == 'OpenVPN') |
572 fields.push('VPN.OpenVPN.Username'); | 572 fields.push('VPN.OpenVPN.Username'); |
573 else if (properties.VPN.Type == 'L2TP-IPsec') | 573 else if (properties.VPN.Type == 'L2TP-IPsec') |
574 fields.push('VPN.L2TP.Username'); | 574 fields.push('VPN.L2TP.Username'); |
575 else if (properties.VPN.Type == 'ThirdPartyVPN') | 575 else if (properties.VPN.Type == 'ThirdPartyVPN') |
576 fields.push('VPN.ThirdPartyVPN.ProviderName'); | 576 fields.push('VPN.ThirdPartyVPN.ProviderName'); |
577 } | 577 } |
578 if (properties.Type == CrOnc.Type.WI_FI) | 578 if (properties.Type == CrOnc.Type.WI_FI) |
579 fields.push('RestrictedConnectivity'); | 579 fields.push('RestrictedConnectivity'); |
580 if (properties.Type == CrOnc.Type.WI_MAX) { | 580 if (properties.Type == CrOnc.Type.WI_MAX) { |
581 fields.push('RestrictedConnectivity', 'WiMAX.EAP.Identity'); | 581 fields.push('RestrictedConnectivity', 'WiMAX.EAP.Identity'); |
582 } | 582 } |
583 return fields; | 583 return fields; |
584 }, | 584 }, |
585 | 585 |
586 /** | 586 /** |
587 * @param {!CrOnc.NetworkProperties} properties | 587 * @param {!CrOnc.NetworkProperties} properties |
588 * @return {!Array<string>} The fields to display in the Advanced section. | 588 * @return {!Array<string>} The fields to display in the Advanced section. |
589 * @private | 589 * @private |
590 */ | 590 */ |
591 getAdvancedFields_: function(properties) { | 591 getAdvancedFields_: function(properties) { |
592 /** @type {!Array<string>} */ var fields = []; | 592 /** @type {!Array<string>} */ var fields = []; |
593 if (!properties) | 593 if (!properties) |
594 return fields; | 594 return fields; |
595 fields.push('MacAddress'); | 595 fields.push('MacAddress'); |
596 if (properties.Type == CrOnc.Type.CELLULAR) { | 596 if (properties.Type == CrOnc.Type.CELLULAR) { |
597 fields.push('Cellular.Carrier', | 597 fields.push( |
598 'Cellular.Family', | 598 'Cellular.Carrier', 'Cellular.Family', 'Cellular.NetworkTechnology', |
599 'Cellular.NetworkTechnology', | 599 'Cellular.ServingOperator.Code'); |
600 'Cellular.ServingOperator.Code'); | |
601 } | 600 } |
602 if (properties.Type == CrOnc.Type.WI_FI) { | 601 if (properties.Type == CrOnc.Type.WI_FI) { |
603 fields.push('WiFi.SSID', | 602 fields.push( |
604 'WiFi.BSSID', | 603 'WiFi.SSID', 'WiFi.BSSID', 'WiFi.Security', 'WiFi.SignalStrength', |
605 'WiFi.Security', | 604 'WiFi.Frequency'); |
606 'WiFi.SignalStrength', | |
607 'WiFi.Frequency'); | |
608 } | 605 } |
609 if (properties.Type == CrOnc.Type.WI_MAX) | 606 if (properties.Type == CrOnc.Type.WI_MAX) |
610 fields.push('WiFi.SignalStrength'); | 607 fields.push('WiFi.SignalStrength'); |
611 return fields; | 608 return fields; |
612 }, | 609 }, |
613 | 610 |
614 /** | 611 /** |
615 * @param {!CrOnc.NetworkProperties} properties | 612 * @param {!CrOnc.NetworkProperties} properties |
616 * @return {!Array<string>} The fields to display in the device section. | 613 * @return {!Array<string>} The fields to display in the device section. |
617 * @private | 614 * @private |
618 */ | 615 */ |
619 getDeviceFields_: function(properties) { | 616 getDeviceFields_: function(properties) { |
620 /** @type {!Array<string>} */ var fields = []; | 617 /** @type {!Array<string>} */ var fields = []; |
621 if (!properties) | 618 if (!properties) |
622 return fields; | 619 return fields; |
623 if (properties.Type == CrOnc.Type.CELLULAR) { | 620 if (properties.Type == CrOnc.Type.CELLULAR) { |
624 fields.push('Cellular.HomeProvider.Name', | 621 fields.push( |
625 'Cellular.HomeProvider.Country', | 622 'Cellular.HomeProvider.Name', 'Cellular.HomeProvider.Country', |
626 'Cellular.HomeProvider.Code', | 623 'Cellular.HomeProvider.Code', 'Cellular.Manufacturer', |
627 'Cellular.Manufacturer', | 624 'Cellular.ModelID', 'Cellular.FirmwareRevision', |
628 'Cellular.ModelID', | 625 'Cellular.HardwareRevision', 'Cellular.ESN', 'Cellular.ICCID', |
629 'Cellular.FirmwareRevision', | 626 'Cellular.IMEI', 'Cellular.IMSI', 'Cellular.MDN', 'Cellular.MEID', |
630 'Cellular.HardwareRevision', | 627 'Cellular.MIN', 'Cellular.PRLVersion'); |
631 'Cellular.ESN', | |
632 'Cellular.ICCID', | |
633 'Cellular.IMEI', | |
634 'Cellular.IMSI', | |
635 'Cellular.MDN', | |
636 'Cellular.MEID', | |
637 'Cellular.MIN', | |
638 'Cellular.PRLVersion'); | |
639 } | 628 } |
640 return fields; | 629 return fields; |
641 }, | 630 }, |
642 | 631 |
643 /** | 632 /** |
644 * @param {!CrOnc.NetworkProperties} properties | 633 * @param {!CrOnc.NetworkProperties} properties |
645 * @return {boolean} True if there are any advanced fields to display. | 634 * @return {boolean} |
646 * @private | 635 * @private |
647 */ | 636 */ |
648 hasAdvancedOrDeviceFields_: function(properties) { | 637 hasAdvancedOrDeviceFields_: function(properties) { |
649 return this.getAdvancedFields_(properties).length > 0 || | 638 return this.hasAdvancedFields_(properties) || |
650 this.hasDeviceFields_(properties); | 639 this.hasDeviceFields_(properties); |
651 }, | 640 }, |
652 | 641 |
653 /** | 642 /** |
654 * @param {!CrOnc.NetworkProperties} properties | 643 * @param {!CrOnc.NetworkProperties} properties |
655 * @return {boolean} True if there are any device fields to display. | 644 * @return {boolean} |
645 * @private | |
646 */ | |
647 hasAdvancedFields_: function(properties) { | |
648 return this.hasVisibleFields_(this.getAdvancedFields_(properties)); | |
649 }, | |
650 | |
651 /** | |
652 * @param {!CrOnc.NetworkProperties} properties | |
653 * @return {boolean} | |
656 * @private | 654 * @private |
657 */ | 655 */ |
658 hasDeviceFields_: function(properties) { | 656 hasDeviceFields_: function(properties) { |
659 var fields = this.getDeviceFields_(properties); | 657 return this.hasVisibleFields_(this.getDeviceFields_(properties)); |
660 return fields.length > 0; | |
661 }, | 658 }, |
662 | 659 |
663 /** | 660 /** |
664 * @param {!CrOnc.NetworkProperties} properties | 661 * @param {!CrOnc.NetworkProperties} properties |
665 * @return {boolean} True if the network section should be shown. | 662 * @return {boolean} True if the network section should be shown. |
666 * @private | 663 * @private |
667 */ | 664 */ |
668 hasNetworkSection_: function(properties) { | 665 hasNetworkSection_: function(properties) { |
669 return properties.Type != CrOnc.Type.VPN; | 666 return properties.Type != CrOnc.Type.VPN; |
670 }, | 667 }, |
671 | 668 |
672 /** | 669 /** |
673 * @param {!CrOnc.NetworkProperties} properties | 670 * @param {!CrOnc.NetworkProperties} properties |
674 * @param {string} type The network type. | 671 * @param {string} type The network type. |
675 * @return {boolean} True if the network type matches 'type'. | 672 * @return {boolean} True if the network type matches 'type'. |
676 * @private | 673 * @private |
677 */ | 674 */ |
678 isType_: function(properties, type) { | 675 isType_: function(properties, type) { return properties.Type == type; }, |
dschuyler
2016/07/26 01:18:23
nit: I think it's wise to keep executable lines se
stevenjb
2016/07/26 16:47:17
clang-format does this. It's a huge pita to format
dschuyler
2016/07/26 19:19:46
I setup a similar function and tried to set a brea
stevenjb
2016/07/26 20:17:59
Ugh, you're right, I swear that used to work.
Aft
| |
679 return properties.Type == type; | |
680 }, | |
681 | 676 |
682 /** | 677 /** |
683 * @param {!CrOnc.NetworkProperties} properties | 678 * @param {!CrOnc.NetworkProperties} properties |
684 * @return {boolean} True if the Cellular SIM section should be shown. | 679 * @return {boolean} True if the Cellular SIM section should be shown. |
685 * @private | 680 * @private |
686 */ | 681 */ |
687 showCellularSim_: function(properties) { | 682 showCellularSim_: function(properties) { |
688 if (!properties || properties.Type != 'Cellular' || !properties.Cellular) | 683 if (!properties || properties.Type != 'Cellular' || !properties.Cellular) |
689 return false; | 684 return false; |
690 return properties.Cellular.Family == 'GSM'; | 685 return properties.Cellular.Family == 'GSM'; |
(...skipping 10 matching lines...) Expand all Loading... | |
701 */ | 696 */ |
702 allPropertiesMatch_: function(curValue, newValue) { | 697 allPropertiesMatch_: function(curValue, newValue) { |
703 for (let key in newValue) { | 698 for (let key in newValue) { |
704 if (newValue[key] != curValue[key]) | 699 if (newValue[key] != curValue[key]) |
705 return false; | 700 return false; |
706 } | 701 } |
707 return true; | 702 return true; |
708 } | 703 } |
709 }); | 704 }); |
710 })(); | 705 })(); |
OLD | NEW |