Skip to content

Commit

Permalink
fix: webview exiting fullscreen presentation mode (#39660)
Browse files Browse the repository at this point in the history
Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
  • Loading branch information
trop[bot] and codebytere committed Aug 28, 2023
1 parent e1465f6 commit 5707be5
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 24 deletions.
1 change: 0 additions & 1 deletion patches/chromium/.patches
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ make_gtk_getlibgtk_public.patch
build_disable_print_content_analysis.patch
custom_protocols_plzserviceworker.patch
feat_filter_out_non-shareable_windows_in_the_current_application_in.patch
fix_allow_guest_webcontents_to_enter_fullscreen.patch
disable_freezing_flags_after_init_in_node.patch
short-circuit_permissions_checks_in_mediastreamdevicescontroller.patch
chore_add_electron_deps_to_gitignores.patch
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ index 1e9dcbb9f0a5e401a50d63be490755bc3eeaa1a3..1e2e0a321df6fe9dea4401ed327c9373
// RenderFrameMetadataProvider::Observer implementation.
void OnRenderFrameMetadataChangedBeforeActivation(
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 36cd52f18c83adc007d6f896a4136a93f0fa1c83..99f6e45fe48449c2dbe88514648a4d907999e282 100644
index 61d985829d54e2f98351f39d1b58e5702f10fa79..6ee703fc50459901068c364a3a0ccd3a60ce28bb 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -8319,7 +8319,7 @@ void WebContentsImpl::OnFocusedElementChangedInFrame(
@@ -8323,7 +8323,7 @@ void WebContentsImpl::OnFocusedElementChangedInFrame(
"WebContentsImpl::OnFocusedElementChangedInFrame",
"render_frame_host", frame);
RenderWidgetHostViewBase* root_view =
Expand Down
67 changes: 66 additions & 1 deletion patches/chromium/webview_fullscreen.patch
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ the parent frame should also enter fullscreen mode too. Chromium handles
this for iframes, but not for webviews as they are essentially main
frames instead of child frames.

This patch makes webviews propagate the fullscreen state to embedder.
This patch makes webviews propagate the fullscreen state to embedder.It also handles a
DCHECK preventing guest webcontents from becoming the focused webContents.

Note that we also need to manually update embedder's
`api::WebContents::IsFullscreenForTabOrPending` value.
Expand All @@ -35,3 +36,67 @@ index 01eb116b51037bff5da7a87d119b78387f5e72c6..7ab5609215ce352b2595b4953e1b9ca0
// Focus the window if another frame may have delegated the capability.
if (had_fullscreen_token && !GetView()->HasFocus())
GetView()->Focus();
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 8d5a0e6aa6ea3a0965ed6abb76368d1f8e3ea91e..61d985829d54e2f98351f39d1b58e5702f10fa79 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -3569,21 +3569,25 @@ KeyboardEventProcessingResult WebContentsImpl::PreHandleKeyboardEvent(
const NativeWebKeyboardEvent& event) {
OPTIONAL_TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("content.verbose"),
"WebContentsImpl::PreHandleKeyboardEvent");
- auto* outermost_contents = GetOutermostWebContents();
- // TODO(wjmaclean): Generalize this to forward all key events to the outermost
- // delegate's handler.
- if (outermost_contents != this && IsFullscreen() &&
- event.windows_key_code == ui::VKEY_ESCAPE) {
- // When an inner WebContents has focus and is fullscreen, redirect <esc>
- // key events to the outermost WebContents so it can be handled by that
- // WebContents' delegate.
- if (outermost_contents->PreHandleKeyboardEvent(event) ==
- KeyboardEventProcessingResult::HANDLED) {
+
+ auto handled = delegate_ ? delegate_->PreHandleKeyboardEvent(this, event)
+ : KeyboardEventProcessingResult::NOT_HANDLED;
+
+ if (IsFullscreen() && event.windows_key_code == ui::VKEY_ESCAPE) {
+ if (handled == KeyboardEventProcessingResult::HANDLED)
return KeyboardEventProcessingResult::HANDLED;
+
+ // When an inner WebContents has focus and is fullscreen, traverse through
+ // containing webcontents to any that may handle the escape key.
+ while (auto* outer_web_contents = GetOuterWebContents()) {
+ auto result = outer_web_contents->PreHandleKeyboardEvent(event);
+ if (result == KeyboardEventProcessingResult::HANDLED) {
+ return KeyboardEventProcessingResult::HANDLED;
+ }
}
}
- return delegate_ ? delegate_->PreHandleKeyboardEvent(this, event)
- : KeyboardEventProcessingResult::NOT_HANDLED;
+
+ return handled;
}

bool WebContentsImpl::HandleMouseEvent(const blink::WebMouseEvent& event) {
@@ -3715,7 +3719,7 @@ void WebContentsImpl::EnterFullscreenMode(
OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::EnterFullscreenMode");
DCHECK(CanEnterFullscreenMode(requesting_frame, options));
DCHECK(requesting_frame->IsActive());
- DCHECK(ContainsOrIsFocusedWebContents());
+ DCHECK(ContainsOrIsFocusedWebContents() || IsGuest());

// When WebView is the `delegate_` we can end up with VisualProperties changes
// synchronously. Notify the view ahead so it can handle the transition.
diff --git a/third_party/blink/renderer/core/fullscreen/fullscreen.cc b/third_party/blink/renderer/core/fullscreen/fullscreen.cc
index f58ade7ed652ea0d97c123dc78715c049cb5e500..6619207f2f8731a7d8e88d6c1613e77ca4abc558 100644
--- a/third_party/blink/renderer/core/fullscreen/fullscreen.cc
+++ b/third_party/blink/renderer/core/fullscreen/fullscreen.cc
@@ -99,7 +99,7 @@ void FullscreenElementChanged(Document& document,
// is the iframe element for the out-of-process frame that contains the
// fullscreen element. Hence, it must match :-webkit-full-screen-ancestor.
if (new_request_type & FullscreenRequestType::kForCrossProcessDescendant) {
- DCHECK(IsA<HTMLIFrameElement>(new_element));
+ // DCHECK(IsA<HTMLIFrameElement>(new_element));
new_element->SetContainsFullScreenElement(true);
}
new_element->SetContainsFullScreenElementOnAncestorsCrossingFrameBoundaries(

0 comments on commit 5707be5

Please sign in to comment.