Switch more callers who were begging for it over to GetOwnerDoc(). Bug 255337,

r+sr=peterv.
This commit is contained in:
bzbarsky%mit.edu 2004-10-11 16:29:42 +00:00
Родитель 3c30b395b0
Коммит 65033a43f8
7 изменённых файлов: 25 добавлений и 89 удалений

Просмотреть файл

@ -51,7 +51,7 @@
#include "nsIContentPolicy.h"
#include "nsIMemory.h"
#include "nsIServiceManager.h"
#include "nsIDOMDocument.h"
#include "nsIContent.h"
//XXXtw sadly, this makes consumers of nsContentPolicyUtils depend on widget
#include "nsIDocument.h"
@ -210,12 +210,9 @@ NS_CP_GetDocShellFromContext(nsISupports *aContext)
if (!doc) {
// we were not a document after all, get our ownerDocument,
// hopefully
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aContext);
if (node) {
nsCOMPtr<nsIDOMDocument> ownerDoc;
node->GetOwnerDocument(getter_AddRefs(ownerDoc));
// and turn it into an nsIDocument
doc = do_QueryInterface(ownerDoc);
nsCOMPtr<nsIContent> content = do_QueryInterface(aContext);
if (content) {
doc = content->GetOwnerDoc();
}
}

Просмотреть файл

@ -556,17 +556,7 @@ nsImageLoadingContent::GetOurDocument()
nsCOMPtr<nsIContent> thisContent = do_QueryInterface(this);
NS_ENSURE_TRUE(thisContent, nsnull);
nsIDocument* doc = thisContent->GetDocument();
if (!doc) { // nodeinfo time
// XXXbz GetOwnerDocument
nsINodeInfo *nodeInfo = thisContent->GetNodeInfo();
if (nodeInfo) {
doc = nsContentUtils::GetDocument(nodeInfo);
}
}
return doc;
return thisContent->GetOwnerDoc();
}
nsresult

Просмотреть файл

