cef/libcef/common/frame_util.cc
Marshall Greenblatt 955097ea77 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.
2021-08-19 19:41:44 -04:00

40 lines
1.2 KiB
C++

// Copyright (c) 2019 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that can
// be found in the LICENSE file.
#include "libcef/common/frame_util.h"
#include "libcef/browser/thread_util.h"
#include <limits>
#include <sstream>
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
namespace frame_util {
content::GlobalRenderFrameHostId GetGlobalId(
content::NavigationHandle* navigation_handle) {
CEF_REQUIRE_UIT();
return navigation_handle->HasCommitted()
? navigation_handle->GetRenderFrameHost()->GetGlobalId()
: navigation_handle->GetPreviousRenderFrameHostId();
}
std::string GetFrameDebugString(int64_t frame_id) {
uint32_t process_id = frame_id >> 32;
uint32_t routing_id = std::numeric_limits<uint32_t>::max() & frame_id;
std::stringstream ss;
ss << frame_id << " [" << process_id << "," << routing_id << "]";
return ss.str();
}
std::string GetFrameDebugString(
const content::GlobalRenderFrameHostId& global_id) {
return GetFrameDebugString(MakeFrameId(global_id));
}
} // namespace frame_util