tor-browser

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

panel.js (2867B)


      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 // @ts-check
      5 "use strict";
      6 
      7 /**
      8 * This file contains the PerformancePanel, which uses a common API for DevTools to
      9 * start and load everything. This will call `gInit` from the initializer.js file,
     10 * which does the important initialization for the panel. This code is more concerned
     11 * with wiring this panel into the rest of DevTools and fetching the Actor's fronts.
     12 */
     13 
     14 /**
     15 * @typedef {import("../@types/perf").PanelWindow} PanelWindow
     16 * @typedef {import("../@types/perf").Toolbox} Toolbox
     17 * @typedef {import("../@types/perf").Target} Target
     18 * @typedef {import("../@types/perf").Commands} Commands
     19 */
     20 
     21 class PerformancePanel {
     22  /**
     23   * @param {PanelWindow} iframeWindow
     24   * @param {Toolbox} toolbox
     25   * @param {Commands} commands
     26   */
     27  constructor(iframeWindow, toolbox, commands) {
     28    this.panelWin = iframeWindow;
     29    this.toolbox = toolbox;
     30    this.commands = commands;
     31 
     32    const EventEmitter = require("resource://devtools/shared/event-emitter.js");
     33    EventEmitter.decorate(this);
     34  }
     35 
     36  /**
     37   * This is implemented (and overwritten) by the EventEmitter. Is there a way
     38   * to use mixins with JSDoc?
     39   *
     40   * @param {string} _eventName
     41   */
     42  emit(_eventName) {}
     43 
     44  /**
     45   * Open is effectively an asynchronous constructor.
     46   *
     47   * @return {Promise<PerformancePanel>} Resolves when the Perf tool completes
     48   *     opening.
     49   */
     50  open() {
     51    if (!this._opening) {
     52      this._opening = this._doOpen();
     53    }
     54    return this._opening;
     55  }
     56 
     57  /**
     58   * This function is the actual implementation of the open() method.
     59   *
     60   * @returns Promise<PerformancePanel>
     61   */
     62  async _doOpen() {
     63    this.panelWin.gToolbox = this.toolbox;
     64    this.panelWin.gIsPanelDestroyed = false;
     65 
     66    const perfFront = await this.commands.client.mainRoot.getFront("perf");
     67 
     68    // Note: we are not using traits in the panel at the moment but we keep the
     69    // wiring in case we need it later on.
     70    const traits = {};
     71 
     72    await this.panelWin.gInit(
     73      perfFront,
     74      traits,
     75      "devtools",
     76      this._openAboutProfiling
     77    );
     78    return this;
     79  }
     80 
     81  _openAboutProfiling() {
     82    const {
     83      openTrustedLink,
     84    } = require("resource://devtools/client/shared/link.js");
     85    openTrustedLink("about:profiling", {});
     86  }
     87 
     88  // DevToolPanel API:
     89 
     90  /**
     91   * @returns {Target} target
     92   */
     93  get target() {
     94    return this.toolbox.target;
     95  }
     96 
     97  destroy() {
     98    // Make sure this panel is not already destroyed.
     99    if (this._destroyed) {
    100      return;
    101    }
    102    this.panelWin.gDestroy();
    103    this.emit("destroyed");
    104    this._destroyed = true;
    105    this.panelWin.gIsPanelDestroyed = true;
    106  }
    107 }
    108 
    109 exports.PerformancePanel = PerformancePanel;