Skip to content

Commit

Permalink
Remove dangling raw_ptr for WebContentsImpl::current_fullscreen_frame_.
Browse files Browse the repository at this point in the history
It may be possible for the referenced RenderFrameHost to be deleted
without clearing this member, so replace it with an ID instead. It turns
out this member was only needed for comparisons anyway, and looking up
the corresponding RenderFrameHost is never needed.

Bug: 1291138
Change-Id: I39edef6d9b3b8f42a712d7ae8a982ab48922e595
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4908280
Commit-Queue: Charlie Reis <creis@chromium.org>
Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1205560}
  • Loading branch information
creis authored and Chromium LUCI CQ committed Oct 4, 2023
1 parent 6b5b381 commit 207e93c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
2 changes: 1 addition & 1 deletion content/browser/display_cutout/display_cutout_host_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class DisplayCutoutHostImpl : public blink::mojom::DisplayCutoutHost {

// Stores the current |RenderFrameHost| that has the applied safe area insets
// and is controlling the viewport fit value. This value is different than
// `WebContentsImpl::current_fullscreen_frame_` because it also considers
// `WebContentsImpl::current_fullscreen_frame_id_` because it also considers
// browser side driven fullscreen mode, not just renderer side requested
// frames.
base::WeakPtr<RenderFrameHostImpl> current_rfh_;
Expand Down
9 changes: 5 additions & 4 deletions content/browser/web_contents/web_contents_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3782,7 +3782,7 @@ void WebContentsImpl::ExitFullscreenMode(bool will_cause_resize) {
}
}

current_fullscreen_frame_ = nullptr;
current_fullscreen_frame_id_ = GlobalRenderFrameHostId();

