tor-browser

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

network.sys.mjs (2145B)


      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  NavigableManager: "chrome://remote/content/shared/NavigableManager.sys.mjs",
     11  RootMessageHandler:
     12    "chrome://remote/content/shared/messagehandler/RootMessageHandler.sys.mjs",
     13  TabManager: "chrome://remote/content/shared/TabManager.sys.mjs",
     14 });
     15 
     16 class NetworkModule extends Module {
     17  destroy() {}
     18 
     19  interceptEvent(name, payload) {
     20    if (name == "network._beforeStopRequest") {
     21      const { channelId, decodedBodySize } = payload;
     22      this.messageHandler.handleCommand({
     23        moduleName: "network",
     24        commandName: "_setDecodedBodySize",
     25        params: { channelId, decodedBodySize },
     26        destination: {
     27          type: lazy.RootMessageHandler.type,
     28        },
     29      });
     30 
     31      // The _beforeStopRequest event is only used in order to feed the
     32      // decodedBodySize map in the parent process. Return null to swallow the
     33      // event.
     34      return null;
     35    } else if (name == "network._windowGlobalNetworkResource") {
     36      const { context, request, response } = payload;
     37      if (!lazy.TabManager.isValidCanonicalBrowsingContext(context)) {
     38        // Discard events for invalid browsing contexts.
     39        return null;
     40      }
     41 
     42      // Resolve browsing context to a Navigable id.
     43      request.contextId =
     44        lazy.NavigableManager.getIdForBrowsingContext(context);
     45 
     46      this.messageHandler.handleCommand({
     47        moduleName: "network",
     48        commandName: "_sendEventsForWindowGlobalNetworkResource",
     49        params: { request, response },
     50        destination: {
     51          type: lazy.RootMessageHandler.type,
     52        },
     53      });
     54 
     55      // The _cachedResourceSent event is only used to call a command on the root.
     56      // Return null to swallow the event.
     57      return null;
     58    }
     59 
     60    return payload;
     61  }
     62 }
     63 
     64 export const network = NetworkModule;