2019-05-24 22:23:43 +02:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
#ifndef CEF_LIBCEF_COMMON_FRAME_UTIL_H_
|
|
|
|
#define CEF_LIBCEF_COMMON_FRAME_UTIL_H_
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2024-04-30 17:45:07 +02:00
|
|
|
|
2024-01-26 03:12:43 +01:00
|
|
|
#include <optional>
|
2021-06-01 01:18:33 +02:00
|
|
|
#include <string>
|
2019-05-24 22:23:43 +02:00
|
|
|
|
2021-08-19 23:07:44 +02:00
|
|
|
#include "base/logging.h"
|
2023-01-30 18:43:54 +01:00
|
|
|
#include "content/public/browser/child_process_host.h"
|
2021-08-19 23:07:44 +02:00
|
|
|
#include "content/public/browser/global_routing_id.h"
|
|
|
|
|
|
|
|
namespace content {
|
|
|
|
class NavigationHandle;
|
|
|
|
}
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
namespace frame_util {
|
|
|
|
|
2021-08-19 23:07:44 +02:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
2019-05-24 22:23:43 +02:00
|
|
|
|
2024-01-26 03:12:43 +01:00
|
|
|
// Returns true if |frame_token| is valid.
|
|
|
|
inline bool IsValidFrameToken(const blink::LocalFrameToken& frame_token) {
|
|
|
|
return !frame_token->is_empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if |global_token| is valid.
|
|
|
|
inline bool IsValidGlobalToken(
|
|
|
|
const content::GlobalRenderFrameHostToken& global_token) {
|
|
|
|
return IsValidChildId(global_token.child_id) &&
|
|
|
|
IsValidFrameToken(global_token.frame_token);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a global token from a frame identifier. Returns std::nullopt if
|
|
|
|
// |identifier| is invalid.
|
|
|
|
std::optional<content::GlobalRenderFrameHostToken> ParseFrameIdentifier(
|
|
|
|
const std::string& identifier);
|
|
|
|
|
|
|
|
// Return the frame identifier for a global token. Returns empty if
|
|
|
|
// |global_token| is invalid.
|
|
|
|
std::string MakeFrameIdentifier(
|
|
|
|
const content::GlobalRenderFrameHostToken& global_token);
|
|
|
|
|
|
|
|
// Returns a human-readable version of the ID/token.
|
2021-08-19 23:07:44 +02:00
|
|
|
std::string GetFrameDebugString(
|
|
|
|
const content::GlobalRenderFrameHostId& global_id);
|
2024-01-26 03:12:43 +01:00
|
|
|
std::string GetFrameDebugString(
|
|
|
|
const content::GlobalRenderFrameHostToken& global_token);
|
2021-05-21 03:42:58 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
} // namespace frame_util
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_COMMON_FRAME_UTIL_H_
|