@ -1897,15 +1897,7 @@ nsEventListenerManager::DispatchEvent(nsIDOMEvent* aEvent, PRBool *_retval)
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIDocument> document = targetContent->GetDocument();
if (!document) {
// XXXbz GetOwnerDocument
nsINodeInfo *nodeInfo = targetContent->GetNodeInfo();
if (nodeInfo) {
document = nsContentUtils::GetDocument(nodeInfo);
}
}
nsCOMPtr<nsIDocument> document = targetContent->GetOwnerDoc();
// Do nothing if the element does not belong to a document
if (!document) {

Просмотреть файл

@ -4878,39 +4878,13 @@ nsNodeSH::PreCreate(nsISupports *nativeObj, JSContext *cx, JSObject *globalObj,
nsCOMPtr<nsIDocument> doc;
if (content) {
doc = content->GetDocument();
// If the content node doesn't have a document, it's either a node
// that's not yet in a document, or the node is part of a document
// that's being torn down. In the latter case it's important to
// *not* use globalObj as the nodes parent since that would give
// the node the principal of globalObj (i.e. the principal of the
// document that's being loaded) and not the principal of the
// document that's being unloaded. So when there's no document for
// the node, try to reach the original document through the node's
// nodeinfo, or through the nodeinfo for the node's parent (in
// case the node is a text node).
//
// Make sure that we get the owner document of the content node, in case
// we're in document teardown. If we are, it's important to *not* use
// globalObj as the nodes parent since that would give the node the
// principal of globalObj (i.e. the principal of the document that's being
// loaded) and not the principal of the document that's being unloaded.
// See http://bugzilla.mozilla.org/show_bug.cgi?id=227417
//
// XXX: nsIDOMNode::GetOwnerDocument() should do all of this for
// us, but it doesn't yet, so until it does, we'll need to do this
// by hand. http://bugzilla.mozilla.org/show_bug.cgi?id=227421
if (!doc) {
nsINodeInfo *ni = content->GetNodeInfo();
if (!ni) {
nsIContent *parent = content->GetParent();
if (parent) {
ni = parent->GetNodeInfo();
}
}
if (ni) {
doc = ni->GetDocument();
}
}
doc = content->GetOwnerDoc();
}
if (!doc) {

Просмотреть файл

@ -2573,13 +2573,10 @@ FindCanvasBackground(nsPresContext* aPresContext,
if (result->IsTransparent()) {
nsIContent* content = aForFrame->GetContent();
if (content) {
nsCOMPtr<nsIDOMNode> node( do_QueryInterface(content) );
// Use |GetOwnerDocument| so it works during destruction.
nsCOMPtr<nsIDOMDocument> doc;
node->GetOwnerDocument(getter_AddRefs(doc));
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(doc);
// Use |GetOwnerDoc| so it works during destruction.
nsIDocument* document = content->GetOwnerDoc();
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(document);
if (htmlDoc) {
nsCOMPtr<nsIDocument> document = do_QueryInterface(doc);
if (!document->IsCaseSensitive()) { // HTML, not XHTML
nsCOMPtr<nsIDOMHTMLElement> body;
htmlDoc->GetBody(getter_AddRefs(body));
@ -2643,14 +2640,11 @@ FindElementBackground(nsPresContext* aPresContext,
return PR_TRUE; // not frame for <BODY> element
// We should only look at the <html> background if we're in an HTML document
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(content));
nsCOMPtr<nsIDOMDocument> doc;
node->GetOwnerDocument(getter_AddRefs(doc));
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(do_QueryInterface(doc));
nsIDocument* document = content->GetOwnerDoc();
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(document);
if (!htmlDoc)
return PR_TRUE;
nsCOMPtr<nsIDocument> document(do_QueryInterface(doc));
if (document->IsCaseSensitive()) // XHTML, not HTML
return PR_TRUE;

Просмотреть файл

@ -2573,13 +2573,10 @@ FindCanvasBackground(nsPresContext* aPresContext,
if (result->IsTransparent()) {
nsIContent* content = aForFrame->GetContent();
if (content) {
nsCOMPtr<nsIDOMNode> node( do_QueryInterface(content) );
// Use |GetOwnerDocument| so it works during destruction.
nsCOMPtr<nsIDOMDocument> doc;
node->GetOwnerDocument(getter_AddRefs(doc));
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(doc);
// Use |GetOwnerDoc| so it works during destruction.
nsIDocument* document = content->GetOwnerDoc();
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(document);
if (htmlDoc) {
nsCOMPtr<nsIDocument> document = do_QueryInterface(doc);
if (!document->IsCaseSensitive()) { // HTML, not XHTML
nsCOMPtr<nsIDOMHTMLElement> body;
htmlDoc->GetBody(getter_AddRefs(body));
@ -2643,14 +2640,11 @@ FindElementBackground(nsPresContext* aPresContext,
return PR_TRUE; // not frame for <BODY> element
// We should only look at the <html> background if we're in an HTML document
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(content));
nsCOMPtr<nsIDOMDocument> doc;
node->GetOwnerDocument(getter_AddRefs(doc));
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(do_QueryInterface(doc));
nsIDocument* document = content->GetOwnerDoc();
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(document);
if (!htmlDoc)
return PR_TRUE;
nsCOMPtr<nsIDocument> document(do_QueryInterface(doc));
if (document->IsCaseSensitive()) // XHTML, not HTML
return PR_TRUE;

Просмотреть файл

@ -101,18 +101,13 @@
static void PR_CALLBACK
HandleImagePLEvent(nsIContent *aContent, PRUint32 aMessage, PRUint32 aFlags)
{
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(aContent));
if (!node) {
NS_ERROR("null or non-DOM node passed to HandleImagePLEvent!");
if (!aContent) {
NS_ERROR("null node passed to HandleImagePLEvent!");
return;
}
nsCOMPtr<nsIDOMDocument> dom_doc;
node->GetOwnerDocument(getter_AddRefs(dom_doc));
nsCOMPtr<nsIDocument> doc(do_QueryInterface(dom_doc));
nsIDocument* doc = aContent->GetOwnerDoc();
if (!doc) {
return;