tor-browser

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

StartupContentSubframe.sys.mjs (1735B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 /**
      5 * test helper JSWindowActors used by the browser_startup_content_subframe.js test.
      6 */
      7 
      8 export class StartupContentSubframeParent extends JSWindowActorParent {
      9  receiveMessage(msg) {
     10    // Tell the test about the data we received from the content process.
     11    Services.obs.notifyObservers(
     12      msg.data,
     13      "startup-content-subframe-loaded-scripts"
     14    );
     15  }
     16 }
     17 
     18 export class StartupContentSubframeChild extends JSWindowActorChild {
     19  async handleEvent() {
     20    // When the remote subframe is loaded, an event will be fired to this actor,
     21    // which will cause us to send the `LoadedScripts` message to the parent
     22    // process.
     23    // Wait a spin of the event loop before doing so to ensure we don't
     24    // miss any scripts loaded immediately after the load event.
     25    await new Promise(resolve => Services.tm.dispatchToMainThread(resolve));
     26 
     27    const Cm = Components.manager;
     28    Cm.QueryInterface(Ci.nsIServiceManager);
     29    const { AppConstants } = ChromeUtils.importESModule(
     30      "resource://gre/modules/AppConstants.sys.mjs"
     31    );
     32    let collectStacks = AppConstants.NIGHTLY_BUILD || AppConstants.DEBUG;
     33 
     34    let modules = new Map();
     35    for (let module of Cu.loadedESModules) {
     36      modules.set(module, collectStacks ? Cu.getModuleImportStack(module) : "");
     37    }
     38 
     39    let services = new Map();
     40    for (let contractID of Object.keys(Cc)) {
     41      try {
     42        if (Cm.isServiceInstantiatedByContractID(contractID, Ci.nsISupports)) {
     43          services.set(contractID, "");
     44        }
     45      } catch (e) {}
     46    }
     47    this.sendAsyncMessage("LoadedScripts", {
     48      modules,
     49      services,
     50    });
     51  }
     52 }