observers_.NotifyObservers(
&WebContentsObserver::DidToggleFullscreenModeForTab, IsFullscreen(),
Expand Down Expand Up @@ -3898,7 +3898,7 @@ void WebContentsImpl::FullscreenFrameSetUpdated() {
OPTIONAL_TRACE_EVENT0("content",
"WebContentsImpl::FullscreenFrameSetUpdated");
if (fullscreen_frames_.empty()) {
current_fullscreen_frame_ = nullptr;
current_fullscreen_frame_id_ = GlobalRenderFrameHostId();
return;
}

Expand All @@ -3910,9 +3910,10 @@ void WebContentsImpl::FullscreenFrameSetUpdated() {

// If we have already notified observers about this frame then we should not
// fire the observers again.
if (new_fullscreen_frame == current_fullscreen_frame_)
if (new_fullscreen_frame->GetGlobalId() == current_fullscreen_frame_id_) {
return;
current_fullscreen_frame_ = new_fullscreen_frame;
}
current_fullscreen_frame_id_ = new_fullscreen_frame->GetGlobalId();

observers_.NotifyObservers(&WebContentsObserver::DidAcquireFullscreen,
new_fullscreen_frame);
Expand Down
9 changes: 5 additions & 4 deletions content/browser/web_contents/web_contents_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1824,7 +1824,7 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents,
void ClearTargetURL();

// Called each time |fullscreen_frames_| is updated. Find the new
// |current_fullscreen_frame_| and notify observers whenever it changes.
// |current_fullscreen_frame_id_| and notify observers whenever it changes.
void FullscreenFrameSetUpdated();

// ui::NativeThemeObserver:
Expand Down Expand Up @@ -2307,9 +2307,10 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents,
// See https://fullscreen.spec.whatwg.org.
std::set<RenderFrameHostImpl*> fullscreen_frames_;

// Store the frame that is currently fullscreen, nullptr if there is none.
raw_ptr<RenderFrameHostImpl, DanglingUntriaged> current_fullscreen_frame_ =
nullptr;
// Store an ID for the frame that is currently fullscreen, or an invalid ID if
// there is none.
GlobalRenderFrameHostId current_fullscreen_frame_id_ =
GlobalRenderFrameHostId();

// Whether location bar should be focused by default. This is computed in
// DidStartNavigation/DidFinishNavigation and only set for an initial
Expand Down
27 changes: 18 additions & 9 deletions content/browser/web_contents/web_contents_impl_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "content/public/browser/back_forward_cache.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/file_select_listener.h"
#include "content/public/browser/global_routing_id.h"
#include "content/public/browser/host_zoom_map.h"
#include "content/public/browser/invalidate_type.h"
#include "content/public/browser/javascript_dialog_manager.h"
Expand Down Expand Up @@ -159,7 +160,7 @@ class WebContentsImplBrowserTest : public ContentBrowserTest {
bool IsInFullscreen() {
WebContentsImpl* web_contents =
static_cast<WebContentsImpl*>(shell()->web_contents());
return web_contents->current_fullscreen_frame_;
return !!web_contents->current_fullscreen_frame_id_;
}

protected:
Expand Down Expand Up @@ -3827,7 +3828,8 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, NotifyFullscreenAcquired) {

fullscreen_frames.insert(main_frame);
EXPECT_EQ(fullscreen_frames, web_contents->fullscreen_frames_);
EXPECT_EQ(main_frame, web_contents->current_fullscreen_frame_);
EXPECT_EQ(main_frame->GetGlobalId(),
web_contents->current_fullscreen_frame_id_);

// Make the child frame fullscreen.
{
Expand All @@ -3839,7 +3841,8 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, NotifyFullscreenAcquired) {

fullscreen_frames.insert(child_frame);
EXPECT_EQ(fullscreen_frames, web_contents->fullscreen_frames_);
EXPECT_EQ(child_frame, web_contents->current_fullscreen_frame_);
EXPECT_EQ(child_frame->GetGlobalId(),
web_contents->current_fullscreen_frame_id_);

// Exit fullscreen on the child frame.
// This will not work with --site-per-process until crbug.com/617369
Expand All @@ -3853,7 +3856,8 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, NotifyFullscreenAcquired) {

fullscreen_frames.erase(child_frame);
EXPECT_EQ(fullscreen_frames, web_contents->fullscreen_frames_);
EXPECT_EQ(main_frame, web_contents->current_fullscreen_frame_);
EXPECT_EQ(main_frame->GetGlobalId(),
web_contents->current_fullscreen_frame_id_);
}
}

Expand Down Expand Up @@ -3951,7 +3955,8 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,

nodes.insert(main_frame);
EXPECT_EQ(nodes, web_contents->fullscreen_frames_);
EXPECT_EQ(main_frame, web_contents->current_fullscreen_frame_);
EXPECT_EQ(main_frame->GetGlobalId(),
web_contents->current_fullscreen_frame_id_);

// Make the child frame fullscreen.
{
Expand All @@ -3963,7 +3968,8 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,

nodes.insert(child_frame);
EXPECT_EQ(nodes, web_contents->fullscreen_frames_);
EXPECT_EQ(child_frame, web_contents->current_fullscreen_frame_);
EXPECT_EQ(child_frame->GetGlobalId(),
web_contents->current_fullscreen_frame_id_);

// Perform a cross origin navigation on the main frame.
EXPECT_TRUE(
Expand Down Expand Up @@ -4000,7 +4006,8 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,

fullscreen_frames.insert(main_frame);
EXPECT_EQ(fullscreen_frames, web_contents->fullscreen_frames_);
EXPECT_EQ(main_frame, web_contents->current_fullscreen_frame_);
EXPECT_EQ(main_frame->GetGlobalId(),
web_contents->current_fullscreen_frame_id_);

// Make the child frame fullscreen.
{
Expand All @@ -4012,7 +4019,8 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,

fullscreen_frames.insert(child_frame);
EXPECT_EQ(fullscreen_frames, web_contents->fullscreen_frames_);
EXPECT_EQ(child_frame, web_contents->current_fullscreen_frame_);
EXPECT_EQ(child_frame->GetGlobalId(),
web_contents->current_fullscreen_frame_id_);

// Exit fullscreen on the child frame.
{
Expand All @@ -4023,7 +4031,8 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,

fullscreen_frames.erase(child_frame);
EXPECT_EQ(fullscreen_frames, web_contents->fullscreen_frames_);
EXPECT_EQ(main_frame, web_contents->current_fullscreen_frame_);
EXPECT_EQ(main_frame->GetGlobalId(),
web_contents->current_fullscreen_frame_id_);
}

IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, PropagateFullscreenOptions) {
Expand Down

0 comments on commit 207e93c

Please sign in to comment.