2017-07-06 22:39:37 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright (c) 2011 The Chromium 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/renderer/render_frame_util.h"
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
#include "libcef/common/frame_util.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "libcef/renderer/blink_glue.h"
|
2017-07-06 22:39:37 +02:00
|
|
|
|
|
|
|
#include "base/logging.h"
|
2019-06-19 16:53:31 +02:00
|
|
|
#include "content/public/renderer/render_thread.h"
|
2017-07-06 22:39:37 +02:00
|
|
|
#include "content/renderer/render_frame_impl.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "third_party/blink/public/web/web_local_frame.h"
|
2017-07-06 22:39:37 +02:00
|
|
|
|
|
|
|
namespace render_frame_util {
|
|
|
|
|
2024-01-26 03:12:43 +01:00
|
|
|
std::string GetIdentifier(blink::WebLocalFrame* frame) {
|
2017-07-06 22:39:37 +02:00
|
|
|
// Each WebFrame will have an associated RenderFrame. The RenderFrame
|
|
|
|
// routing IDs are unique within a given renderer process.
|
2024-01-26 03:12:43 +01:00
|
|
|
return frame_util::MakeFrameIdentifier(content::GlobalRenderFrameHostToken(
|
|
|
|
content::RenderThread::Get()->GetClientId(),
|
|
|
|
frame->GetLocalFrameToken()));
|
2017-07-06 22:39:37 +02:00
|
|
|
}
|
|
|
|
|
2018-03-28 19:30:15 +02:00
|
|
|
std::string GetName(blink::WebLocalFrame* frame) {
|
|
|
|
DCHECK(frame);
|
|
|
|
// Return the assigned name if it is non-empty. This represents the name
|
|
|
|
// property on the frame DOM element. If the assigned name is empty, revert to
|
2019-05-24 22:23:43 +02:00
|
|
|
// the internal unique name. This matches the logic in
|
|
|
|
// CefFrameHostImpl::RefreshAttributes.
|
2018-03-28 19:30:15 +02:00
|
|
|
if (frame->AssignedName().length() > 0) {
|
|
|
|
return frame->AssignedName().Utf8();
|
|
|
|
}
|
2017-07-06 22:39:37 +02:00
|
|
|
content::RenderFrameImpl* render_frame =
|
|
|
|
content::RenderFrameImpl::FromWebFrame(frame);
|
|
|
|
DCHECK(render_frame);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (render_frame) {
|
2017-07-06 22:39:37 +02:00
|
|
|
return render_frame->unique_name();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-07-06 22:39:37 +02:00
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
|
2024-01-26 03:12:43 +01:00
|
|
|
std::optional<blink::LocalFrameToken> ParseFrameTokenFromIdentifier(
|
|
|
|
const std::string& identifier) {
|
|
|
|
const auto& global_token = frame_util::ParseFrameIdentifier(identifier);
|
|
|
|
if (!global_token ||
|
|
|
|
global_token->child_id != content::RenderThread::Get()->GetClientId()) {
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
return global_token->frame_token;
|
|
|
|
}
|
|
|
|
|
2017-07-27 01:19:27 +02:00
|
|
|
} // namespace render_frame_util
|