Bug 1279613 - Apply fullscreen enabled flag to about:blank as well. r?smaug
MozReview-Commit-ID: JL3ZIdXpLiX
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -3808,16 +3808,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;
@@ -8021,19 +8028,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;
@@ -894,16 +895,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>