Bug 933483 - Don't fire events (and especially request animation frame events) when we're in a modal dialog. Also protect ourselves from resuming events on a closed window. r=smaug
☠☠ backed out by 59672fad0777 ☠ ☠
authorBlake Kaplan <mrbkap@gmail.com>
Mon, 02 Dec 2013 15:38:36 -0800
changeset 174046 77c1f23afc1c1d4180148cf1858de0d9a22e078a
parent 174045 d58fa9a72f915ebfa501c7b9c75647d565d0e2c3
child 174047 f1cca0891dbe0aae4f597c5b3db83d789aa7bf57
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs933483
milestone28.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 933483 - Don't fire events (and especially request animation frame events) when we're in a modal dialog. Also protect ourselves from resuming events on a closed window. r=smaug
content/base/src/nsDocument.cpp
dom/base/nsGlobalWindow.cpp
dom/tests/mochitest/bugs/test_bug61098.html
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -8485,17 +8485,20 @@ static void
 FireOrClearDelayedEvents(nsTArray<nsCOMPtr<nsIDocument> >& aDocuments,
                          bool aFireEvents)
 {
   nsIFocusManager* fm = nsFocusManager::GetFocusManager();
   if (!fm)
     return;
 
   for (uint32_t i = 0; i < aDocuments.Length(); ++i) {
-    if (!aDocuments[i]->EventHandlingSuppressed()) {
+    // NB: Don't bother trying to fire delayed events on documents that were
+    // closed before this event ran.
+    if (!aDocuments[i]->EventHandlingSuppressed() &&
+        aDocuments[i]->IsActive()) {
       fm->FireDelayedEvents(aDocuments[i]);
       nsCOMPtr<nsIPresShell> shell = aDocuments[i]->GetShell();
       if (shell) {
         shell->FireOrClearDelayedEvents(aFireEvents);
       }
     }
   }
 }
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -8180,34 +8180,33 @@ nsGlobalWindow::EnterModalState()
       }
     }
   }
 
   if (topWin->mModalStateDepth == 0) {
     NS_ASSERTION(!mSuspendedDoc, "Shouldn't have mSuspendedDoc here!");
 
     mSuspendedDoc = topWin->GetExtantDoc();
-    if (mSuspendedDoc && mSuspendedDoc->EventHandlingSuppressed()) {
+    if (mSuspendedDoc) {
       mSuspendedDoc->SuppressEventHandling();
-    } else {
-      mSuspendedDoc = nullptr;
     }
   }
   topWin->mModalStateDepth++;
 }
 
 // static
 void
 nsGlobalWindow::RunPendingTimeoutsRecursive(nsGlobalWindow *aTopWindow,
                                             nsGlobalWindow *aWindow)
 {
   nsGlobalWindow *inner;
 
   // Return early if we're frozen or have no inner window.
-  if (!(inner = aWindow->GetCurrentInnerWindowInternal()) ||
+  if (aWindow->IsClosedOrClosing() ||
+      !(inner = aWindow->GetCurrentInnerWindowInternal()) ||
       inner->IsFrozen()) {
     return;
   }
 
   inner->RunTimeout(nullptr);
 
   // Check again if we're frozen since running pending timeouts
   // could've frozen us.
--- a/dom/tests/mochitest/bugs/test_bug61098.html
+++ b/dom/tests/mochitest/bugs/test_bug61098.html
@@ -16,17 +16,16 @@ https://bugzilla.mozilla.org/show_bug.cg
 </p>
 <div id="content" style="display: none"> 
 </div>
 <pre id="test">
 </pre>
 <script class="testbody" type="text/javascript">
 /** Test for Bug 61098 **/
 
-SimpleTest.expectAssertions(8);
 SimpleTest.waitForExplicitFinish();
 
 var mockPromptServiceRegisterer, mockPromptFactoryRegisterer;
 
 var promptState;
 
 function registerMockPromptService()
 {