diff --git a/b2g/installer/package-manifest.in b/b2g/installer/package-manifest.in index 558a15c8b53b..c45f190f5315 100644 --- a/b2g/installer/package-manifest.in +++ b/b2g/installer/package-manifest.in @@ -471,6 +471,8 @@ @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 diff --git a/dom/system/gonk/Makefile.in b/dom/system/gonk/Makefile.in index 60b3874ed5e8..a48c12ed9437 100644 --- a/dom/system/gonk/Makefile.in +++ b/dom/system/gonk/Makefile.in @@ -43,6 +43,8 @@ EXTRA_COMPONENTS = \ RadioInterfaceLayer.manifest \ RadioInterfaceLayer.js \ RILContentHelper.js \ + NetworkInterfaceListService.manifest \ + NetworkInterfaceListService.js \ $(NULL) EXTRA_JS_MODULES = \ diff --git a/dom/system/gonk/NetworkInterfaceListService.js b/dom/system/gonk/NetworkInterfaceListService.js new file mode 100644 index 000000000000..2230d88db3b8 --- /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]); + diff --git a/dom/system/gonk/NetworkInterfaceListService.manifest b/dom/system/gonk/NetworkInterfaceListService.manifest new file mode 100644 index 000000000000..a827e778f5e7 --- /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} diff --git a/dom/system/gonk/NetworkManager.js b/dom/system/gonk/NetworkManager.js index 5c5006674f95..3affc853603f 100644 --- a/dom/system/gonk/NetworkManager.js +++ b/dom/system/gonk/NetworkManager.js @@ -22,6 +22,10 @@ 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", @@ -210,6 +214,8 @@ function NetworkManager() { debug("Error reading the 'tethering.wifi.enabled' setting: " + aErrorMessage); } }); + + ppmm.addMessageListener('NetworkInterfaceList:ListInterface', this); } NetworkManager.prototype = { classID: NETWORKMANAGER_CID, @@ -320,6 +326,38 @@ NetworkManager.prototype = { } }, + 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) { diff --git a/dom/system/gonk/moz.build b/dom/system/gonk/moz.build index 4caea5b76495..3b82b7986507 100644 --- a/dom/system/gonk/moz.build +++ b/dom/system/gonk/moz.build @@ -17,6 +17,7 @@ XPIDL_SOURCES += [ 'nsIAudioManager.idl', 'nsINavigatorAudioChannelManager.idl', + 'nsINetworkInterfaceListService.idl', 'nsINetworkManager.idl', 'nsIRadioInterfaceLayer.idl', 'nsISystemWorkerManager.idl', diff --git a/dom/system/gonk/nsINetworkInterfaceListService.idl b/dom/system/gonk/nsINetworkInterfaceListService.idl new file mode 100644 index 000000000000..9325e4aaee06 --- /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); +};