panel.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. "use strict";
  5. const { Cc, Ci, Cu, Cr } = require("chrome");
  6. const { Task } = require("devtools/shared/task");
  7. const EventEmitter = require("devtools/shared/event-emitter");
  8. const { MemoryFront } = require("devtools/shared/fronts/memory");
  9. const HeapAnalysesClient = require("devtools/shared/heapsnapshot/HeapAnalysesClient");
  10. const promise = require("promise");
  11. function MemoryPanel(iframeWindow, toolbox) {
  12. this.panelWin = iframeWindow;
  13. this._toolbox = toolbox;
  14. EventEmitter.decorate(this);
  15. }
  16. MemoryPanel.prototype = {
  17. open: Task.async(function* () {
  18. if (this._opening) {
  19. return this._opening;
  20. }
  21. this.panelWin.gToolbox = this._toolbox;
  22. this.panelWin.gTarget = this.target;
  23. const rootForm = yield this.target.root;
  24. this.panelWin.gFront = new MemoryFront(this.target.client,
  25. this.target.form,
  26. rootForm);
  27. this.panelWin.gHeapAnalysesClient = new HeapAnalysesClient();
  28. yield this.panelWin.gFront.attach();
  29. this._opening = this.panelWin.initialize().then(() => {
  30. this.isReady = true;
  31. this.emit("ready");
  32. return this;
  33. });
  34. return this._opening;
  35. }),
  36. // DevToolPanel API
  37. get target() {
  38. return this._toolbox.target;
  39. },
  40. destroy: Task.async(function* () {
  41. // Make sure this panel is not already destroyed.
  42. if (this._destroyer) {
  43. return this._destroyer;
  44. }
  45. yield this.panelWin.gFront.detach();
  46. this._destroyer = this.panelWin.destroy().then(() => {
  47. // Destroy front to ensure packet handler is removed from client
  48. this.panelWin.gFront.destroy();
  49. this.panelWin.gHeapAnalysesClient.destroy();
  50. this.panelWin = null;
  51. this._opening = null;
  52. this.isReady = false;
  53. this.emit("destroyed");
  54. });
  55. return this._destroyer;
  56. })
  57. };
  58. exports.MemoryPanel = MemoryPanel;