Bug 1439101 - Port bug 1431960 to TB: Forcibly construct the frame for browser to construct browser binding in preferences subdialog. r=jorgk
authorRichard Marti <richard.marti@gmail.com>
Sat, 17 Feb 2018 13:22:46 +0100
changeset 31127 4715b23ab74bb421ffc4e231b969ae88820a0734
parent 31126 4e30bc0739dd51c4b67af5c9d6646189d8ef8282
child 31128 4a54dd076ea940e6545df17c81f5108a0de09464
push id383
push userclokep@gmail.com
push dateMon, 07 May 2018 21:52:48 +0000
reviewersjorgk
bugs1439101, 1431960
Bug 1439101 - Port bug 1431960 to TB: Forcibly construct the frame for browser to construct browser binding in preferences subdialog. r=jorgk
mail/components/preferences/subdialogs.js
--- a/mail/components/preferences/subdialogs.js
+++ b/mail/components/preferences/subdialogs.js
@@ -66,16 +66,26 @@ SubDialog.prototype = {
     );
     this._frame.contentDocument.insertBefore(contentStylesheet,
                                              this._frame.contentDocument.documentElement);
   },
 
   async open(aURL, aFeatures = null, aParams = null, aClosingCallback = null) {
     // Wait until frame is ready to prevent browser crash in tests
     await this._frameCreated;
+
+    if (!this._frame.contentWindow) {
+      // Given the binding constructor execution is asynchronous, and "load"
+      // event can be dispatched before the browser element is shown, the
+      // browser binding might not be constructed at this point.  Forcibly
+      // construct the frame and construct the binding.
+      // FIXME: Remove this (bug 1437247)
+      this._frame.getBoundingClientRect();
+    }
+
     // If we're open on some (other) URL or we're closing, open when closing has finished.
     if (this._openedURL || this._isClosing) {
       if (!this._isClosing) {
         this.close();
       }
       this._closingPromise.then(() => {
         this.open(aURL, aFeatures, aParams, aClosingCallback);
       });
@@ -506,24 +516,29 @@ var gSubDialog = {
   },
 
   open(aURL, aFeatures = null, aParams = null, aClosingCallback = null) {
     // If we're already open/opening on this URL, do nothing.
     if (this._topDialog && this._topDialog._openedURL == aURL) {
       return;
     }
 
+    if (this._dialogs.length == 0) {
+      // When opening the first dialog, show the dialog stack to make sure
+      // the browser binding can be constructed.
+      this._dialogStack.hidden = false;
+    }
+
     this._preloadDialog.open(aURL, aFeatures, aParams, aClosingCallback);
     this._dialogs.push(this._preloadDialog);
     this._preloadDialog = new SubDialog({template: this._dialogTemplate,
                                          parentElement: this._dialogStack,
                                          id: this._nextDialogID++});
 
     if (this._dialogs.length == 1) {
-      this._dialogStack.hidden = false;
       this._ensureStackEventListeners();
     }
   },
 
   close() {
     this._topDialog.close();
   },