Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
window.open from an iframe doesn't exit fullscreen for parent document
https://bugs.webkit.org/show_bug.cgi?id=255813
rdar://108387151

Reviewed by Tim Nguyen.

Currently, invoking `window.open` from an `iframe` that has a parent document
is fullscreen does not exit fullscreen, while invoking `window.open` from
the main frame does.

On macOS, the user is taken to a new tab, which is made visible, while the
fullscreen content remains in its own space. On iOS, the user is taken to a new
tab, but the existing content remains in fullscreen, leaving the user unaware
of what has happened.

WebKit's existing behavior in this scenario on macOS differs from both Chrome
and Firefox, which completely exit fullscreen regardless of which frame invoked
`window.open`. Additionally, the iOS behavior is confusing, as the user will
suddenly viewing another page after they decide to exit fullscreen.

To fix, ensure any successful call to `window.open` always exits fullscreen.

* LayoutTests/fullscreen/enter-fullscreen-main-frame-window-open-iframe-expected.txt: Added.
* LayoutTests/fullscreen/enter-fullscreen-main-frame-window-open-iframe.html: Added.
* LayoutTests/fullscreen/resources/window-open-iframe.html: Added.
* LayoutTests/platform/mac-wk1/TestExpectations:

Skip test on WK1, similar to another "exit fullscreen from iframe" test.

* Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::createWindow):

Call `FullscreenManager::cancelFullscreen` unconditionally, rather than checking
if the frame's document has a fullscreen element, which would be false if the
fullscreen element is in another document.

`cancelFullscreen` already accounts for the top document, and is a no-op if there
is no fullscreen element in any document.

Canonical link: https://commits.webkit.org/263284@main
  • Loading branch information
pxlcoder committed Apr 22, 2023
1 parent 7684dab commit 0aa6c90
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
@@ -0,0 +1,8 @@
To test manually, click the "Open window" button - the page should exit fullscreen mode.

EVENT(fullscreenchange)
TEST(document.fullscreenElement===document.body) OK
EVENT(fullscreenchange)
TEST(document.fullscreenElement===null) OK
END OF TEST

@@ -0,0 +1,20 @@
<p>To test manually, click the "Open window" button - the page should exit fullscreen mode.</p>
<script src="full-screen-test.js"></script>
<script>
function runTest() {
waitForEventOnce(document, 'fullscreenchange', function() {
test("document.fullscreenElement===document.body")
waitForEventOnce(document, 'fullscreenchange', function() {
test("document.fullscreenElement===null")
endTest();
});
document.getElementById("frame").contentWindow.exitFullscreen();
});

runWithKeyDown(function() {
document.body.requestFullscreen();
});
}
</script>
<iframe id="frame" src="resources/window-open-iframe.html" width="300" height="100" onload="runTest()">
</iframe>
11 changes: 11 additions & 0 deletions LayoutTests/fullscreen/resources/window-open-iframe.html
@@ -0,0 +1,11 @@
<script>
window.exitFullscreen = function(args) {
if (!window.internals)
return;

internals.withUserGesture(function() {
window.open('about:blank');
});
}
</script>
<button onclick="window.open('about:blank')">Open window</button>
2 changes: 2 additions & 0 deletions LayoutTests/platform/mac-wk1/TestExpectations
Expand Up @@ -1002,6 +1002,8 @@ webkit.org/b/112533 media/auto-play-in-sandbox-with-allow-scripts.html [ Pass Ti

webkit.org/b/139778 fullscreen/exit-full-screen-iframe.html [ Skip ]

webkit.org/b/139778 fullscreen/enter-fullscreen-main-frame-window-open-iframe.html [ Skip ]

webkit.org/b/139862 editing/spelling/grammar-edit-word.html [ Skip ]

webkit.org/b/144127 compositing/scrolling/touch-scroll-to-clip.html [ Pass Failure ]
Expand Down
4 changes: 2 additions & 2 deletions Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp
Expand Up @@ -309,8 +309,8 @@ OptionSet<WebEventModifier> modifiersForNavigationAction(const NavigationAction&
Page* WebChromeClient::createWindow(LocalFrame& frame, const WindowFeatures& windowFeatures, const NavigationAction& navigationAction)
{
#if ENABLE(FULLSCREEN_API)
if (frame.document() && frame.document()->fullscreenManager().currentFullscreenElement())
frame.document()->fullscreenManager().cancelFullscreen();
if (auto* document = frame.document())
document->fullscreenManager().cancelFullscreen();
#endif

auto& webProcess = WebProcess::singleton();
Expand Down

0 comments on commit 0aa6c90

Please sign in to comment.