tor-browser

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

ext-devtools-network.js (2022B)


      1 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
      2 /* vim: set sts=2 sw=2 et tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 "use strict";
      8 
      9 /**
     10 * Responsible for fetching HTTP response content from the backend.
     11 *
     12 * @param {DevtoolsExtensionContext}
     13 *   A devtools extension context running in a child process.
     14 * @param {object} options
     15 */
     16 class ChildNetworkResponseLoader {
     17  constructor(context, requestId) {
     18    this.context = context;
     19    this.requestId = requestId;
     20  }
     21 
     22  api() {
     23    const { context, requestId } = this;
     24    return {
     25      getContent(callback) {
     26        return context.childManager.callParentAsyncFunction(
     27          "devtools.network.Request.getContent",
     28          [requestId],
     29          callback
     30        );
     31      },
     32    };
     33  }
     34 }
     35 
     36 this.devtools_network = class extends ExtensionAPI {
     37  getAPI(context) {
     38    return {
     39      devtools: {
     40        network: {
     41          onRequestFinished: new EventManager({
     42            context,
     43            name: "devtools.network.onRequestFinished",
     44            register: fire => {
     45              let onFinished = data => {
     46                const loader = new ChildNetworkResponseLoader(
     47                  context,
     48                  data.requestId
     49                );
     50                const harEntry = { ...data.harEntry, ...loader.api() };
     51                const result = Cu.cloneInto(harEntry, context.cloneScope, {
     52                  cloneFunctions: true,
     53                });
     54                fire.asyncWithoutClone(result);
     55              };
     56 
     57              let parent = context.childManager.getParentEvent(
     58                "devtools.network.onRequestFinished"
     59              );
     60              parent.addListener(onFinished);
     61              return () => {
     62                parent.removeListener(onFinished);
     63              };
     64            },
     65          }).api(),
     66        },
     67      },
     68    };
     69  }
     70 };