Bug 867933 - Part 1 - enumerate network interfaces in content process. r=swu
--- a/b2g/installer/package-manifest.in
+++ b/b2g/installer/package-manifest.in
@@ -466,16 +466,18 @@
@BINPATH@/components/MobileMessageDatabaseService.manifest
@BINPATH@/components/MobileMessageDatabaseService.js
@BINPATH@/components/WifiWorker.js
@BINPATH@/components/WifiWorker.manifest
@BINPATH@/components/DOMWifiManager.js
@BINPATH@/components/DOMWifiManager.manifest
@BINPATH@/components/NetworkStatsManager.js
@BINPATH@/components/NetworkStatsManager.manifest
+@BINPATH@/components/NetworkInterfaceListService.manifest
+@BINPATH@/components/NetworkInterfaceListService.js
#endif
#ifdef MOZ_B2G_FM
@BINPATH@/components/DOMFMRadioChild.js
@BINPATH@/components/DOMFMRadio.manifest
#endif
#ifdef MOZ_ENABLE_DBUS
@BINPATH@/components/@DLL_PREFIX@dbusservice@DLL_SUFFIX@
#endif
--- a/dom/system/gonk/Makefile.in
+++ b/dom/system/gonk/Makefile.in
@@ -38,16 +38,18 @@ LOCAL_INCLUDES = \
$(NULL)
EXTRA_COMPONENTS = \
NetworkManager.manifest \
NetworkManager.js \
RadioInterfaceLayer.manifest \
RadioInterfaceLayer.js \
RILContentHelper.js \
+ NetworkInterfaceListService.manifest \
+ NetworkInterfaceListService.js \
$(NULL)
EXTRA_JS_MODULES = \
net_worker.js \
ril_consts.js \
ril_worker.js \
systemlibs.js \
$(NULL)
new file mode 100644
--- /dev/null
+++ b/dom/system/gonk/NetworkInterfaceListService.js
@@ -0,0 +1,63 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+const NETWORKLISTSERVICE_CONTRACTID =
+ "@mozilla.org/network/interface-list-service;1";
+const NETWORKLISTSERVICE_CID =
+ Components.ID("{3780be6e-7012-4e53-ade6-15212fb88a0d}");
+
+XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
+ "@mozilla.org/childprocessmessagemanager;1",
+ "nsISyncMessageSender");
+
+function NetworkInterfaceListService () {
+}
+
+NetworkInterfaceListService.prototype = {
+ classID: NETWORKLISTSERVICE_CID,
+
+ QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkInterfaceListService]),
+
+ getDataInterfaceList: function(aConditions) {
+ return new NetworkInterfaceList(
+ cpmm.sendSyncMessage(
+ 'NetworkInterfaceList:ListInterface',
+ {
+ excludeSupl: (aConditions &
+ Ci.nsINetworkInterfaceListService.
+ LIST_NOT_INCLUDE_SUPL_INTERFACES) != 0,
+ excludeMms: (aConditions &
+ Ci.nsINetworkInterfaceListService.
+ LIST_NOT_INCLUDE_MMS_INTERFACES) != 0
+ }
+ )[0]);
+ }
+};
+
+function NetworkInterfaceList (aInterfaces) {
+ this._interfaces = aInterfaces;
+}
+
+NetworkInterfaceList.prototype = {
+ QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkInterfaceList]),
+ getNumberOfInterface: function() {
+ return this._interfaces.length;
+ },
+
+ getInterface: function(index) {
+ if (!this._interfaces) {
+ return null;
+ }
+ return this._interfaces[index];
+ }
+};
+
+this.NSGetFactory = XPCOMUtils.generateNSGetFactory([NetworkInterfaceListService]);
+
new file mode 100644
--- /dev/null
+++ b/dom/system/gonk/NetworkInterfaceListService.manifest
@@ -0,0 +1,17 @@
+# Copyright 2012 Mozilla Foundation and Mozilla contributors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# NetworkInterfaceListService.js
+component {3780be6e-7012-4e53-ade6-15212fb88a0d} NetworkInterfaceListService.js
+contract @mozilla.org/network/interface-list-service;1 {3780be6e-7012-4e53-ade6-15212fb88a0d}
--- a/dom/system/gonk/NetworkManager.js
+++ b/dom/system/gonk/NetworkManager.js
@@ -17,16 +17,20 @@ const NETWORKINTERFACE_CONTRACTID = "@mo
const NETWORKINTERFACE_CID =
Components.ID("{266c3edd-78f0-4512-8178-2d6fee2d35ee}");
const DEFAULT_PREFERRED_NETWORK_TYPE = Ci.nsINetworkInterface.NETWORK_TYPE_WIFI;
XPCOMUtils.defineLazyServiceGetter(this, "gSettingsService",
"@mozilla.org/settingsService;1",
"nsISettingsService");
+XPCOMUtils.defineLazyGetter(this, "ppmm", function() {
+ return Cc["@mozilla.org/parentprocessmessagemanager;1"]
+ .getService(Ci.nsIMessageBroadcaster);
+});
XPCOMUtils.defineLazyServiceGetter(this, "gDNSService",
"@mozilla.org/network/dns-service;1",
"nsIDNSService");
const TOPIC_INTERFACE_STATE_CHANGED = "network-interface-state-changed";
const TOPIC_INTERFACE_REGISTERED = "network-interface-registered";
const TOPIC_INTERFACE_UNREGISTERED = "network-interface-unregistered";
@@ -205,16 +209,18 @@ function NetworkManager() {
settingsLock.set(SETTINGS_WIFI_ENABLED, aResult, null);
});
},
handleError: function (aErrorMessage) {
debug("Error reading the 'tethering.wifi.enabled' setting: " + aErrorMessage);
}
});
+
+ ppmm.addMessageListener('NetworkInterfaceList:ListInterface', this);
}
NetworkManager.prototype = {
classID: NETWORKMANAGER_CID,
classInfo: XPCOMUtils.generateCI({classID: NETWORKMANAGER_CID,
contractID: NETWORKMANAGER_CONTRACTID,
classDescription: "Network Manager",
interfaces: [Ci.nsINetworkManager]}),
QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkManager,
@@ -315,16 +321,48 @@ NetworkManager.prototype = {
Services.obs.removeObserver(this, TOPIC_MOZSETTINGS_CHANGED);
Services.obs.removeObserver(this, TOPIC_INTERFACE_REGISTERED);
Services.obs.removeObserver(this, TOPIC_INTERFACE_UNREGISTERED);
Services.obs.removeObserver(this, TOPIC_INTERFACE_STATE_CHANGED);
break;
}
},
+ receiveMessage: function receiveMessage(aMsg) {
+ switch (aMsg.name) {
+ case "NetworkInterfaceList:ListInterface": {
+ let excludeMms = aMsg.json.exculdeMms;
+ let excludeSupl = aMsg.json.exculdeSupl;
+ let interfaces = [];
+
+ for each (let i in this.networkInterfaces) {
+ if ((i.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS && excludeMms) ||
+ (i.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL && excludeSupl)) {
+ continue;
+ }
+ interfaces.push({
+ state: i.state,
+ type: i.type,
+ name: i.name,
+ dhcp: i.dhcp,
+ ip: i.ip,
+ netmask: i.netmask,
+ broadcast: i.broadcast,
+ gateway: i.gateway,
+ dns1: i.dns1,
+ dns2: i.dns2,
+ httpProxyHost: i.httpProxyHost,
+ httpProxyPort: i.httpProxyPort
+ });
+ }
+ return interfaces;
+ }
+ }
+ },
+
// nsINetworkManager
registerNetworkInterface: function registerNetworkInterface(network) {
if (!(network instanceof Ci.nsINetworkInterface)) {
throw Components.Exception("Argument must be nsINetworkInterface.",
Cr.NS_ERROR_INVALID_ARG);
}
if (network.name in this.networkInterfaces) {
--- a/dom/system/gonk/moz.build
+++ b/dom/system/gonk/moz.build
@@ -12,16 +12,17 @@
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
XPIDL_SOURCES += [
'nsIAudioManager.idl',
'nsINavigatorAudioChannelManager.idl',
+ 'nsINetworkInterfaceListService.idl',
'nsINetworkManager.idl',
'nsIRadioInterfaceLayer.idl',
'nsISystemWorkerManager.idl',
'nsIVolume.idl',
'nsIVolumeMountLock.idl',
'nsIVolumeService.idl',
'nsIVolumeStat.idl',
'nsIWorkerHolder.idl',
new file mode 100644
--- /dev/null
+++ b/dom/system/gonk/nsINetworkInterfaceListService.idl
@@ -0,0 +1,36 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "nsINetworkManager.idl"
+#include "nsISupports.idl"
+
+[scriptable, uuid(b44d74db-c9d6-41dd-98ae-a56918d6e6ad)]
+interface nsINetworkInterfaceList : nsISupports
+{
+ /**
+ * Number of the network interfaces that is available.
+ */
+ long getNumberOfInterface();
+
+ /**
+ * Get the i-th interface from the list.
+ * @param interfaceIndex index of interface, from 0 to number of interface - 1.
+ */
+ nsINetworkInterface getInterface(in long interfaceIndex);
+};
+
+[scriptable, uuid(5be50bcb-bfe9-4742-b7e6-3e9bb4835369)]
+interface nsINetworkInterfaceListService : nsISupports
+{
+ const long LIST_NOT_INCLUDE_MMS_INTERFACES = 1;
+ const long LIST_NOT_INCLUDE_SUPL_INTERFACES = 2;
+
+ /**
+ * Obtain a list of network interfaces that satisfy the specified condition.
+ * @param condition flags that specify the interfaces to be returned. This
+ * can be OR combination of LIST_* flags, or zero to make all available
+ * interfaces returned.
+ */
+ nsINetworkInterfaceList getDataInterfaceList(in long condition);
+};