| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @fileoverview Polymer element wrapping cr-network-list including the | |
| 7 * networkingPrivate calls to populate it. | |
| 8 */ | |
| 9 | |
| 10 /** | |
| 11 * @element cr-network-select | |
| 12 */ | |
| 13 Polymer({ | |
| 14 is: 'cr-network-select', | |
| 15 | |
| 16 properties: { | |
| 17 /** | |
| 18 * Network state for the active network. | |
| 19 * @type {?CrOnc.NetworkStateProperties} | |
| 20 */ | |
| 21 activeNetworkState: { | |
| 22 type: Object, | |
| 23 value: null | |
| 24 }, | |
| 25 | |
| 26 /** | |
| 27 * If true, the element includes an 'expand' button that toggles the | |
| 28 * expanded state of the network list. | |
| 29 */ | |
| 30 expandable: { | |
| 31 type: Boolean, | |
| 32 value: false | |
| 33 }, | |
| 34 | |
| 35 /** | |
| 36 * The maximum height in pixels for the list. | |
| 37 */ | |
| 38 maxHeight: { | |
| 39 type: Number, | |
| 40 value: 1000 | |
| 41 }, | |
| 42 | |
| 43 /** | |
| 44 * If true, expand the network list. | |
| 45 */ | |
| 46 networkListOpened: { | |
| 47 type: Boolean, | |
| 48 value: true, | |
| 49 observer: "networkListOpenedChanged_" | |
| 50 }, | |
| 51 | |
| 52 /** | |
| 53 * If true, show the active network state. | |
| 54 */ | |
| 55 showActive: { | |
| 56 type: Boolean, | |
| 57 value: false | |
| 58 }, | |
| 59 | |
| 60 /** | |
| 61 * List of all network state data for all visible networks. | |
| 62 * @type {!Array<!CrOnc.NetworkStateProperties>} | |
| 63 */ | |
| 64 networkStateList: { | |
| 65 type: Array, | |
| 66 value: function() { return []; } | |
| 67 } | |
| 68 }, | |
| 69 | |
| 70 /** | |
| 71 * Listener function for chrome.networkingPrivate.onNetworkListChanged event. | |
| 72 * @type {function(!Array<string>)} | |
| 73 * @private | |
| 74 */ | |
| 75 networkListChangedListener_: function() {}, | |
| 76 | |
| 77 /** | |
| 78 * Listener function for chrome.networkingPrivate.onDeviceStateListChanged | |
| 79 * event. | |
| 80 * @type {function(!Array<string>)} | |
| 81 * @private | |
| 82 */ | |
| 83 deviceStateListChangedListener_: function() {}, | |
| 84 | |
| 85 /** @override */ | |
| 86 attached: function() { | |
| 87 this.networkListChangedListener_ = this.refreshNetworks_.bind(this); | |
| 88 chrome.networkingPrivate.onNetworkListChanged.addListener( | |
| 89 this.networkListChangedListener_); | |
| 90 | |
| 91 this.deviceStateListChangedListener_ = this.refreshNetworks_.bind(this); | |
| 92 chrome.networkingPrivate.onDeviceStateListChanged.addListener( | |
| 93 this.deviceStateListChangedListener_); | |
| 94 | |
| 95 this.refreshNetworks_(); | |
| 96 chrome.networkingPrivate.requestNetworkScan(); | |
| 97 }, | |
| 98 | |
| 99 /** @override */ | |
| 100 detached: function() { | |
| 101 chrome.networkingPrivate.onNetworkListChanged.removeListener( | |
| 102 this.networkListChangedListener_); | |
| 103 chrome.networkingPrivate.onDeviceStateListChanged.removeListener( | |
| 104 this.deviceStateListChangedListener_); | |
| 105 }, | |
| 106 | |
| 107 /** | |
| 108 * Polymer chnaged function. | |
| 109 * @private | |
| 110 */ | |
| 111 networkListOpenedChanged_: function() { | |
| 112 if (this.networkListOpened) | |
| 113 chrome.networkingPrivate.requestNetworkScan(); | |
| 114 }, | |
| 115 | |
| 116 /** | |
| 117 * Request the list of visible networks. | |
| 118 * @private | |
| 119 */ | |
| 120 refreshNetworks_: function() { | |
| 121 var filter = { | |
| 122 networkType: chrome.networkingPrivate.NetworkType.ALL, | |
| 123 visible: true, | |
| 124 configured: false | |
| 125 }; | |
| 126 chrome.networkingPrivate.getNetworks( | |
| 127 filter, this.getNetworksCallback_.bind(this)); | |
| 128 }, | |
| 129 | |
| 130 /** | |
| 131 * @param {!Array<!CrOnc.NetworkStateProperties>} states | |
| 132 * @private | |
| 133 */ | |
| 134 getNetworksCallback_: function(states) { | |
| 135 this.activeNetworkState = states[0] || null; | |
| 136 this.networkStateList = states; | |
| 137 }, | |
| 138 | |
| 139 /** | |
| 140 * Event triggered when a cr-network-list-item is selected. | |
| 141 * @param {!{detail: !CrOnc.NetworkStateProperties}} event | |
| 142 * @private | |
| 143 */ | |
| 144 onNetworkListItemSelected_: function(event) { | |
| 145 var state = event.detail; | |
| 146 if (state.ConnectionState != CrOnc.ConnectionState.NOT_CONNECTED) | |
| 147 return; | |
| 148 chrome.networkingPrivate.startConnect(state.GUID, function() { | |
| 149 var lastError = chrome.runtime.lastError; | |
| 150 if (lastError && lastError != 'connecting') | |
| 151 console.error('networkingPrivate.startConnect error:', lastError); | |
| 152 }); | |
| 153 }, | |
| 154 }); | |
| OLD | NEW |