bug 209539, 209089, crash on several ways when linking to a non-existing XSLT stylesheet, r=sicking, sr=peterv

This commit is contained in:
axel%pike.org 2005-11-02 07:40:49 +00:00
Родитель c0f7dd27f1
Коммит 97e4f4396e
4 изменённых файлов: 51 добавлений и 43 удалений

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

@ -291,4 +291,44 @@ PRBool URIUtils::CanCallerAccess(nsIDOMNode *aNode)
return NS_SUCCEEDED(rv);
}
// static
void
URIUtils::ResetWithSource(nsIDocument *aNewDoc, nsIDOMNode *aSourceNode)
{
if (!aSourceNode) {
aNewDoc->Reset(nsnull, nsnull);
return;
}
nsCOMPtr<nsIDocument> sourceDoc = do_QueryInterface(aSourceNode);
if (!sourceDoc) {
nsCOMPtr<nsIDOMDocument> sourceDOMDocument;
aSourceNode->GetOwnerDocument(getter_AddRefs(sourceDOMDocument));
sourceDoc = do_QueryInterface(sourceDOMDocument);
}
if (!sourceDoc) {
NS_ASSERTION(0, "no source document found");
aNewDoc->Reset(nsnull, nsnull);
return;
}
nsCOMPtr<nsILoadGroup> loadGroup;
nsCOMPtr<nsIChannel> channel;
sourceDoc->GetDocumentLoadGroup(getter_AddRefs(loadGroup));
nsCOMPtr<nsIIOService> serv = do_GetService(NS_IOSERVICE_CONTRACTID);
if (serv) {
// Create a temporary channel to get nsIDocument->Reset to
// do the right thing. We want the output document to get
// much of the input document's characteristics.
nsCOMPtr<nsIURI> docURL;
sourceDoc->GetDocumentURL(getter_AddRefs(docURL));
serv->NewChannelFromURI(docURL, getter_AddRefs(channel));
}
aNewDoc->Reset(channel, loadGroup);
nsCOMPtr<nsIURI> baseURL;
sourceDoc->GetBaseURL(getter_AddRefs(baseURL));
aNewDoc->SetBaseURL(baseURL);
}
#endif /* TX_EXE */

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

@ -44,6 +44,7 @@
#else
#include "nsIDOMNode.h"
class nsIDocument;
class nsIScriptSecurityManager;
extern nsIScriptSecurityManager *gTxSecurityManager;
@ -93,6 +94,11 @@ public:
*/
static PRBool CanCallerAccess(nsIDOMNode *aNode);
/**
* Reset the given document with the document of the source node
*/
static void ResetWithSource(nsIDocument *aNewDoc, nsIDOMNode *aSourceNode);
#endif /* TX_EXE */
/**

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

@ -66,6 +66,7 @@
#include "nsINameSpaceManager.h"
#include "nsICSSStyleSheet.h"
#include "txStringUtils.h"
#include "txUriUtils.h"
#include "nsIHTMLDocument.h"
#include "nsIStyleSheetLinkingElement.h"
#include "nsIDocumentTransformer.h"
@ -721,23 +722,7 @@ txMozillaXMLOutput::createResultDocument(const nsAString& aName, PRInt32 aNsID,
mCurrentNode = mDocument;
// Reset and set up the document
nsCOMPtr<nsILoadGroup> loadGroup;
nsCOMPtr<nsIChannel> channel;
nsCOMPtr<nsIDocument> sourceDoc = do_QueryInterface(aSourceDocument);
sourceDoc->GetDocumentLoadGroup(getter_AddRefs(loadGroup));
nsCOMPtr<nsIIOService> serv = do_GetService(NS_IOSERVICE_CONTRACTID);
if (serv) {
// Create a temporary channel to get nsIDocument->Reset to
// do the right thing. We want the output document to get
// much of the input document's characteristics.
nsCOMPtr<nsIURI> docURL;
sourceDoc->GetDocumentURL(getter_AddRefs(docURL));
serv->NewChannelFromURI(docURL, getter_AddRefs(channel));
}
doc->Reset(channel, loadGroup);
nsCOMPtr<nsIURI> baseURL;
sourceDoc->GetBaseURL(getter_AddRefs(baseURL));
doc->SetBaseURL(baseURL);
URIUtils::ResetWithSource(doc, aSourceDocument);
// Set the mime-type
if (!mOutputFormat.mMediaType.IsEmpty()) {

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

@ -327,13 +327,13 @@ txMozillaXSLTProcessor::SetTransformObserver(nsITransformObserver* aObserver)
nsresult
txMozillaXSLTProcessor::SetSourceContentModel(nsIDOMNode* aSourceDOM)
{
mSource = aSourceDOM;
if (NS_FAILED(mTransformResult)) {
notifyError();
return NS_OK;
}
mSource = aSourceDOM;
if (mStylesheet) {
return DoTransform();
}
@ -736,35 +736,12 @@ txMozillaXSLTProcessor::notifyError()
return;
}
nsCOMPtr<nsIDOMDocument> sourceDOMDocument;
mSource->GetOwnerDocument(getter_AddRefs(sourceDOMDocument));
if (!sourceDOMDocument) {
sourceDOMDocument = do_QueryInterface(mSource);
}
nsCOMPtr<nsIDocument> sourceDoc = do_QueryInterface(sourceDOMDocument);
// Set up the document
nsCOMPtr<nsIDocument> document = do_QueryInterface(errorDocument);
if (!document) {
return;
}
nsCOMPtr<nsILoadGroup> loadGroup;
nsCOMPtr<nsIChannel> channel;
sourceDoc->GetDocumentLoadGroup(getter_AddRefs(loadGroup));
nsCOMPtr<nsIIOService> serv = do_GetService(NS_IOSERVICE_CONTRACTID);
if (serv) {
// Create a temporary channel to get nsIDocument->Reset to
// do the right thing. We want the output document to get
// much of the input document's characteristics.
nsCOMPtr<nsIURI> docURL;
sourceDoc->GetDocumentURL(getter_AddRefs(docURL));
serv->NewChannelFromURI(docURL, getter_AddRefs(channel));
}
document->Reset(channel, loadGroup);
nsCOMPtr<nsIURI> baseURL;
sourceDoc->GetBaseURL(getter_AddRefs(baseURL));
document->SetBaseURL(baseURL);
URIUtils::ResetWithSource(document, mSource);
NS_NAMED_LITERAL_STRING(ns, "http://www.mozilla.org/newlayout/xml/parsererror.xml");