Bug 1493131 - use custom memoization for the inspector; r=ochameau
authoryulia <ystartsev@mozilla.com>
Fri, 05 Oct 2018 08:39:47 +0000
changeset 488127 81624993c03d6f14f774cc73e4a9bb7bd60fde4d
parent 488126 24b0c3333b72593737a205d73cc248ccf60c3125
child 488128 8c0d100a4307c28b73d09e151dcdf2d466edd2e0
push id246
push userfmarier@mozilla.com
push dateSat, 13 Oct 2018 00:15:40 +0000
reviewersochameau
bugs1493131
milestone64.0a1
Bug 1493131 - use custom memoization for the inspector; r=ochameau Differential Revision: https://phabricator.services.mozilla.com/D7703
devtools/client/framework/target.js
devtools/client/framework/toolbox.js
devtools/client/menus.js
--- a/devtools/client/framework/target.js
+++ b/devtools/client/framework/target.js
@@ -232,16 +232,20 @@ function TabTarget({ form, client, chrom
     const isContentProcessTarget =
       this._form.actor.match(/conn\d+\.content-process\d+\/contentProcessTarget\d+/);
     this._isBrowsingContext = !this.isLegacyAddon && !isContentProcessTarget;
   }
 
   // Cache of already created targed-scoped fronts
   // [typeName:string => Front instance]
   this.fronts = new Map();
+  // Temporary fix for bug #1493131 - inspector has a different life cycle
+  // than most other fronts because it is closely related to the toolbox.
+  // TODO: remove once inspector is separated from the toolbox
+  this._inspector = null;
 }
 
 exports.TabTarget = TabTarget;
 
 TabTarget.prototype = {
   /**
    * Returns a promise for the protocol description from the root actor. Used
    * internally with `target.actorHasMethod`. Takes advantage of caching if
@@ -370,16 +374,28 @@ TabTarget.prototype = {
     return this._form;
   },
 
   // Get a promise of the RootActor's form
   get root() {
     return this.client.mainRoot.rootForm;
   },
 
+  // Temporary fix for bug #1493131 - inspector has a different life cycle
+  // than most other fronts because it is closely related to the toolbox.
+  // TODO: remove once inspector is separated from the toolbox
+  getInspector(typeName) {
+    // the front might have been destroyed and no longer have an actor ID
+    if (this._inspector && this._inspector.actorID) {
+      return this._inspector;
+    }
+    this._inspector = getFront(this.client, "inspector", this.form);
+    return this._inspector;
+  },
+
   // Get a Front for a target-scoped actor.
   // i.e. an actor served by RootActor.listTabs or RootActorActor.getTab requests
   getFront(typeName) {
     let front = this.fronts.get(typeName);
     // the front might have been destroyed and no longer have an actor ID
     if (front && front.actorID) {
       return front;
     }
--- a/devtools/client/framework/toolbox.js
+++ b/devtools/client/framework/toolbox.js
@@ -2672,17 +2672,20 @@ Toolbox.prototype = {
 
   /**
    * Initialize the inspector/walker/selection/highlighter fronts.
    * Returns a promise that resolves when the fronts are initialized
    */
   initInspector: function() {
     if (!this._initInspector) {
       this._initInspector = (async function() {
-        this._inspector = this.target.getFront("inspector");
+        // Temporary fix for bug #1493131 - inspector has a different life cycle
+        // than most other fronts because it is closely related to the toolbox.
+        // TODO: replace with getFront once inspector is separated from the toolbox
+        this._inspector = this.target.getInspector();
         const pref = "devtools.inspector.showAllAnonymousContent";
         const showAllAnonymousContent = Services.prefs.getBoolPref(pref);
         this._walker = await this._inspector.getWalker({ showAllAnonymousContent });
         this._selection = new Selection(this._walker);
         this._selection.on("new-node-front", this._onNewSelectedNodeFront);
 
         if (this.highlighterUtils.isRemoteHighlightable()) {
           this.walker.on("highlighter-ready", this._highlighterReady);
@@ -2743,16 +2746,17 @@ Toolbox.prototype = {
 
       jsterm.inspectObjectActor(objectActor);
     }
   },
 
   /**
    * Destroy the inspector/walker/selection fronts
    * Returns a promise that resolves when the fronts are destroyed
+   * TODO: move to the inspector front once we can have listener hooks into fronts
    */
   destroyInspector: function() {
     if (this._destroyingInspector) {
       return this._destroyingInspector;
     }
 
     this._destroyingInspector = (async function() {
       if (!this._inspector) {
@@ -2764,16 +2768,19 @@ Toolbox.prototype = {
       await this._initInspector;
 
       const currentPanel = this.getCurrentPanel();
       if (currentPanel.stopPicker) {
         await currentPanel.stopPicker();
       } else {
         await this.highlighterUtils.stopPicker();
       }
+      // Temporary fix for bug #1493131 - inspector has a different life cycle
+      // than most other fronts because it is closely related to the toolbox.
+      this._inspector.destroy();
 
       if (this._highlighter) {
         // Note that if the toolbox is closed, this will work fine, but will fail
         // in case the browser is closed and will trigger a noSuchActor message.
         // We ignore the promise that |_hideBoxModel| returns, since we should still
         // proceed with the rest of destruction if it fails.
         // FF42+ now does the cleanup from the actor.
         if (!this.highlighter.traits.autoHideOnDestroy) {
--- a/devtools/client/menus.js
+++ b/devtools/client/menus.js
@@ -98,17 +98,20 @@ exports.menuitems = [
     checkbox: true
   },
   { id: "menu_eyedropper",
     l10nKey: "eyedropper",
     async oncommand(event) {
       const window = event.target.ownerDocument.defaultView;
       const target = await TargetFactory.forTab(window.gBrowser.selectedTab);
       await target.attach();
-      const inspectorFront = await target.getFront("inspector");
+    // Temporary fix for bug #1493131 - inspector has a different life cycle
+    // than most other fronts because it is closely related to the toolbox.
+    // TODO: replace with getFront once inspector is separated from the toolbox
+      const inspectorFront = await target.getInspector();
       inspectorFront.pickColorFromPage({copyOnSelect: true, fromMenu: true});
     },
     checkbox: true
   },
   { id: "menu_scratchpad",
     l10nKey: "scratchpad",
     oncommand() {
       ScratchpadManager.openScratchpad();