Bug 1441284 - Part 6 - Do not move out subviews when the window is closing. r=Gijs draft
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Mon, 26 Feb 2018 19:47:29 +0000
changeset 760401 dc942b7c9742d217fb1d5c01407a887233434916
parent 760400 943b36219ef9917e51424159d459d7c213527cae
child 760402 300bacf4984a7aedb77ddad482232587c51fa627
push id100626
push userpaolo.mozmail@amadzone.org
push dateTue, 27 Feb 2018 14:19:41 +0000
reviewersGijs
bugs1441284
milestone60.0a1
Bug 1441284 - Part 6 - Do not move out subviews when the window is closing. r=Gijs Since we control the code path that invokes the PanelMultiView destructor, it is now possible to call the _moveOutKids function only as needed, avoiding some unnecessary DOM modifications when the browser window is closing. MozReview-Commit-ID: JTJQmhZKFOh
browser/components/customizableui/PanelMultiView.jsm
--- a/browser/components/customizableui/PanelMultiView.jsm
+++ b/browser/components/customizableui/PanelMultiView.jsm
@@ -88,20 +88,16 @@
  *     └───┴───┴───┴───┘            └───┘
  *       │ ┌───┬───┬───┬───┐        ┌───┐
  *       │ │{A}│(C)│ D │ B │        │ E │              Go back
  *       │ └───┴───┴───┴───┘        └───┘
  *       │   │   │
  *       │   │   └── Currently visible view
  *       │   │   │
  *       └───┴───┴── Open views
- *
- * If the <panelmultiview> element is "ephemeral", imported subviews will be
- * moved out again to the element specified by the viewCacheId attribute, so
- * that the panel element can be removed safely.
  */
 
 "use strict";
 
 var EXPORTED_SYMBOLS = [
   "PanelMultiView",
   "PanelView",
 ];
@@ -302,24 +298,30 @@ var PanelMultiView = class extends this.
       panelNode.hidePopup();
     }
   }
 
   /**
    * Removes the specified <panel> from the document, ensuring that any
    * <panelmultiview> node it contains is destroyed properly.
    *
+   * If the viewCacheId attribute is present on the <panelmultiview> element,
+   * imported subviews will be moved out again to the element it specifies, so
+   * that the panel element can be removed safely.
+   *
    * If the panel does not contain a <panelmultiview>, it is removed directly.
    * This allows consumers like page actions to accept different panel types.
    */
   static removePopup(panelNode) {
     try {
       let panelMultiViewNode = panelNode.querySelector("panelmultiview");
       if (panelMultiViewNode) {
-        this.forNode(panelMultiViewNode).disconnect();
+        let panelMultiView = this.forNode(panelMultiViewNode);
+        panelMultiView._moveOutKids();
+        panelMultiView.disconnect();
       }
     } finally {
       // Make sure to remove the panel element even if disconnecting fails.
       panelNode.remove();
     }
   }
 
   /**
@@ -434,17 +436,16 @@ var PanelMultiView = class extends this.
 
   disconnect() {
     // Guard against re-entrancy.
     if (!this.node || !this.connected)
       return;
 
     this._cleanupTransitionPhase();
 
-    this._moveOutKids();
     this._panel.removeEventListener("mousemove", this);
     this._panel.removeEventListener("popupshowing", this);
     this._panel.removeEventListener("popuppositioned", this);
     this._panel.removeEventListener("popupshown", this);
     this._panel.removeEventListener("popuphidden", this);
     this.window.removeEventListener("keydown", this);
     this.node = this._openPopupPromise = this._openPopupCancelCallback =
       this._viewContainer = this._viewStack = this.__dwu =