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

Unified Diff: chrome/browser/resources/chromeos/network/network_config.js

Issue 260083007: Replace chrome://network implementation with networkConfig API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Feedback Created 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/chromeos/network/network_config.js
diff --git a/chrome/browser/resources/chromeos/network/network_config.js b/chrome/browser/resources/chromeos/network/network_config.js
new file mode 100644
index 0000000000000000000000000000000000000000..45e4082a49c9e64080a57d576a7701e63f44693d
--- /dev/null
+++ b/chrome/browser/resources/chromeos/network/network_config.js
@@ -0,0 +1,147 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+'use strict';
+
+// This object provides a similar API to chrome.networkingPrivate. It simulates
+// the extension callback model by storing callbacks in a member object and
+// invoking them when the corresponding method is called by Chrome in response
+// to a chrome.send call.
+
+var networkConfig = {
+ // ONC types
+ Type: {
+ All: 'All',
+ Cellular: 'Cellular',
+ Ethernet: 'Ethernet',
+ VPN: 'VPN',
+ WiFi: 'WiFi'
+ },
+
+ // ONC Network properties
+ ONC: {
+ Cellular: {
+ NetworkTechnology: 'Cellular.NetworkTechnology',
+ ActivationState: 'Cellular.ActivationState',
+ RoamingState: 'Cellular.RoamingState',
+ OutOfCredits: 'Cellular.OutOfCredits'
+ },
+ Connectable: 'Connectable',
+ ConnectionState: 'ConnectionState',
+ EAP: {
+ EAP: 'EAP.EAP'
+ },
+ ErrorState: 'ErrorState',
+ GUID: 'GUID',
+ Name: 'Name',
+ OncSource: 'onc_source', // TODO(stevenjb): Replace with 'Policies'.
+ Profile: 'Profile',
+ WiFi: {
+ Security: 'WiFi.Security',
+ SignalStrength: 'WiFi.SignalStrength'
+ },
+ ServicePath: 'ServicePath',
+ Type: 'Type'
+ },
+
+ /**
+ * Return the property associated with a key (which may reference a
+ * sub-object).
+ *
+ * @param {Object} properties The object containing the network properties
+ * @param {string} key The ONC key for the property
+ * @return {Mixed} The value associated with the property
+ */
+ getValueFromProperties: function(properties, key) {
+ if (!key) {
+ console.error('Empty key');
+ return undefined;
+ }
+ var dot = key.indexOf('.');
+ if (dot > 0) {
+ var key1 = key.substring(0, dot);
+ var key2 = key.substring(dot + 1);
+ var subobject = properties[key1];
+ if (subobject)
+ return subobject[key2];
+ }
+ return properties[key];
+ },
+
+ /**
+ * Generate a unique id for 'callback' and store it for future retrieval.
+ *
+ * @param {function} callback The associated callback
+ * @return {integer} The id of the callback
+ */
+ callbackId: 1,
+ callbackMap: {},
+ storeCallback: function(callback) {
+ var id = networkConfig.callbackId++;
+ networkConfig.callbackMap[id] = callback;
+ return id;
+ },
+
+ /**
+ * Retrieve the callback associated with |id| and remove it from the map.
+ *
+ * @param {integer} id The id of the callback
+ * @return {function} The associated callback
+ */
+ retrieveCallback: function(id) {
+ var callback = networkConfig.callbackMap[id];
+ delete networkConfig.callbackMap[id];
+ return callback;
+ },
+
+ /**
+ * Callback invoked by Chrome
+ *
+ * @param {string} data A list of arguments passed to the callback. The first
pneubeck (no reviews) 2014/05/08 09:21:43 nit: data -> args (similarly below)
stevenjb 2014/05/21 20:22:44 Done.
+ * entry must be the callbackId passed to chrome.send.
+ */
+ chromeCallbackSuccess: function(data) {
+ var callbackId = data.shift();
+ var callback = networkConfig.retrieveCallback(callbackId);
+ if (callback)
+ callback.apply(null, data);
+ else
+ console.error('Callback not found for id: ' + callbackId);
+ },
+
+ /**
+ * Error Callback invoked by Chrome
+ *
+ * @param {string} data A list of arguments. The first entry must be the
+ * callbackId passed to chrome.send.
+ */
+ chromeCallbackError: function(data) {
+ var callbackId = data.shift();
+ var error = data.shift();
+ // Get the callback so that it is deleted from the map.
+ networkConfig.retrieveCallback(callbackId);
+ console.error('Callback error: "' + error + '" for id: ' + callbackId);
+ },
+
+ /**
+ * Implement networkingPrivate.getProperties
+ *
+ * @param {string} type The type of networks to return
+ */
+ getProperties: function(guid, callback) {
+ var callbackId = networkConfig.storeCallback(callback);
+ chrome.send('networkConfig.getProperties', [callbackId, guid]);
+ },
+
+ /**
+ * Implement networkingPrivate.getVisibleNetworks
+ *
+ * @param {string} type The type of networks to return
+ */
+ getVisibleNetworks: function(type, callback) {
+ var callbackId = networkConfig.storeCallback(callback);
+ chrome.send('networkConfig.getVisibleNetworks', [callbackId, type]);
+ }
+
+};

Powered by Google App Engine
This is Rietveld 408576698