| 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 Polymer element for displaying a summary of network states | 6 * @fileoverview Polymer element for displaying a summary of network states |
| 7 * by type: Ethernet, WiFi, Cellular, WiMAX, and VPN. | 7 * by type: Ethernet, WiFi, Cellular, WiMAX, and VPN. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 /** @typedef {chrome.networkingPrivate.DeviceStateProperties} */ | 10 /** @typedef {chrome.networkingPrivate.DeviceStateProperties} */ |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 * Highest priority connected network or null. | 40 * Highest priority connected network or null. |
| 41 * @type {?CrOnc.NetworkStateProperties} | 41 * @type {?CrOnc.NetworkStateProperties} |
| 42 */ | 42 */ |
| 43 defaultNetwork: { | 43 defaultNetwork: { |
| 44 type: Object, | 44 type: Object, |
| 45 value: null, | 45 value: null, |
| 46 notify: true, | 46 notify: true, |
| 47 }, | 47 }, |
| 48 | 48 |
| 49 /** | 49 /** |
| 50 * The device state for each network device type. | |
| 51 * @type {DeviceStateObject} | |
| 52 */ | |
| 53 deviceStates: { | |
| 54 type: Object, | |
| 55 value: function() { return {}; }, | |
| 56 }, | |
| 57 | |
| 58 /** | |
| 59 * Array of active network states, one per device type. | |
| 60 * @type {!Array<!CrOnc.NetworkStateProperties>} | |
| 61 */ | |
| 62 activeNetworkStates: { | |
| 63 type: Array, | |
| 64 value: function() { return []; }, | |
| 65 }, | |
| 66 | |
| 67 /** | |
| 68 * List of network state data for each network type. | |
| 69 * @type {NetworkStateListObject} | |
| 70 */ | |
| 71 networkStateLists: { | |
| 72 type: Object, | |
| 73 value: function() { return {}; }, | |
| 74 }, | |
| 75 | |
| 76 /** | |
| 77 * Interface for networkingPrivate calls, passed from internet_page. | 50 * Interface for networkingPrivate calls, passed from internet_page. |
| 78 * @type {NetworkingPrivate} | 51 * @type {NetworkingPrivate} |
| 79 */ | 52 */ |
| 80 networkingPrivate: { | 53 networkingPrivate: Object, |
| 54 |
| 55 /** |
| 56 * The device state for each network device type. |
| 57 * @private {DeviceStateObject} |
| 58 */ |
| 59 deviceStates_: { |
| 81 type: Object, | 60 type: Object, |
| 61 value: function() { |
| 62 return {}; |
| 63 }, |
| 64 }, |
| 65 |
| 66 /** |
| 67 * Array of active network states, one per device type. |
| 68 * @private {!Array<!CrOnc.NetworkStateProperties>} |
| 69 */ |
| 70 activeNetworkStates_: { |
| 71 type: Array, |
| 72 value: function() { |
| 73 return []; |
| 74 }, |
| 75 }, |
| 76 |
| 77 /** |
| 78 * List of network state data for each network type. |
| 79 * @private {NetworkStateListObject} |
| 80 */ |
| 81 networkStateLists_: { |
| 82 type: Object, |
| 83 value: function() { |
| 84 return {}; |
| 85 }, |
| 82 }, | 86 }, |
| 83 }, | 87 }, |
| 84 | 88 |
| 85 /** | 89 /** |
| 86 * Listener function for chrome.networkingPrivate.onNetworkListChanged event. | 90 * Listener function for chrome.networkingPrivate.onNetworkListChanged event. |
| 87 * @type {function(!Array<string>)} | 91 * @type {function(!Array<string>)} |
| 88 * @private | 92 * @private |
| 89 */ | 93 */ |
| 90 networkListChangedListener_: function() {}, | 94 networkListChangedListener_: function() {}, |
| 91 | 95 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 if (event.detail.enabled) | 185 if (event.detail.enabled) |
| 182 this.networkingPrivate.enableNetworkType(event.detail.type); | 186 this.networkingPrivate.enableNetworkType(event.detail.type); |
| 183 else | 187 else |
| 184 this.networkingPrivate.disableNetworkType(event.detail.type); | 188 this.networkingPrivate.disableNetworkType(event.detail.type); |
| 185 }, | 189 }, |
| 186 | 190 |
| 187 /** | 191 /** |
| 188 * networkingPrivate.onNetworkListChanged event callback. | 192 * networkingPrivate.onNetworkListChanged event callback. |
| 189 * @private | 193 * @private |
| 190 */ | 194 */ |
| 191 onNetworkListChangedEvent_: function() { this.getNetworkLists_(); }, | 195 onNetworkListChangedEvent_: function() { |
| 196 this.getNetworkLists_(); |
| 197 }, |
| 192 | 198 |
| 193 /** | 199 /** |
| 194 * networkingPrivate.onDeviceStateListChanged event callback. | 200 * networkingPrivate.onDeviceStateListChanged event callback. |
| 195 * @private | 201 * @private |
| 196 */ | 202 */ |
| 197 onDeviceStateListChangedEvent_: function() { this.getNetworkLists_(); }, | 203 onDeviceStateListChangedEvent_: function() { |
| 204 this.getNetworkLists_(); |
| 205 }, |
| 198 | 206 |
| 199 /** | 207 /** |
| 200 * networkingPrivate.onNetworksChanged event callback. | 208 * networkingPrivate.onNetworksChanged event callback. |
| 201 * @param {!Array<string>} networkIds The list of changed network GUIDs. | 209 * @param {!Array<string>} networkIds The list of changed network GUIDs. |
| 202 * @private | 210 * @private |
| 203 */ | 211 */ |
| 204 onNetworksChangedEvent_: function(networkIds) { | 212 onNetworksChangedEvent_: function(networkIds) { |
| 205 if (!this.activeNetworkIds_) | 213 if (!this.activeNetworkIds_) |
| 206 return; // Initial list of networks not received yet. | 214 return; // Initial list of networks not received yet. |
| 207 networkIds.forEach(function(id) { | 215 networkIds.forEach(function(id) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 return; | 250 return; |
| 243 } | 251 } |
| 244 // Async call, ensure id still exists. | 252 // Async call, ensure id still exists. |
| 245 if (!this.activeNetworkIds_.has(id)) | 253 if (!this.activeNetworkIds_.has(id)) |
| 246 return; | 254 return; |
| 247 if (!state) { | 255 if (!state) { |
| 248 this.activeNetworkIds_.delete(id); | 256 this.activeNetworkIds_.delete(id); |
| 249 return; | 257 return; |
| 250 } | 258 } |
| 251 // Find the active state for the type and update it. | 259 // Find the active state for the type and update it. |
| 252 for (let i = 0; i < this.activeNetworkStates.length; ++i) { | 260 for (let i = 0; i < this.activeNetworkStates_.length; ++i) { |
| 253 if (this.activeNetworkStates[i].type == state.type) { | 261 if (this.activeNetworkStates_[i].type == state.type) { |
| 254 this.activeNetworkStates[i] = state; | 262 this.activeNetworkStates_[i] = state; |
| 255 return; | 263 return; |
| 256 } | 264 } |
| 257 } | 265 } |
| 258 // Not found | 266 // Not found |
| 259 console.error('Active state not found: ' + state.Name); | 267 console.error('Active state not found: ' + state.Name); |
| 260 }, | 268 }, |
| 261 | 269 |
| 262 /** | 270 /** |
| 263 * Handles UI requests to connect to a network. | 271 * Handles UI requests to connect to a network. |
| 264 * TODO(stevenjb): Handle Cellular activation, etc. | 272 * TODO(stevenjb): Handle Cellular activation, etc. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 * defined the existing list of device states will be used. | 328 * defined the existing list of device states will be used. |
| 321 * @private | 329 * @private |
| 322 */ | 330 */ |
| 323 updateNetworkStates_: function(networkStates, opt_deviceStates) { | 331 updateNetworkStates_: function(networkStates, opt_deviceStates) { |
| 324 var newDeviceStates; | 332 var newDeviceStates; |
| 325 if (opt_deviceStates) { | 333 if (opt_deviceStates) { |
| 326 newDeviceStates = /** @type {!DeviceStateObject} */ ({}); | 334 newDeviceStates = /** @type {!DeviceStateObject} */ ({}); |
| 327 for (let state of opt_deviceStates) | 335 for (let state of opt_deviceStates) |
| 328 newDeviceStates[state.Type] = state; | 336 newDeviceStates[state.Type] = state; |
| 329 } else { | 337 } else { |
| 330 newDeviceStates = this.deviceStates; | 338 newDeviceStates = this.deviceStates_; |
| 331 } | 339 } |
| 332 | 340 |
| 333 // Clear any current networks. | 341 // Clear any current networks. |
| 334 var activeNetworkStatesByType = | 342 var activeNetworkStatesByType = |
| 335 /** @type {!Map<string, !CrOnc.NetworkStateProperties>} */ (new Map); | 343 /** @type {!Map<string, !CrOnc.NetworkStateProperties>} */ (new Map); |
| 336 | 344 |
| 337 // Complete list of states by type. | 345 // Complete list of states by type. |
| 338 /** @type {!NetworkStateListObject} */ var newNetworkStateLists = { | 346 /** @type {!NetworkStateListObject} */ var newNetworkStateLists = { |
| 339 Ethernet: [], | 347 Ethernet: [], |
| 340 WiFi: [], | 348 WiFi: [], |
| (...skipping 28 matching lines...) Expand all Loading... |
| 369 // Push the active networks onto newActiveNetworkStates in device order, | 377 // Push the active networks onto newActiveNetworkStates in device order, |
| 370 // creating an empty state for devices with no networks. | 378 // creating an empty state for devices with no networks. |
| 371 var newActiveNetworkStates = []; | 379 var newActiveNetworkStates = []; |
| 372 this.activeNetworkIds_ = new Set; | 380 this.activeNetworkIds_ = new Set; |
| 373 for (let type in newDeviceStates) { | 381 for (let type in newDeviceStates) { |
| 374 var state = activeNetworkStatesByType.get(type) || {GUID: '', Type: type}; | 382 var state = activeNetworkStatesByType.get(type) || {GUID: '', Type: type}; |
| 375 newActiveNetworkStates.push(state); | 383 newActiveNetworkStates.push(state); |
| 376 this.activeNetworkIds_.add(state.GUID); | 384 this.activeNetworkIds_.add(state.GUID); |
| 377 } | 385 } |
| 378 | 386 |
| 379 this.deviceStates = newDeviceStates; | 387 this.deviceStates_ = newDeviceStates; |
| 380 this.networkStateLists = newNetworkStateLists; | 388 this.networkStateLists_ = newNetworkStateLists; |
| 381 // Set activeNetworkStates last to rebuild the dom-repeat. | 389 // Set activeNetworkStates last to rebuild the dom-repeat. |
| 382 this.activeNetworkStates = newActiveNetworkStates; | 390 this.activeNetworkStates_ = newActiveNetworkStates; |
| 383 }, | 391 }, |
| 384 }); | 392 }); |
| OLD | NEW |