Skip to content

Commit

Permalink
Remove explicit tracking of guest view frames
Browse files Browse the repository at this point in the history
This is no longer required now that we have implicit exclusion
of certain frame types including guest view frames.

Rename GuestView to ExcludedView in the renderer process.
  • Loading branch information
magreenblatt committed Apr 26, 2024
1 parent 65234a6 commit 5065aba
Show file tree
Hide file tree
Showing 27 changed files with 164 additions and 372 deletions.
6 changes: 3 additions & 3 deletions libcef/browser/alloy/alloy_browser_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "libcef/browser/browser_info_manager.h"
#include "libcef/browser/browser_platform_delegate.h"
#include "libcef/browser/context.h"
#include "libcef/browser/extensions/browser_extensions_util.h"
#include "libcef/browser/hang_monitor.h"
#include "libcef/browser/media_access_query.h"
#include "libcef/browser/osr/osr_util.h"
Expand Down Expand Up @@ -604,9 +605,8 @@ void AlloyBrowserHostImpl::CancelContextMenu() {
bool AlloyBrowserHostImpl::MaybeAllowNavigation(
content::RenderFrameHost* opener,
const content::OpenURLParams& params) {
bool is_guest_view = false;
GetFrameForHost(opener, &is_guest_view);

const bool is_guest_view = extensions::IsBrowserPluginGuest(
content::WebContents::FromRenderFrameHost(opener));
if (is_guest_view && !params.is_pdf &&
!params.url.SchemeIs(extensions::kExtensionScheme) &&
!params.url.SchemeIs(content::kChromeUIScheme)) {
Expand Down
5 changes: 2 additions & 3 deletions libcef/browser/browser_contents_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ void CefBrowserContentsDelegate::ObserveWebContents(
// Make sure MaybeCreateFrame is called at least one time.
// Create the frame representation before OnAfterCreated is called for a new
// browser.
browser_info_->MaybeCreateFrame(new_contents->GetPrimaryMainFrame(),
false /* is_guest_view */);
browser_info_->MaybeCreateFrame(new_contents->GetPrimaryMainFrame());

// Make sure RenderWidgetCreated is called at least one time. This Observer
// is registered too late to catch the initial creation.
Expand Down Expand Up @@ -319,7 +318,7 @@ void CefBrowserContentsDelegate::DraggableRegionsChanged(

void CefBrowserContentsDelegate::RenderFrameCreated(
content::RenderFrameHost* render_frame_host) {
browser_info_->MaybeCreateFrame(render_frame_host, false /* is_guest_view */);
browser_info_->MaybeCreateFrame(render_frame_host);
if (render_frame_host->GetParent() == nullptr) {
auto render_view_host = render_frame_host->GetRenderViewHost();
auto base_background_color = platform_delegate()->GetBackgroundColor();
Expand Down
6 changes: 2 additions & 4 deletions libcef/browser/browser_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,7 @@ std::vector<CefBrowserContext*> CefBrowserContext::GetAll() {
void CefBrowserContext::OnRenderFrameCreated(
CefRequestContextImpl* request_context,
const content::GlobalRenderFrameHostId& global_id,
bool is_main_frame,
bool is_guest_view) {
bool is_main_frame) {
CEF_REQUIRE_UIT();
DCHECK(frame_util::IsValidGlobalId(global_id));

Expand All @@ -302,8 +301,7 @@ void CefBrowserContext::OnRenderFrameCreated(
void CefBrowserContext::OnRenderFrameDeleted(
CefRequestContextImpl* request_context,
const content::GlobalRenderFrameHostId& global_id,
bool is_main_frame,
bool is_guest_view) {
bool is_main_frame) {
CEF_REQUIRE_UIT();
DCHECK(frame_util::IsValidGlobalId(global_id));

Expand Down
6 changes: 2 additions & 4 deletions libcef/browser/browser_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,12 @@ class CefBrowserContext {
// Called from CefRequestContextImpl::OnRenderFrameCreated.
void OnRenderFrameCreated(CefRequestContextImpl* request_context,
const content::GlobalRenderFrameHostId& global_id,
bool is_main_frame,
bool is_guest_view);
bool is_main_frame);

// Called from CefRequestContextImpl::OnRenderFrameDeleted.
void OnRenderFrameDeleted(CefRequestContextImpl* request_context,
const content::GlobalRenderFrameHostId& global_id,
bool is_main_frame,
bool is_guest_view);
bool is_main_frame);

// Returns the handler that matches the specified IDs. Pass -1 for unknown
// values. If |require_frame_match| is true only exact matches will be
Expand Down
10 changes: 5 additions & 5 deletions libcef/browser/browser_frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ void CefBrowserFrame::FrameAttached(
bool reattached) {
// Always send to the newly created RFH, which may be speculative when
// navigating cross-origin.
bool excluded_type;
if (auto host = GetFrameHost(/*prefer_speculative=*/true, &excluded_type)) {
bool is_excluded;
if (auto host = GetFrameHost(/*prefer_speculative=*/true, &is_excluded)) {
host->FrameAttached(std::move(render_frame), reattached);
} else if (excluded_type) {
} else if (is_excluded) {
VLOG(1) << "frame "
<< frame_util::GetFrameDebugString(
render_frame_host()->GetGlobalFrameToken())
Expand All @@ -82,8 +82,8 @@ void CefBrowserFrame::UpdateDraggableRegions(

CefRefPtr<CefFrameHostImpl> CefBrowserFrame::GetFrameHost(
bool prefer_speculative,
bool* excluded_type) const {
bool* is_excluded) const {
return CefBrowserInfoManager::GetFrameHost(
render_frame_host(), prefer_speculative,
/*browser_info=*/nullptr, excluded_type);
/*browser_info=*/nullptr, is_excluded);
}
2 changes: 1 addition & 1 deletion libcef/browser/browser_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CefBrowserFrame
bool ShouldCloseOnFinishNavigation() const override { return false; }

CefRefPtr<CefFrameHostImpl> GetFrameHost(bool prefer_speculative,
bool* excluded_type = nullptr) const;
bool* is_excluded = nullptr) const;
};

#endif // CEF_LIBCEF_BROWSER_BROWSER_FRAME_H_
22 changes: 10 additions & 12 deletions libcef/browser/browser_host_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ CefRefPtr<CefBrowserHostBase> CefBrowserHostBase::GetBrowserForContents(
return browser;
}

// Try the owner WebContents if |contents| originates from a guest view such
// as the PDF viewer or Print Preview.
// This is safe to call even if Alloy extensions are disabled.
// Try the owner WebContents if |contents| originates from an excluded view
// such as the PDF viewer or Print Preview. This is safe to call even if Alloy
// extensions are disabled.
if (auto* owner_contents = extensions::GetOwnerForGuestContents(contents)) {
return WebContentsUserDataAdapter::Get(owner_contents);
}
Expand All @@ -153,8 +153,7 @@ CefRefPtr<CefBrowserHostBase> CefBrowserHostBase::GetBrowserForGlobalId(
return GetBrowserForHost(render_frame_host);
} else {
// Use the thread-safe approach.
auto info = CefBrowserInfoManager::GetInstance()->GetBrowserInfo(global_id,
nullptr);
auto info = CefBrowserInfoManager::GetInstance()->GetBrowserInfo(global_id);
if (info) {
auto browser = info->browser();
if (!browser) {
Expand Down Expand Up @@ -185,8 +184,8 @@ CefRefPtr<CefBrowserHostBase> CefBrowserHostBase::GetBrowserForGlobalToken(
return GetBrowserForHost(render_frame_host);
} else {
// Use the thread-safe approach.
auto info = CefBrowserInfoManager::GetInstance()->GetBrowserInfo(
global_token, nullptr);
auto info =
CefBrowserInfoManager::GetInstance()->GetBrowserInfo(global_token);
if (info) {
auto browser = info->browser();
if (!browser) {
Expand Down Expand Up @@ -1121,24 +1120,23 @@ void CefBrowserHostBase::OnWebContentsDestroyed(
content::WebContents* web_contents) {}

CefRefPtr<CefFrame> CefBrowserHostBase::GetFrameForHost(
const content::RenderFrameHost* host,
bool* is_guest_view) {
const content::RenderFrameHost* host) {
CEF_REQUIRE_UIT();
if (!host) {
return nullptr;
}

return browser_info_->GetFrameForHost(host, is_guest_view);
return browser_info_->GetFrameForHost(host);
}

CefRefPtr<CefFrame> CefBrowserHostBase::GetFrameForGlobalId(
const content::GlobalRenderFrameHostId& global_id) {
return browser_info_->GetFrameForGlobalId(global_id, nullptr);
return browser_info_->GetFrameForGlobalId(global_id);
}

CefRefPtr<CefFrame> CefBrowserHostBase::GetFrameForGlobalToken(
const content::GlobalRenderFrameHostToken& global_token) {
return browser_info_->GetFrameForGlobalToken(global_token, nullptr);
return browser_info_->GetFrameForGlobalToken(global_token);
}

void CefBrowserHostBase::AddObserver(Observer* observer) {
Expand Down
8 changes: 2 additions & 6 deletions libcef/browser/browser_host_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,8 @@ class CefBrowserHostBase : public CefBrowserHost,
void OnWebContentsDestroyed(content::WebContents* web_contents) override;

// Returns the frame object matching the specified |host| or nullptr if no
// match is found. Nullptr will also be returned if a guest view match is
// found because we don't create frame objects for guest views. If
// |is_guest_view| is non-nullptr it will be set to true in this case. Must be
// called on the UI thread.
CefRefPtr<CefFrame> GetFrameForHost(const content::RenderFrameHost* host,
bool* is_guest_view = nullptr);
// match is found. Must be called on the UI thread.
CefRefPtr<CefFrame> GetFrameForHost(const content::RenderFrameHost* host);

// Returns the frame associated with the specified global ID/token. See
// documentation on RenderFrameHost::GetFrameTreeNodeId/Token() for why the
Expand Down
61 changes: 16 additions & 45 deletions libcef/browser/browser_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ void CefBrowserInfo::SetClosing() {
is_closing_ = true;
}

void CefBrowserInfo::MaybeCreateFrame(content::RenderFrameHost* host,
bool is_guest_view) {
void CefBrowserInfo::MaybeCreateFrame(content::RenderFrameHost* host) {
CEF_REQUIRE_UIT();

if (CefBrowserInfoManager::IsExcludedFrameHost(host)) {
Expand Down Expand Up @@ -129,11 +128,10 @@ void CefBrowserInfo::MaybeCreateFrame(content::RenderFrameHost* host,
#if DCHECK_IS_ON()
// Check that the frame info hasn't changed unexpectedly.
DCHECK_EQ(info->global_id_, global_id);
DCHECK_EQ(info->is_guest_view_, is_guest_view);
DCHECK_EQ(info->is_main_frame_, is_main_frame);
#endif

if (!info->is_guest_view_ && info->is_speculative_ && !is_speculative) {
if (info->is_speculative_ && !is_speculative) {
// Upgrade the frame info from speculative to non-speculative.
if (info->is_main_frame_) {
// Set the main frame object.
Expand All @@ -147,28 +145,23 @@ void CefBrowserInfo::MaybeCreateFrame(content::RenderFrameHost* host,
auto frame_info = new FrameInfo;
frame_info->host_ = host;
frame_info->global_id_ = global_id;
frame_info->is_guest_view_ = is_guest_view;
frame_info->is_main_frame_ = is_main_frame;
frame_info->is_speculative_ = is_speculative;

// Guest views don't get their own CefBrowser or CefFrame objects.
if (!is_guest_view) {
// Create a new frame object.
frame_info->frame_ = new CefFrameHostImpl(this, host);
MaybeNotifyFrameCreated(frame_info->frame_);
if (is_main_frame && !is_speculative) {
SetMainFrame(browser_, frame_info->frame_);
}
// Create a new frame object.
frame_info->frame_ = new CefFrameHostImpl(this, host);
MaybeNotifyFrameCreated(frame_info->frame_);
if (is_main_frame && !is_speculative) {
SetMainFrame(browser_, frame_info->frame_);
}

#if DCHECK_IS_ON()
// Check that the frame info hasn't changed unexpectedly.
DCHECK(host->GetGlobalFrameToken() == *frame_info->frame_->frame_token());
DCHECK_EQ(frame_info->is_main_frame_, frame_info->frame_->IsMain());
// Check that the frame info hasn't changed unexpectedly.
DCHECK(host->GetGlobalFrameToken() == *frame_info->frame_->frame_token());
DCHECK_EQ(frame_info->is_main_frame_, frame_info->frame_->IsMain());
#endif
}

browser_->request_context()->OnRenderFrameCreated(global_id, is_main_frame,
is_guest_view);
browser_->request_context()->OnRenderFrameCreated(global_id, is_main_frame);

// Populate the lookup maps.
frame_id_map_.insert(std::make_pair(global_id, frame_info));
Expand Down Expand Up @@ -238,8 +231,8 @@ void CefBrowserInfo::RemoveFrame(content::RenderFrameHost* host) {

auto frame_info = it->second;

browser_->request_context()->OnRenderFrameDeleted(
global_id, frame_info->is_main_frame_, frame_info->is_guest_view_);
browser_->request_context()->OnRenderFrameDeleted(global_id,
frame_info->is_main_frame_);

// Remove from the lookup maps.
frame_id_map_.erase(it);
Expand Down Expand Up @@ -290,29 +283,19 @@ CefRefPtr<CefFrameHostImpl> CefBrowserInfo::CreateTempSubFrame(

CefRefPtr<CefFrameHostImpl> CefBrowserInfo::GetFrameForHost(
const content::RenderFrameHost* host,
bool* is_guest_view,
bool prefer_speculative) const {
if (is_guest_view) {
*is_guest_view = false;
}

if (!host) {
return nullptr;
}

return GetFrameForGlobalId(
const_cast<content::RenderFrameHost*>(host)->GetGlobalId(), is_guest_view,
const_cast<content::RenderFrameHost*>(host)->GetGlobalId(),
prefer_speculative);
}

CefRefPtr<CefFrameHostImpl> CefBrowserInfo::GetFrameForGlobalId(
const content::GlobalRenderFrameHostId& global_id,
bool* is_guest_view,
bool prefer_speculative) const {
if (is_guest_view) {
*is_guest_view = false;
}

if (!frame_util::IsValidGlobalId(global_id)) {
return nullptr;
}
Expand All @@ -323,13 +306,6 @@ CefRefPtr<CefFrameHostImpl> CefBrowserInfo::GetFrameForGlobalId(
if (it != frame_id_map_.end()) {
const auto info = it->second;

if (info->is_guest_view_) {
if (is_guest_view) {
*is_guest_view = true;
}
return nullptr;
}

if (info->is_speculative_ && !prefer_speculative) {
if (info->is_main_frame_ && main_frame_) {
// Always prefer the non-speculative main frame.
Expand All @@ -349,12 +325,7 @@ CefRefPtr<CefFrameHostImpl> CefBrowserInfo::GetFrameForGlobalId(

CefRefPtr<CefFrameHostImpl> CefBrowserInfo::GetFrameForGlobalToken(
const content::GlobalRenderFrameHostToken& global_token,
bool* is_guest_view,
bool prefer_speculative) const {
if (is_guest_view) {
*is_guest_view = false;
}

if (!frame_util::IsValidGlobalToken(global_token)) {
return nullptr;
}
Expand All @@ -370,7 +341,7 @@ CefRefPtr<CefFrameHostImpl> CefBrowserInfo::GetFrameForGlobalToken(
global_id = it->second;
}

return GetFrameForGlobalId(global_id, is_guest_view, prefer_speculative);
return GetFrameForGlobalId(global_id, prefer_speculative);
}

CefBrowserInfo::FrameHostList CefBrowserInfo::GetAllFrames() const {
Expand Down
25 changes: 6 additions & 19 deletions libcef/browser/browser_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@ class CefBrowserInfo : public base::RefCountedThreadSafe<CefBrowserInfo> {
// Ensure that a frame record exists for |host|. Called for the main frame
// when the RenderView is created, or for a sub-frame when the associated
// RenderFrame is created in the renderer process.
// Called from CefBrowserContentsDelegate::RenderFrameCreated (is_guest_view =
// false) or CefMimeHandlerViewGuestDelegate::OnGuestAttached (is_guest_view =
// true).
void MaybeCreateFrame(content::RenderFrameHost* host, bool is_guest_view);
// Called from CefBrowserContentsDelegate::RenderFrameCreated.
void MaybeCreateFrame(content::RenderFrameHost* host);

// Used to track state changes such as entering/exiting the BackForwardCache.
// Called from CefBrowserContentsDelegate::RenderFrameHostStateChanged.
Expand Down Expand Up @@ -102,32 +100,22 @@ class CefBrowserInfo : public base::RefCountedThreadSafe<CefBrowserInfo> {
const content::GlobalRenderFrameHostId& parent_global_id);

// Returns the frame object matching the specified host or nullptr if no match
// is found. Nullptr will also be returned if a guest view match is found
// because we don't create frame objects for guest views. If |is_guest_view|
// is non-nullptr it will be set to true in this case. Must be called on the
// UI thread.
// is found. Must be called on the UI thread.
CefRefPtr<CefFrameHostImpl> GetFrameForHost(
const content::RenderFrameHost* host,
bool* is_guest_view = nullptr,
bool prefer_speculative = false) const;

// Returns the frame object matching the specified ID/token or nullptr if no
// match is found. Nullptr will also be returned if a guest view match is
// found because we don't create frame objects for guest views. If
// |is_guest_view| is non-nullptr it will be set to true in this case. Safe to
// call from any thread.
// match is found. Safe to call from any thread.
CefRefPtr<CefFrameHostImpl> GetFrameForGlobalId(
const content::GlobalRenderFrameHostId& global_id,
bool* is_guest_view = nullptr,
bool prefer_speculative = false) const;
CefRefPtr<CefFrameHostImpl> GetFrameForGlobalToken(
const content::GlobalRenderFrameHostToken& global_token,
bool* is_guest_view = nullptr,
bool prefer_speculative = false) const;

// Returns all non-speculative frame objects that currently exist. Guest views
// will be excluded because they don't have a frame object. Safe to call from
// any thread.
// Returns all non-speculative frame objects that currently exist. Safe to
// call from any thread.
using FrameHostList = std::set<CefRefPtr<CefFrameHostImpl>>;
FrameHostList GetAllFrames() const;

Expand Down Expand Up @@ -184,7 +172,6 @@ class CefBrowserInfo : public base::RefCountedThreadSafe<CefBrowserInfo> {

content::RenderFrameHost* host_;
content::GlobalRenderFrameHostId global_id_;
bool is_guest_view_;
bool is_main_frame_;
bool is_speculative_;
bool is_in_bfcache_ = false;
Expand Down
Loading

0 comments on commit 5065aba

Please sign in to comment.