tor-browser

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

browsingContext.sys.mjs (1779B)


      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  getBrowsingContextInfo:
     11    "chrome://remote/content/webdriver-bidi/modules/root/browsingContext.sys.mjs",
     12  NavigableManager: "chrome://remote/content/shared/NavigableManager.sys.mjs",
     13  TabManager: "chrome://remote/content/shared/TabManager.sys.mjs",
     14 });
     15 
     16 class BrowsingContextModule extends Module {
     17  destroy() {}
     18 
     19  interceptEvent(name, payload) {
     20    if (
     21      name == "browsingContext.contextCreated" ||
     22      name == "browsingContext.domContentLoaded" ||
     23      name == "browsingContext.load"
     24    ) {
     25      const browsingContext = payload.context;
     26      if (!lazy.TabManager.isValidCanonicalBrowsingContext(browsingContext)) {
     27        // Discard events for invalid browsing contexts.
     28        return null;
     29      }
     30 
     31      // Resolve browsing context to a Navigable id.
     32      payload.context =
     33        lazy.NavigableManager.getIdForBrowsingContext(browsingContext);
     34 
     35      if (name == "browsingContext.contextCreated") {
     36        payload = {
     37          ...payload,
     38          ...lazy.getBrowsingContextInfo(browsingContext, { maxDepth: 0 }),
     39        };
     40      } else {
     41        // Resolve navigation id.
     42        const navigation =
     43          this.messageHandler.navigationManager.getNavigationForBrowsingContext(
     44            browsingContext
     45          );
     46        payload.navigation = navigation ? navigation.navigationId : null;
     47      }
     48    }
     49 
     50    return payload;
     51  }
     52 }
     53 
     54 export const browsingContext = BrowsingContextModule;