Bug 867933 - Part 1 - enumerate network interfaces in content process. r=swu

This commit is contained in:
Patrick Wang 2013-05-02 19:41:20 +08:00
Родитель 7181ea0687
Коммит f7af0872d2
7 изменённых файлов: 159 добавлений и 0 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -43,6 +43,8 @@ EXTRA_COMPONENTS = \
RadioInterfaceLayer.manifest \
RadioInterfaceLayer.js \
RILContentHelper.js \
NetworkInterfaceListService.manifest \
NetworkInterfaceListService.js \
$(NULL)
EXTRA_JS_MODULES = \

Просмотреть файл

@ -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]);

Просмотреть файл

@ -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}

Просмотреть файл

@ -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) {

Просмотреть файл

@ -17,6 +17,7 @@
XPIDL_SOURCES += [
'nsIAudioManager.idl',
'nsINavigatorAudioChannelManager.idl',
'nsINetworkInterfaceListService.idl',
'nsINetworkManager.idl',
'nsIRadioInterfaceLayer.idl',
'nsISystemWorkerManager.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);
};