Bug 1455226 - Move browserRequire creation to panel.js;r=ochameau draft
authorJulian Descottes <jdescottes@mozilla.com>
Thu, 19 Apr 2018 19:21:04 +0200
changeset 785105 f9a8e2a427b0ab5fbe1589ef8093f222002ebf8a
parent 785104 7dfe7d053e55ebdf5625cf4fd5e8653ddc05ace3
push id107144
push userjdescottes@mozilla.com
push dateThu, 19 Apr 2018 17:59:08 +0000
reviewersochameau
bugs1455226
milestone61.0a1
Bug 1455226 - Move browserRequire creation to panel.js;r=ochameau MozReview-Commit-ID: 3XzKPf3HUsh
devtools/client/memory/memory.xhtml
devtools/client/memory/panel.js
--- a/devtools/client/memory/memory.xhtml
+++ b/devtools/client/memory/memory.xhtml
@@ -19,29 +19,16 @@
   <body class="theme-body">
     <div id="app"></div>
 
     <script type="application/javascript"
             src="chrome://devtools/content/shared/theme-switching.js"
             defer="true">
     </script>
 
-    <script type="application/javascript">
-      const BrowserLoaderModule = {};
-      ChromeUtils.import("resource://devtools/client/shared/browser-loader.js", BrowserLoaderModule);
-      const { require } = BrowserLoaderModule.BrowserLoader({
-        baseURI: "resource://devtools/client/memory/",
-        window
-      });
-      let { initialize, destroy } = require("devtools/client/memory/initializer");
-      // Expose initialize and destroy on the window, will be accessed by panel.js
-      window.initialize = initialize;
-      window.destroy = destroy;
-    </script>
-
     <script type="application/javascript"
             src="chrome://devtools/content/shared/vendor/d3.js"
             defer="true">
     </script>
 
     <script type="application/javascript"
             src="chrome://devtools/content/shared/vendor/dagre-d3.js"
             defer="true">
--- a/devtools/client/memory/panel.js
+++ b/devtools/client/memory/panel.js
@@ -1,22 +1,30 @@
 /* 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("devtools/shared/event-emitter");
 const { MemoryFront } = require("devtools/shared/fronts/memory");
+const { Cu } = require("chrome");
 const HeapAnalysesClient = require("devtools/shared/heapsnapshot/HeapAnalysesClient");
 
 function MemoryPanel(iframeWindow, toolbox) {
   this.panelWin = iframeWindow;
   this._toolbox = toolbox;
 
+  const { BrowserLoader } = Cu.import("resource://devtools/client/shared/browser-loader.js", {});
+  const browserRequire = BrowserLoader({
+    baseURI: "resource://devtools/client/memory/",
+    window: this.panelWin
+  }).require;
+  this.initializer = browserRequire("devtools/client/memory/initializer");
+
   EventEmitter.decorate(this);
 }
 
 MemoryPanel.prototype = {
   async open() {
     if (this._opening) {
       return this._opening;
     }
@@ -27,17 +35,17 @@ MemoryPanel.prototype = {
     const rootForm = await this.target.root;
     this.panelWin.gFront = new MemoryFront(this.target.client,
                                            this.target.form,
                                            rootForm);
     this.panelWin.gHeapAnalysesClient = new HeapAnalysesClient();
 
     await this.panelWin.gFront.attach();
 
-    this._opening = this.panelWin.initialize().then(() => {
+    this._opening = this.initializer.initialize().then(() => {
       this.isReady = true;
       this.emit("ready");
       return this;
     });
 
     return this._opening;
   },
 
@@ -50,17 +58,17 @@ MemoryPanel.prototype = {
   async destroy() {
     // Make sure this panel is not already destroyed.
     if (this._destroyer) {
       return this._destroyer;
     }
 
     await this.panelWin.gFront.detach();
 
-    this._destroyer = this.panelWin.destroy().then(() => {
+    this._destroyer = this.initializer.destroy().then(() => {
       // Destroy front to ensure packet handler is removed from client
       this.panelWin.gFront.destroy();
       this.panelWin.gHeapAnalysesClient.destroy();
       this.panelWin = null;
       this._opening = null;
       this.isReady = false;
       this.emit("destroyed");
     });