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',
22 value: 'internet-known-networks',
35 * Whether the page is a subpage.
43 * Title for the page header and navigation menu.
48 return loadTimeData.getString('internetKnownNetworksPageTitle');
53 * Reflects the selected settings page. We use this to extract networkType
54 * from window.location.href when this page is navigated to. This is a
55 * workaround for a bug in the 1.0 version of more-routing where
56 * selected-params='{{params}}' is not correctly setting params in
57 * settings_main.html. TODO(stevenjb): Remove once more-routing is fixed.
58 * @type {?{PAGE_ID: string}}
63 observer: 'selectedPageChanged_'
67 * Name of the 'core-icon' to show.
71 value: 'settings-ethernet',
76 * The type of networks to list.
77 * @type {chrome.networkingPrivate.NetworkType}
81 value: CrOnc.Type.WI_FI,
82 observer: 'networkTypeChanged_',
86 * The maximum height in pixels for the list of networks.
94 * List of all network state data for the network type.
95 * @type {!Array<!CrOnc.NetworkStateProperties>}
99 value: function() { return []; }
104 * Listener function for chrome.networkingPrivate.onNetworksChanged event.
105 * @type {function(!Array<string>)}
108 networksChangedListener_: function() {},
111 attached: function() {
112 this.networksChangedListener_ = this.onNetworksChangedEvent_.bind(this);
113 chrome.networkingPrivate.onNetworksChanged.addListener(
114 this.networksChangedListener_);
118 detached: function() {
119 chrome.networkingPrivate.onNetworksChanged.removeListener(
120 this.networksChangedListener_);
124 * Polymer type changed method.
126 networkTypeChanged_: function() {
127 if (!this.networkType)
129 this.refreshNetworks_();
133 * Polymer selectedPage changed method. TODO(stevenjb): Remove, see above.
135 selectedPageChanged_: function() {
136 if ((this.selectedPage && this.selectedPage.PAGE_ID) != this.PAGE_ID)
138 var href = window.location.href;
139 var idx = href.lastIndexOf('/');
140 var type = href.slice(idx + 1);
143 /** @type {chrome.networkingPrivate.NetworkType} */(type);
148 * networkingPrivate.onNetworksChanged event callback.
149 * @param {!Array<string>} networkIds The list of changed network GUIDs.
152 onNetworksChangedEvent_: function(networkIds) {
153 this.refreshNetworks_();
157 * Requests the list of network states from Chrome. Updates networkStates
158 * once the results are returned from Chrome.
161 refreshNetworks_: function() {
163 networkType: this.networkType,
167 chrome.networkingPrivate.getNetworks(
169 function(states) { this.networkStateList = states; }.bind(this));
173 * Event triggered when a cr-network-list item is selected.
174 * @param {!{detail: !CrOnc.NetworkStateProperties}} event
177 onListItemSelected_: function(event) {
178 var state = event.detail;
179 MoreRouting.navigateTo('internet-detail', {guid: state.GUID});
183 * Event triggered when a cr-network-list item 'remove' button is pressed.
184 * @param {!{detail: !CrOnc.NetworkStateProperties}} event
187 onRemove_: function(event) {
188 var state = event.detail;
191 chrome.networkingPrivate.forgetNetwork(state.GUID);
195 * Event triggered when a cr-network-list item 'preferred' button is toggled.
196 * @param {!{detail: !CrOnc.NetworkStateProperties}} event
199 onTogglePreferred_: function(event) {
200 var state = event.detail;
203 var preferred = state.Priority > 0;
204 var onc = {Priority: preferred ? 0 : 1};
205 chrome.networkingPrivate.setProperties(state.GUID, onc);
209 * Navigate to the previous page.
212 navigateBack_: function() {
213 MoreRouting.navigateTo('internet');