Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(395)

Side by Side Diff: chrome/browser/resources/chromeos/network_ui/network_ui.js

Issue 1030963003: Use networkingPrivate types in JS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 var NetworkUI = (function() { 5 var NetworkUI = (function() {
6 'use strict'; 6 'use strict';
7 7
8 // Properties to display in the network state table. Each entry can be either 8 // Properties to display in the network state table. Each entry can be either
9 // a single state field or an array of state fields. If more than one is 9 // a single state field or an array of state fields. If more than one is
10 // specified then the first non empty value is used. 10 // specified then the first non empty value is used.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 var createTableRowElement = function() { 51 var createTableRowElement = function() {
52 return /** @type {!HTMLTableRowElement} */(document.createElement('tr')); 52 return /** @type {!HTMLTableRowElement} */(document.createElement('tr'));
53 }; 53 };
54 54
55 /** 55 /**
56 * Returns the ONC data property for networkState associated with a key. Used 56 * Returns the ONC data property for networkState associated with a key. Used
57 * to access properties in the networkState by |key| which may may refer to a 57 * to access properties in the networkState by |key| which may may refer to a
58 * nested property, e.g. 'WiFi.Security'. If any part of a nested key is 58 * nested property, e.g. 'WiFi.Security'. If any part of a nested key is
59 * missing, this will return undefined. 59 * missing, this will return undefined.
60 * 60 *
61 * @param {!CrOnc.NetworkConfigType} networkState The network state 61 * @param {!chrome.networkingPrivate.NetworkStateProperties} networkState The
michaelpg 2015/03/31 19:18:46 lol @ being able to fit 1 word of description. I g
62 * property dictionary. 62 * network state property dictionary.
63 * @param {string} key The ONC key for the property. 63 * @param {string} key The ONC key for the property.
64 * @return {*} The value associated with the property or undefined if the 64 * @return {*} The value associated with the property or undefined if the
65 * key (any part of it) is not defined. 65 * key (any part of it) is not defined.
66 */ 66 */
67 var getOncProperty = function(networkState, key) { 67 var getOncProperty = function(networkState, key) {
68 var dict = /** @type {!Object} */(networkState); 68 var dict = /** @type {!Object} */(networkState);
69 var keys = key.split('.'); 69 var keys = key.split('.');
70 while (keys.length > 1) { 70 while (keys.length > 1) {
71 var k = keys.shift(); 71 var k = keys.shift();
72 dict = dict[k]; 72 dict = dict[k];
(...skipping 19 matching lines...) Expand all
92 }); 92 });
93 button.className = 'state-table-expand-button'; 93 button.className = 'state-table-expand-button';
94 button.textContent = '+'; 94 button.textContent = '+';
95 cell.appendChild(button); 95 cell.appendChild(button);
96 return cell; 96 return cell;
97 }; 97 };
98 98
99 /** 99 /**
100 * Creates a cell with an icon representing the network state. 100 * Creates a cell with an icon representing the network state.
101 * 101 *
102 * @param {CrOnc.NetworkConfigType} networkState The network state properties. 102 * @param {!chrome.networkingPrivate.NetworkStateProperties} networkState The
103 * network state properties.
103 * @return {!HTMLTableCellElement} The created td element that displays the 104 * @return {!HTMLTableCellElement} The created td element that displays the
104 * icon. 105 * icon.
105 */ 106 */
106 var createStateTableIcon = function(networkState) { 107 var createStateTableIcon = function(networkState) {
107 var cell = createTableCellElement(); 108 var cell = createTableCellElement();
108 cell.className = 'state-table-icon-cell'; 109 cell.className = 'state-table-icon-cell';
109 var icon = /** @type {!CrNetworkIconElement} */( 110 var icon = /** @type {!CrNetworkIconElement} */(
110 document.createElement('cr-network-icon')); 111 document.createElement('cr-network-icon'));
111 icon.isListItem = true; 112 icon.isListItem = true;
112 icon.networkState = CrOncDataElement.create(networkState); 113 icon.networkState = CrOncDataElement.create(networkState);
(...skipping 11 matching lines...) Expand all
124 var createStateTableCell = function(value) { 125 var createStateTableCell = function(value) {
125 var cell = createTableCellElement(); 126 var cell = createTableCellElement();
126 cell.textContent = value || ''; 127 cell.textContent = value || '';
127 return cell; 128 return cell;
128 }; 129 };
129 130
130 /** 131 /**
131 * Creates a row in the network state table. 132 * Creates a row in the network state table.
132 * 133 *
133 * @param {Array} stateFields The state fields to use for the row. 134 * @param {Array} stateFields The state fields to use for the row.
134 * @param {CrOnc.NetworkConfigType} networkState The network state properties. 135 * @param {!chrome.networkingPrivate.NetworkStateProperties} networkState The
136 * network state properties.
135 * @return {!HTMLTableRowElement} The created tr element that contains the 137 * @return {!HTMLTableRowElement} The created tr element that contains the
136 * network state information. 138 * network state information.
137 */ 139 */
138 var createStateTableRow = function(stateFields, networkState) { 140 var createStateTableRow = function(stateFields, networkState) {
139 var row = createTableRowElement(); 141 var row = createTableRowElement();
140 row.className = 'state-table-row'; 142 row.className = 'state-table-row';
141 var guid = networkState.GUID; 143 var guid = networkState.GUID;
142 row.appendChild(createStateTableExpandButton(guid)); 144 row.appendChild(createStateTableExpandButton(guid));
143 row.appendChild(createStateTableIcon(networkState)); 145 row.appendChild(createStateTableIcon(networkState));
144 for (var i = 0; i < stateFields.length; ++i) { 146 for (var i = 0; i < stateFields.length; ++i) {
(...skipping 12 matching lines...) Expand all
157 value = value.slice(0, 8); 159 value = value.slice(0, 8);
158 row.appendChild(createStateTableCell(value)); 160 row.appendChild(createStateTableCell(value));
159 } 161 }
160 return row; 162 return row;
161 }; 163 };
162 164
163 /** 165 /**
164 * Creates a table for networks or favorites. 166 * Creates a table for networks or favorites.
165 * 167 *
166 * @param {string} tablename The name of the table to be created. 168 * @param {string} tablename The name of the table to be created.
167 * @param {Array} stateFields The list of fields for the table. 169 * @param {!Array<string>} stateFields The list of fields for the table.
168 * @param {Array} states An array of network or favorite states. 170 * @param {!Array<!chrome.networkingPrivate.NetworkStateProperties>} states
171 * An array of network or favorite states.
169 */ 172 */
170 var createStateTable = function(tablename, stateFields, states) { 173 var createStateTable = function(tablename, stateFields, states) {
171 var table = $(tablename); 174 var table = $(tablename);
172 var oldRows = table.querySelectorAll('.state-table-row'); 175 var oldRows = table.querySelectorAll('.state-table-row');
173 for (var i = 0; i < oldRows.length; ++i) 176 for (var i = 0; i < oldRows.length; ++i)
174 table.removeChild(oldRows[i]); 177 table.removeChild(oldRows[i]);
175 states.forEach(function(state) { 178 states.forEach(function(state) {
176 table.appendChild(createStateTableRow( 179 table.appendChild(createStateTableRow(stateFields, state));
177 stateFields, /** @type {!CrOnc.NetworkConfigType} */(state)));
178 }); 180 });
179 }; 181 };
180 182
181 /** 183 /**
182 * Returns a valid HTMLElement id from |guid|. 184 * Returns a valid HTMLElement id from |guid|.
183 * 185 *
184 * @param {string} guid A GUID which may start with a digit. 186 * @param {string} guid A GUID which may start with a digit.
185 * @return {string} A valid HTMLElement id. 187 * @return {string} A valid HTMLElement id.
186 */ 188 */
187 var idFromGuid = function(guid) { 189 var idFromGuid = function(guid) {
188 return '_' + guid.replace(/[{}]/g, ''); 190 return '_' + guid.replace(/[{}]/g, '');
189 }; 191 };
190 192
191 /** 193 /**
192 * This callback function is triggered when visible networks are received. 194 * This callback function is triggered when visible networks are received.
193 * 195 *
194 * @param {!Array<!Object>} states A list of network state information for 196 * @param {!Array<!chrome.networkingPrivate.NetworkStateProperties>} states
195 * each visible network. 197 * A list of network state information for each visible network.
196 */ 198 */
197 var onVisibleNetworksReceived = function(states) { 199 var onVisibleNetworksReceived = function(states) {
198 /** @type {CrOnc.NetworkConfigType} */ var defaultState; 200 /** @type {chrome.networkingPrivate.NetworkStateProperties} */ var
201 defaultState;
199 if (states.length > 0) 202 if (states.length > 0)
200 defaultState = /** @type {!CrOnc.NetworkConfigType} */(states[0]); 203 defaultState = states[0];
201 var icon = /** @type {CrNetworkIconElement} */($('default-network-icon')); 204 var icon = /** @type {CrNetworkIconElement} */($('default-network-icon'));
202 if (defaultState && defaultState.Type != 'VPN') { 205 if (defaultState &&
206 defaultState.Type != chrome.networkingPrivate.NetworkType.VPN) {
203 $('default-network-text').textContent = 207 $('default-network-text').textContent =
204 loadTimeData.getStringF('defaultNetworkText', 208 loadTimeData.getStringF('defaultNetworkText',
205 defaultState.Name, 209 defaultState.Name,
206 defaultState.ConnectionState); 210 defaultState.ConnectionState);
207 icon.networkState = CrOncDataElement.create(defaultState); 211 icon.networkState = CrOncDataElement.create(defaultState);
208 } else { 212 } else {
209 $('default-network-text').textContent = 213 $('default-network-text').textContent =
210 loadTimeData.getString('noNetworkText'); 214 loadTimeData.getString('noNetworkText');
211 // Show the disconnected wifi icon if there are no networks. 215 // Show the disconnected wifi icon if there are no networks.
212 icon.networkType = CrOnc.Type.WIFI; 216 icon.networkType = chrome.networkingPrivate.NetworkType.WiFi;
213 } 217 }
214 218
215 createStateTable('network-state-table', NETWORK_STATE_FIELDS, states); 219 createStateTable('network-state-table', NETWORK_STATE_FIELDS, states);
216 }; 220 };
217 221
218 /** 222 /**
219 * This callback function is triggered when favorite networks are received. 223 * This callback function is triggered when favorite networks are received.
220 * 224 *
221 * @param {!Array<!Object>} states A list of network state information for 225 * @param {!Array<!chrome.networkingPrivate.NetworkStateProperties>} states
222 * each favorite network. 226 * A list of network state information for each favorite network.
223 */ 227 */
224 var onFavoriteNetworksReceived = function(states) { 228 var onFavoriteNetworksReceived = function(states) {
225 createStateTable('favorite-state-table', FAVORITE_STATE_FIELDS, states); 229 createStateTable('favorite-state-table', FAVORITE_STATE_FIELDS, states);
226 }; 230 };
227 231
228 /** 232 /**
229 * Toggles the button state and add or remove a row displaying the complete 233 * Toggles the button state and add or remove a row displaying the complete
230 * state information for a row. 234 * state information for a row.
231 * 235 *
232 * @param {!HTMLElement} btn The button that was clicked. 236 * @param {!HTMLElement} btn The button that was clicked.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 document.addEventListener('DOMContentLoaded', function() { 343 document.addEventListener('DOMContentLoaded', function() {
340 $('refresh').onclick = requestNetworks; 344 $('refresh').onclick = requestNetworks;
341 setRefresh(); 345 setRefresh();
342 requestNetworks(); 346 requestNetworks();
343 }); 347 });
344 348
345 return { 349 return {
346 getShillPropertiesResult: getShillPropertiesResult 350 getShillPropertiesResult: getShillPropertiesResult
347 }; 351 };
348 })(); 352 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698