Bug 1446027 - Prevents synchronous uninterruptible reflow from ExtensionPopups.jsm. draft
authorLuca Greco <lgreco@mozilla.com>
Thu, 15 Mar 2018 12:01:46 +0100
changeset 799343 8943af6d330214e5b9f54c9a90c39ac65f839731
parent 799267 043e4ab6e72469ed8121f4da98dcdfef983a49d9
push id111018
push userluca.greco@alcacoop.it
push dateThu, 24 May 2018 14:37:17 +0000
bugs1446027
milestone62.0a1
Bug 1446027 - Prevents synchronous uninterruptible reflow from ExtensionPopups.jsm. MozReview-Commit-ID: Kjmn67ZfNWd
browser/components/extensions/ExtensionPopups.jsm
--- a/browser/components/extensions/ExtensionPopups.jsm
+++ b/browser/components/extensions/ExtensionPopups.jsm
@@ -507,53 +507,56 @@ class ViewPopup extends BasePopup {
 
     if (this.destroyed) {
       CustomizableUI.hidePanelForNode(viewNode);
       return false;
     }
 
     this.attached = true;
 
-
-    // Store the initial height of the view, so that we never resize menu panel
-    // sub-views smaller than the initial height of the menu.
-    this.viewHeight = this.viewNode.boxObject.height;
-
-    // Calculate the extra height available on the screen above and below the
-    // menu panel. Use that to calculate the how much the sub-view may grow.
-    let popupRect = this.panel.getBoundingClientRect();
-
     this.setBackground(this.background);
 
-    let win = this.window;
-    let popupBottom = win.mozInnerScreenY + popupRect.bottom;
-    let popupTop = win.mozInnerScreenY + popupRect.top;
+    let flushPromise = this.window.promiseDocumentFlushed(() => {
+      let win = this.window;
+
+      // Calculate the extra height available on the screen above and below the
+      // menu panel. Use that to calculate the how much the sub-view may grow.
+      let popupRect = this.panel.getBoundingClientRect();
+      let screenBottom = win.screen.availTop + win.screen.availHeight;
+      let popupBottom = win.mozInnerScreenY + popupRect.bottom;
+      let popupTop = win.mozInnerScreenY + popupRect.top;
 
-    let screenBottom = win.screen.availTop + win.screen.availHeight;
-    this.extraHeight = {
-      bottom: Math.max(0, screenBottom - popupBottom),
-      top:  Math.max(0, popupTop - win.screen.availTop),
-    };
+      // Store the initial height of the view, so that we never resize menu panel
+      // sub-views smaller than the initial height of the menu.
+      this.viewHeight = this.viewNode.boxObject.height;
+
+      this.extraHeight = {
+        bottom: Math.max(0, screenBottom - popupBottom),
+        top:  Math.max(0, popupTop - win.screen.availTop),
+      };
+    });
 
     // Create a new browser in the real popup.
     let browser = this.browser;
     await this.createBrowser(this.viewNode);
 
-    this.ignoreResizes = false;
-
     this.browser.swapDocShells(browser);
     this.destroyBrowser(browser);
 
+    await flushPromise;
+
     if (this.dimensions) {
       if (this.fixedWidth) {
         delete this.dimensions.width;
       }
       this.resizeBrowser(this.dimensions);
     }
 
+    this.ignoreResizes = false;
+
     this.viewNode.customRectGetter = () => {
       return {height: this.lastCalculatedInViewHeight || this.viewHeight};
     };
 
     this.removeTempPanel();
 
     this.shown = true;