Skip to content

Commit

Permalink
Make requestFullscreen() consume user activation
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=247920
rdar://102355401

Reviewed by Youenn Fablet.

Matches Chrome & Firefox implementations, we should reset the activation timestamps when requesting fullscreen.
This disallows double non-user initiated requestFullscreen calls.

Spec PR: whatwg/fullscreen#153

WPT upstream revision: web-platform-tests/wpt@897b406

* LayoutTests/imported/w3c/web-platform-tests/fullscreen/api/element-request-fullscreen-consume-user-activation-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/fullscreen/api/element-request-fullscreen-consume-user-activation.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/fullscreen/api/element-request-fullscreen-same-element-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/fullscreen/api/element-request-fullscreen-same-element.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/fullscreen/api/w3c-import.log:
* LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/fullscreen/api/element-request-fullscreen-same-element-expected.txt: Added.
* Source/WebCore/dom/FullscreenManager.cpp:
(WebCore::FullscreenManager::requestFullscreenForElement):

Canonical link: https://commits.webkit.org/257554@main
  • Loading branch information
nt1m committed Dec 8, 2022
1 parent 710c43c commit 823024a
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

PASS Element#requestFullscreen() consumes user activation

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<title>Element#requestFullscreen() consumes user activation</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<div id="log"></div>
<script>
promise_test(async (t) => {
t.add_cleanup(() => {
if (document.fullscreenElement) return document.exitFullscreen();
});
const div = document.querySelector("div");

await test_driver.bless("fullscreen");
assert_true(navigator.userActivation.isActive, "Activation must be active");
// Request fullscreen twice in a row. The first request should consume the
// user activation and succeed, and the second request should fail because
// of the user activation requirement.
const p1 = div.requestFullscreen();
assert_false(navigator.userActivation.isActive, "Transient activation is consumed");
const p2 = promise_rejects_js(t, TypeError, div.requestFullscreen());
await Promise.all([p1, p2]);
});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

PASS Element#requestFullscreen() on the current fullscreen element

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<title>Element#requestFullscreen() on the current fullscreen element</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<div id="log"></div>
<script>
promise_test(async (t) => {
t.add_cleanup(() => {
if (document.fullscreenElement) return document.exitFullscreen();
});

// Use the body element as the fullscreen element, because the second
// test_driver.bless() call needs to insert a button inside of it, which
// can't be clicked if another element is already fullscreen.
const target = document.body;

// First enter fullscreen.
await test_driver.bless("fullscreen", () => target.requestFullscreen());
assert_equals(document.fullscreenElement, target, "fullscreen element after first request");

// Now request fullscreen again, which should be a no-op.
await test_driver.bless("fullscreen", () => target.requestFullscreen());
assert_equals(document.fullscreenElement, target, "fullscreen element after second request");
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ List of files:
/LayoutTests/imported/w3c/web-platform-tests/fullscreen/api/document-fullscreen-enabled.html
/LayoutTests/imported/w3c/web-platform-tests/fullscreen/api/document-onfullscreenerror.html
/LayoutTests/imported/w3c/web-platform-tests/fullscreen/api/element-request-fullscreen-active-document.html
/LayoutTests/imported/w3c/web-platform-tests/fullscreen/api/element-request-fullscreen-consume-user-activation.html
/LayoutTests/imported/w3c/web-platform-tests/fullscreen/api/element-request-fullscreen-dialog.html
/LayoutTests/imported/w3c/web-platform-tests/fullscreen/api/element-request-fullscreen-not-allowed.html
/LayoutTests/imported/w3c/web-platform-tests/fullscreen/api/element-request-fullscreen-options.html
/LayoutTests/imported/w3c/web-platform-tests/fullscreen/api/element-request-fullscreen-options.tentative.html
/LayoutTests/imported/w3c/web-platform-tests/fullscreen/api/element-request-fullscreen-same-element.html
/LayoutTests/imported/w3c/web-platform-tests/fullscreen/api/element-request-fullscreen.html
/LayoutTests/imported/w3c/web-platform-tests/fullscreen/api/fullscreen-display-contents-expected.html
/LayoutTests/imported/w3c/web-platform-tests/fullscreen/api/fullscreen-display-contents-ref.html
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

FAIL Element#requestFullscreen() on the current fullscreen element assert_equals: fullscreen element after first request expected Element node <body><div id="log"></div>
<script>
promise_test(async (t... but got null

2 changes: 1 addition & 1 deletion Source/WebCore/dom/FullscreenManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void FullscreenManager::requestFullscreenForElement(Ref<Element>&& element, RefP
return;
}

if (!document().domWindow() || !document().domWindow()->hasTransientActivation()) {
if (!document().domWindow() || !document().domWindow()->consumeTransientActivation()) {
ERROR_LOG(LOGIDENTIFIER, "!hasTransientActivation; failing.");
failedPreflights(WTFMove(element), WTFMove(promise));
return;
Expand Down

0 comments on commit 823024a

Please sign in to comment.