summaryrefslogtreecommitdiffstats
path: root/devtools/client/memory/panel.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /devtools/client/memory/panel.js
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/memory/panel.js')
-rw-r--r--devtools/client/memory/panel.js74
1 files changed, 74 insertions, 0 deletions
diff --git a/devtools/client/memory/panel.js b/devtools/client/memory/panel.js
new file mode 100644
index 0000000000..e6143aafa4
--- /dev/null
+++ b/devtools/client/memory/panel.js
@@ -0,0 +1,74 @@
+/* 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/. */
+
+"use strict";
+
+const EventEmitter = require("resource://devtools/shared/event-emitter.js");
+const HeapAnalysesClient = require("resource://devtools/shared/heapsnapshot/HeapAnalysesClient.js");
+
+function MemoryPanel(iframeWindow, toolbox, commands) {
+ this.panelWin = iframeWindow;
+ this._toolbox = toolbox;
+ this._commands = commands;
+
+ const { BrowserLoader } = ChromeUtils.import(
+ "resource://devtools/shared/loader/browser-loader.js"
+ );
+ const browserRequire = BrowserLoader({
+ baseURI: "resource://devtools/client/memory/",
+ window: this.panelWin,
+ }).require;
+ this.initializer = browserRequire("devtools/client/memory/initializer");
+
+ this._onTargetAvailable = this._onTargetAvailable.bind(this);
+
+ EventEmitter.decorate(this);
+}
+
+MemoryPanel.prototype = {
+ async open() {
+ this.panelWin.gToolbox = this._toolbox;
+ this.panelWin.gHeapAnalysesClient = new HeapAnalysesClient();
+
+ await this.initializer.initialize(this._commands);
+
+ await this._commands.targetCommand.watchTargets({
+ types: [this._commands.targetCommand.TYPES.FRAME],
+ onAvailable: this._onTargetAvailable,
+ });
+
+ return this;
+ },
+
+ async _onTargetAvailable({ targetFront }) {
+ if (targetFront.isTopLevel) {
+ const front = await targetFront.getFront("memory");
+ await front.attach();
+ this.initializer.updateFront(front);
+ }
+ },
+
+ // DevToolPanel API
+
+ destroy() {
+ // Make sure this panel is not already destroyed.
+ if (this._destroyed) {
+ return;
+ }
+ this._destroyed = true;
+
+ this._commands.targetCommand.unwatchTargets({
+ types: [this._commands.targetCommand.TYPES.FRAME],
+ onAvailable: this._onTargetAvailable,
+ });
+
+ this.initializer.destroy();
+
+ this.panelWin.gHeapAnalysesClient.destroy();
+ this.panelWin = null;
+ this.emit("destroyed");
+ },
+};
+
+exports.MemoryPanel = MemoryPanel;