Bug 1279613 - Apply fullscreen enabled flag to about:blank as well. r=smaug, a=lizzard
authorXidorn Quan <me@upsuper.org>
Mon, 20 Jun 2016 07:16:00 +1000
changeset 341751 65053532049544c6f7fb161fedd6fea50864475d
parent 341750 dcc1086117447e34a1037967b5d80024a54593dc
child 341752 f20f82876561686c4f8a619a0e1baa9f58261e0f
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, lizzard
bugs1279613
milestone49.0a2
Bug 1279613 - Apply fullscreen enabled flag to about:blank as well. r=smaug, a=lizzard MozReview-Commit-ID: JL3ZIdXpLiX
docshell/base/nsDocShell.cpp
docshell/base/nsIDocShell.idl
dom/base/nsDocument.cpp
testing/web-platform/tests/html/semantics/embedded-content/the-iframe-element/iframe-allowfullscreen.html
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -3799,16 +3799,23 @@ nsDocShell::IsSandboxedFrom(nsIDocShell*
       return false;
     }
   }
 
   // Otherwise, we are sandboxed from aTargetDocShell.
   return true;
 }
 
+void
+nsDocShell::ApplySandboxAndFullscreenFlags(nsIDocument* aDoc)
+{
+  aDoc->SetSandboxFlags(mSandboxFlags);
+  aDoc->SetFullscreenEnabled(GetFullscreenAllowed());
+}
+
 NS_IMETHODIMP
 nsDocShell::GetTreeOwner(nsIDocShellTreeOwner** aTreeOwner)
 {
   NS_ENSURE_ARG_POINTER(aTreeOwner);
 
   *aTreeOwner = mTreeOwner;
   NS_IF_ADDREF(*aTreeOwner);
   return NS_OK;
@@ -8010,19 +8017,19 @@ nsDocShell::CreateAboutBlankContentViewe
                                     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(this);
 
-      // Copy our sandbox flags to the document. These are immutable
-      // after being set here.
-      blankDoc->SetSandboxFlags(mSandboxFlags);
+      // Apply the sandbox and fullscreen enabled flags to the document.
+      // These are immutable after being set here.
+      ApplySandboxAndFullscreenFlags(blankDoc);
 
       // create a content viewer for us and the new document
       docFactory->CreateInstanceForDocument(
         NS_ISUPPORTS_CAST(nsIDocShell*, this), blankDoc, "view",
         getter_AddRefs(viewer));
 
       // hook 'em up
       if (viewer) {
--- a/docshell/base/nsIDocShell.idl
+++ b/docshell/base/nsIDocShell.idl
@@ -20,16 +20,17 @@ class nsIPresShell;
 [ptr] native nsPresContext(nsPresContext);
 [ptr] native nsIPresShell(nsIPresShell);
 
 interface nsIURI;
 interface nsIChannel;
 interface nsIContentViewer;
 interface nsIDOMEventTarget;
 interface nsIDocShellLoadInfo;
+interface nsIDocument;
 interface nsIEditor;
 interface nsIEditingSession;
 interface nsISimpleEnumerator;
 interface nsIInputStream;
 interface nsIRequest;
 interface nsISHEntry;
 interface nsILayoutHistoryState;
 interface nsISecureBrowserUI;
@@ -896,16 +897,21 @@ interface nsIDocShell : nsIDocShellTreeI
 
   /**
    * Returns true if we are sandboxed from aTargetDocShell.
    * aTargetDocShell - the browsing context we are attempting to navigate.
    */
   [noscript,notxpcom,nostdcall] bool isSandboxedFrom(in nsIDocShell aTargetDocShell);
 
   /**
+   * Apply sandbox flags and fullscreen enabled flag to the given document.
+   */
+  [noscript,notxpcom] void applySandboxAndFullscreenFlags(in nsIDocument aDoc);
+
+  /**
    * This member variable determines whether a document has Mixed Active Content that
    * was initially blocked from loading, but the user has choosen to override the
    * block and allow the content to load. mMixedContentChannel is set to the document's
    * channel when the user allows mixed content. The nsMixedContentBlocker content policy
    * checks if the document's root channel matches the mMixedContentChannel.  If it matches,
    * then Mixed Content is loaded.  If it does match, mixed content is blocked.
    *
    * A match implies that there is definitely mixed active content on a page that was
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -2590,20 +2590,18 @@ nsDocument::StartDocumentLoad(const char
   }
 
   // If this document is being loaded by a docshell, copy its sandbox flags
   // to the document, and store the fullscreen enabled flag. These are
   // immutable after being set here.
   nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(aContainer);
 
   if (docShell) {
-    nsresult rv = docShell->GetSandboxFlags(&mSandboxFlags);
-    NS_ENSURE_SUCCESS(rv, rv);
+    docShell->ApplySandboxAndFullscreenFlags(this);
     WarnIfSandboxIneffective(docShell, mSandboxFlags, GetChannel());
-    mFullscreenEnabled = docShell->GetFullscreenAllowed();
   }
 
   // The CSP directive upgrade-insecure-requests not only applies to the
   // toplevel document, but also to nested documents. Let's propagate that
   // flag from the parent to the nested document.
   nsCOMPtr<nsIDocShellTreeItem> treeItem = this->GetDocShell();
   if (treeItem) {
     nsCOMPtr<nsIDocShellTreeItem> sameTypeParent;
--- a/testing/web-platform/tests/html/semantics/embedded-content/the-iframe-element/iframe-allowfullscreen.html
+++ b/testing/web-platform/tests/html/semantics/embedded-content/the-iframe-element/iframe-allowfullscreen.html
@@ -43,16 +43,18 @@
   }, "iframe-allowfullscreen");
 
   async_test(function(t) {
     test_allowfullscreen(t, function(iframe) {
       iframe.setAttribute("sandbox", "allow-same-origin");
     });
   }, "iframe-sandbox-allowfullscreen");
 
+  /* Fullscreen enabled flag with dialog */
+
   function test_allowfullscreen_dialog(t, setup_iframe, check) {
     var iframe = document.createElement("iframe");
     setup_iframe(iframe);
     iframe.src = "support/blank.htm";
     var eventWatcher = new EventWatcher(t, iframe, "load");
     document.body.appendChild(iframe);
     t.add_cleanup(function() {
       document.body.removeChild(iframe);
@@ -81,9 +83,33 @@
 
   async_test(function(t) {
     test_allowfullscreen_dialog(t, function(iframe) {
       iframe.setAttribute("sandbox", "allow-same-origin allow-popups");
     }, function(newWin) {
       assert_false(newWin.document.fullscreenEnabled, "Document in the new window should inherit the sandboxed fullscreen flag and should not have fullscreen enabled flag set");
     });
   }, "iframe-sandbox-allowfullscreen-dialog");
+
+  /* Fullscreen enabled flag with about:blank */
+
+  function test_allowfullscreen_noload(setup_iframe, check) {
+    var iframe = document.createElement("iframe");
+    setup_iframe(iframe);
+    document.body.appendChild(iframe);
+    check(iframe.contentDocument);
+    document.body.removeChild(iframe);
+  }
+
+  test(function() {
+    test_allowfullscreen_noload(function() {}, function(doc) {
+      assert_false(doc.fullscreenEnabled, "Fullscreen should not be enabled without allowfullscreen attribute");
+    });
+  }, "iframe-noload-noallowfullscreen");
+
+  test(function() {
+    test_allowfullscreen_noload(function(iframe) {
+      iframe.setAttribute("allowfullscreen", true);
+    }, function(doc) {
+      assert_true(doc.fullscreenEnabled, "Fullscreen should be enabled with allowfullscreen attribute");
+    });
+  }, "iframe-noload-allowfullscreen");
 </script>