Bug 797909, null principal for initial about:blank, r=bz
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Fri, 05 Oct 2012 02:01:34 +0300
changeset 115543 fd724f194a1f65540289872d7c97765623f81bc0
parent 115542 58f3ccaa02b89bf3436a5af454cd214c1f3707ba
child 115544 a119cc1cdf0a728990df7c17dcba3e1ca28ae45d
push id1708
push userakeybl@mozilla.com
push dateMon, 19 Nov 2012 21:10:21 +0000
treeherdermozilla-beta@27b14fe50103 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs797909
milestone18.0a1
first release with
nightly linux32
fd724f194a1f / 18.0a1 / 20121005030609 / files
nightly linux64
fd724f194a1f / 18.0a1 / 20121005030609 / files
nightly mac
fd724f194a1f / 18.0a1 / 20121005030609 / files
nightly win32
fd724f194a1f / 18.0a1 / 20121005030609 / files
nightly win64
fd724f194a1f / 18.0a1 / 20121005030609 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 797909, null principal for initial about:blank, r=bz
docshell/base/nsDocShell.cpp
docshell/test/Makefile.in
docshell/test/test_bug797909.html
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -6772,18 +6772,24 @@ nsDocShell::CreateAboutBlankContentViewe
   // unloads... but that's ok, more or less.  Would be nice if it fired load
   // too, of course.
   mFiredUnloadEvent = false;
 
   nsCOMPtr<nsIDocumentLoaderFactory> docFactory =
       nsContentUtils::FindInternalContentViewer("text/html");
 
   if (docFactory) {
+    nsCOMPtr<nsIPrincipal> principal;
+    if (mSandboxFlags & SANDBOXED_ORIGIN) {
+      principal = do_CreateInstance("@mozilla.org/nullprincipal;1");
+    } else {
+      principal = aPrincipal;
+    }
     // generate (about:blank) document to load
-    docFactory->CreateBlankDocument(mLoadGroup, aPrincipal,
+    docFactory->CreateBlankDocument(mLoadGroup, principal,
                                     getter_AddRefs(blankDoc));
     if (blankDoc) {
       // Hack: set the base URI manually, since this document never
       // got Reset() with a channel.
       blankDoc->SetBaseURI(aBaseURI);
 
       blankDoc->SetContainer(static_cast<nsIDocShell *>(this));
 
--- a/docshell/test/Makefile.in
+++ b/docshell/test/Makefile.in
@@ -95,16 +95,17 @@ MOCHITEST_FILES = \
 		test_bug691547.html \
 		bug691547_frame.html \
 		test_bug694612.html \
 		test_bug703855.html \
 		file_bug703855.html \
 		test_bug713825.html \
 		test_bug728939.html \
 		file_bug728939.html \
+		test_bug797909.html \
 		$(NULL)
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
 MOCHITEST_FILES += \
 		test_bug511449.html \
 		file_bug511449.html \
 		$(NULL)
 endif
new file mode 100644
--- /dev/null
+++ b/docshell/test/test_bug797909.html
@@ -0,0 +1,66 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=797909
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 797909</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body onload="runTest()">
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=797909">Mozilla Bug 797909</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+  
+</div>
+<pre id="test">
+<script type="application/javascript">
+  /** Test for Bug 797909 **/
+
+  SimpleTest.waitForExplicitFinish();
+
+  function runTest() {
+    iframe = document.getElementById("ifr");
+    try {
+      var iframeDoc = iframe.contentWindow.document;
+      ok(false, "Should have thrown an exception");
+    } catch (ex) {
+      ok(true, "Got an exception");
+    }
+
+    iframe = document.createElement("iframe");
+    // set sandbox attribute
+    iframe.sandbox = "allow-scripts";
+    // and then insert into the doc
+    document.body.appendChild(iframe);
+
+    try {
+      var iframeDoc = iframe.contentWindow.document;
+      ok(false, "Should have thrown an exception");
+    } catch (ex) {
+      ok(true, "Got an exception");
+    }
+
+    iframe = document.createElement("iframe");
+    // set sandbox attribute
+    iframe.sandbox = "allow-same-origin";
+    // and then insert into the doc
+    document.body.appendChild(iframe);
+
+    try {
+      var iframeDoc = iframe.contentWindow.document;
+      ok(true, "Shouldn't have thrown an exception");
+    } catch (ex) {
+      ok(false, "Got an unexpected exception");
+    }
+
+    SimpleTest.finish();
+  }
+
+</script>
+</pre>
+<iframe id="ifr" sandbox = "allow-scripts"></iframe>
+</body>
+</html>