dom/system/gonk/NetworkInterfaceListService.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/system/gonk/NetworkInterfaceListService.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,109 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +"use strict";
     1.9 +
    1.10 +const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
    1.11 +
    1.12 +Cu.import("resource://gre/modules/XPCOMUtils.jsm");
    1.13 +
    1.14 +const NETWORKLISTSERVICE_CONTRACTID =
    1.15 +        "@mozilla.org/network/interface-list-service;1";
    1.16 +const NETWORKLISTSERVICE_CID =
    1.17 +        Components.ID("{3780be6e-7012-4e53-ade6-15212fb88a0d}");
    1.18 +
    1.19 +XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
    1.20 +                                   "@mozilla.org/childprocessmessagemanager;1",
    1.21 +                                   "nsISyncMessageSender");
    1.22 +
    1.23 +function NetworkInterfaceListService () {
    1.24 +}
    1.25 +
    1.26 +NetworkInterfaceListService.prototype = {
    1.27 +  classID: NETWORKLISTSERVICE_CID,
    1.28 +
    1.29 +  QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkInterfaceListService]),
    1.30 +
    1.31 +  getDataInterfaceList: function(aConditions) {
    1.32 +    return new NetworkInterfaceList(
    1.33 +      cpmm.sendSyncMessage(
    1.34 +        'NetworkInterfaceList:ListInterface',
    1.35 +        {
    1.36 +          excludeSupl: (aConditions &
    1.37 +                        Ci.nsINetworkInterfaceListService.
    1.38 +                        LIST_NOT_INCLUDE_SUPL_INTERFACES) != 0,
    1.39 +          excludeMms: (aConditions &
    1.40 +                       Ci.nsINetworkInterfaceListService.
    1.41 +                       LIST_NOT_INCLUDE_MMS_INTERFACES) != 0,
    1.42 +          excludeIms: (aConditions &
    1.43 +                       Ci.nsINetworkInterfaceListService.
    1.44 +                       LIST_NOT_INCLUDE_IMS_INTERFACES) != 0,
    1.45 +          excludeDun: (aConditions &
    1.46 +                       Ci.nsINetworkInterfaceListService.
    1.47 +                       LIST_NOT_INCLUDE_DUN_INTERFACES) != 0
    1.48 +        }
    1.49 +      )[0]);
    1.50 +  }
    1.51 +};
    1.52 +
    1.53 +function FakeNetworkInterface(aAttributes) {
    1.54 +  this.state = aAttributes.state;
    1.55 +  this.type = aAttributes.type;
    1.56 +  this.name = aAttributes.name;
    1.57 +  this.ips = aAttributes.ips;
    1.58 +  this.prefixLengths = aAttributes.prefixLengths;
    1.59 +  this.gateways = aAttributes.gateways;
    1.60 +  this.dnses = aAttributes.dnses;
    1.61 +  this.httpProxyHost = aAttributes.httpProxyHost;
    1.62 +  this.httpProxyPort = aAttributes.httpProxyPort;
    1.63 +}
    1.64 +FakeNetworkInterface.prototype = {
    1.65 +  QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkInterface]),
    1.66 +
    1.67 +  getAddresses: function (ips, prefixLengths) {
    1.68 +    ips.value = this.ips.slice();
    1.69 +    prefixLengths.value = this.prefixLengths.slice();
    1.70 +
    1.71 +    return this.ips.length;
    1.72 +  },
    1.73 +
    1.74 +  getGateways: function (count) {
    1.75 +    if (count) {
    1.76 +      count.value = this.gateways.length;
    1.77 +    }
    1.78 +    return this.gateways.slice();
    1.79 +  },
    1.80 +
    1.81 +  getDnses: function (count) {
    1.82 +    if (count) {
    1.83 +      count.value = this.dnses.length;
    1.84 +    }
    1.85 +    return this.dnses.slice();
    1.86 +  }
    1.87 +};
    1.88 +
    1.89 +function NetworkInterfaceList (aInterfaceLiterals) {
    1.90 +  this._interfaces = [];
    1.91 +  for (let entry of aInterfaceLiterals) {
    1.92 +    this._interfaces.push(new FakeNetworkInterface(entry));
    1.93 +  }
    1.94 +}
    1.95 +
    1.96 +NetworkInterfaceList.prototype = {
    1.97 +  QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkInterfaceList]),
    1.98 +
    1.99 +  getNumberOfInterface: function() {
   1.100 +    return this._interfaces.length;
   1.101 +  },
   1.102 +
   1.103 +  getInterface: function(index) {
   1.104 +    if (!this._interfaces) {
   1.105 +      return null;
   1.106 +    }
   1.107 +    return this._interfaces[index];
   1.108 +  }
   1.109 +};
   1.110 +
   1.111 +this.NSGetFactory = XPCOMUtils.generateNSGetFactory([NetworkInterfaceListService]);
   1.112 +

mercurial