Bug 1440262 - Enter/exit modal state on scriptable top window. r=smaug
authorAndreas Farre <farre@mozilla.com>
Thu, 26 Apr 2018 05:44:00 +0300
changeset 416047 ba1278f999e00118b1f21d0cc32fde07f47a046c
parent 416046 89f8eb048586fa80f06632b43fc3a9c1141c275a
child 416048 5fbb27f31ec8e4d0650b1b452cfbe83f269e6853
push id33915
push userncsoregi@mozilla.com
push dateFri, 27 Apr 2018 21:53:44 +0000
treeherdermozilla-central@8b2c1fc3d6c3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1440262
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1440262 - Enter/exit modal state on scriptable top window. r=smaug If inner windows are torn down before modal dialog close messages have propagated fully we loose the possibility of getting a hold of an windows's scriptable top, which is needed to leave modal state. By making sure that the prompt fetches top on its own we guarantee that we have the correct window to suspend/resume.
toolkit/components/prompts/src/nsPrompter.js
--- a/toolkit/components/prompts/src/nsPrompter.js
+++ b/toolkit/components/prompts/src/nsPrompter.js
@@ -435,18 +435,23 @@ function openRemotePrompt(domWin, args, 
     let messageManager = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
                                  .getInterface(Ci.nsITabChild)
                                  .messageManager;
 
     let inPermitUnload = docShell.contentViewer && docShell.contentViewer.inPermitUnload;
     let eventDetail = Cu.cloneInto({tabPrompt, inPermitUnload}, domWin);
     PromptUtils.fireDialogEvent(domWin, "DOMWillOpenModalDialog", null, eventDetail);
 
-    let winUtils = domWin.QueryInterface(Ci.nsIInterfaceRequestor)
-                         .getInterface(Ci.nsIDOMWindowUtils);
+    // If domWin is reloaded while we're showing a remote modal
+    // dialog, it is possible to detach domWin from its tree, and make
+    // it impossible to reach its scriptable top,
+    // a.k.a. window.top. To prevent this, make sure to enter/exit
+    // modal state beginning from top.
+    let winUtils = domWin.top.QueryInterface(Ci.nsIInterfaceRequestor)
+                             .getInterface(Ci.nsIDOMWindowUtils);
     winUtils.enterModalState();
     let closed = false;
 
     let frameMM = docShell.getInterface(Ci.nsIContentFrameMessageManager);
 
     // It should be hard or impossible to cause a window to create multiple
     // prompts, but just in case, give our prompt an ID.
     let id = "id" + Cc["@mozilla.org/uuid-generator;1"]