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

@ -4,63 +4,42 @@
#include "libcef/browser/request_context_handler_map.h"
#include "libcef/common/frame_util.h"
CefRequestContextHandlerMap::CefRequestContextHandlerMap() = default;
CefRequestContextHandlerMap::~CefRequestContextHandlerMap() = default;
void CefRequestContextHandlerMap::AddHandler(
int render_process_id,
int render_frame_id,
int frame_tree_node_id,
const content::GlobalRenderFrameHostId& global_id,
CefRefPtr<CefRequestContextHandler> handler) {
DCHECK_GE(render_process_id, 0);
DCHECK_GE(render_frame_id, 0);
DCHECK_GE(frame_tree_node_id, 0);
DCHECK(frame_util::IsValidGlobalId(global_id));
DCHECK(handler);
render_id_handler_map_.insert(std::make_pair(
std::make_pair(render_process_id, render_frame_id), handler));
node_id_handler_map_.insert(std::make_pair(frame_tree_node_id, handler));
render_id_handler_map_.insert(std::make_pair(global_id, handler));
}
void CefRequestContextHandlerMap::RemoveHandler(int render_process_id,
int render_frame_id,
int frame_tree_node_id) {
DCHECK_GE(render_process_id, 0);
DCHECK_GE(render_frame_id, 0);
DCHECK_GE(frame_tree_node_id, 0);
void CefRequestContextHandlerMap::RemoveHandler(
const content::GlobalRenderFrameHostId& global_id) {
DCHECK(frame_util::IsValidGlobalId(global_id));
auto it1 = render_id_handler_map_.find(
std::make_pair(render_process_id, render_frame_id));
auto it1 = render_id_handler_map_.find(global_id);
if (it1 != render_id_handler_map_.end())
render_id_handler_map_.erase(it1);
auto it2 = node_id_handler_map_.find(frame_tree_node_id);
if (it2 != node_id_handler_map_.end())
node_id_handler_map_.erase(it2);
}
CefRefPtr<CefRequestContextHandler> CefRequestContextHandlerMap::GetHandler(
int render_process_id,
int render_frame_id,
int frame_tree_node_id,
const content::GlobalRenderFrameHostId& global_id,
bool require_frame_match) const {
if (render_process_id >= 0 && render_frame_id >= 0) {
const auto it1 = render_id_handler_map_.find(
std::make_pair(render_process_id, render_frame_id));
if (frame_util::IsValidGlobalId(global_id)) {
const auto it1 = render_id_handler_map_.find(global_id);
if (it1 != render_id_handler_map_.end())
return it1->second;
}
if (frame_tree_node_id >= 0) {
const auto it2 = node_id_handler_map_.find(frame_tree_node_id);
if (it2 != node_id_handler_map_.end())
return it2->second;
}
if (render_process_id >= 0 && !require_frame_match) {
if (frame_util::IsValidChildId(global_id.child_id) && !require_frame_match) {
// Choose an arbitrary handler for the same process.
for (auto& kv : render_id_handler_map_) {
if (kv.first.first == render_process_id)
if (kv.first.child_id == global_id.child_id)
return kv.second;
}
}