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.
7 * 'cr-settings-internet-known-networks' is the settings subpage listing the
8 * known networks for a type (currently always WiFi).
10 * @group Chrome Settings Elements
11 * @element cr-settings-internet-known-networks
14 is: 'cr-settings-internet-known-networks-page',
18 * The type of networks to list.
19 * @type {chrome.networkingPrivate.NetworkType}
23 value: CrOnc.Type.WI_FI,
24 observer: 'networkTypeChanged_',
28 * The maximum height in pixels for the list of networks.
36 * List of all network state data for the network type.
37 * @type {!Array<!CrOnc.NetworkStateProperties>}
41 value: function() { return []; }
46 * Listener function for chrome.networkingPrivate.onNetworksChanged event.
47 * @type {function(!Array<string>)}
50 networksChangedListener_: function() {},
53 attached: function() {
54 this.networksChangedListener_ = this.onNetworksChangedEvent_.bind(this);
55 chrome.networkingPrivate.onNetworksChanged.addListener(
56 this.networksChangedListener_);
60 detached: function() {
61 chrome.networkingPrivate.onNetworksChanged.removeListener(
62 this.networksChangedListener_);
66 * Polymer type changed method.
68 networkTypeChanged_: function() {
69 if (!this.networkType)
71 this.refreshNetworks_();
75 * networkingPrivate.onNetworksChanged event callback.
76 * @param {!Array<string>} networkIds The list of changed network GUIDs.
79 onNetworksChangedEvent_: function(networkIds) {
80 this.refreshNetworks_();
84 * Requests the list of network states from Chrome. Updates networkStates
85 * once the results are returned from Chrome.
88 refreshNetworks_: function() {
90 networkType: this.networkType,
94 chrome.networkingPrivate.getNetworks(
96 function(states) { this.networkStateList = states; }.bind(this));
100 * Event triggered when a cr-network-list item is selected.
101 * @param {!{detail: !CrOnc.NetworkStateProperties}} event
104 onListItemSelected_: function(event) {
105 this.fire('show-detail', event.detail);
109 * Event triggered when a cr-network-list item 'remove' button is pressed.
110 * @param {!{detail: !CrOnc.NetworkStateProperties}} event
113 onRemove_: function(event) {
114 var state = event.detail;
117 chrome.networkingPrivate.forgetNetwork(state.GUID);
121 * Event triggered when a cr-network-list item 'preferred' button is toggled.
122 * @param {!{detail: !CrOnc.NetworkStateProperties}} event
125 onTogglePreferred_: function(event) {
126 var state = event.detail;
129 var preferred = state.Priority > 0;
130 var onc = {Priority: preferred ? 0 : 1};
131 chrome.networkingPrivate.setProperties(state.GUID, onc);