diff --git a/content/xslt/src/base/txURIUtils.cpp b/content/xslt/src/base/txURIUtils.cpp index 57730eda1df4..c3198634fb50 100644 --- a/content/xslt/src/base/txURIUtils.cpp +++ b/content/xslt/src/base/txURIUtils.cpp @@ -207,6 +207,7 @@ void URIUtils::ResetWithSource(nsIDocument *aNewDoc, nsIDOMNode *aSourceNode) { if (!aSourceNode) { + // XXXbz passing nsnull as the first arg to Reset is illegal aNewDoc->Reset(nsnull, nsnull); return; } @@ -219,13 +220,31 @@ URIUtils::ResetWithSource(nsIDocument *aNewDoc, nsIDOMNode *aSourceNode) } if (!sourceDoc) { NS_ASSERTION(0, "no source document found"); + // XXXbz passing nsnull as the first arg to Reset is illegal aNewDoc->Reset(nsnull, nsnull); return; } + nsIPrincipal* sourcePrincipal = sourceDoc->GetPrincipal(); + if (!sourcePrincipal) { + return; + } + // Copy the channel and loadgroup from the source document. nsCOMPtr loadGroup = sourceDoc->GetDocumentLoadGroup(); - aNewDoc->Reset(sourceDoc->GetChannel(), loadGroup); + nsCOMPtr channel = sourceDoc->GetChannel(); + if (!channel) { + // Need to synthesize one + if (NS_FAILED(NS_NewChannel(getter_AddRefs(channel), + sourceDoc->GetDocumentURI(), + nsnull, + loadGroup))) { + return; + } + channel->SetOwner(sourcePrincipal); + } + aNewDoc->Reset(channel, loadGroup); + aNewDoc->SetPrincipal(sourcePrincipal); aNewDoc->SetBaseURI(sourceDoc->GetBaseURI()); // Copy charset diff --git a/content/xslt/src/xslt/txMozillaTextOutput.cpp b/content/xslt/src/xslt/txMozillaTextOutput.cpp index e7b9ed164b8d..e40eff2f9901 100644 --- a/content/xslt/src/xslt/txMozillaTextOutput.cpp +++ b/content/xslt/src/xslt/txMozillaTextOutput.cpp @@ -50,6 +50,7 @@ #include "nsIDOMNSDocument.h" #include "nsIParser.h" #include "nsICharsetAlias.h" +#include "nsIPrincipal.h" static NS_DEFINE_CID(kXMLDocumentCID, NS_XMLDOCUMENT_CID); @@ -173,9 +174,26 @@ void txMozillaTextOutput::createResultDocument(nsIDOMDocument* aSourceDocument, // Reset and set up document nsCOMPtr sourceDoc = do_QueryInterface(aSourceDocument); + nsIPrincipal* sourcePrincipal = sourceDoc->GetPrincipal(); + if (!sourcePrincipal) { + return; + } + nsCOMPtr loadGroup = sourceDoc->GetDocumentLoadGroup(); + nsCOMPtr channel = sourceDoc->GetChannel(); + if (!channel) { + // Need to synthesize one + if (NS_FAILED(NS_NewChannel(getter_AddRefs(channel), + sourceDoc->GetDocumentURI(), + nsnull, + loadGroup))) { + return; + } + channel->SetOwner(sourcePrincipal); + } // Copy the channel and loadgroup from the source document. - doc->Reset(sourceDoc->GetChannel(), loadGroup); + doc->Reset(channel, loadGroup); + doc->SetPrincipal(sourcePrincipal); doc->SetBaseURI(sourceDoc->GetBaseURI()); // Set the charset