Fixing
bug 428847. Don't show an error page if an XML file references an XSLT stylesheet it doesn't have permission to load. r+sr=jonas@sicking.cc, a=beltzner
--- a/content/base/test/Makefile.in
+++ b/content/base/test/Makefile.in
@@ -166,17 +166,20 @@ include $(topsrcdir)/config/rules.mk
test_bug429157.html \
test_XHR.html \
file_XHR_pass1.xml \
file_XHR_pass2.txt \
file_XHR_pass3.txt \
file_XHR_pass3.txt^headers^ \
file_XHR_fail1.txt \
file_XHR_fail1.txt^headers^ \
- $(NULL)
+ test_bug428847.html \
+ file_bug428847-1.xhtml \
+ file_bug428847-2.xhtml \
+ $(NULL)
libs:: $(_TEST_FILES)
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
check::
@$(EXIT_ON_ERROR) \
for f in $(subst .cpp,,$(CPP_UNIT_TESTS)); do \
XPCOM_DEBUG_BREAK=stack-and-abort $(RUN_TEST_PROGRAM) $(DIST)/bin/$$f; \
new file mode 100644
--- /dev/null
+++ b/content/base/test/file_bug428847-1.xhtml
@@ -0,0 +1,4 @@
+<?xml-stylesheet type="text/xsl" href="http://www.mozilla.com/whatever.xsl"?>
+<html xmlns="http://www.w3.org/1999/xhtml">
+<body id='body' onload="if (document.getElementById('body')) parent.iframe1Loaded = true;"/>
+</html>
new file mode 100644
--- /dev/null
+++ b/content/base/test/file_bug428847-2.xhtml
@@ -0,0 +1,4 @@
+<?xml-stylesheet type="text/xsl" href=":"?>
+<html xmlns="http://www.w3.org/1999/xhtml">
+<body id='body' onload="if (document.getElementById('body')) parent.iframeLoaded = true;"/>
+</html>
new file mode 100644
--- /dev/null
+++ b/content/base/test/test_bug428847.html
@@ -0,0 +1,34 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=428847
+-->
+<head>
+ <title>Test for Bug 428847</title>
+ <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body onload="runtests();">
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=428847">Mozilla Bug 428847</a>
+<script class="testbody" type="text/javascript">
+var iframe1Loaded = false;
+var iframe2Loaded = false;
+
+function runtests()
+{
+ is(iframe1Loaded, true,
+ "Iframe with cross-origin xslt stylesheet failed to load");
+ is(iframe2Loaded, false,
+ "Iframe with invalid xslt stylesheet URI didn't fail to load");
+
+ SimpleTest.finish();
+}
+
+SimpleTest.waitForExplicitFinish();
+</script>
+<iframe src="file_bug428847-1.xhtml">
+<iframe src="file_bug428847-2.xhtml">
+</body>
+</html>
+
--- a/content/xml/document/src/nsXMLContentSink.cpp
+++ b/content/xml/document/src/nsXMLContentSink.cpp
@@ -699,33 +699,40 @@ nsXMLContentSink::AddContentAsLeaf(nsICo
return result;
}
// Create an XML parser and an XSL content sink and start parsing
// the XSL stylesheet located at the given URI.
nsresult
nsXMLContentSink::LoadXSLStyleSheet(nsIURI* aUrl)
{
- mXSLTProcessor =
+ nsCOMPtr<nsIDocumentTransformer> processor =
do_CreateInstance("@mozilla.org/document-transformer;1?type=xslt");
- if (!mXSLTProcessor) {
+ if (!processor) {
// No XSLT processor available, continue normal document loading
return NS_OK;
}
- mXSLTProcessor->Init(mDocument->NodePrincipal());
- mXSLTProcessor->SetTransformObserver(this);
+ processor->Init(mDocument->NodePrincipal());
+ processor->SetTransformObserver(this);
nsCOMPtr<nsILoadGroup> loadGroup = mDocument->GetDocumentLoadGroup();
if (!loadGroup) {
- mXSLTProcessor = nsnull;
return NS_ERROR_FAILURE;
}
- return mXSLTProcessor->LoadStyleSheet(aUrl, loadGroup);
+ if (NS_SUCCEEDED(processor->LoadStyleSheet(aUrl, loadGroup))) {
+ mXSLTProcessor.swap(processor);
+ }
+
+ // Intentionally ignore errors here, we should continue loading the
+ // XML document whether we're able to load the XSLT stylesheet or
+ // not.
+
+ return NS_OK;
}
nsresult
nsXMLContentSink::ProcessStyleLink(nsIContent* aElement,
const nsSubstring& aHref,
PRBool aAlternate,
const nsSubstring& aTitle,
const nsSubstring& aType,