panel.js (2113B)
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 EventEmitter = require("resource://devtools/shared/event-emitter.js"); 8 const HeapAnalysesClient = require("resource://devtools/shared/heapsnapshot/HeapAnalysesClient.js"); 9 10 class MemoryPanel extends EventEmitter { 11 constructor(iframeWindow, toolbox, commands) { 12 super(); 13 14 this.panelWin = iframeWindow; 15 this._toolbox = toolbox; 16 this._commands = commands; 17 18 const { BrowserLoader } = ChromeUtils.importESModule( 19 "resource://devtools/shared/loader/browser-loader.sys.mjs" 20 ); 21 const browserRequire = BrowserLoader({ 22 baseURI: "resource://devtools/client/memory/", 23 window: this.panelWin, 24 }).require; 25 this.initializer = browserRequire("devtools/client/memory/initializer"); 26 27 this._onTargetAvailable = this._onTargetAvailable.bind(this); 28 } 29 async open() { 30 this.panelWin.gToolbox = this._toolbox; 31 this.panelWin.gHeapAnalysesClient = new HeapAnalysesClient(); 32 33 await this.initializer.initialize(this._commands); 34 35 await this._commands.targetCommand.watchTargets({ 36 types: [this._commands.targetCommand.TYPES.FRAME], 37 onAvailable: this._onTargetAvailable, 38 }); 39 40 return this; 41 } 42 43 async _onTargetAvailable({ targetFront }) { 44 if (targetFront.isTopLevel) { 45 const front = await targetFront.getFront("memory"); 46 await front.attach(); 47 this.initializer.updateFront(front); 48 } 49 } 50 51 // DevToolPanel API 52 53 destroy() { 54 // Make sure this panel is not already destroyed. 55 if (this._destroyed) { 56 return; 57 } 58 this._destroyed = true; 59 60 this._commands.targetCommand.unwatchTargets({ 61 types: [this._commands.targetCommand.TYPES.FRAME], 62 onAvailable: this._onTargetAvailable, 63 }); 64 65 this.initializer.destroy(); 66 67 this.panelWin.gHeapAnalysesClient.destroy(); 68 this.panelWin = null; 69 this.emit("destroyed"); 70 } 71 } 72 73 exports.MemoryPanel = MemoryPanel;