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 wrapping cr-network-list including the | 6 * @fileoverview Polymer element wrapping cr-network-list including the |
| 7 * networkingPrivate calls to populate it. | 7 * networkingPrivate calls to populate it. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 Polymer({ | 10 Polymer({ |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 /** | 49 /** |
| 50 * If true, show the active network state. | 50 * If true, show the active network state. |
| 51 */ | 51 */ |
| 52 showActive: { | 52 showActive: { |
| 53 type: Boolean, | 53 type: Boolean, |
| 54 value: false | 54 value: false |
| 55 }, | 55 }, |
| 56 | 56 |
| 57 /** | 57 /** |
| 58 * List of all network state data for all visible networks. | 58 * List of all network state data for all visible networks. |
| 59 * Consists of networksFromAPI_ + networkStateAddon. | |
| 60 * See <cr-network-list-item/> for details. | |
| 61 * | |
| 59 * @type {!Array<!CrOnc.NetworkStateProperties>} | 62 * @type {!Array<!CrOnc.NetworkStateProperties>} |
| 60 */ | 63 */ |
| 61 networkStateList: { | 64 networkStateList: { |
| 62 type: Array, | 65 type: Array, |
| 63 value: function() { return []; } | 66 value: function() { return []; } |
| 64 } | 67 }, |
| 68 | |
| 69 /** | |
| 70 * Additional list of network states to be always added to networkStateList. | |
| 71 * See <cr-network-list-item/> for details. | |
| 72 * | |
| 73 * @type {!Array<!CrOnc.NetworkStateProperties>} | |
| 74 */ | |
| 75 networkStateAddon: { | |
| 76 type: Array, | |
| 77 value: function() { return []; }, | |
| 78 observer: "networkStateAddonChanged_" | |
| 79 }, | |
| 80 | |
| 81 /** | |
| 82 * Hides all buttons in list items. | |
| 83 */ | |
| 84 noButtons: { | |
| 85 type: Boolean, | |
| 86 value: false, | |
| 87 }, | |
| 88 | |
| 89 /** | |
| 90 * This is callback, which is called when user taps on list item. | |
| 91 * | |
| 92 * @type {Function} | |
| 93 */ | |
| 94 onNetworkListItemSelectedObserver: { | |
| 95 type: Object, | |
| 96 value: null, | |
| 97 }, | |
| 98 | |
| 99 /** | |
| 100 * This event is fired on each NetworkStateProperties object when it has | |
| 101 * state 'Connected'. | |
| 102 * | |
| 103 * @type {String} | |
| 104 */ | |
| 105 networkConnectedEvent: { | |
| 106 type: String, | |
| 107 value: null, | |
| 108 }, | |
| 65 }, | 109 }, |
| 66 | 110 |
| 67 /** | 111 /** |
| 112 * List of all network state data for all visible networks. | |
| 113 * @type {!Array<!CrOnc.NetworkStateProperties>} | |
| 114 */ | |
| 115 networksFromAPI_: [], | |
| 116 | |
| 117 /** | |
| 68 * Listener function for chrome.networkingPrivate.onNetworkListChanged event. | 118 * Listener function for chrome.networkingPrivate.onNetworkListChanged event. |
| 69 * @type {function(!Array<string>)} | 119 * @type {function(!Array<string>)} |
| 70 * @private | 120 * @private |
| 71 */ | 121 */ |
| 72 networkListChangedListener_: function() {}, | 122 networkListChangedListener_: function() {}, |
| 73 | 123 |
| 74 /** | 124 /** |
| 75 * Listener function for chrome.networkingPrivate.onDeviceStateListChanged | 125 * Listener function for chrome.networkingPrivate.onDeviceStateListChanged |
| 76 * event. | 126 * event. |
| 77 * @type {function(!Array<string>)} | 127 * @type {function(!Array<string>)} |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 95 | 145 |
| 96 /** @override */ | 146 /** @override */ |
| 97 detached: function() { | 147 detached: function() { |
| 98 chrome.networkingPrivate.onNetworkListChanged.removeListener( | 148 chrome.networkingPrivate.onNetworkListChanged.removeListener( |
| 99 this.networkListChangedListener_); | 149 this.networkListChangedListener_); |
| 100 chrome.networkingPrivate.onDeviceStateListChanged.removeListener( | 150 chrome.networkingPrivate.onDeviceStateListChanged.removeListener( |
| 101 this.deviceStateListChangedListener_); | 151 this.deviceStateListChangedListener_); |
| 102 }, | 152 }, |
| 103 | 153 |
| 104 /** | 154 /** |
| 105 * Polymer chnaged function. | 155 * Polymer changed function. |
| 106 * @private | 156 * @private |
| 107 */ | 157 */ |
| 108 networkListOpenedChanged_: function() { | 158 networkListOpenedChanged_: function() { |
| 109 if (this.networkListOpened) | 159 if (this.networkListOpened) |
| 110 chrome.networkingPrivate.requestNetworkScan(); | 160 chrome.networkingPrivate.requestNetworkScan(); |
| 111 }, | 161 }, |
| 112 | 162 |
| 113 /** | 163 /** |
| 164 * Polymer changed function. | |
| 165 * @private | |
| 166 */ | |
| 167 networkStateAddonChanged_: function() { | |
| 168 this.UpdateNetworkStateList_(); | |
| 169 }, | |
| 170 | |
| 171 /** | |
| 114 * Request the list of visible networks. | 172 * Request the list of visible networks. |
| 115 * @private | 173 * @private |
| 116 */ | 174 */ |
| 117 refreshNetworks_: function() { | 175 refreshNetworks_: function() { |
| 118 var filter = { | 176 var filter = { |
| 119 networkType: chrome.networkingPrivate.NetworkType.ALL, | 177 networkType: chrome.networkingPrivate.NetworkType.ALL, |
| 120 visible: true, | 178 visible: true, |
| 121 configured: false | 179 configured: false |
| 122 }; | 180 }; |
| 123 chrome.networkingPrivate.getNetworks( | 181 chrome.networkingPrivate.getNetworks( |
| 124 filter, this.getNetworksCallback_.bind(this)); | 182 filter, this.getNetworksCallback_.bind(this)); |
| 125 }, | 183 }, |
| 126 | 184 |
| 127 /** | 185 /** |
| 128 * @param {!Array<!CrOnc.NetworkStateProperties>} states | 186 * @param {!Array<!CrOnc.NetworkStateProperties>} states |
| 129 * @private | 187 * @private |
| 130 */ | 188 */ |
| 131 getNetworksCallback_: function(states) { | 189 getNetworksCallback_: function(states) { |
| 132 this.activeNetworkState = states[0] || null; | 190 this.activeNetworkState = states[0] || null; |
| 133 this.networkStateList = states; | 191 this.networksFromAPI_ = states; |
| 192 this.UpdateNetworkStateList_(); | |
| 134 }, | 193 }, |
| 135 | 194 |
| 136 /** | 195 /** |
| 196 * Updates networkStateList. | |
| 197 * @private | |
| 198 */ | |
| 199 UpdateNetworkStateList_: function() { | |
| 200 this.networkStateList = | |
| 201 Array.from(this.networksFromAPI_).concat(this.networkStateAddon); | |
| 202 }, | |
| 203 | |
| 204 /** | |
| 137 * Event triggered when a cr-network-list-item is selected. | 205 * Event triggered when a cr-network-list-item is selected. |
| 138 * @param {!{detail: !CrOnc.NetworkStateProperties}} event | 206 * @param {!{detail: !CrOnc.NetworkStateProperties}} event |
| 139 * @private | 207 * @private |
| 140 */ | 208 */ |
| 141 onNetworkListItemSelected_: function(event) { | 209 onNetworkListItemSelected_: function(event) { |
| 142 var state = event.detail; | 210 var state = event.detail; |
| 211 if (state.onTapEvent) { | |
| 212 this.fire(state.onTapEvent, state); | |
| 213 return; | |
| 214 } | |
| 215 | |
| 216 if (this.onNetworkListItemSelectedObserver) | |
| 217 this.onNetworkListItemSelectedObserver(state); | |
|
stevenjb
2016/06/16 17:41:34
Why have a callback in addition to firing an event
Alexander Alekseev
2016/06/22 08:24:18
Before user clicks on a network, we cannot proceed
stevenjb
2016/06/22 21:03:24
I am still confused. If we relaly need to do somet
| |
| 218 | |
| 143 if (state.ConnectionState != CrOnc.ConnectionState.NOT_CONNECTED) | 219 if (state.ConnectionState != CrOnc.ConnectionState.NOT_CONNECTED) |
| 144 return; | 220 return; |
| 221 | |
| 145 chrome.networkingPrivate.startConnect(state.GUID, function() { | 222 chrome.networkingPrivate.startConnect(state.GUID, function() { |
| 146 var lastError = chrome.runtime.lastError; | 223 var lastError = chrome.runtime.lastError; |
| 147 if (lastError && lastError != 'connecting') | 224 if (lastError && lastError != 'connecting') |
| 148 console.error('networkingPrivate.startConnect error: ' + lastError); | 225 console.error('networkingPrivate.startConnect error: ' + lastError); |
| 149 }); | 226 }); |
| 150 }, | 227 }, |
| 151 }); | 228 }); |
| OLD | NEW |