summaryrefslogtreecommitdiffstats
path: root/devtools/client/performance-new/panel.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /devtools/client/performance-new/panel.js
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/performance-new/panel.js')
-rw-r--r--devtools/client/performance-new/panel.js90
1 files changed, 90 insertions, 0 deletions
diff --git a/devtools/client/performance-new/panel.js b/devtools/client/performance-new/panel.js
new file mode 100644
index 0000000000..2a6394942a
--- /dev/null
+++ b/devtools/client/performance-new/panel.js
@@ -0,0 +1,90 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+// @ts-check
+"use strict";
+
+/**
+ * This file contains the PerformancePanel, which uses a common API for DevTools to
+ * start and load everything. This will call `gInit` from the initializer.js file,
+ * which does the important initialization for the panel. This code is more concerned
+ * with wiring this panel into the rest of DevTools and fetching the Actor's fronts.
+ */
+
+/**
+ * @typedef {import("./@types/perf").PanelWindow} PanelWindow
+ * @typedef {import("./@types/perf").Toolbox} Toolbox
+ * @typedef {import("./@types/perf").Target} Target
+ */
+
+class PerformancePanel {
+ /**
+ * @param {PanelWindow} iframeWindow
+ * @param {Toolbox} toolbox
+ */
+ constructor(iframeWindow, toolbox) {
+ this.panelWin = iframeWindow;
+ this.toolbox = toolbox;
+
+ const EventEmitter = require("devtools/shared/event-emitter");
+ EventEmitter.decorate(this);
+ }
+
+ /**
+ * This is implemented (and overwritten) by the EventEmitter. Is there a way
+ * to use mixins with JSDoc?
+ *
+ * @param {string} eventName
+ */
+ emit(eventName) {}
+
+ /**
+ * Open is effectively an asynchronous constructor.
+ * @return {Promise<PerformancePanel>} Resolves when the Perf tool completes
+ * opening.
+ */
+ open() {
+ if (!this._opening) {
+ this._opening = this._doOpen();
+ }
+ return this._opening;
+ }
+
+ /**
+ * This function is the actual implementation of the open() method.
+ * @returns Promise<PerformancePanel>
+ */
+ async _doOpen() {
+ this.panelWin.gToolbox = this.toolbox;
+ this.panelWin.gIsPanelDestroyed = false;
+
+ const perfFront = await this.target.client.mainRoot.getFront("perf");
+
+ this.isReady = true;
+ this.emit("ready");
+ this.panelWin.gInit(perfFront, "devtools");
+ return this;
+ }
+
+ // DevToolPanel API:
+
+ /**
+ * @returns {Target} target
+ */
+ get target() {
+ return this.toolbox.target;
+ }
+
+ destroy() {
+ // Make sure this panel is not already destroyed.
+ if (this._destroyed) {
+ return;
+ }
+ this.panelWin.gDestroy();
+ this.emit("destroyed");
+ this._destroyed = true;
+ this.panelWin.gIsPanelDestroyed = true;
+ }
+}
+
+exports.PerformancePanel = PerformancePanel;