Chromium Code Reviews| 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} */ | |
| 11 var DeviceStateProperties; | |
| 12 | |
| 13 /** | 10 /** |
| 14 * @typedef {{ | 11 * @typedef {{ |
| 15 * Ethernet: (DeviceStateProperties|undefined), | 12 * Ethernet: (!CrOnc.DeviceStateProperties|undefined), |
| 16 * WiFi: (DeviceStateProperties|undefined), | 13 * WiFi: (!CrOnc.DeviceStateProperties|undefined), |
| 17 * Cellular: (DeviceStateProperties|undefined), | 14 * Cellular: (!CrOnc.DeviceStateProperties|undefined), |
| 18 * WiMAX: (DeviceStateProperties|undefined), | 15 * WiMAX: (!CrOnc.DeviceStateProperties|undefined), |
| 19 * VPN: (DeviceStateProperties|undefined) | 16 * VPN: (!CrOnc.DeviceStateProperties|undefined) |
| 20 * }} | 17 * }} |
| 21 */ | 18 */ |
| 22 var DeviceStateObject; | 19 var DeviceStateObject; |
| 23 | 20 |
| 24 /** | 21 /** |
| 25 * @typedef {{ | 22 * @typedef {{ |
| 26 * Ethernet: (Array<CrOnc.NetworkStateProperties>|undefined), | 23 * Ethernet: (Array<!CrOnc.NetworkStateProperties>|undefined), |
| 27 * WiFi: (Array<CrOnc.NetworkStateProperties>|undefined), | 24 * WiFi: (Array<!CrOnc.NetworkStateProperties>|undefined), |
| 28 * Cellular: (Array<CrOnc.NetworkStateProperties>|undefined), | 25 * Cellular: (Array<!CrOnc.NetworkStateProperties>|undefined), |
| 29 * WiMAX: (Array<CrOnc.NetworkStateProperties>|undefined), | 26 * WiMAX: (Array<!CrOnc.NetworkStateProperties>|undefined), |
| 30 * VPN: (Array<CrOnc.NetworkStateProperties>|undefined) | 27 * VPN: (Array<!CrOnc.NetworkStateProperties>|undefined) |
| 31 * }} | 28 * }} |
| 32 */ | 29 */ |
| 33 var NetworkStateListObject; | 30 var NetworkStateListObject; |
| 34 | 31 |
| 35 Polymer({ | 32 Polymer({ |
| 36 is: 'network-summary', | 33 is: 'network-summary', |
| 37 | 34 |
| 38 behaviors: [CrPolicyNetworkBehavior], | 35 behaviors: [CrPolicyNetworkBehavior], |
| 39 | 36 |
| 40 properties: { | 37 properties: { |
| 41 /** | 38 /** |
| 42 * Highest priority connected network or null. | 39 * Highest priority connected network or null. |
| 43 * @type {?CrOnc.NetworkStateProperties} | 40 * @type {?CrOnc.NetworkStateProperties} |
| 44 */ | 41 */ |
| 45 defaultNetwork: { | 42 defaultNetwork: { |
| 46 type: Object, | 43 type: Object, |
| 47 value: null, | 44 value: null, |
| 48 notify: true, | 45 notify: true, |
| 49 }, | 46 }, |
| 50 | 47 |
| 51 /** | 48 /** |
| 52 * Interface for networkingPrivate calls, passed from internet_page. | 49 * Interface for networkingPrivate calls, passed from internet_page. |
| 53 * @type {NetworkingPrivate} | 50 * @type {!NetworkingPrivate} |
| 54 */ | 51 */ |
| 55 networkingPrivate: Object, | 52 networkingPrivate: Object, |
| 56 | 53 |
| 57 /** | 54 /** |
| 58 * The device state for each network device type. We initialize this to | 55 * The device state for each network device type. We initialize this to |
| 59 * include a disabled WiFi type since WiFi is always present. This reduces | 56 * include a disabled WiFi type since WiFi is always present. This reduces |
| 60 * the amount of visual change on first load. | 57 * the amount of visual change on first load. |
| 61 * @private {DeviceStateObject} | 58 * @private {!DeviceStateObject} |
| 62 */ | 59 */ |
| 63 deviceStates: { | 60 deviceStates: { |
| 64 type: Object, | 61 type: Object, |
| 65 value: function() { | 62 value: function() { |
| 66 return { | 63 return { |
| 67 WiFi: { | 64 WiFi: {Type: CrOnc.Type.WI_FI, State: CrOnc.DeviceState.DISABLED}, |
| 68 Type: chrome.networkingPrivate.NetworkType.WI_FI, | |
| 69 State: chrome.networkingPrivate.DeviceStateType.DISABLED | |
| 70 }, | |
| 71 }; | 65 }; |
| 72 }, | 66 }, |
| 73 notify: true, | 67 notify: true, |
| 74 }, | 68 }, |
| 75 | 69 |
| 76 /** | 70 /** |
| 77 * Array of active network states, one per device type. Initialized to | 71 * Array of active network states, one per device type. Initialized to |
| 78 * include a default WiFi state (see deviceStates comment). | 72 * include a default WiFi state (see deviceStates comment). |
| 79 * @private {!Array<!CrOnc.NetworkStateProperties>} | 73 * @private {!Array<!CrOnc.NetworkStateProperties>} |
| 80 */ | 74 */ |
| 81 activeNetworkStates_: { | 75 activeNetworkStates_: { |
| 82 type: Array, | 76 type: Array, |
| 83 value: function() { | 77 value: function() { |
| 84 return [{GUID: '', Type: chrome.networkingPrivate.NetworkType.WI_FI}]; | 78 return [{GUID: '', Type: CrOnc.Type.WI_FI}]; |
| 85 }, | 79 }, |
| 86 }, | 80 }, |
| 87 | 81 |
| 88 /** | 82 /** |
| 89 * List of network state data for each network type. | 83 * List of network state data for each network type. |
| 90 * @private {NetworkStateListObject} | 84 * @private {!NetworkStateListObject} |
| 91 */ | 85 */ |
| 92 networkStateLists_: { | 86 networkStateLists_: { |
| 93 type: Object, | 87 type: Object, |
| 94 value: function() { | 88 value: function() { |
| 95 return {WiFi: []}; | 89 return {WiFi: []}; |
| 96 }, | 90 }, |
| 97 }, | 91 }, |
| 98 }, | 92 }, |
| 99 | 93 |
| 100 /** | 94 /** |
| 101 * Listener function for chrome.networkingPrivate.onNetworkListChanged event. | 95 * Listener function for chrome.networkingPrivate.onNetworkListChanged event. |
| 102 * @type {?function(!Array<string>)} | 96 * @private {?function(!Array<string>)} |
| 103 * @private | |
| 104 */ | 97 */ |
| 105 networkListChangedListener_: null, | 98 networkListChangedListener_: null, |
| 106 | 99 |
| 107 /** | 100 /** |
| 108 * Listener function for chrome.networkingPrivate.onDeviceStateListChanged | 101 * Listener function for chrome.networkingPrivate.onDeviceStateListChanged |
| 109 * event. | 102 * event. |
| 110 * @type {?function(!Array<string>)} | 103 * @private {?function(!Array<string>)} |
| 111 * @private | |
| 112 */ | 104 */ |
| 113 deviceStateListChangedListener_: null, | 105 deviceStateListChangedListener_: null, |
| 114 | 106 |
| 115 /** | 107 /** |
| 116 * Listener function for chrome.networkingPrivate.onNetworksChanged event. | 108 * Listener function for chrome.networkingPrivate.onNetworksChanged event. |
| 117 * @type {?function(!Array<string>)} | 109 * @private {?function(!Array<string>)} |
| 118 * @private | |
| 119 */ | 110 */ |
| 120 networksChangedListener_: null, | 111 networksChangedListener_: null, |
| 121 | 112 |
| 122 /** | 113 /** |
| 123 * Set of GUIDs identifying active networks, one for each type. | 114 * Set of GUIDs identifying active networks, one for each type. |
| 124 * @type {?Set<string>} | 115 * @private {?Set<string>} |
| 125 * @private | |
| 126 */ | 116 */ |
| 127 activeNetworkIds_: null, | 117 activeNetworkIds_: null, |
| 128 | 118 |
| 129 /** @override */ | 119 /** @override */ |
| 130 attached: function() { | 120 attached: function() { |
| 131 this.getNetworkLists_(); | 121 this.getNetworkLists_(); |
| 132 | 122 |
| 133 this.networkListChangedListener_ = this.networkListChangedListener_ || | 123 this.networkListChangedListener_ = this.networkListChangedListener_ || |
| 134 this.onNetworkListChangedEvent_.bind(this); | 124 this.onNetworkListChangedEvent_.bind(this); |
| 135 this.networkingPrivate.onNetworkListChanged.addListener( | 125 this.networkingPrivate.onNetworkListChanged.addListener( |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 if (this.activeNetworkIds_.has(id)) { | 177 if (this.activeNetworkIds_.has(id)) { |
| 188 this.networkingPrivate.getState( | 178 this.networkingPrivate.getState( |
| 189 id, this.getActiveStateCallback_.bind(this, id)); | 179 id, this.getActiveStateCallback_.bind(this, id)); |
| 190 } | 180 } |
| 191 }, this); | 181 }, this); |
| 192 }, | 182 }, |
| 193 | 183 |
| 194 /** | 184 /** |
| 195 * networkingPrivate.getState event callback for an active state. | 185 * networkingPrivate.getState event callback for an active state. |
| 196 * @param {string} id The id of the requested state. | 186 * @param {string} id The id of the requested state. |
| 197 * @param {!chrome.networkingPrivate.NetworkStateProperties} state | 187 * @param {!CrOnc.NetworkStateProperties} state |
| 198 * @private | 188 * @private |
| 199 */ | 189 */ |
| 200 getActiveStateCallback_: function(id, state) { | 190 getActiveStateCallback_: function(id, state) { |
| 201 if (chrome.runtime.lastError) { | 191 if (chrome.runtime.lastError) { |
| 202 var message = chrome.runtime.lastError.message; | 192 var message = chrome.runtime.lastError.message; |
| 203 if (message != 'Error.NetworkUnavailable') { | 193 if (message != 'Error.NetworkUnavailable') { |
| 204 console.error( | 194 console.error( |
| 205 'Unexpected networkingPrivate.getState error: ' + message + | 195 'Unexpected networkingPrivate.getState error: ' + message + |
| 206 ' For: ' + id); | 196 ' For: ' + id); |
| 207 } | 197 } |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 236 this.networkingPrivate.getDeviceStates(function(deviceStates) { | 226 this.networkingPrivate.getDeviceStates(function(deviceStates) { |
| 237 // Second get the network states. | 227 // Second get the network states. |
| 238 this.getNetworkStates_(deviceStates); | 228 this.getNetworkStates_(deviceStates); |
| 239 }.bind(this)); | 229 }.bind(this)); |
| 240 }, | 230 }, |
| 241 | 231 |
| 242 /** | 232 /** |
| 243 * Requests the list of network states from Chrome. Updates | 233 * Requests the list of network states from Chrome. Updates |
| 244 * activeNetworkStates and networkStateLists once the results are returned | 234 * activeNetworkStates and networkStateLists once the results are returned |
| 245 * from Chrome. | 235 * from Chrome. |
| 246 * @param {!Array<!DeviceStateProperties>=} opt_deviceStates | 236 * @param {!Array<!CrOnc.DeviceStateProperties>} deviceStates |
| 247 * Optional list of state properties for all available devices. | |
|
stevenjb
2017/05/31 19:01:46
This is no longer optional, this is now only calle
| |
| 248 * @private | 237 * @private |
| 249 */ | 238 */ |
| 250 getNetworkStates_: function(opt_deviceStates) { | 239 getNetworkStates_: function(deviceStates) { |
| 251 var filter = { | 240 var filter = { |
| 252 networkType: chrome.networkingPrivate.NetworkType.ALL, | 241 networkType: CrOnc.Type.ALL, |
| 253 visible: true, | 242 visible: true, |
| 254 configured: false | 243 configured: false |
| 255 }; | 244 }; |
| 256 this.networkingPrivate.getNetworks(filter, function(networkStates) { | 245 this.networkingPrivate.getNetworks(filter, function(networkStates) { |
| 257 this.updateNetworkStates_(networkStates, opt_deviceStates); | 246 this.updateNetworkStates_(networkStates, deviceStates); |
| 258 }.bind(this)); | 247 }.bind(this)); |
| 259 }, | 248 }, |
| 260 | 249 |
| 261 /** | 250 /** |
| 262 * Called after network states are received from getNetworks. | 251 * Called after network states are received from getNetworks. |
| 263 * @param {!Array<!CrOnc.NetworkStateProperties>} networkStates The state | 252 * @param {!Array<!CrOnc.NetworkStateProperties>} networkStates The state |
| 264 * properties for all visible networks. | 253 * properties for all visible networks. |
| 265 * @param {!Array<!DeviceStateProperties>=} opt_deviceStates | 254 * @param {!Array<!CrOnc.DeviceStateProperties>} deviceStates |
| 266 * Optional list of state properties for all available devices. If not | |
| 267 * defined the existing list of device states will be used. | |
| 268 * @private | 255 * @private |
| 269 */ | 256 */ |
| 270 updateNetworkStates_: function(networkStates, opt_deviceStates) { | 257 updateNetworkStates_: function(networkStates, deviceStates) { |
| 271 var newDeviceStates; | 258 var newDeviceStates = /** @type {!DeviceStateObject} */ ({}); |
| 272 if (opt_deviceStates) { | 259 for (var i = 0; i < deviceStates.length; ++i) { |
| 273 newDeviceStates = /** @type {!DeviceStateObject} */ ({}); | 260 var state = deviceStates[i]; |
| 274 for (var i = 0; i < opt_deviceStates.length; ++i) { | 261 newDeviceStates[state.Type] = state; |
| 275 var state = opt_deviceStates[i]; | |
| 276 newDeviceStates[state.Type] = state; | |
| 277 } | |
| 278 } else { | |
| 279 newDeviceStates = Object.assign({}, this.deviceStates); | |
| 280 } | 262 } |
| 281 | 263 |
| 282 // Clear any current networks. | 264 // Clear any current networks. |
| 283 var activeNetworkStatesByType = | 265 var activeNetworkStatesByType = |
| 284 /** @type {!Map<string, !CrOnc.NetworkStateProperties>} */ (new Map); | 266 /** @type {!Map<string, !CrOnc.NetworkStateProperties>} */ (new Map); |
| 285 | 267 |
| 286 // Complete list of states by type. | 268 // Complete list of states by type. |
| 287 /** @type {!NetworkStateListObject} */ var newNetworkStateLists = { | 269 /** @type {!NetworkStateListObject} */ var newNetworkStateLists = { |
| 288 Ethernet: [], | 270 Ethernet: [], |
| 289 Tether: [], | 271 Tether: [], |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 303 firstConnectedNetwork = networkState; | 285 firstConnectedNetwork = networkState; |
| 304 } | 286 } |
| 305 } | 287 } |
| 306 newNetworkStateLists[type].push(networkState); | 288 newNetworkStateLists[type].push(networkState); |
| 307 }, this); | 289 }, this); |
| 308 | 290 |
| 309 this.defaultNetwork = firstConnectedNetwork; | 291 this.defaultNetwork = firstConnectedNetwork; |
| 310 | 292 |
| 311 // Create a VPN entry in deviceStates if there are any VPN networks. | 293 // Create a VPN entry in deviceStates if there are any VPN networks. |
| 312 if (newNetworkStateLists.VPN && newNetworkStateLists.VPN.length > 0) { | 294 if (newNetworkStateLists.VPN && newNetworkStateLists.VPN.length > 0) { |
| 313 newDeviceStates.VPN = /** @type {DeviceStateProperties} */ ({ | 295 newDeviceStates.VPN = { |
| 314 Type: CrOnc.Type.VPN, | 296 Type: CrOnc.Type.VPN, |
| 315 State: chrome.networkingPrivate.DeviceStateType.ENABLED | 297 State: CrOnc.DeviceState.ENABLED |
| 316 }); | 298 }; |
| 317 } | 299 } |
| 318 | 300 |
| 319 // Push the active networks onto newActiveNetworkStates in order based on | 301 // Push the active networks onto newActiveNetworkStates in order based on |
| 320 // device priority, creating an empty state for devices with no networks. | 302 // device priority, creating an empty state for devices with no networks. |
| 321 var newActiveNetworkStates = []; | 303 var newActiveNetworkStates = []; |
| 322 this.activeNetworkIds_ = new Set; | 304 this.activeNetworkIds_ = new Set; |
| 323 var orderedDeviceTypes = [ | 305 var orderedDeviceTypes = [ |
| 324 CrOnc.Type.ETHERNET, CrOnc.Type.WI_FI, CrOnc.Type.CELLULAR, | 306 CrOnc.Type.ETHERNET, CrOnc.Type.WI_FI, CrOnc.Type.CELLULAR, |
| 325 CrOnc.Type.TETHER, CrOnc.Type.WI_MAX, CrOnc.Type.VPN | 307 CrOnc.Type.TETHER, CrOnc.Type.WI_MAX, CrOnc.Type.VPN |
| 326 ]; | 308 ]; |
| 327 for (var i = 0; i < orderedDeviceTypes.length; ++i) { | 309 for (var i = 0; i < orderedDeviceTypes.length; ++i) { |
| 328 var type = orderedDeviceTypes[i]; | 310 var type = orderedDeviceTypes[i]; |
| 329 var device = newDeviceStates[type]; | 311 var device = newDeviceStates[type]; |
| 330 if (!device) | 312 if (!device) |
| 331 continue; | 313 continue; |
| 332 var state = activeNetworkStatesByType.get(type) || {GUID: '', Type: type}; | 314 var state = activeNetworkStatesByType.get(type) || {GUID: '', Type: type}; |
| 333 if (state.Source === undefined && | 315 if (state.Source === undefined && |
| 334 device.State == chrome.networkingPrivate.DeviceStateType.PROHIBITED) { | 316 device.State == CrOnc.DeviceState.PROHIBITED) { |
| 335 // Prohibited technologies are enforced by the device policy. | 317 // Prohibited technologies are enforced by the device policy. |
| 336 state.Source = CrOnc.Source.DEVICE_POLICY; | 318 state.Source = CrOnc.Source.DEVICE_POLICY; |
| 337 } | 319 } |
| 338 newActiveNetworkStates.push(state); | 320 newActiveNetworkStates.push(state); |
| 339 this.activeNetworkIds_.add(state.GUID); | 321 this.activeNetworkIds_.add(state.GUID); |
| 340 } | 322 } |
| 341 | 323 |
| 342 this.deviceStates = newDeviceStates; | 324 this.deviceStates = newDeviceStates; |
| 343 this.networkStateLists_ = newNetworkStateLists; | 325 this.networkStateLists_ = newNetworkStateLists; |
| 344 // Set activeNetworkStates last to rebuild the dom-repeat. | 326 // Set activeNetworkStates last to rebuild the dom-repeat. |
| 345 this.activeNetworkStates_ = newActiveNetworkStates; | 327 this.activeNetworkStates_ = newActiveNetworkStates; |
| 346 }, | 328 }, |
| 347 }); | 329 }); |
| OLD | NEW |