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
authorjst@mozilla.org
Thu, 17 Apr 2008 15:22:44 -0700
changeset 14436 dabf1468a101807c8e732fa25a38356edd5843b0
parent 14435 fa2f9d66bdc4379c7a5957c153702eec33975418
child 14437 88f8ba037468cf1855fb11c9164016822762521c
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbeltzner
bugs428847
milestone1.9pre
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
content/base/test/Makefile.in
content/base/test/file_bug428847-1.xhtml
content/base/test/file_bug428847-2.xhtml
content/base/test/test_bug428847.html
content/xml/document/src/nsXMLContentSink.cpp
--- 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,