| 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 30 matching lines...) Expand all Loading... |
| 41 /** | 41 /** |
| 42 * Highest priority connected network or null. | 42 * Highest priority connected network or null. |
| 43 * @type {?CrOnc.NetworkStateProperties} | 43 * @type {?CrOnc.NetworkStateProperties} |
| 44 */ | 44 */ |
| 45 defaultNetwork: { | 45 defaultNetwork: { |
| 46 type: Object, | 46 type: Object, |
| 47 value: null, | 47 value: null, |
| 48 notify: true, | 48 notify: true, |
| 49 }, | 49 }, |
| 50 | 50 |
| 51 /** @type {!chrome.networkingPrivate.GlobalPolicy|undefined} */ | |
| 52 globalPolicy: Object, | |
| 53 | |
| 54 /** | 51 /** |
| 55 * Interface for networkingPrivate calls, passed from internet_page. | 52 * Interface for networkingPrivate calls, passed from internet_page. |
| 56 * @type {NetworkingPrivate} | 53 * @type {NetworkingPrivate} |
| 57 */ | 54 */ |
| 58 networkingPrivate: Object, | 55 networkingPrivate: Object, |
| 59 | 56 |
| 60 /** | 57 /** |
| 61 * The device state for each network device type. | 58 * The device state for each network device type. |
| 62 * @private {DeviceStateObject} | 59 * @private {DeviceStateObject} |
| 63 */ | 60 */ |
| (...skipping 23 matching lines...) Expand all Loading... |
| 87 networkStateLists_: { | 84 networkStateLists_: { |
| 88 type: Object, | 85 type: Object, |
| 89 value: function() { | 86 value: function() { |
| 90 return {}; | 87 return {}; |
| 91 }, | 88 }, |
| 92 }, | 89 }, |
| 93 }, | 90 }, |
| 94 | 91 |
| 95 /** | 92 /** |
| 96 * Listener function for chrome.networkingPrivate.onNetworkListChanged event. | 93 * Listener function for chrome.networkingPrivate.onNetworkListChanged event. |
| 97 * @type {function(!Array<string>)} | 94 * @type {?function(!Array<string>)} |
| 98 * @private | 95 * @private |
| 99 */ | 96 */ |
| 100 networkListChangedListener_: function() {}, | 97 networkListChangedListener_: null, |
| 101 | 98 |
| 102 /** | 99 /** |
| 103 * Listener function for chrome.networkingPrivate.onDeviceStateListChanged | 100 * Listener function for chrome.networkingPrivate.onDeviceStateListChanged |
| 104 * event. | 101 * event. |
| 105 * @type {function(!Array<string>)} | 102 * @type {?function(!Array<string>)} |
| 106 * @private | 103 * @private |
| 107 */ | 104 */ |
| 108 deviceStateListChangedListener_: function() {}, | 105 deviceStateListChangedListener_: null, |
| 109 | 106 |
| 110 /** | 107 /** |
| 111 * Listener function for chrome.networkingPrivate.onNetworksChanged event. | 108 * Listener function for chrome.networkingPrivate.onNetworksChanged event. |
| 112 * @type {function(!Array<string>)} | 109 * @type {?function(!Array<string>)} |
| 113 * @private | 110 * @private |
| 114 */ | 111 */ |
| 115 networksChangedListener_: function() {}, | 112 networksChangedListener_: null, |
| 116 | 113 |
| 117 /** | 114 /** |
| 118 * Set of GUIDs identifying active networks, one for each type. | 115 * Set of GUIDs identifying active networks, one for each type. |
| 119 * @type {?Set<string>} | 116 * @type {?Set<string>} |
| 120 * @private | 117 * @private |
| 121 */ | 118 */ |
| 122 activeNetworkIds_: null, | 119 activeNetworkIds_: null, |
| 123 | 120 |
| 124 /** @override */ | 121 /** @override */ |
| 125 attached: function() { | 122 attached: function() { |
| 126 this.getNetworkLists_(); | 123 this.getNetworkLists_(); |
| 127 | 124 |
| 128 this.networkListChangedListener_ = | 125 this.networkListChangedListener_ = this.networkListChangedListener_ || |
| 129 this.onNetworkListChangedEvent_.bind(this); | 126 this.onNetworkListChangedEvent_.bind(this); |
| 130 this.networkingPrivate.onNetworkListChanged.addListener( | 127 this.networkingPrivate.onNetworkListChanged.addListener( |
| 131 this.networkListChangedListener_); | 128 this.networkListChangedListener_); |
| 132 | 129 |
| 133 this.deviceStateListChangedListener_ = | 130 this.deviceStateListChangedListener_ = |
| 131 this.deviceStateListChangedListener_ || |
| 134 this.onDeviceStateListChangedEvent_.bind(this); | 132 this.onDeviceStateListChangedEvent_.bind(this); |
| 135 this.networkingPrivate.onDeviceStateListChanged.addListener( | 133 this.networkingPrivate.onDeviceStateListChanged.addListener( |
| 136 this.deviceStateListChangedListener_); | 134 this.deviceStateListChangedListener_); |
| 137 | 135 |
| 138 this.networksChangedListener_ = this.onNetworksChangedEvent_.bind(this); | 136 this.networksChangedListener_ = this.networksChangedListener_ || |
| 137 this.onNetworksChangedEvent_.bind(this); |
| 139 this.networkingPrivate.onNetworksChanged.addListener( | 138 this.networkingPrivate.onNetworksChanged.addListener( |
| 140 this.networksChangedListener_); | 139 this.networksChangedListener_); |
| 141 }, | 140 }, |
| 142 | 141 |
| 143 /** @override */ | 142 /** @override */ |
| 144 detached: function() { | 143 detached: function() { |
| 145 this.networkingPrivate.onNetworkListChanged.removeListener( | 144 this.networkingPrivate.onNetworkListChanged.removeListener( |
| 146 this.networkListChangedListener_); | 145 assert(this.networkListChangedListener_)); |
| 147 | 146 |
| 148 this.networkingPrivate.onDeviceStateListChanged.removeListener( | 147 this.networkingPrivate.onDeviceStateListChanged.removeListener( |
| 149 this.deviceStateListChangedListener_); | 148 assert(this.deviceStateListChangedListener_)); |
| 150 | 149 |
| 151 this.networkingPrivate.onNetworksChanged.removeListener( | 150 this.networkingPrivate.onNetworksChanged.removeListener( |
| 152 this.networksChangedListener_); | 151 assert(this.networksChangedListener_)); |
| 153 }, | 152 }, |
| 154 | 153 |
| 155 /** | 154 /** |
| 156 * Event triggered when the network-summary-item is expanded. | |
| 157 * @param {!{detail: {expanded: boolean, type: string}}} event | |
| 158 * @private | |
| 159 */ | |
| 160 onExpanded_: function(event) { | |
| 161 if (!event.detail.expanded) | |
| 162 return; | |
| 163 // Get the latest network states. | |
| 164 this.getNetworkStates_(); | |
| 165 }, | |
| 166 | |
| 167 /** | |
| 168 * Event triggered when a network-summary-item is selected. | |
| 169 * @param {!{detail: !CrOnc.NetworkStateProperties}} event | |
| 170 * @private | |
| 171 */ | |
| 172 onSelected_: function(event) { | |
| 173 var state = event.detail; | |
| 174 if (this.canConnect_(state, this.globalPolicy)) { | |
| 175 this.connectToNetwork_(state); | |
| 176 return; | |
| 177 } | |
| 178 this.fire('show-detail', state); | |
| 179 }, | |
| 180 | |
| 181 /** | |
| 182 * networkingPrivate.onNetworkListChanged event callback. | 155 * networkingPrivate.onNetworkListChanged event callback. |
| 183 * @private | 156 * @private |
| 184 */ | 157 */ |
| 185 onNetworkListChangedEvent_: function() { | 158 onNetworkListChangedEvent_: function() { |
| 186 this.getNetworkLists_(); | 159 this.getNetworkLists_(); |
| 187 }, | 160 }, |
| 188 | 161 |
| 189 /** | 162 /** |
| 190 * networkingPrivate.onDeviceStateListChanged event callback. | 163 * networkingPrivate.onDeviceStateListChanged event callback. |
| 191 * @private | 164 * @private |
| (...skipping 12 matching lines...) Expand all Loading... |
| 204 return; // Initial list of networks not received yet. | 177 return; // Initial list of networks not received yet. |
| 205 networkIds.forEach(function(id) { | 178 networkIds.forEach(function(id) { |
| 206 if (this.activeNetworkIds_.has(id)) { | 179 if (this.activeNetworkIds_.has(id)) { |
| 207 this.networkingPrivate.getState( | 180 this.networkingPrivate.getState( |
| 208 id, this.getActiveStateCallback_.bind(this, id)); | 181 id, this.getActiveStateCallback_.bind(this, id)); |
| 209 } | 182 } |
| 210 }, this); | 183 }, this); |
| 211 }, | 184 }, |
| 212 | 185 |
| 213 /** | 186 /** |
| 214 * Determines whether or not a network state can be connected to. | |
| 215 * @param {!CrOnc.NetworkStateProperties} state The network state. | |
| 216 * @param {!chrome.networkingPrivate.GlobalPolicy|undefined} globalPolicy | |
| 217 * @private | |
| 218 */ | |
| 219 canConnect_: function(state, globalPolicy) { | |
| 220 if (state.Type == CrOnc.Type.ETHERNET || | |
| 221 state.Type == CrOnc.Type.VPN && !this.defaultNetwork) { | |
| 222 return false; | |
| 223 } | |
| 224 if (state.Type == CrOnc.Type.WI_FI && !!globalPolicy && | |
| 225 globalPolicy.AllowOnlyPolicyNetworksToConnect && | |
| 226 !this.isPolicySource(state.Source)) { | |
| 227 return false; | |
| 228 } | |
| 229 return state.ConnectionState == CrOnc.ConnectionState.NOT_CONNECTED; | |
| 230 }, | |
| 231 | |
| 232 /** | |
| 233 * networkingPrivate.getState event callback for an active state. | 187 * networkingPrivate.getState event callback for an active state. |
| 234 * @param {string} id The id of the requested state. | 188 * @param {string} id The id of the requested state. |
| 235 * @param {!chrome.networkingPrivate.NetworkStateProperties} state | 189 * @param {!chrome.networkingPrivate.NetworkStateProperties} state |
| 236 * @private | 190 * @private |
| 237 */ | 191 */ |
| 238 getActiveStateCallback_: function(id, state) { | 192 getActiveStateCallback_: function(id, state) { |
| 239 if (chrome.runtime.lastError) { | 193 if (chrome.runtime.lastError) { |
| 240 var message = chrome.runtime.lastError.message; | 194 var message = chrome.runtime.lastError.message; |
| 241 if (message != 'Error.NetworkUnavailable') { | 195 if (message != 'Error.NetworkUnavailable') { |
| 242 console.error( | 196 console.error( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 257 if (this.activeNetworkStates_[i].type == state.type) { | 211 if (this.activeNetworkStates_[i].type == state.type) { |
| 258 this.activeNetworkStates_[i] = state; | 212 this.activeNetworkStates_[i] = state; |
| 259 return; | 213 return; |
| 260 } | 214 } |
| 261 } | 215 } |
| 262 // Not found | 216 // Not found |
| 263 console.error('Active state not found: ' + state.Name); | 217 console.error('Active state not found: ' + state.Name); |
| 264 }, | 218 }, |
| 265 | 219 |
| 266 /** | 220 /** |
| 267 * Handles UI requests to connect to a network. | |
| 268 * TODO(stevenjb): Handle Cellular activation, etc. | |
| 269 * @param {!CrOnc.NetworkStateProperties} state The network state. | |
| 270 * @private | |
| 271 */ | |
| 272 connectToNetwork_: function(state) { | |
| 273 this.networkingPrivate.startConnect(state.GUID, function() { | |
| 274 if (chrome.runtime.lastError) { | |
| 275 var message = chrome.runtime.lastError.message; | |
| 276 if (message != 'connecting') { | |
| 277 console.error( | |
| 278 'Unexpected networkingPrivate.startConnect error: ' + message + | |
| 279 'For: ' + state.GUID); | |
| 280 } | |
| 281 } | |
| 282 }); | |
| 283 }, | |
| 284 | |
| 285 /** | |
| 286 * Requests the list of device states and network states from Chrome. | 221 * Requests the list of device states and network states from Chrome. |
| 287 * Updates deviceStates, activeNetworkStates, and networkStateLists once the | 222 * Updates deviceStates, activeNetworkStates, and networkStateLists once the |
| 288 * results are returned from Chrome. | 223 * results are returned from Chrome. |
| 289 * @private | 224 * @private |
| 290 */ | 225 */ |
| 291 getNetworkLists_: function() { | 226 getNetworkLists_: function() { |
| 292 // First get the device states. | 227 // First get the device states. |
| 293 this.networkingPrivate.getDeviceStates(function(deviceStates) { | 228 this.networkingPrivate.getDeviceStates(function(deviceStates) { |
| 294 // Second get the network states. | 229 // Second get the network states. |
| 295 this.getNetworkStates_(deviceStates); | 230 this.getNetworkStates_(deviceStates); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 newActiveNetworkStates.push(state); | 329 newActiveNetworkStates.push(state); |
| 395 this.activeNetworkIds_.add(state.GUID); | 330 this.activeNetworkIds_.add(state.GUID); |
| 396 } | 331 } |
| 397 | 332 |
| 398 this.deviceStates = newDeviceStates; | 333 this.deviceStates = newDeviceStates; |
| 399 this.networkStateLists_ = newNetworkStateLists; | 334 this.networkStateLists_ = newNetworkStateLists; |
| 400 // Set activeNetworkStates last to rebuild the dom-repeat. | 335 // Set activeNetworkStates last to rebuild the dom-repeat. |
| 401 this.activeNetworkStates_ = newActiveNetworkStates; | 336 this.activeNetworkStates_ = newActiveNetworkStates; |
| 402 }, | 337 }, |
| 403 }); | 338 }); |
| OLD | NEW |