michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; michael@0: michael@0: Cu.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: michael@0: const NETWORKLISTSERVICE_CONTRACTID = michael@0: "@mozilla.org/network/interface-list-service;1"; michael@0: const NETWORKLISTSERVICE_CID = michael@0: Components.ID("{3780be6e-7012-4e53-ade6-15212fb88a0d}"); michael@0: michael@0: XPCOMUtils.defineLazyServiceGetter(this, "cpmm", michael@0: "@mozilla.org/childprocessmessagemanager;1", michael@0: "nsISyncMessageSender"); michael@0: michael@0: function NetworkInterfaceListService () { michael@0: } michael@0: michael@0: NetworkInterfaceListService.prototype = { michael@0: classID: NETWORKLISTSERVICE_CID, michael@0: michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkInterfaceListService]), michael@0: michael@0: getDataInterfaceList: function(aConditions) { michael@0: return new NetworkInterfaceList( michael@0: cpmm.sendSyncMessage( michael@0: 'NetworkInterfaceList:ListInterface', michael@0: { michael@0: excludeSupl: (aConditions & michael@0: Ci.nsINetworkInterfaceListService. michael@0: LIST_NOT_INCLUDE_SUPL_INTERFACES) != 0, michael@0: excludeMms: (aConditions & michael@0: Ci.nsINetworkInterfaceListService. michael@0: LIST_NOT_INCLUDE_MMS_INTERFACES) != 0, michael@0: excludeIms: (aConditions & michael@0: Ci.nsINetworkInterfaceListService. michael@0: LIST_NOT_INCLUDE_IMS_INTERFACES) != 0, michael@0: excludeDun: (aConditions & michael@0: Ci.nsINetworkInterfaceListService. michael@0: LIST_NOT_INCLUDE_DUN_INTERFACES) != 0 michael@0: } michael@0: )[0]); michael@0: } michael@0: }; michael@0: michael@0: function FakeNetworkInterface(aAttributes) { michael@0: this.state = aAttributes.state; michael@0: this.type = aAttributes.type; michael@0: this.name = aAttributes.name; michael@0: this.ips = aAttributes.ips; michael@0: this.prefixLengths = aAttributes.prefixLengths; michael@0: this.gateways = aAttributes.gateways; michael@0: this.dnses = aAttributes.dnses; michael@0: this.httpProxyHost = aAttributes.httpProxyHost; michael@0: this.httpProxyPort = aAttributes.httpProxyPort; michael@0: } michael@0: FakeNetworkInterface.prototype = { michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkInterface]), michael@0: michael@0: getAddresses: function (ips, prefixLengths) { michael@0: ips.value = this.ips.slice(); michael@0: prefixLengths.value = this.prefixLengths.slice(); michael@0: michael@0: return this.ips.length; michael@0: }, michael@0: michael@0: getGateways: function (count) { michael@0: if (count) { michael@0: count.value = this.gateways.length; michael@0: } michael@0: return this.gateways.slice(); michael@0: }, michael@0: michael@0: getDnses: function (count) { michael@0: if (count) { michael@0: count.value = this.dnses.length; michael@0: } michael@0: return this.dnses.slice(); michael@0: } michael@0: }; michael@0: michael@0: function NetworkInterfaceList (aInterfaceLiterals) { michael@0: this._interfaces = []; michael@0: for (let entry of aInterfaceLiterals) { michael@0: this._interfaces.push(new FakeNetworkInterface(entry)); michael@0: } michael@0: } michael@0: michael@0: NetworkInterfaceList.prototype = { michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkInterfaceList]), michael@0: michael@0: getNumberOfInterface: function() { michael@0: return this._interfaces.length; michael@0: }, michael@0: michael@0: getInterface: function(index) { michael@0: if (!this._interfaces) { michael@0: return null; michael@0: } michael@0: return this._interfaces[index]; michael@0: } michael@0: }; michael@0: michael@0: this.NSGetFactory = XPCOMUtils.generateNSGetFactory([NetworkInterfaceListService]); michael@0: