tor-browser

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

windowglobaltoroot.sys.mjs (1282B)


      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 import { Module } from "chrome://remote/content/shared/messagehandler/Module.sys.mjs";
      6 import { RootMessageHandler } from "chrome://remote/content/shared/messagehandler/RootMessageHandler.sys.mjs";
      7 
      8 class WindowGlobalToRootModule extends Module {
      9  constructor(messageHandler) {
     10    super(messageHandler);
     11    this.#assertContentProcess();
     12  }
     13 
     14  destroy() {}
     15 
     16  /**
     17   * Commands
     18   */
     19 
     20  testHandleCommandToRoot() {
     21    return this.messageHandler.handleCommand({
     22      moduleName: "windowglobaltoroot",
     23      commandName: "getValueFromRoot",
     24      destination: {
     25        type: RootMessageHandler.type,
     26      },
     27    });
     28  }
     29 
     30  testSendRootCommand() {
     31    return this.messageHandler.sendRootCommand({
     32      moduleName: "windowglobaltoroot",
     33      commandName: "getValueFromRoot",
     34    });
     35  }
     36 
     37  #assertContentProcess() {
     38    const isContent =
     39      Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT;
     40 
     41    if (!isContent) {
     42      throw new Error("Can only run in a content process");
     43    }
     44  }
     45 }
     46 
     47 export const windowglobaltoroot = WindowGlobalToRootModule;