tor-browser

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

rootOnly.sys.mjs (1866B)


      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 { ContextDescriptorType } from "chrome://remote/content/shared/messagehandler/MessageHandler.sys.mjs";
      6 import { Module } from "chrome://remote/content/shared/messagehandler/Module.sys.mjs";
      7 
      8 class RootOnlyModule extends Module {
      9  #sessionDataReceived;
     10  #subscribedEvents;
     11 
     12  constructor(messageHandler) {
     13    super(messageHandler);
     14 
     15    this.#sessionDataReceived = [];
     16    this.#subscribedEvents = new Set();
     17  }
     18 
     19  destroy() {}
     20 
     21  /**
     22   * Commands
     23   */
     24 
     25  getSessionDataReceived() {
     26    return this.#sessionDataReceived;
     27  }
     28 
     29  testCommand(params = {}) {
     30    return params;
     31  }
     32 
     33  _applySessionData(params) {
     34    const added = [];
     35    const removed = [];
     36 
     37    const filteredSessionData = params.sessionData.filter(item =>
     38      this.messageHandler.matchesContext(item.contextDescriptor)
     39    );
     40    for (const event of this.#subscribedEvents.values()) {
     41      const hasSessionItem = filteredSessionData.some(
     42        item => item.value === event
     43      );
     44      // If there are no session items for this context, we should unsubscribe from the event.
     45      if (!hasSessionItem) {
     46        this.#subscribedEvents.delete(event);
     47        removed.push(event);
     48      }
     49    }
     50 
     51    // Subscribe to all events, which have an item in SessionData
     52    for (const { value } of filteredSessionData) {
     53      if (!this.#subscribedEvents.has(value)) {
     54        this.#subscribedEvents.add(value);
     55        added.push(value);
     56      }
     57    }
     58 
     59    this.#sessionDataReceived.push({
     60      category: params.category,
     61      added,
     62      removed,
     63      contextDescriptor: {
     64        type: ContextDescriptorType.All,
     65      },
     66    });
     67  }
     68 }
     69 
     70 export const rootOnly = RootOnlyModule;