tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

index.js (10771B)


      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
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 // Registry indexing all specs and front modules
      8 //
      9 // All spec and front modules should be listed here
     10 // in order to be referenced by any other spec or front module.
     11 
     12 // Declare in which spec module and front module a set of types are defined.
     13 // This array should be sorted by `spec` attribute, and this is verified in the
     14 // test devtools/shared/protocol/tests/xpcshell/test_protocol_index.js
     15 const Types = (exports.__TypesForTests = [
     16  {
     17    types: [
     18      "accessible",
     19      "accessiblewalker",
     20      "accessibility",
     21      "parentaccessibility",
     22    ],
     23    spec: "devtools/shared/specs/accessibility",
     24    front: "devtools/client/fronts/accessibility",
     25  },
     26  {
     27    types: ["addons"],
     28    spec: "devtools/shared/specs/addon/addons",
     29    front: "devtools/client/fronts/addon/addons",
     30  },
     31  {
     32    types: ["webExtensionInspectedWindow"],
     33    spec: "devtools/shared/specs/addon/webextension-inspected-window",
     34    front: "devtools/client/fronts/addon/webextension-inspected-window",
     35  },
     36  {
     37    types: ["animationplayer", "animations"],
     38    spec: "devtools/shared/specs/animation",
     39    front: "devtools/client/fronts/animation",
     40  },
     41  {
     42    types: ["arraybuffer"],
     43    spec: "devtools/shared/specs/array-buffer",
     44    front: "devtools/client/fronts/array-buffer",
     45  },
     46  {
     47    types: ["blackboxing"],
     48    spec: "devtools/shared/specs/blackboxing",
     49    front: "devtools/client/fronts/blackboxing",
     50  },
     51  {
     52    types: ["breakpoint-list"],
     53    spec: "devtools/shared/specs/breakpoint-list",
     54    front: "devtools/client/fronts/breakpoint-list",
     55  },
     56  {
     57    types: ["compatibility"],
     58    spec: "devtools/shared/specs/compatibility",
     59    front: "devtools/client/fronts/compatibility",
     60  },
     61  {
     62    types: ["cssProperties"],
     63    spec: "devtools/shared/specs/css-properties",
     64    front: "devtools/client/fronts/css-properties",
     65  },
     66  {
     67    types: ["processDescriptor"],
     68    spec: "devtools/shared/specs/descriptors/process",
     69    front: "devtools/client/fronts/descriptors/process",
     70  },
     71  {
     72    types: ["tabDescriptor"],
     73    spec: "devtools/shared/specs/descriptors/tab",
     74    front: "devtools/client/fronts/descriptors/tab",
     75  },
     76  {
     77    types: ["webExtensionDescriptor"],
     78    spec: "devtools/shared/specs/descriptors/webextension",
     79    front: "devtools/client/fronts/descriptors/webextension",
     80  },
     81  {
     82    types: ["workerDescriptor"],
     83    spec: "devtools/shared/specs/descriptors/worker",
     84    front: "devtools/client/fronts/descriptors/worker",
     85  },
     86  {
     87    types: ["device"],
     88    spec: "devtools/shared/specs/device",
     89    front: "devtools/client/fronts/device",
     90  },
     91  {
     92    types: ["environment"],
     93    spec: "devtools/shared/specs/environment",
     94    front: null,
     95  },
     96  {
     97    types: ["frame"],
     98    spec: "devtools/shared/specs/frame",
     99    front: "devtools/client/fronts/frame",
    100  },
    101  {
    102    types: ["heapSnapshotFile"],
    103    spec: "devtools/shared/specs/heap-snapshot-file",
    104    front: "devtools/client/fronts/heap-snapshot-file",
    105  },
    106  {
    107    types: ["customhighlighter"],
    108    spec: "devtools/shared/specs/highlighters",
    109    front: "devtools/client/fronts/highlighters",
    110  },
    111  {
    112    types: ["inspector"],
    113    spec: "devtools/shared/specs/inspector",
    114    front: "devtools/client/fronts/inspector",
    115  },
    116  {
    117    types: ["flexbox", "grid", "layout"],
    118    spec: "devtools/shared/specs/layout",
    119    front: "devtools/client/fronts/layout",
    120  },
    121  {
    122    types: ["manifest"],
    123    spec: "devtools/shared/specs/manifest",
    124    front: "devtools/client/fronts/manifest",
    125  },
    126  {
    127    types: ["memory"],
    128    spec: "devtools/shared/specs/memory",
    129    front: "devtools/client/fronts/memory",
    130  },
    131  {
    132    types: ["networkContent"],
    133    spec: "devtools/shared/specs/network-content",
    134    front: "devtools/client/fronts/network-content",
    135  },
    136  {
    137    types: ["netEvent"],
    138    spec: "devtools/shared/specs/network-event",
    139    front: null,
    140  },
    141  {
    142    types: ["networkParent"],
    143    spec: "devtools/shared/specs/network-parent",
    144    front: "devtools/client/fronts/network-parent",
    145  },
    146  /* imageData isn't an actor but just a DictType */
    147  {
    148    types: ["imageData", "disconnectedNode", "disconnectedNodeArray"],
    149    spec: "devtools/shared/specs/node",
    150    front: null,
    151  },
    152  {
    153    types: ["domnode", "domnodelist"],
    154    spec: "devtools/shared/specs/node",
    155    front: "devtools/client/fronts/node",
    156  },
    157  {
    158    types: ["obj", "object.descriptor"],
    159    spec: "devtools/shared/specs/object",
    160    front: null,
    161  },
    162  {
    163    types: ["objects-manager"],
    164    spec: "devtools/shared/specs/objects-manager",
    165    front: "devtools/client/fronts/objects-manager",
    166  },
    167  {
    168    types: ["pagestyle"],
    169    spec: "devtools/shared/specs/page-style",
    170    front: "devtools/client/fronts/page-style",
    171  },
    172  {
    173    types: ["perf"],
    174    spec: "devtools/shared/specs/perf",
    175    front: "devtools/client/fronts/perf",
    176  },
    177  {
    178    types: ["preference"],
    179    spec: "devtools/shared/specs/preference",
    180    front: "devtools/client/fronts/preference",
    181  },
    182  {
    183    types: ["privatePropertiesIterator"],
    184    spec: "devtools/shared/specs/private-properties-iterator",
    185    front: "devtools/client/fronts/private-properties-iterator",
    186  },
    187  {
    188    types: ["propertyIterator"],
    189    spec: "devtools/shared/specs/property-iterator",
    190    front: "devtools/client/fronts/property-iterator",
    191  },
    192  {
    193    types: ["reflow"],
    194    spec: "devtools/shared/specs/reflow",
    195    front: "devtools/client/fronts/reflow",
    196  },
    197  {
    198    types: ["responsive"],
    199    spec: "devtools/shared/specs/responsive",
    200    front: "devtools/client/fronts/responsive",
    201  },
    202  {
    203    types: ["root"],
    204    spec: "devtools/shared/specs/root",
    205    front: "devtools/client/fronts/root",
    206  },
    207  {
    208    types: ["screenshot"],
    209    spec: "devtools/shared/specs/screenshot",
    210    front: "devtools/client/fronts/screenshot",
    211  },
    212  {
    213    types: ["screenshot-content"],
    214    spec: "devtools/shared/specs/screenshot-content",
    215    front: "devtools/client/fronts/screenshot-content",
    216  },
    217  {
    218    types: ["source"],
    219    spec: "devtools/shared/specs/source",
    220    front: "devtools/client/fronts/source",
    221  },
    222  {
    223    types: [
    224      "Cache",
    225      "cookies",
    226      "localStorage",
    227      "extensionStorage",
    228      "indexedDB",
    229      "sessionStorage",
    230    ],
    231    spec: "devtools/shared/specs/storage",
    232    front: "devtools/client/fronts/storage",
    233  },
    234  /* longstring is special, it has a wrapper type. See its spec module */
    235  {
    236    types: ["longstring"],
    237    spec: "devtools/shared/specs/string",
    238    front: null,
    239  },
    240  {
    241    types: ["longstractor"],
    242    spec: "devtools/shared/specs/string",
    243    front: "devtools/client/fronts/string",
    244  },
    245  {
    246    types: ["domstylerule"],
    247    spec: "devtools/shared/specs/style-rule",
    248    front: "devtools/client/fronts/style-rule",
    249  },
    250  {
    251    types: ["stylesheets"],
    252    spec: "devtools/shared/specs/style-sheets",
    253    front: "devtools/client/fronts/style-sheets",
    254  },
    255  {
    256    types: ["symbol"],
    257    spec: "devtools/shared/specs/symbol",
    258    front: null,
    259  },
    260  {
    261    types: ["symbolIterator"],
    262    spec: "devtools/shared/specs/symbol-iterator",
    263    front: "devtools/client/fronts/symbol-iterator",
    264  },
    265  {
    266    types: ["target-configuration"],
    267    spec: "devtools/shared/specs/target-configuration",
    268    front: "devtools/client/fronts/target-configuration",
    269  },
    270  {
    271    types: ["contentProcessTarget"],
    272    spec: "devtools/shared/specs/targets/content-process",
    273    front: null,
    274  },
    275  {
    276    types: ["contentScriptTarget"],
    277    spec: "devtools/shared/specs/targets/content-script",
    278    front: null,
    279  },
    280  {
    281    types: ["parentProcessTarget"],
    282    spec: "devtools/shared/specs/targets/parent-process",
    283    front: null,
    284  },
    285  {
    286    types: ["windowGlobalTarget"],
    287    spec: "devtools/shared/specs/targets/window-global",
    288    front: "devtools/client/fronts/targets/window-global",
    289  },
    290  {
    291    types: ["workerTarget"],
    292    spec: "devtools/shared/specs/targets/worker",
    293    front: "devtools/client/fronts/targets/worker",
    294  },
    295  {
    296    types: ["thread"],
    297    spec: "devtools/shared/specs/thread",
    298    front: "devtools/client/fronts/thread",
    299  },
    300  {
    301    types: ["thread-configuration"],
    302    spec: "devtools/shared/specs/thread-configuration",
    303    front: "devtools/client/fronts/thread-configuration",
    304  },
    305  {
    306    types: ["tracer"],
    307    spec: "devtools/shared/specs/tracer",
    308    front: "devtools/client/fronts/tracer",
    309  },
    310  {
    311    types: ["domwalker"],
    312    spec: "devtools/shared/specs/walker",
    313    front: "devtools/client/fronts/walker",
    314  },
    315  {
    316    types: ["watcher"],
    317    spec: "devtools/shared/specs/watcher",
    318    front: "devtools/client/fronts/watcher",
    319  },
    320  {
    321    types: ["console"],
    322    spec: "devtools/shared/specs/webconsole",
    323    front: "devtools/client/fronts/webconsole",
    324  },
    325  {
    326    types: ["pushSubscription"],
    327    spec: "devtools/shared/specs/worker/push-subscription",
    328    front: "devtools/client/fronts/worker/push-subscription",
    329  },
    330  {
    331    types: ["serviceWorker"],
    332    spec: "devtools/shared/specs/worker/service-worker",
    333    front: "devtools/client/fronts/worker/service-worker",
    334  },
    335  {
    336    types: ["serviceWorkerRegistration"],
    337    spec: "devtools/shared/specs/worker/service-worker-registration",
    338    front: "devtools/client/fronts/worker/service-worker-registration",
    339  },
    340 ]);
    341 
    342 const lazySpecs = new Map();
    343 const lazyFronts = new Map();
    344 
    345 // Convert the human readable `Types` list into efficient maps
    346 Types.forEach(item => {
    347  item.types.forEach(type => {
    348    lazySpecs.set(type, item.spec);
    349    lazyFronts.set(type, item.front);
    350  });
    351 });
    352 
    353 /**
    354 * Try lazy loading spec module for the given type.
    355 *
    356 * @param [string] type
    357 *    Type name
    358 *
    359 * @returns true, if it matched a lazy loaded type and tried to load it.
    360 */
    361 function lazyLoadSpec(type) {
    362  const modulePath = lazySpecs.get(type);
    363  if (modulePath) {
    364    try {
    365      require(modulePath);
    366    } catch (e) {
    367      throw new Error(
    368        `Unable to load lazy spec module '${modulePath}' for type '${type}'.
    369        Error: ${e}`
    370      );
    371    }
    372    lazySpecs.delete(type);
    373    return true;
    374  }
    375  return false;
    376 }
    377 exports.lazyLoadSpec = lazyLoadSpec;
    378 
    379 /**
    380 * Try lazy loading front module for the given type.
    381 *
    382 * @param [string] type
    383 *    Type name
    384 *
    385 * @returns true, if it matched a lazy loaded type and tried to load it.
    386 */
    387 function lazyLoadFront(type) {
    388  const modulePath = lazyFronts.get(type);
    389  if (modulePath) {
    390    try {
    391      require(modulePath);
    392    } catch (e) {
    393      throw new Error(
    394        `Unable to load lazy front module '${modulePath}' for type '${type}'.
    395        Error: ${e}`
    396      );
    397    }
    398    lazyFronts.delete(type);
    399    return true;
    400  }
    401  return false;
    402 }
    403 exports.lazyLoadFront = lazyLoadFront;