Bug 812744 part 1. Set XSLT result documents to be data documents when we plan to return them to script. r=sicking

This commit is contained in:
Boris Zbarsky 2012-11-21 11:18:57 -05:00
parent a9ed661f6f
commit 52e3d77eed
9 changed files with 42 additions and 22 deletions

View File

@ -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);

View File

@ -172,7 +172,7 @@ RemoveFromAgentSheets(nsCOMArray<nsIStyleSheet> &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;
}

View File

@ -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;
}

View File

@ -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<nsIDocument> source = do_QueryInterface(aSourceDocument);
NS_ENSURE_STATE(source);

View File

@ -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);

View File

@ -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

View File

@ -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();

View File

@ -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<nsIDOMDocument> mSourceDocument;
nsCOMPtr<nsITransformObserver> 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<txMozillaTextOutput> 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<txMozillaTextOutput> 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<txXPathNode> 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);

View File

@ -96,7 +96,8 @@ public:
return mSource;
}
nsresult TransformToDoc(nsIDOMDocument **aResult);
nsresult TransformToDoc(nsIDOMDocument **aResult,
bool aCreateDataDocument);
bool IsLoadDisabled()
{