mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
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:
@ -8,14 +8,76 @@
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "content/public/browser/global_routing_id.h"
|
||||
#include "content/public/common/child_process_host.h"
|
||||
|
||||
namespace content {
|
||||
class NavigationHandle;
|
||||
}
|
||||
|
||||
namespace frame_util {
|
||||
|
||||
// Returns the frame ID, which is a 64-bit combination of |render_process_id|
|
||||
// and |render_routing_id|.
|
||||
int64_t MakeFrameId(int32_t render_process_id, int32_t render_routing_id);
|
||||
// Create a frame ID in the format exposed by the CEF API.
|
||||
inline int64_t MakeFrameId(int child_id, int frame_routing_id) {
|
||||
return (static_cast<uint64_t>(child_id) << 32) |
|
||||
static_cast<uint64_t>(frame_routing_id);
|
||||
}
|
||||
|
||||
// Returns a human-readable version of |frame_id|.
|
||||
// Create a frame ID in the format exposed by the CEF API.
|
||||
inline int64_t MakeFrameId(const content::GlobalRenderFrameHostId& global_id) {
|
||||
return MakeFrameId(global_id.child_id, global_id.frame_routing_id);
|
||||
}
|
||||
|
||||
// Returns true if |child_id| is valid.
|
||||
inline bool IsValidChildId(int child_id) {
|
||||
// See comments in ChildProcessHostImpl::GenerateChildProcessUniqueId().
|
||||
return child_id != content::ChildProcessHost::kInvalidUniqueID &&
|
||||
child_id != 0;
|
||||
}
|
||||
|
||||
// Returns true if |frame_routing_id| is valid.
|
||||
inline bool IsValidRoutingId(int frame_routing_id) {
|
||||
return frame_routing_id != MSG_ROUTING_NONE;
|
||||
}
|
||||
|
||||
// Returns true if |global_id| is valid.
|
||||
inline bool IsValidGlobalId(const content::GlobalRenderFrameHostId& global_id) {
|
||||
return IsValidChildId(global_id.child_id) &&
|
||||
IsValidRoutingId(global_id.frame_routing_id);
|
||||
}
|
||||
|
||||
// Create a global ID from components.
|
||||
inline content::GlobalRenderFrameHostId MakeGlobalId(
|
||||
int child_id,
|
||||
int frame_routing_id,
|
||||
bool allow_invalid_frame_id = false) {
|
||||
DCHECK(IsValidChildId(child_id));
|
||||
DCHECK(allow_invalid_frame_id || IsValidRoutingId(frame_routing_id));
|
||||
return content::GlobalRenderFrameHostId(child_id, frame_routing_id);
|
||||
}
|
||||
|
||||
// Create a global ID from a frame ID.
|
||||
inline content::GlobalRenderFrameHostId MakeGlobalId(int64_t frame_id) {
|
||||
uint32_t child_id = frame_id >> 32;
|
||||
uint32_t frame_routing_id = std::numeric_limits<uint32_t>::max() & frame_id;
|
||||
return MakeGlobalId(child_id, frame_routing_id);
|
||||
}
|
||||
|
||||
// Returns an invalid global ID value.
|
||||
inline content::GlobalRenderFrameHostId InvalidGlobalId() {
|
||||
return content::GlobalRenderFrameHostId();
|
||||
}
|
||||
|
||||
// Returns the best match of global ID for |navigation_handle|. For pre-commit
|
||||
// navigations this will return the current RFH, if any, or an invalid ID.
|
||||
content::GlobalRenderFrameHostId GetGlobalId(
|
||||
content::NavigationHandle* navigation_handle);
|
||||
|
||||
// Returns a human-readable version of the ID.
|
||||
std::string GetFrameDebugString(int64_t frame_id);
|
||||
std::string GetFrameDebugString(
|
||||
const content::GlobalRenderFrameHostId& global_id);
|
||||
|
||||
} // namespace frame_util
|
||||
|
||||
|
Reference in New Issue
Block a user