Bug 1491601 - Synchronize subdialog.js with M-C to fix JS TypeError. r=jorgk
authorRichard Marti <richard.marti@gmail.com>
Sun, 07 Oct 2018 10:06:02 +0200
changeset 33329 eaaaf728d1d6b430224c999efa5b95b14216040e
parent 33328 d1c3b7b0b9c209a5e6af479ae616aeb8cbb28f5e
child 33330 da7cae0efc9d380eae26d9ef2f1b571bf8fcf811
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersjorgk
bugs1491601
Bug 1491601 - Synchronize subdialog.js with M-C to fix JS TypeError. r=jorgk
mail/components/preferences/subdialogs.js
--- a/mail/components/preferences/subdialogs.js
+++ b/mail/components/preferences/subdialogs.js
@@ -38,17 +38,18 @@ SubDialog.prototype = {
   _frameCreated: null,
   _overlay: null,
   _box: null,
   _openedURL: null,
   _injectedStyleSheets: [
     "chrome://messenger/skin/preferences/preferences.css",
     "chrome://global/skin/in-content/common.css",
     "chrome://messenger/skin/preferences/aboutPreferences.css",
-    "chrome://messenger/skin/preferences/dialog.css"],
+    "chrome://messenger/skin/preferences/dialog.css",
+  ],
 
   // Store the original instantApply pref for restoring after closing the dialog
   _instantApplyOrig: Services.prefs.getBoolPref("browser.preferences.instantApply"),
   _resizeObserver: null,
   _template: null,
   _id: null,
   _titleElement: null,
   _closeButton: null,
@@ -81,18 +82,19 @@ SubDialog.prototype = {
       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();
       }
+      let args = Array.from(arguments);
       this._closingPromise.then(() => {
-        this.open(aURL, aFeatures, aParams, aClosingCallback);
+        this.open.apply(this, args);
       });
       return;
     }
     this._addDialogEventListeners();
 
     Services.prefs.setBoolPref("browser.preferences.instantApply", true);
     let features = (aFeatures ? aFeatures + "," : "") + "resizable,dialog=no,centerscreen";
     let dialog = window.openDialog(aURL, `dialogFrame-${this._id}`, features, aParams);
@@ -154,17 +156,19 @@ SubDialog.prototype = {
           this._frame.removeEventListener("load", onBlankLoad);
           // We're now officially done closing, so update the state to reflect that.
           this._openedURL = null;
           this._isClosing = false;
           this._resolveClosePromise();
         }
       };
       this._frame.addEventListener("load", onBlankLoad);
-      this._frame.loadURI("about:blank");
+      this._frame.loadURI("about:blank", {
+        triggeringPrincipal: Services.scriptSecurityManager.createNullPrincipal({}),
+      });
     }, 0);
   },
 
   handleEvent(aEvent) {
     switch (aEvent.type) {
       case "click":
         // Close the dialog if the user clicked the overlay background, just
         // like when the user presses the ESC key (case "command" below).
@@ -283,17 +287,26 @@ SubDialog.prototype = {
     let boxVerticalBorder = 2 * parseFloat(getComputedStyle(this._box).borderTopWidth);
 
     // The difference between the frame and box shouldn't change, either:
     let boxRect = this._box.getBoundingClientRect();
     let frameRect = this._frame.getBoundingClientRect();
     let frameSizeDifference = (frameRect.top - boxRect.top) + (boxRect.bottom - frameRect.bottom);
 
     // Then determine and set a bunch of width stuff:
-    let frameMinWidth = docEl.style.width || docEl.scrollWidth + "px";
+    let frameMinWidth = docEl.style.width;
+    if (!frameMinWidth) {
+      if (docEl.ownerDocument.body) {
+        // HTML documents have a body but XUL documents don't
+        frameMinWidth = docEl.ownerDocument.body.scrollWidth;
+      } else {
+        frameMinWidth = docEl.scrollWidth;
+      }
+      frameMinWidth += "px";
+    }
     let frameWidth = docEl.getAttribute("width") ? docEl.getAttribute("width") + "px" :
                      frameMinWidth;
     this._frame.style.width = frameWidth;
     this._box.style.minWidth = "calc(" +
                                (boxHorizontalBorder + boxHorizontalPadding) +
                                "px + " + frameMinWidth + ")";
 
     // Now do the same but for the height. We need to do this afterwards because otherwise
@@ -309,18 +322,17 @@ SubDialog.prototype = {
     // Do this with a frame height in pixels...
     let comparisonFrameHeight;
     if (frameHeight.endsWith("em")) {
       let fontSize = parseFloat(getComputedStyle(this._frame).fontSize);
       comparisonFrameHeight = parseFloat(frameHeight, 10) * fontSize;
     } else if (frameHeight.endsWith("px")) {
       comparisonFrameHeight = parseFloat(frameHeight, 10);
     } else {
-      Cu.reportError(
-                     "This dialog (" + this._frame.contentWindow.location.href + ") " +
+      Cu.reportError("This dialog (" + this._frame.contentWindow.location.href + ") " +
                      "set a height in non-px-non-em units ('" + frameHeight + "'), " +
                      "which is likely to lead to bad sizing in in-content preferences. " +
                      "Please consider changing this.");
       comparisonFrameHeight = parseFloat(frameHeight);
     }
 
     if (comparisonFrameHeight > maxHeight) {
       // If the height is bigger than that of the window, we should let the contents scroll:
@@ -340,16 +352,17 @@ SubDialog.prototype = {
     this._overlay.dispatchEvent(new CustomEvent("dialogopen", {
       bubbles: true,
       detail: { dialog: this },
     }));
     this._overlay.style.visibility = "visible";
     this._overlay.style.opacity = ""; // XXX: focus hack continued from _onContentLoaded
 
     if (this._box.getAttribute("resizable") == "true") {
+      this._onResize = this._onResize.bind(this);
       this._resizeObserver = new MutationObserver(this._onResize);
       this._resizeObserver.observe(this._box, {attributes: true});
     }
 
     this._trapFocus();
   },
 
   _onResize(mutations) {