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

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

mercurial