| Index: chrome/browser/resources/chromeos/network_ui/network_ui.js
|
| diff --git a/chrome/browser/resources/chromeos/network.js b/chrome/browser/resources/chromeos/network_ui/network_ui.js
|
| similarity index 69%
|
| rename from chrome/browser/resources/chromeos/network.js
|
| rename to chrome/browser/resources/chromeos/network_ui/network_ui.js
|
| index 4f952bc1d55c77d75aae979282600fd17d9bf715..aeb6dbcb3c6409cf9f2cfac7af3d767d6b1c89e1 100644
|
| --- a/chrome/browser/resources/chromeos/network.js
|
| +++ b/chrome/browser/resources/chromeos/network_ui/network_ui.js
|
| @@ -2,20 +2,35 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -var NetworkUI = function() {
|
| +var NetworkUI = (function() {
|
| + 'use strict';
|
| +
|
| + var ONC = networkConfig.ONC;
|
| +
|
| // Properties to display in the network state table. Each entry can be either
|
| // a single state field or an array of state fields. If more than one is
|
| // specified then the first non empty value is used.
|
| var NETWORK_STATE_FIELDS = [
|
| - 'Name', 'Type', 'State', 'Profile', 'Connectable',
|
| - 'Error', 'Security',
|
| - ['Cellular.NetworkTechnology', 'EAP.EAP'],
|
| - 'Cellular.ActivationState', 'Cellular.RoamingState',
|
| - 'Cellular.OutOfCredits', 'Strength'
|
| + ONC.GUID,
|
| + ONC.Name,
|
| + ONC.Type,
|
| + ONC.ConnectionState,
|
| + ONC.ErrorState,
|
| + ONC.WiFi.Security,
|
| + [ONC.Cellular.NetworkTechnology,
|
| + ONC.EAP.EAP],
|
| + ONC.Cellular.ActivationState,
|
| + ONC.Cellular.RoamingState,
|
| + ONC.Cellular.OutOfCredits,
|
| + ONC.WiFi.SignalStrength
|
| ];
|
|
|
| var FAVORITE_STATE_FIELDS = [
|
| - 'Name', 'Type', 'Profile', 'onc_source'
|
| + ONC.GUID,
|
| + ONC.Name,
|
| + ONC.Type,
|
| + ONC.Profile,
|
| + ONC.OncSource
|
| ];
|
|
|
| var LOG_LEVEL_CLASSNAME = {
|
| @@ -100,12 +115,12 @@ var NetworkUI = function() {
|
| * @param {dictionary} state Property values for the network or favorite.
|
| * @return {DOMElement} The created td element that displays the given value.
|
| */
|
| - var createStateTableExpandButton = function(state) {
|
| + var createStateTableExpandButton = function(guid) {
|
| var cell = document.createElement('td');
|
| cell.className = 'state-table-expand-button-cell';
|
| var button = document.createElement('button');
|
| button.addEventListener('click', function(event) {
|
| - toggleExpandRow(event.target, state);
|
| + toggleExpandRow(event.target, guid);
|
| });
|
| button.className = 'state-table-expand-button';
|
| cell.appendChild(button);
|
| @@ -128,32 +143,29 @@ var NetworkUI = function() {
|
| * Create a row in the network state table.
|
| *
|
| * @param {string} stateFields The state fields to use for the row.
|
| - * @param {string} path The network or favorite path.
|
| * @param {dictionary} state Property values for the network or favorite.
|
| * @return {DOMElement} The created tr element that contains the network
|
| * state information.
|
| */
|
| - var createStateTableRow = function(stateFields, path, state) {
|
| + var createStateTableRow = function(stateFields, state) {
|
| var row = document.createElement('tr');
|
| row.className = 'state-table-row';
|
| - row.appendChild(createStateTableExpandButton(state));
|
| - row.appendChild(createStateTableCell(path));
|
| - var guid = state['GUID'];
|
| - if (guid)
|
| - guid = guid.slice(1, 9);
|
| - row.appendChild(createStateTableCell(guid));
|
| + var guid = networkConfig.getValueFromProperties(state, ONC.GUID);
|
| + row.appendChild(createStateTableExpandButton(guid));
|
| for (var i = 0; i < stateFields.length; ++i) {
|
| var field = stateFields[i];
|
| var value = '';
|
| if (typeof field == 'string') {
|
| - value = state[field];
|
| + value = networkConfig.getValueFromProperties(state, field);
|
| } else {
|
| for (var j = 0; j < field.length; ++j) {
|
| - value = state[field[j]];
|
| + value = networkConfig.getValueFromProperties(state, field[j]);
|
| if (value)
|
| break;
|
| }
|
| }
|
| + if (field == ONC.GUID && field[0] != '/')
|
| + value = value.slice(0, 12);
|
| row.appendChild(createStateTableCell(value));
|
| }
|
| return row;
|
| @@ -171,22 +183,38 @@ var NetworkUI = function() {
|
| var oldRows = table.querySelectorAll('.state-table-row');
|
| for (var i = 0; i < oldRows.length; ++i)
|
| table.removeChild(oldRows[i]);
|
| - for (var path in states)
|
| - table.appendChild(createStateTableRow(stateFields, path, states[path]));
|
| + states.forEach(function(state) {
|
| + table.appendChild(createStateTableRow(stateFields, state));
|
| + });
|
| + };
|
| +
|
| + /**
|
| + * This callback function is triggered when the network log is received.
|
| + *
|
| + * @param {dictionary} data A JSON structure of event log entries.
|
| + */
|
| + var getNetworkLogCallback = function(data) {
|
| + createEventLog(JSON.parse(data));
|
| + };
|
| +
|
| + /**
|
| + * This callback function is triggered when visible networks are received.
|
| + *
|
| + * @param {dictionary} data A list of network state information for each
|
| + * visible network.
|
| + */
|
| + var onVisibleNetworksReceived = function(states) {
|
| + createStateTable('network-state-table', NETWORK_STATE_FIELDS, states);
|
| };
|
|
|
| /**
|
| - * This callback function is triggered when the data is received.
|
| + * This callback function is triggered when favorite networks are received.
|
| *
|
| - * @param {dictionary} data A dictionary that contains network state
|
| - * information.
|
| + * @param {dictionary} data A list of network state information for each
|
| + * favorite network.
|
| */
|
| - var onNetworkInfoReceived = function(data) {
|
| - createEventLog(JSON.parse(data.networkEventLog));
|
| - createStateTable(
|
| - 'network-state-table', NETWORK_STATE_FIELDS, data.networkStates);
|
| - createStateTable(
|
| - 'favorite-state-table', FAVORITE_STATE_FIELDS, data.favoriteStates);
|
| + var onFavoriteNetworksReceived = function(states) {
|
| + createStateTable('favorite-state-table', FAVORITE_STATE_FIELDS, states);
|
| };
|
|
|
| /**
|
| @@ -196,7 +224,7 @@ var NetworkUI = function() {
|
| * @param {DOMElement} btn The button that was clicked.
|
| * @param {dictionary} state Property values for the network or favorite.
|
| */
|
| - var toggleExpandRow = function(btn, state) {
|
| + var toggleExpandRow = function(btn, guid) {
|
| var cell = btn.parentNode;
|
| var row = cell.parentNode;
|
| if (btn.classList.contains('state-table-expand-button-expanded')) {
|
| @@ -204,7 +232,7 @@ var NetworkUI = function() {
|
| row.parentNode.removeChild(row.nextSibling);
|
| } else {
|
| btn.classList.add('state-table-expand-button-expanded');
|
| - var expandedRow = createExpandedRow(state, row);
|
| + var expandedRow = createExpandedRow(guid, row);
|
| row.parentNode.insertBefore(expandedRow, row.nextSibling);
|
| }
|
| };
|
| @@ -216,7 +244,7 @@ var NetworkUI = function() {
|
| * @param {DOMElement} baseRow The unexpanded row associated with the new row.
|
| * @return {DOMElement} The created tr element for the expanded row.
|
| */
|
| - var createExpandedRow = function(state, baseRow) {
|
| + var createExpandedRow = function(guid, baseRow) {
|
| var expandedRow = document.createElement('tr');
|
| expandedRow.className = 'state-table-row';
|
| var emptyCell = document.createElement('td');
|
| @@ -225,16 +253,27 @@ var NetworkUI = function() {
|
| var detailCell = document.createElement('td');
|
| detailCell.className = 'state-table-expanded-cell';
|
| detailCell.colSpan = baseRow.childNodes.length - 1;
|
| - detailCell.innerHTML = JSON.stringify(state, null, '\t');
|
| expandedRow.appendChild(detailCell);
|
| + networkConfig.getProperties(guid, function(state) {
|
| + detailCell.innerHTML = JSON.stringify(state, null, '\t');
|
| + });
|
| return expandedRow;
|
| };
|
|
|
| /**
|
| - * Sends a refresh request.
|
| + * Requests a network log update.
|
| + */
|
| + var requestLog = function() {
|
| + chrome.send('NetworkUI.getNetworkLog');
|
| + };
|
| +
|
| + /**
|
| + * Requests an update of all network info.
|
| */
|
| - var sendRefresh = function() {
|
| - chrome.send('requestNetworkInfo');
|
| + var requestNetworks = function() {
|
| + networkConfig.getVisibleNetworks(networkConfig.Type.All,
|
| + onVisibleNetworksReceived);
|
| + // TODO(stevenjb): Request favorites.
|
| };
|
|
|
| /**
|
| @@ -243,31 +282,32 @@ var NetworkUI = function() {
|
| var setRefresh = function() {
|
| var interval = parseQueryParams(window.location)['refresh'];
|
| if (interval && interval != '')
|
| - setInterval(sendRefresh, parseInt(interval) * 1000);
|
| + setInterval(requestNetworks, parseInt(interval) * 1000);
|
| };
|
|
|
| /**
|
| * Get network information from WebUI.
|
| */
|
| document.addEventListener('DOMContentLoaded', function() {
|
| - $('log-refresh').onclick = sendRefresh;
|
| + $('log-refresh').onclick = requestLog;
|
| $('log-error').checked = true;
|
| - $('log-error').onclick = sendRefresh;
|
| + $('log-error').onclick = requestLog;
|
| $('log-user').checked = true;
|
| - $('log-user').onclick = sendRefresh;
|
| + $('log-user').onclick = requestLog;
|
| $('log-event').checked = true;
|
| - $('log-event').onclick = sendRefresh;
|
| + $('log-event').onclick = requestLog;
|
| $('log-debug').checked = false;
|
| - $('log-debug').onclick = sendRefresh;
|
| + $('log-debug').onclick = requestLog;
|
| $('log-fileinfo').checked = false;
|
| - $('log-fileinfo').onclick = sendRefresh;
|
| + $('log-fileinfo').onclick = requestLog;
|
| $('log-timedetail').checked = false;
|
| - $('log-timedetail').onclick = sendRefresh;
|
| + $('log-timedetail').onclick = requestLog;
|
| setRefresh();
|
| - sendRefresh();
|
| + requestLog();
|
| + requestNetworks();
|
| });
|
|
|
| return {
|
| - onNetworkInfoReceived: onNetworkInfoReceived
|
| + getNetworkLogCallback: getNetworkLogCallback
|
| };
|
| -}();
|
| +})();
|
|
|