fix: {exit|enter}-html-fullscreen emitted after esc in webview (#30537)
This commit is contained in:
parent
7cdd132d18
commit
a9a90fa1b6
3 changed files with 43 additions and 9 deletions
|
@ -1239,31 +1239,29 @@ void WebContents::OnEnterFullscreenModeForTab(
|
||||||
content::RenderFrameHost* requesting_frame,
|
content::RenderFrameHost* requesting_frame,
|
||||||
const blink::mojom::FullscreenOptions& options,
|
const blink::mojom::FullscreenOptions& options,
|
||||||
bool allowed) {
|
bool allowed) {
|
||||||
if (!allowed)
|
if (!allowed || !owner_window_)
|
||||||
return;
|
|
||||||
if (!owner_window_)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto* source = content::WebContents::FromRenderFrameHost(requesting_frame);
|
auto* source = content::WebContents::FromRenderFrameHost(requesting_frame);
|
||||||
if (IsFullscreenForTabOrPending(source)) {
|
if (IsFullscreenForTabOrPending(source)) {
|
||||||
DCHECK_EQ(fullscreen_frame_, source->GetFocusedFrame());
|
DCHECK_EQ(fullscreen_frame_, source->GetFocusedFrame());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetHtmlApiFullscreen(true);
|
SetHtmlApiFullscreen(true);
|
||||||
owner_window_->NotifyWindowEnterHtmlFullScreen();
|
|
||||||
|
|
||||||
if (native_fullscreen_) {
|
if (native_fullscreen_) {
|
||||||
// Explicitly trigger a view resize, as the size is not actually changing if
|
// Explicitly trigger a view resize, as the size is not actually changing if
|
||||||
// the browser is fullscreened, too.
|
// the browser is fullscreened, too.
|
||||||
source->GetRenderViewHost()->GetWidget()->SynchronizeVisualProperties();
|
source->GetRenderViewHost()->GetWidget()->SynchronizeVisualProperties();
|
||||||
}
|
}
|
||||||
Emit("enter-html-full-screen");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::ExitFullscreenModeForTab(content::WebContents* source) {
|
void WebContents::ExitFullscreenModeForTab(content::WebContents* source) {
|
||||||
if (!owner_window_)
|
if (!owner_window_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SetHtmlApiFullscreen(false);
|
SetHtmlApiFullscreen(false);
|
||||||
owner_window_->NotifyWindowLeaveHtmlFullScreen();
|
|
||||||
|
|
||||||
if (native_fullscreen_) {
|
if (native_fullscreen_) {
|
||||||
// Explicitly trigger a view resize, as the size is not actually changing if
|
// Explicitly trigger a view resize, as the size is not actually changing if
|
||||||
|
@ -1271,7 +1269,6 @@ void WebContents::ExitFullscreenModeForTab(content::WebContents* source) {
|
||||||
// `chrome/browser/ui/exclusive_access/fullscreen_controller.cc`.
|
// `chrome/browser/ui/exclusive_access/fullscreen_controller.cc`.
|
||||||
source->GetRenderViewHost()->GetWidget()->SynchronizeVisualProperties();
|
source->GetRenderViewHost()->GetWidget()->SynchronizeVisualProperties();
|
||||||
}
|
}
|
||||||
Emit("leave-html-full-screen");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::RendererUnresponsive(
|
void WebContents::RendererUnresponsive(
|
||||||
|
@ -3564,7 +3561,7 @@ void WebContents::SetHtmlApiFullscreen(bool enter_fullscreen) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::UpdateHtmlApiFullscreen(bool fullscreen) {
|
void WebContents::UpdateHtmlApiFullscreen(bool fullscreen) {
|
||||||
if (fullscreen == html_fullscreen_)
|
if (fullscreen == is_html_fullscreen())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
html_fullscreen_ = fullscreen;
|
html_fullscreen_ = fullscreen;
|
||||||
|
@ -3575,11 +3572,19 @@ void WebContents::UpdateHtmlApiFullscreen(bool fullscreen) {
|
||||||
->GetWidget()
|
->GetWidget()
|
||||||
->SynchronizeVisualProperties();
|
->SynchronizeVisualProperties();
|
||||||
|
|
||||||
// The embedder WebContents is spearated from the frame tree of webview, so
|
// The embedder WebContents is separated from the frame tree of webview, so
|
||||||
// we must manually sync their fullscreen states.
|
// we must manually sync their fullscreen states.
|
||||||
if (embedder_)
|
if (embedder_)
|
||||||
embedder_->SetHtmlApiFullscreen(fullscreen);
|
embedder_->SetHtmlApiFullscreen(fullscreen);
|
||||||
|
|
||||||
|
if (fullscreen) {
|
||||||
|
Emit("enter-html-full-screen");
|
||||||
|
owner_window_->NotifyWindowEnterHtmlFullScreen();
|
||||||
|
} else {
|
||||||
|
Emit("leave-html-full-screen");
|
||||||
|
owner_window_->NotifyWindowLeaveHtmlFullScreen();
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure all child webviews quit html fullscreen.
|
// Make sure all child webviews quit html fullscreen.
|
||||||
if (!fullscreen && !IsGuest()) {
|
if (!fullscreen && !IsGuest()) {
|
||||||
auto* manager = WebViewManager::GetWebViewManager(web_contents());
|
auto* manager = WebViewManager::GetWebViewManager(web_contents());
|
||||||
|
|
|
@ -456,6 +456,34 @@ describe('<webview> tag', function () {
|
||||||
await delay(0);
|
await delay(0);
|
||||||
expect(w.isFullScreen()).to.be.false();
|
expect(w.isFullScreen()).to.be.false();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('pressing ESC should emit the leave-html-full-screen event', async () => {
|
||||||
|
const w = new BrowserWindow({
|
||||||
|
show: false,
|
||||||
|
webPreferences: {
|
||||||
|
webviewTag: true,
|
||||||
|
nodeIntegration: true,
|
||||||
|
contextIsolation: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const didAttachWebview = emittedOnce(w.webContents, 'did-attach-webview');
|
||||||
|
w.loadFile(path.join(fixtures, 'pages', 'webview-did-attach-event.html'));
|
||||||
|
|
||||||
|
const [, webContents] = await didAttachWebview;
|
||||||
|
|
||||||
|
const enterFSWindow = emittedOnce(w, 'enter-html-full-screen');
|
||||||
|
const enterFSWebview = emittedOnce(webContents, 'enter-html-full-screen');
|
||||||
|
await webContents.executeJavaScript('document.getElementById("div").requestFullscreen()', true);
|
||||||
|
await enterFSWindow;
|
||||||
|
await enterFSWebview;
|
||||||
|
|
||||||
|
const leaveFSWindow = emittedOnce(w, 'leave-html-full-screen');
|
||||||
|
const leaveFSWebview = emittedOnce(webContents, 'leave-html-full-screen');
|
||||||
|
webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Escape' });
|
||||||
|
await leaveFSWindow;
|
||||||
|
await leaveFSWebview;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('nativeWindowOpen option', () => {
|
describe('nativeWindowOpen option', () => {
|
||||||
|
|
1
spec/fixtures/pages/a.html
vendored
1
spec/fixtures/pages/a.html
vendored
|
@ -3,6 +3,7 @@
|
||||||
<link rel="icon" type="image/png" href="http://test.com/favicon.png"/>
|
<link rel="icon" type="image/png" href="http://test.com/favicon.png"/>
|
||||||
<meta http-equiv="content-security-policy" content="script-src 'self' 'unsafe-inline'" />
|
<meta http-equiv="content-security-policy" content="script-src 'self' 'unsafe-inline'" />
|
||||||
<body>
|
<body>
|
||||||
|
<div id="div">Hello World</div>
|
||||||
<script type="text/javascript" charset="utf-8">
|
<script type="text/javascript" charset="utf-8">
|
||||||
console.log('a');
|
console.log('a');
|
||||||
document.title = "test"
|
document.title = "test"
|
||||||
|
|
Loading…
Reference in a new issue