From 0d9cbd7ca3823fd4b8425f6abcad9f3f48ecf6f9 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Tue, 18 Jul 2006 00:18:19 +0000 Subject: [PATCH] Go back to creating an inconsistent DOM and add a null-check elsewhere, because the little mind of the focus code is blown by having no documentElement, apparently. Bug 341730, r+sr=sicking git-svn-id: svn://10.0.0.236/trunk@202270 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/src/nsDocument.cpp | 20 +++++------ .../html/document/src/nsHTMLDocument.cpp | 36 ++++++++++--------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index ec40fba0e88..cf11e154ad6 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -4837,17 +4837,15 @@ nsDocument::Destroy() mIsGoingAway = PR_TRUE; DestroyLinkMap(); for (PRInt32 indx = 0; indx < count; ++indx) { - nsIContent* content = mChildren.ChildAt(indx); - if (content == mRootContent) { - // Null out mRootContent first; this is similar to what RemoveChildAt() - // does. - mRootContent = nsnull; - } - - // XXXbz what about document observer notifications? We really need to get - // rid of this Destroy() method! - - content->UnbindFromTree(); + // XXXbz what we _should_ do here is to clear mChildren and null out + // mRootContent. If we did this (or at least the latter), we could remove + // the silly null-checks in nsHTMLDocument::MatchLinks. Unfortunately, + // doing that introduces several problems: + // 1) Focus issues (see bug 341730). The fix for bug 303260 may fix these. + // 2) Crashes in OnPageHide if it fires after Destroy. See bug 303260 + // comments 9 and 10. + // So we're just creating an inconsistent DOM for now and hoping. :( + mChildren.ChildAt(indx)->UnbindFromTree(); } // Propagate the out-of-band notification to each PresShell's anonymous diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index 37cedd44da9..82a51093162 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -1768,26 +1768,30 @@ PRBool nsHTMLDocument::MatchLinks(nsIContent *aContent, PRInt32 aNamespaceID, nsIAtom* aAtom, const nsAString& aData) { - NS_ASSERTION(aContent->IsInDoc(), - "This method should never be called on content nodes that " - "are not in a document!"); + nsIDocument* doc = aContent->GetCurrentDoc(); + + if (doc) { + NS_ASSERTION(aContent->IsInDoc(), + "This method should never be called on content nodes that " + "are not in a document!"); #ifdef DEBUG - { - nsCOMPtr htmldoc = - do_QueryInterface(aContent->GetCurrentDoc()); - NS_ASSERTION(htmldoc, - "Huh, how did this happen? This should only be used with " - "HTML documents!"); - } + { + nsCOMPtr htmldoc = + do_QueryInterface(aContent->GetCurrentDoc()); + NS_ASSERTION(htmldoc, + "Huh, how did this happen? This should only be used with " + "HTML documents!"); + } #endif - nsINodeInfo *ni = aContent->NodeInfo(); - PRInt32 namespaceID = aContent->GetCurrentDoc()->GetDefaultNamespaceID(); + nsINodeInfo *ni = aContent->NodeInfo(); + PRInt32 namespaceID = doc->GetDefaultNamespaceID(); - nsIAtom *localName = ni->NameAtom(); - if (ni->NamespaceID() == namespaceID && - (localName == nsHTMLAtoms::a || localName == nsHTMLAtoms::area)) { - return aContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::href); + nsIAtom *localName = ni->NameAtom(); + if (ni->NamespaceID() == namespaceID && + (localName == nsHTMLAtoms::a || localName == nsHTMLAtoms::area)) { + return aContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::href); + } } return PR_FALSE;