From c4edc9c24e01161468c00df31be65df9b84b3d94 Mon Sep 17 00:00:00 2001 From: "peterv%propagandism.org" Date: Wed, 2 Nov 2005 07:43:02 +0000 Subject: [PATCH] Fix for bug 27382 (ownerDocument of orphan text and attr nodes is null). Patch by sicking, updated by peterv, r=bz, sr=peterv. --- content/xslt/src/base/txURIUtils.cpp | 14 +---------- .../src/xpath/txMozillaXPathTreeWalker.cpp | 24 +++++++------------ content/xslt/src/xpath/txXPathTreeWalker.h | 8 +++---- .../src/xslt/txMozillaStylesheetCompiler.cpp | 2 +- 4 files changed, 13 insertions(+), 35 deletions(-) diff --git a/content/xslt/src/base/txURIUtils.cpp b/content/xslt/src/base/txURIUtils.cpp index f1856f1998c..83342470a4f 100644 --- a/content/xslt/src/base/txURIUtils.cpp +++ b/content/xslt/src/base/txURIUtils.cpp @@ -275,19 +275,7 @@ PRBool URIUtils::CanCallerAccess(nsIDOMNode *aNode) nsCOMPtr domDoc; aNode->GetOwnerDocument(getter_AddRefs(domDoc)); if (!domDoc) { - nsINodeInfo *ni; - if (content) { - ni = content->GetNodeInfo(); - } - else { - ni = attr->NodeInfo(); - } - - if (!ni) { - // aNode is not part of a document, let any caller access it. - - return PR_TRUE; - } + nsINodeInfo *ni = content ? content->NodeInfo() : attr->NodeInfo(); principal = ni->GetDocumentPrincipal(); if (!principal) { diff --git a/content/xslt/src/xpath/txMozillaXPathTreeWalker.cpp b/content/xslt/src/xpath/txMozillaXPathTreeWalker.cpp index a6908434d01..3b8d3a9e2ac 100644 --- a/content/xslt/src/xpath/txMozillaXPathTreeWalker.cpp +++ b/content/xslt/src/xpath/txMozillaXPathTreeWalker.cpp @@ -403,8 +403,8 @@ txXPathNodeUtils::getLocalName(const txXPathNode& aNode, nsAString& aLocalName) } if (aNode.isContent()) { - nsINodeInfo* nodeInfo = aNode.mContent->GetNodeInfo(); - if (nodeInfo) { + if (aNode.mContent->IsContentOfType(nsIContent::eELEMENT)) { + nsINodeInfo* nodeInfo = aNode.mContent->NodeInfo(); nodeInfo->GetLocalName(aLocalName); // Check for html @@ -437,7 +437,7 @@ txXPathNodeUtils::getLocalName(const txXPathNode& aNode, nsAString& aLocalName) localName->ToString(aLocalName); // Check for html - if (aNode.mContent->GetNodeInfo()->NamespaceEquals(kNameSpaceID_None) && + if (aNode.mContent->NodeInfo()->NamespaceEquals(kNameSpaceID_None) && aNode.mContent->IsContentOfType(nsIContent::eHTML)) { ToUpperCase(aLocalName); } @@ -454,8 +454,8 @@ txXPathNodeUtils::getNodeName(const txXPathNode& aNode, nsAString& aName) } if (aNode.isContent()) { - nsINodeInfo* nodeInfo = aNode.mContent->GetNodeInfo(); - if (nodeInfo) { + if (aNode.mContent->IsContentOfType(nsIContent::eELEMENT)) { + nsINodeInfo* nodeInfo = aNode.mContent->NodeInfo(); nodeInfo->GetQualifiedName(aName); // Check for html @@ -500,7 +500,7 @@ txXPathNodeUtils::getNodeName(const txXPathNode& aNode, nsAString& aName) AppendUTF8toUTF16(attrName, aName); // Check for html - if (aNode.mContent->GetNodeInfo()->NamespaceEquals(kNameSpaceID_None) && + if (aNode.mContent->NodeInfo()->NamespaceEquals(kNameSpaceID_None) && aNode.mContent->IsContentOfType(nsIContent::eHTML)) { ToUpperCase(aName); } @@ -515,9 +515,7 @@ txXPathNodeUtils::getNamespaceID(const txXPathNode& aNode) } if (aNode.isContent()) { - nsINodeInfo* ni = aNode.mContent->GetNodeInfo(); - - return ni ? ni->NamespaceID() : kNameSpaceID_None; + return aNode.mContent->GetNameSpaceID(); } nsCOMPtr name, prefix; @@ -656,13 +654,7 @@ txXPathNodeUtils::getOwnerDocument(const txXPathNode& aNode) return new txXPathNode(aNode); } - nsIDocument* document = aNode.mContent->GetDocument(); - if (!document) { - nsINodeInfo* ni = aNode.mContent->GetNodeInfo(); - if (ni) { - document = ni->GetDocument(); - } - } + nsIDocument* document = aNode.mContent->GetOwnerDoc(); return document ? new txXPathNode(document) : nsnull; } diff --git a/content/xslt/src/xpath/txXPathTreeWalker.h b/content/xslt/src/xpath/txXPathTreeWalker.h index e86146c43b1..63c8e4d24cf 100644 --- a/content/xslt/src/xpath/txXPathTreeWalker.h +++ b/content/xslt/src/xpath/txXPathTreeWalker.h @@ -263,11 +263,9 @@ txXPathNodeUtils::localNameEquals(const txXPathNode& aNode, return localName == aLocalName; #else - if (aNode.isContent()) { - nsINodeInfo *ni = aNode.mContent->GetNodeInfo(); - if (ni) { - return ni->Equals(aLocalName); - } + if (aNode.isContent() && + aNode.mContent->IsContentOfType(nsIContent::eELEMENT)) { + return aNode.mContent->NodeInfo()->Equals(aLocalName); } nsCOMPtr localName = txXPathNodeUtils::getLocalName(aNode); diff --git a/content/xslt/src/xslt/txMozillaStylesheetCompiler.cpp b/content/xslt/src/xslt/txMozillaStylesheetCompiler.cpp index 960ebfd661c..8b931cabe4c 100644 --- a/content/xslt/src/xslt/txMozillaStylesheetCompiler.cpp +++ b/content/xslt/src/xslt/txMozillaStylesheetCompiler.cpp @@ -635,7 +635,7 @@ handleNode(nsIDOMNode* aNode, txStylesheetCompiler* aCompiler) } } - nsINodeInfo *ni = element->GetNodeInfo(); + nsINodeInfo *ni = element->NodeInfo(); rv = aCompiler->startElement(ni->NamespaceID(), ni->NameAtom(),