tor-browser

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

WindowGlobalBiDiModule.sys.mjs (2493B)


      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 
      7 const lazy = {};
      8 
      9 ChromeUtils.defineESModuleGetters(lazy, {
     10  deserialize: "chrome://remote/content/webdriver-bidi/RemoteValue.sys.mjs",
     11  serialize: "chrome://remote/content/webdriver-bidi/RemoteValue.sys.mjs",
     12 });
     13 
     14 /**
     15 * Base class for all WindowGlobal BiDi MessageHandler modules.
     16 */
     17 export class WindowGlobalBiDiModule extends Module {
     18  get #nodeCache() {
     19    return this.#processActor.getNodeCache();
     20  }
     21 
     22  get #processActor() {
     23    return ChromeUtils.domProcessChild.getActor("WebDriverProcessData");
     24  }
     25 
     26  /**
     27   * Wrapper to deserialize a local / remote value.
     28   *
     29   * @param {object} serializedValue
     30   *     Value of any type to be deserialized.
     31   * @param {Realm} realm
     32   *     The Realm in which the value is deserialized.
     33   * @param {ExtraSerializationOptions=} extraOptions
     34   *     Extra Remote Value deserialization options.
     35   *
     36   * @returns {object}
     37   *     Deserialized representation of the value.
     38   */
     39  deserialize(serializedValue, realm, extraOptions = {}) {
     40    extraOptions.nodeCache = this.#nodeCache;
     41 
     42    return lazy.deserialize(serializedValue, realm, extraOptions);
     43  }
     44 
     45  /**
     46   * Wrapper to serialize a value as a remote value.
     47   *
     48   * @param {object} value
     49   *     Value of any type to be serialized.
     50   * @param {SerializationOptions} serializationOptions
     51   *     Options which define how ECMAScript objects should be serialized.
     52   * @param {OwnershipModel} ownershipType
     53   *     The ownership model to use for this serialization.
     54   * @param {Realm} realm
     55   *     The Realm from which comes the value being serialized.
     56   * @param {ExtraSerializationOptions} extraOptions
     57   *     Extra Remote Value serialization options.
     58   *
     59   * @returns {object}
     60   *     Promise that resolves to the serialized representation of the value.
     61   */
     62  serialize(
     63    value,
     64    serializationOptions,
     65    ownershipType,
     66    realm,
     67    extraOptions = {}
     68  ) {
     69    const { nodeCache = this.#nodeCache, seenNodeIds = new Map() } =
     70      extraOptions;
     71 
     72    const serializedValue = lazy.serialize(
     73      value,
     74      serializationOptions,
     75      ownershipType,
     76      new Map(),
     77      realm,
     78      { nodeCache, seenNodeIds }
     79    );
     80 
     81    return serializedValue;
     82  }
     83 }