From 9d375e91f7a3a94a8cd259f74bd0a17e8e92452e Mon Sep 17 00:00:00 2001 From: Neil Deakin Date: Mon, 22 Jun 2009 15:49:10 -0400 Subject: [PATCH] Bug 497633, 497878, fix two crashes with similar tests that remove frames during blur, r+sr=smaug --- dom/base/nsFocusManager.cpp | 15 ++++++++++----- dom/tests/mochitest/general/Makefile.in | 2 ++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/dom/base/nsFocusManager.cpp b/dom/base/nsFocusManager.cpp index c59edd2fa0f0..52cd9a697743 100644 --- a/dom/base/nsFocusManager.cpp +++ b/dom/base/nsFocusManager.cpp @@ -1377,9 +1377,11 @@ nsFocusManager::Blur(nsPIDOMWindow* aWindowToClear, mFocusedContent = nsnull; // pass 1 for the focus method when calling SendFocusOrBlurEvent just so - // that the check is made for suppressed documents + // that the check is made for suppressed documents. Check to ensure that + // the document isn't null in case someone closed it during the blur above nsCOMPtr doc = do_QueryInterface(window->GetExtantDocument()); - SendFocusOrBlurEvent(NS_BLUR_CONTENT, presShell, doc, doc, 1); + if (doc) + SendFocusOrBlurEvent(NS_BLUR_CONTENT, presShell, doc, doc, 1); if (mFocusedWindow == nsnull) SendFocusOrBlurEvent(NS_BLUR_CONTENT, presShell, doc, window, 1); @@ -1418,6 +1420,8 @@ nsFocusManager::Focus(nsPIDOMWindow* aWindow, // Keep a reference to the presShell since dispatching the DOM event may // cause the document to be destroyed. nsCOMPtr docShell = aWindow->GetDocShell(); + if (!docShell) + return; nsCOMPtr presShell; docShell->GetPresShell(getter_AddRefs(presShell)); @@ -1481,8 +1485,9 @@ nsFocusManager::Focus(nsPIDOMWindow* aWindow, // document and then the window. if (aIsNewDocument) { nsCOMPtr doc = do_QueryInterface(aWindow->GetExtantDocument()); - SendFocusOrBlurEvent(NS_FOCUS_CONTENT, presShell, doc, - doc, aFlags & FOCUSMETHOD_MASK); + if (doc) + SendFocusOrBlurEvent(NS_FOCUS_CONTENT, presShell, doc, + doc, aFlags & FOCUSMETHOD_MASK); if (mFocusedWindow == aWindow && mFocusedContent == nsnull) SendFocusOrBlurEvent(NS_FOCUS_CONTENT, presShell, doc, aWindow, aFlags & FOCUSMETHOD_MASK); @@ -1572,7 +1577,7 @@ nsFocusManager::SendFocusOrBlurEvent(PRUint32 aType, // for focus events, if this event was from a mouse or key and event // handling on the document is suppressed, queue the event and fire it // later. For blur events, a non-zero value would be set for aFocusMethod. - if (aFocusMethod && aDocument->EventHandlingSuppressed()) { + if (aFocusMethod && aDocument && aDocument->EventHandlingSuppressed()) { for (PRUint32 i = mDelayedBlurFocusEvents.Length(); i > 0; --i) { // if this event was already queued, remove it and append it to the end if (mDelayedBlurFocusEvents[i - 1].mType == aType && diff --git a/dom/tests/mochitest/general/Makefile.in b/dom/tests/mochitest/general/Makefile.in index dd6cb3f29945..7d0d44fb02c9 100644 --- a/dom/tests/mochitest/general/Makefile.in +++ b/dom/tests/mochitest/general/Makefile.in @@ -49,6 +49,8 @@ _TEST_FILES = test_offsets.html \ test_offsets.js \ test_domWindowUtils.html \ test_domWindowUtils_scrollXY.html \ + test_497898.html \ + 497633.html \ $(NULL) libs:: $(_TEST_FILES)