From 13333e839ef914aa5350981c38ca01d92f01678d Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 3 Dec 2008 12:19:47 -0500 Subject: [PATCH] Backed out changeset d351bde7a804 --- content/html/document/src/nsHTMLDocument.cpp | 35 ++++++++++++-------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index 30809e5eeb3..a12283586ac 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -1818,24 +1818,33 @@ nsHTMLDocument::OpenCommon(const nsACString& aContentType, PRBool aReplace) // (since if it's secure, then it's presumeably trusted). nsCOMPtr callerDoc = do_QueryInterface(nsContentUtils::GetDocumentFromContext()); - if (!callerDoc) { - // If we're called from C++ or in some other way without an originating - // document we can't do a document.open w/o changing the principal of the - // document to something like about:blank (as that's the only sane thing to - // do when we don't know the origin of this call), and since we can't - // change the principals of a document for security reasons we'll have to + + // Grab a reference to the calling documents security info (if any) + // and URIs as they may be lost in the call to Reset(). + nsCOMPtr securityInfo; + nsCOMPtr uri, baseURI; + if (callerDoc) { + securityInfo = callerDoc->GetSecurityInfo(); + uri = callerDoc->GetDocumentURI(); + baseURI = callerDoc->GetBaseURI(); + } + + nsCOMPtr callerPrincipal; + nsIScriptSecurityManager *secMan = nsContentUtils::GetSecurityManager(); + + secMan->GetSubjectPrincipal(getter_AddRefs(callerPrincipal)); + + if (!callerPrincipal) { + // If we're called from C++ we can't do a document.open w/o + // changing the principal of the document to something like + // about:blank (as that's the only sane thing to do when we don't + // know the origin of this call), and since we can't change the + // principals of a document for security reasons we'll have to // refuse to go ahead with this call. return NS_ERROR_DOM_SECURITY_ERR; } - // Grab a reference to the calling documents security info (if any) - // and URIs as they may be lost in the call to Reset(). - nsCOMPtr securityInfo = callerDoc->GetSecurityInfo();; - nsCOMPtr uri = callerDoc->GetDocumentURI(); - nsCOMPtr baseURI = callerDoc->GetBaseURI(); - nsCOMPtr callerPrincipal = callerDoc->NodePrincipal(); - // We're called from script. Make sure the script is from the same // origin, not just that the caller can access the document. This is // needed to keep document principals from ever changing, which is