tor-browser

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

breakpoint-list.js (2951B)


      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 "use strict";
      6 
      7 const { Actor } = require("resource://devtools/shared/protocol.js");
      8 const {
      9  breakpointListSpec,
     10 } = require("resource://devtools/shared/specs/breakpoint-list.js");
     11 
     12 const { SessionDataHelpers } = ChromeUtils.importESModule(
     13  "resource://devtools/server/actors/watcher/SessionDataHelpers.sys.mjs",
     14  { global: "contextual" }
     15 );
     16 const { SUPPORTED_DATA } = SessionDataHelpers;
     17 const { BREAKPOINTS, XHR_BREAKPOINTS, EVENT_BREAKPOINTS } = SUPPORTED_DATA;
     18 
     19 /**
     20 * This actor manages the breakpoints list.
     21 *
     22 * Breakpoints should be available as early as possible to new targets and
     23 * will be forwarded to the WatcherActor to populate the shared session data available to
     24 * all DevTools targets.
     25 *
     26 * @class
     27 */
     28 class BreakpointListActor extends Actor {
     29  constructor(watcherActor) {
     30    super(watcherActor.conn, breakpointListSpec);
     31    this.watcherActor = watcherActor;
     32  }
     33 
     34  setBreakpoint(location, options) {
     35    return this.watcherActor.addOrSetDataEntry(
     36      BREAKPOINTS,
     37      [{ location, options }],
     38      "add"
     39    );
     40  }
     41 
     42  removeBreakpoint(location, options) {
     43    return this.watcherActor.removeDataEntry(BREAKPOINTS, [
     44      { location, options },
     45    ]);
     46  }
     47 
     48  /**
     49   * Request to break on next XHR or Fetch request for a given URL and HTTP Method.
     50   *
     51   * @param {string} path
     52   *                 If empty, will pause on regardless or the request's URL.
     53   *                 Otherwise, will pause on any request whose URL includes this string.
     54   *                 This is not specific to URL's path. It can match the URL origin.
     55   * @param {string} method
     56   *                 If set to "ANY", will pause regardless of which method is used.
     57   *                 Otherwise, should be set to any valid HTTP Method (GET, POST, ...)
     58   */
     59  setXHRBreakpoint(path, method) {
     60    return this.watcherActor.addOrSetDataEntry(
     61      XHR_BREAKPOINTS,
     62      [{ path, method }],
     63      "add"
     64    );
     65  }
     66 
     67  /**
     68   * Stop breakpoint on requests we ask to break on via setXHRBreakpoint.
     69   *
     70   * See setXHRBreakpoint for arguments definition.
     71   */
     72  removeXHRBreakpoint(path, method) {
     73    return this.watcherActor.removeDataEntry(XHR_BREAKPOINTS, [
     74      { path, method },
     75    ]);
     76  }
     77 
     78  /**
     79   * Set the active breakpoints
     80   *
     81   * @param {Array<string>} ids
     82   *                        An array of eventlistener breakpoint ids. These
     83   *                        are unique identifiers for event breakpoints.
     84   *                        See devtools/server/actors/utils/event-breakpoints.js
     85   *                        for details.
     86   */
     87  async setActiveEventBreakpoints(ids) {
     88    await this.watcherActor.addOrSetDataEntry(EVENT_BREAKPOINTS, ids, "set");
     89  }
     90 }
     91 
     92 exports.BreakpointListActor = BreakpointListActor;