dom/system/gonk/NetworkInterfaceListService.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 "use strict";
michael@0 6
michael@0 7 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
michael@0 8
michael@0 9 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
michael@0 10
michael@0 11 const NETWORKLISTSERVICE_CONTRACTID =
michael@0 12 "@mozilla.org/network/interface-list-service;1";
michael@0 13 const NETWORKLISTSERVICE_CID =
michael@0 14 Components.ID("{3780be6e-7012-4e53-ade6-15212fb88a0d}");
michael@0 15
michael@0 16 XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
michael@0 17 "@mozilla.org/childprocessmessagemanager;1",
michael@0 18 "nsISyncMessageSender");
michael@0 19
michael@0 20 function NetworkInterfaceListService () {
michael@0 21 }
michael@0 22
michael@0 23 NetworkInterfaceListService.prototype = {
michael@0 24 classID: NETWORKLISTSERVICE_CID,
michael@0 25
michael@0 26 QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkInterfaceListService]),
michael@0 27
michael@0 28 getDataInterfaceList: function(aConditions) {
michael@0 29 return new NetworkInterfaceList(
michael@0 30 cpmm.sendSyncMessage(
michael@0 31 'NetworkInterfaceList:ListInterface',
michael@0 32 {
michael@0 33 excludeSupl: (aConditions &
michael@0 34 Ci.nsINetworkInterfaceListService.
michael@0 35 LIST_NOT_INCLUDE_SUPL_INTERFACES) != 0,
michael@0 36 excludeMms: (aConditions &
michael@0 37 Ci.nsINetworkInterfaceListService.
michael@0 38 LIST_NOT_INCLUDE_MMS_INTERFACES) != 0,
michael@0 39 excludeIms: (aConditions &
michael@0 40 Ci.nsINetworkInterfaceListService.
michael@0 41 LIST_NOT_INCLUDE_IMS_INTERFACES) != 0,
michael@0 42 excludeDun: (aConditions &
michael@0 43 Ci.nsINetworkInterfaceListService.
michael@0 44 LIST_NOT_INCLUDE_DUN_INTERFACES) != 0
michael@0 45 }
michael@0 46 )[0]);
michael@0 47 }
michael@0 48 };
michael@0 49
michael@0 50 function FakeNetworkInterface(aAttributes) {
michael@0 51 this.state = aAttributes.state;
michael@0 52 this.type = aAttributes.type;
michael@0 53 this.name = aAttributes.name;
michael@0 54 this.ips = aAttributes.ips;
michael@0 55 this.prefixLengths = aAttributes.prefixLengths;
michael@0 56 this.gateways = aAttributes.gateways;
michael@0 57 this.dnses = aAttributes.dnses;
michael@0 58 this.httpProxyHost = aAttributes.httpProxyHost;
michael@0 59 this.httpProxyPort = aAttributes.httpProxyPort;
michael@0 60 }
michael@0 61 FakeNetworkInterface.prototype = {
michael@0 62 QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkInterface]),
michael@0 63
michael@0 64 getAddresses: function (ips, prefixLengths) {
michael@0 65 ips.value = this.ips.slice();
michael@0 66 prefixLengths.value = this.prefixLengths.slice();
michael@0 67
michael@0 68 return this.ips.length;
michael@0 69 },
michael@0 70
michael@0 71 getGateways: function (count) {
michael@0 72 if (count) {
michael@0 73 count.value = this.gateways.length;
michael@0 74 }
michael@0 75 return this.gateways.slice();
michael@0 76 },
michael@0 77
michael@0 78 getDnses: function (count) {
michael@0 79 if (count) {
michael@0 80 count.value = this.dnses.length;
michael@0 81 }
michael@0 82 return this.dnses.slice();
michael@0 83 }
michael@0 84 };
michael@0 85
michael@0 86 function NetworkInterfaceList (aInterfaceLiterals) {
michael@0 87 this._interfaces = [];
michael@0 88 for (let entry of aInterfaceLiterals) {
michael@0 89 this._interfaces.push(new FakeNetworkInterface(entry));
michael@0 90 }
michael@0 91 }
michael@0 92
michael@0 93 NetworkInterfaceList.prototype = {
michael@0 94 QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkInterfaceList]),
michael@0 95
michael@0 96 getNumberOfInterface: function() {
michael@0 97 return this._interfaces.length;
michael@0 98 },
michael@0 99
michael@0 100 getInterface: function(index) {
michael@0 101 if (!this._interfaces) {
michael@0 102 return null;
michael@0 103 }
michael@0 104 return this._interfaces[index];
michael@0 105 }
michael@0 106 };
michael@0 107
michael@0 108 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([NetworkInterfaceListService]);
michael@0 109

mercurial