Remove usage of FrameTreeNode IDs (see issue #2421)

With the introduction of prerendering in Chromium it is now possible for
RenderFrameHosts (RFH) to move between FrameTrees. As a consequence we can no
longer rely on FrameTreeNode IDs to uniquely identify a RFH over its lifespan.
We must now switch to using GlobalRenderFrameHostId (child_id, frame_routing_id)
instead for that purpose. Additionally, we simplify existing code by using the
GlobalRenderFrameHostId struct in all places that previously used a
(render_process_id, render_frame_id) pair, since these concepts are equivalent.

See https://crbug.com/1179502#c8 for additional background.
This commit is contained in:
Marshall Greenblatt
2021-08-19 17:07:44 -04:00
parent cfdec92624
commit 955097ea77
33 changed files with 506 additions and 781 deletions

View File

@ -68,14 +68,15 @@ CefFrameHostImpl::CefFrameHostImpl(scoped_refptr<CefBrowserInfo> browser_info,
CefFrameHostImpl::CefFrameHostImpl(scoped_refptr<CefBrowserInfo> browser_info,
content::RenderFrameHost* render_frame_host)
: is_main_frame_(render_frame_host->GetParent() == nullptr),
frame_id_(MakeFrameId(render_frame_host)),
frame_id_(frame_util::MakeFrameId(render_frame_host->GetGlobalId())),
browser_info_(browser_info),
is_focused_(is_main_frame_), // The main frame always starts focused.
url_(render_frame_host->GetLastCommittedURL().spec()),
name_(render_frame_host->GetFrameName()),
parent_frame_id_(is_main_frame_
? kInvalidFrameId
: MakeFrameId(render_frame_host->GetParent())),
parent_frame_id_(
is_main_frame_ ? kInvalidFrameId
: frame_util::MakeFrameId(
render_frame_host->GetParent()->GetGlobalId())),
render_frame_host_(render_frame_host) {
DCHECK(browser_info_);
}
@ -276,8 +277,10 @@ void CefFrameHostImpl::RefreshAttributes() {
}
}
if (!is_main_frame_)
parent_frame_id_ = MakeFrameId(render_frame_host_->GetParent());
if (!is_main_frame_) {
parent_frame_id_ =
frame_util::MakeFrameId(render_frame_host_->GetParent()->GetGlobalId());
}
}
void CefFrameHostImpl::NotifyMoveOrResizeStarted() {
@ -457,20 +460,6 @@ bool CefFrameHostImpl::Detach() {
return first_detach;
}
// static
int64_t CefFrameHostImpl::MakeFrameId(const content::RenderFrameHost* host) {
CEF_REQUIRE_UIT();
auto host_nonconst = const_cast<content::RenderFrameHost*>(host);
return MakeFrameId(host_nonconst->GetProcess()->GetID(),
host_nonconst->GetRoutingID());
}
// static
int64_t CefFrameHostImpl::MakeFrameId(int32_t render_process_id,
int32_t render_routing_id) {
return frame_util::MakeFrameId(render_process_id, render_routing_id);
}
// kMainFrameId must be -1 to align with renderer expectations.
const int64_t CefFrameHostImpl::kMainFrameId = -1;
const int64_t CefFrameHostImpl::kFocusedFrameId = -2;