From 52e3d77eede8794d1feba4835a069a7280ce2eff Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 21 Nov 2012 11:18:57 -0500 Subject: [PATCH] Bug 812744 part 1. Set XSLT result documents to be data documents when we plan to return them to script. r=sicking --- content/base/public/nsIDocument.h | 4 +-- content/html/document/src/nsHTMLDocument.cpp | 3 +- content/xml/document/src/nsXMLDocument.cpp | 3 +- content/xslt/src/xslt/txMozillaTextOutput.cpp | 6 ++-- content/xslt/src/xslt/txMozillaTextOutput.h | 3 +- content/xslt/src/xslt/txMozillaXMLOutput.cpp | 9 ++++-- content/xslt/src/xslt/txMozillaXMLOutput.h | 3 +- .../xslt/src/xslt/txMozillaXSLTProcessor.cpp | 30 ++++++++++++------- .../xslt/src/xslt/txMozillaXSLTProcessor.h | 3 +- 9 files changed, 42 insertions(+), 22 deletions(-) diff --git a/content/base/public/nsIDocument.h b/content/base/public/nsIDocument.h index 3fc21aeed2f..36595fa33c4 100644 --- a/content/base/public/nsIDocument.h +++ b/content/base/public/nsIDocument.h @@ -2060,10 +2060,10 @@ private: // XXX These belong somewhere else nsresult -NS_NewHTMLDocument(nsIDocument** aInstancePtrResult); +NS_NewHTMLDocument(nsIDocument** aInstancePtrResult, bool aLoadedAsData = false); nsresult -NS_NewXMLDocument(nsIDocument** aInstancePtrResult); +NS_NewXMLDocument(nsIDocument** aInstancePtrResult, bool aLoadedAsData = false); nsresult NS_NewSVGDocument(nsIDocument** aInstancePtrResult); diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index bd18f85888b..c758a6492ea 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -172,7 +172,7 @@ RemoveFromAgentSheets(nsCOMArray &aAgentSheets, const nsAString& } nsresult -NS_NewHTMLDocument(nsIDocument** aInstancePtrResult) +NS_NewHTMLDocument(nsIDocument** aInstancePtrResult, bool aLoadedAsData) { nsHTMLDocument* doc = new nsHTMLDocument(); NS_ENSURE_TRUE(doc, NS_ERROR_OUT_OF_MEMORY); @@ -185,6 +185,7 @@ NS_NewHTMLDocument(nsIDocument** aInstancePtrResult) } *aInstancePtrResult = doc; + doc->SetLoadedAsData(aLoadedAsData); return rv; } diff --git a/content/xml/document/src/nsXMLDocument.cpp b/content/xml/document/src/nsXMLDocument.cpp index 46ddf271a0c..e6c4625e65b 100644 --- a/content/xml/document/src/nsXMLDocument.cpp +++ b/content/xml/document/src/nsXMLDocument.cpp @@ -168,7 +168,7 @@ NS_NewDOMDocument(nsIDOMDocument** aInstancePtrResult, nsresult -NS_NewXMLDocument(nsIDocument** aInstancePtrResult) +NS_NewXMLDocument(nsIDocument** aInstancePtrResult, bool aLoadedAsData) { nsXMLDocument* doc = new nsXMLDocument(); NS_ENSURE_TRUE(doc, NS_ERROR_OUT_OF_MEMORY); @@ -181,6 +181,7 @@ NS_NewXMLDocument(nsIDocument** aInstancePtrResult) } *aInstancePtrResult = doc; + doc->SetLoadedAsData(aLoadedAsData); return rv; } diff --git a/content/xslt/src/xslt/txMozillaTextOutput.cpp b/content/xslt/src/xslt/txMozillaTextOutput.cpp index aadeb6d1af0..c2734c385e8 100644 --- a/content/xslt/src/xslt/txMozillaTextOutput.cpp +++ b/content/xslt/src/xslt/txMozillaTextOutput.cpp @@ -113,7 +113,8 @@ txMozillaTextOutput::startDocument() } nsresult -txMozillaTextOutput::createResultDocument(nsIDOMDocument* aSourceDocument) +txMozillaTextOutput::createResultDocument(nsIDOMDocument* aSourceDocument, + bool aLoadedAsData) { /* * Create an XHTML document to hold the text. @@ -132,7 +133,8 @@ txMozillaTextOutput::createResultDocument(nsIDOMDocument* aSourceDocument) */ // Create the document - nsresult rv = NS_NewXMLDocument(getter_AddRefs(mDocument)); + nsresult rv = NS_NewXMLDocument(getter_AddRefs(mDocument), + aLoadedAsData); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr source = do_QueryInterface(aSourceDocument); NS_ENSURE_STATE(source); diff --git a/content/xslt/src/xslt/txMozillaTextOutput.h b/content/xslt/src/xslt/txMozillaTextOutput.h index 6c2aa8c51ff..a893a748725 100644 --- a/content/xslt/src/xslt/txMozillaTextOutput.h +++ b/content/xslt/src/xslt/txMozillaTextOutput.h @@ -28,7 +28,8 @@ public: TX_DECL_TXAXMLEVENTHANDLER TX_DECL_TXAOUTPUTXMLEVENTHANDLER - nsresult createResultDocument(nsIDOMDocument* aSourceDocument); + nsresult createResultDocument(nsIDOMDocument* aSourceDocument, + bool aLoadedAsData); private: nsresult createXHTMLElement(nsIAtom* aName, nsIContent** aResult); diff --git a/content/xslt/src/xslt/txMozillaXMLOutput.cpp b/content/xslt/src/xslt/txMozillaXMLOutput.cpp index c4bda4f44e3..6acc2010d6c 100644 --- a/content/xslt/src/xslt/txMozillaXMLOutput.cpp +++ b/content/xslt/src/xslt/txMozillaXMLOutput.cpp @@ -791,19 +791,22 @@ void txMozillaXMLOutput::processHTTPEquiv(nsIAtom* aHeader, const nsString& aVal nsresult txMozillaXMLOutput::createResultDocument(const nsSubstring& aName, int32_t aNsID, - nsIDOMDocument* aSourceDocument) + nsIDOMDocument* aSourceDocument, + bool aLoadedAsData) { nsresult rv; // Create the document if (mOutputFormat.mMethod == eHTMLOutput) { - rv = NS_NewHTMLDocument(getter_AddRefs(mDocument)); + rv = NS_NewHTMLDocument(getter_AddRefs(mDocument), + aLoadedAsData); NS_ENSURE_SUCCESS(rv, rv); } else { // We should check the root name/namespace here and create the // appropriate document - rv = NS_NewXMLDocument(getter_AddRefs(mDocument)); + rv = NS_NewXMLDocument(getter_AddRefs(mDocument), + aLoadedAsData); NS_ENSURE_SUCCESS(rv, rv); } // This should really be handled by nsIDocument::BeginLoad diff --git a/content/xslt/src/xslt/txMozillaXMLOutput.h b/content/xslt/src/xslt/txMozillaXMLOutput.h index 09214aa8b5a..fb37da46957 100644 --- a/content/xslt/src/xslt/txMozillaXMLOutput.h +++ b/content/xslt/src/xslt/txMozillaXMLOutput.h @@ -74,7 +74,8 @@ public: nsresult closePrevious(bool aFlushText); nsresult createResultDocument(const nsSubstring& aName, int32_t aNsID, - nsIDOMDocument* aSourceDocument); + nsIDOMDocument* aSourceDocument, + bool aLoadedAsData); private: nsresult createTxWrapper(); diff --git a/content/xslt/src/xslt/txMozillaXSLTProcessor.cpp b/content/xslt/src/xslt/txMozillaXSLTProcessor.cpp index c15ab6f9bb7..64b352c5568 100644 --- a/content/xslt/src/xslt/txMozillaXSLTProcessor.cpp +++ b/content/xslt/src/xslt/txMozillaXSLTProcessor.cpp @@ -48,8 +48,10 @@ class txToDocHandlerFactory : public txAOutputHandlerFactory public: txToDocHandlerFactory(txExecutionState* aEs, nsIDOMDocument* aSourceDocument, - nsITransformObserver* aObserver) - : mEs(aEs), mSourceDocument(aSourceDocument), mObserver(aObserver) + nsITransformObserver* aObserver, + bool aDocumentIsData) + : mEs(aEs), mSourceDocument(aSourceDocument), mObserver(aObserver), + mDocumentIsData(aDocumentIsData) { } @@ -59,6 +61,7 @@ private: txExecutionState* mEs; nsCOMPtr mSourceDocument; nsCOMPtr mObserver; + bool mDocumentIsData; }; class txToFragmentHandlerFactory : public txAOutputHandlerFactory @@ -95,7 +98,8 @@ txToDocHandlerFactory::createHandlerWith(txOutputFormat* aFormat, nsresult rv = handler->createResultDocument(EmptyString(), kNameSpaceID_None, - mSourceDocument); + mSourceDocument, + mDocumentIsData); if (NS_SUCCEEDED(rv)) { *aHandler = handler.forget(); } @@ -108,7 +112,8 @@ txToDocHandlerFactory::createHandlerWith(txOutputFormat* aFormat, nsAutoPtr handler( new txMozillaTextOutput(mObserver)); - nsresult rv = handler->createResultDocument(mSourceDocument); + nsresult rv = handler->createResultDocument(mSourceDocument, + mDocumentIsData); if (NS_SUCCEEDED(rv)) { *aHandler = handler.forget(); } @@ -143,7 +148,8 @@ txToDocHandlerFactory::createHandlerWith(txOutputFormat* aFormat, new txMozillaXMLOutput(aFormat, mObserver)); nsresult rv = handler->createResultDocument(aName, aNsID, - mSourceDocument); + mSourceDocument, + mDocumentIsData); if (NS_SUCCEEDED(rv)) { *aHandler = handler.forget(); } @@ -156,7 +162,8 @@ txToDocHandlerFactory::createHandlerWith(txOutputFormat* aFormat, nsAutoPtr handler( new txMozillaTextOutput(mObserver)); - nsresult rv = handler->createResultDocument(mSourceDocument); + nsresult rv = handler->createResultDocument(mSourceDocument, + mDocumentIsData); if (NS_SUCCEEDED(rv)) { *aHandler = handler.forget(); } @@ -522,7 +529,7 @@ public: NS_IMETHOD Run() { - mProcessor->TransformToDoc(nullptr); + mProcessor->TransformToDoc(nullptr, false); return NS_OK; } }; @@ -612,11 +619,12 @@ txMozillaXSLTProcessor::TransformToDocument(nsIDOMNode *aSource, mSource = aSource; - return TransformToDoc(aResult); + return TransformToDoc(aResult, true); } nsresult -txMozillaXSLTProcessor::TransformToDoc(nsIDOMDocument **aResult) +txMozillaXSLTProcessor::TransformToDoc(nsIDOMDocument **aResult, + bool aCreateDataDocument) { nsAutoPtr sourceNode(txXPathNativeNode::createXPathNode(mSource)); if (!sourceNode) { @@ -633,7 +641,9 @@ txMozillaXSLTProcessor::TransformToDoc(nsIDOMDocument **aResult) // XXX Need to add error observers - txToDocHandlerFactory handlerFactory(&es, sourceDOMDocument, mObserver); + // If aResult is non-null, we're a data document + txToDocHandlerFactory handlerFactory(&es, sourceDOMDocument, mObserver, + aCreateDataDocument); es.mOutputHandlerFactory = &handlerFactory; nsresult rv = es.init(*sourceNode, &mVariables); diff --git a/content/xslt/src/xslt/txMozillaXSLTProcessor.h b/content/xslt/src/xslt/txMozillaXSLTProcessor.h index ff8d74e12b8..50a33e35529 100644 --- a/content/xslt/src/xslt/txMozillaXSLTProcessor.h +++ b/content/xslt/src/xslt/txMozillaXSLTProcessor.h @@ -96,7 +96,8 @@ public: return mSource; } - nsresult TransformToDoc(nsIDOMDocument **aResult); + nsresult TransformToDoc(nsIDOMDocument **aResult, + bool aCreateDataDocument); bool IsLoadDisabled() {