Bug 1270648 part 4 - Make fullscreen enabled flag not be affected after document is loaded. r=smaug

MozReview-Commit-ID: L2dMAUr63qv

--HG--
extra : source : 363d7ac04cbf98fa67cad3214ac62330c2652fa8
This commit is contained in:
Xidorn Quan 2016-05-18 09:08:12 +10:00
Родитель 2baf1f45c4
Коммит 51e715f73c
8 изменённых файлов: 94 добавлений и 8 удалений

Просмотреть файл

@ -2521,6 +2521,10 @@ nsDocShell::GetFullscreenAllowed(bool* aFullscreenAllowed)
nsGkAtoms::mozallowfullscreen)) {
return NS_OK;
}
nsIDocument* doc = frameElement->GetUncomposedDoc();
if (!doc || !doc->FullscreenEnabledInternal()) {
return NS_OK;
}
}
// If we have no parent then we're the root docshell; no ancestor of the

Просмотреть файл

@ -596,8 +596,10 @@ ImportLoader::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext)
nsCOMPtr<nsIDocument> master = mImportParent->MasterDocument();
mDocument->SetMasterDocument(master);
// We want to inherit the sandbox flags from the master document.
// We want to inherit the sandbox flags and fullscreen enabled flag
// from the master document.
mDocument->SetSandboxFlags(master->GetSandboxFlags());
mDocument->SetFullscreenEnabled(master->FullscreenEnabledInternal());
// We have to connect the blank document we created with the channel we opened,
// and create its own LoadGroup for it.

Просмотреть файл

@ -1452,6 +1452,7 @@ nsIDocument::nsIDocument()
mFontFaceSetDirty(true),
mGetUserFontSetCalled(false),
mPostedFlushUserFontSet(false),
mFullscreenEnabled(false),
mPartID(0),
mDidFireDOMContentLoaded(true),
mHasScrollLinkedEffect(false),
@ -2579,13 +2580,15 @@ nsDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
}
// If this document is being loaded by a docshell, copy its sandbox flags
// to the document. These are immutable after being set here.
// 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);
WarnIfSandboxIneffective(docShell, mSandboxFlags, GetChannel());
mFullscreenEnabled = docShell->GetFullscreenAllowed();
}
// The CSP directive upgrade-insecure-requests not only applies to the
@ -11768,14 +11771,9 @@ GetFullscreenError(nsIDocument* aDoc, bool aCallerIsChrome)
if (!nsContentUtils::IsFullScreenApiEnabled()) {
return "FullscreenDeniedDisabled";
}
// Ensure that all containing elements are <iframe> and have
// allowfullscreen attribute set.
nsCOMPtr<nsIDocShell> docShell(aDoc->GetDocShell());
if (!docShell || !docShell->GetFullscreenAllowed()) {
if (!aDoc->FullscreenEnabledInternal()) {
return "FullscreenDeniedContainerNotAllowed";
}
return nullptr;
}

Просмотреть файл

@ -2572,6 +2572,11 @@ public:
return !!GetFullscreenElement();
}
void ExitFullscreen();
bool FullscreenEnabledInternal() const { return mFullscreenEnabled; }
void SetFullscreenEnabled(bool aEnabled)
{
mFullscreenEnabled = aEnabled;
}
Element* GetMozPointerLockElement();
void MozExitPointerLock()
{
@ -3031,6 +3036,10 @@ protected:
// Do we currently have an event posted to call FlushUserFontSet?
bool mPostedFlushUserFontSet : 1;
// Whether fullscreen is enabled for this document. This corresponds
// to the "fullscreen enabled flag" in the HTML spec.
bool mFullscreenEnabled : 1;
enum Type {
eUnknown, // should never be used
eHTML,

Просмотреть файл

@ -382,6 +382,7 @@ XULDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
mStillWalking = true;
mMayStartLayout = false;
mDocumentLoadGroup = do_GetWeakReference(aLoadGroup);
mFullscreenEnabled = true;
mChannel = aChannel;

Просмотреть файл

@ -35955,6 +35955,12 @@
"url": "/html/browsers/browsing-the-web/navigating-across-documents/javascript-url-return-value-handling.html"
}
],
"html/semantics/embedded-content/the-iframe-element/iframe-allowfullscreen.html": [
{
"path": "html/semantics/embedded-content/the-iframe-element/iframe-allowfullscreen.html",
"url": "/html/semantics/embedded-content/the-iframe-element/iframe-allowfullscreen.html"
}
],
"html/semantics/embedded-content/the-iframe-element/iframe_sandbox_popups_escaping.html": [
{
"path": "html/semantics/embedded-content/the-iframe-element/iframe_sandbox_popups_escaping.html",

Просмотреть файл

@ -0,0 +1,3 @@
[iframe-allow-fullscreen.html.ini]
type: testharness
prefs: [full-screen-api.unprefix.enabled:true]

Просмотреть файл

@ -0,0 +1,63 @@
<!doctype html>
<meta charset=utf-8>
<title>Check how allowfullscreen affects fullscreen enabled flag</title>
<link rel="author" title="Xidorn Quan" href="https://www.upsuper.org">
<link rel="author" title="Mozilla" href="https://www.mozilla.org">
<link rel="help" href="https://html.spec.whatwg.org/multipage/browsers.html#initialise-the-document-object">
<link rel="help" href="https://fullscreen.spec.whatwg.org/#fullscreen-enabled-flag">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
async_test(function(t) {
var iframe = document.createElement("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);
});
assert_true(document.fullscreenEnabled, "Top level document has fullscreen enabled flag set");
eventWatcher.wait_for("load").then(t.step_func(function() {
assert_false(iframe.contentDocument.fullscreenEnabled, "Document inside iframe without allowfullscreen attribute should not have fullscreen enabled flag set");
iframe.setAttribute("allowfullscreen", true);
assert_false(iframe.contentDocument.fullscreenEnabled, "Setting allowfullscreen attribute after document load should not affect fullscreen enabled flag");
iframe.contentWindow.location.reload();
return eventWatcher.wait_for("load");
})).then(t.step_func(function() {
assert_true(iframe.contentDocument.fullscreenEnabled, "Fullscreen enabled flag should be set when a new document is loaded with allowfullscreen attribute present");
iframe.removeAttribute("allowfullscreen");
assert_true(iframe.contentDocument.fullscreenEnabled, "Removing allowfullscreen attribute should not affect fullscreen enabled flag");
iframe.contentWindow.location.reload();
return eventWatcher.wait_for("load");
})).then(t.step_func_done(function() {
assert_false(iframe.contentDocument.fullscreenEnabled, "Fullscreen enabled flag should be reset when a new document is loaded with allowfullscreen attribute absent");
}));
}, "iframe-allowfullscreen");
async_test(function(t) {
var iframe = document.createElement("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);
});
var newWin;
assert_true(document.fullscreenEnabled, "Top level document has fullscreen enabled flag set");
eventWatcher.wait_for("load").then(t.step_func(function() {
assert_false(iframe.contentDocument.fullscreenEnabled, "Document inside iframe without allowfullscreen attribute should not have fullscreen enabled flag set");
newWin = iframe.contentWindow.open("support/blank.htm");
t.add_cleanup(function() {
newWin.close();
});
var newWinEventWatcher = new EventWatcher(t, newWin, "load");
return newWinEventWatcher.wait_for("load");
})).then(t.step_func_done(function() {
assert_true(newWin.document.fullscreenEnabled, "Document in the new window is a top level document, thus should has fullscreen enabled flag set");
}));
}, "iframe-allowfullscreen-dialog");
</script>