2021-05-14 18:58:55 +02:00
|
|
|
// Copyright 2021 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.
|
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/browser_frame.h"
|
2021-05-14 18:58:55 +02:00
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/browser_host_base.h"
|
|
|
|
#include "cef/libcef/browser/browser_info_manager.h"
|
|
|
|
#include "cef/libcef/browser/thread_util.h"
|
|
|
|
#include "cef/libcef/common/frame_util.h"
|
2021-05-14 18:58:55 +02:00
|
|
|
#include "content/public/browser/render_frame_host.h"
|
|
|
|
#include "content/public/browser/render_process_host.h"
|
|
|
|
#include "content/public/browser/web_contents.h"
|
|
|
|
#include "content/public/browser/web_contents_observer.h"
|
|
|
|
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
|
|
|
|
|
|
|
|
CefBrowserFrame::CefBrowserFrame(
|
|
|
|
content::RenderFrameHost* render_frame_host,
|
|
|
|
mojo::PendingReceiver<cef::mojom::BrowserFrame> receiver)
|
2021-10-19 00:17:16 +02:00
|
|
|
: FrameServiceBase(render_frame_host, std::move(receiver)) {}
|
2021-05-14 18:58:55 +02:00
|
|
|
|
|
|
|
CefBrowserFrame::~CefBrowserFrame() = default;
|
|
|
|
|
|
|
|
// static
|
|
|
|
void CefBrowserFrame::RegisterBrowserInterfaceBindersForFrame(
|
|
|
|
content::RenderFrameHost* render_frame_host,
|
|
|
|
mojo::BinderMapWithContext<content::RenderFrameHost*>* map) {
|
|
|
|
map->Add<cef::mojom::BrowserFrame>(base::BindRepeating(
|
|
|
|
[](content::RenderFrameHost* frame_host,
|
|
|
|
mojo::PendingReceiver<cef::mojom::BrowserFrame> receiver) {
|
|
|
|
// This object is bound to the lifetime of |frame_host| and the mojo
|
2021-07-23 18:40:13 +02:00
|
|
|
// connection. See DocumentServiceBase for details.
|
2021-05-14 18:58:55 +02:00
|
|
|
new CefBrowserFrame(frame_host, std::move(receiver));
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserFrame::SendMessage(const std::string& name,
|
2023-01-30 22:42:40 +01:00
|
|
|
base::Value::List arguments) {
|
2022-02-10 22:52:36 +01:00
|
|
|
// Always send to the newly created RFH, which may be speculative when
|
2021-05-21 03:42:58 +02:00
|
|
|
// navigating cross-origin.
|
|
|
|
if (auto host = GetFrameHost(/*prefer_speculative=*/true)) {
|
2021-05-14 18:58:55 +02:00
|
|
|
host->SendMessage(name, std::move(arguments));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-04 11:49:15 +02:00
|
|
|
void CefBrowserFrame::SendSharedMemoryRegion(
|
|
|
|
const std::string& name,
|
2023-10-17 00:43:29 +02:00
|
|
|
base::WritableSharedMemoryRegion region) {
|
2022-07-04 11:49:15 +02:00
|
|
|
// Always send to the newly created RFH, which may be speculative when
|
|
|
|
// navigating cross-origin.
|
|
|
|
if (auto host = GetFrameHost(/*prefer_speculative=*/true)) {
|
|
|
|
host->SendSharedMemoryRegion(name, std::move(region));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-10 22:52:36 +01:00
|
|
|
void CefBrowserFrame::FrameAttached(
|
|
|
|
mojo::PendingRemote<cef::mojom::RenderFrame> render_frame,
|
|
|
|
bool reattached) {
|
2021-05-19 02:45:05 +02:00
|
|
|
// Always send to the newly created RFH, which may be speculative when
|
|
|
|
// navigating cross-origin.
|
2024-04-24 23:23:47 +02:00
|
|
|
bool is_excluded;
|
|
|
|
if (auto host = GetFrameHost(/*prefer_speculative=*/true, &is_excluded)) {
|
2022-02-10 22:52:36 +01:00
|
|
|
host->FrameAttached(std::move(render_frame), reattached);
|
2024-04-24 23:23:47 +02:00
|
|
|
} else if (is_excluded) {
|
2024-04-17 18:01:26 +02:00
|
|
|
VLOG(1) << "frame "
|
|
|
|
<< frame_util::GetFrameDebugString(
|
|
|
|
render_frame_host()->GetGlobalFrameToken())
|
|
|
|
<< " attach denied";
|
|
|
|
mojo::Remote<cef::mojom::RenderFrame> render_frame_remote;
|
|
|
|
render_frame_remote.Bind(std::move(render_frame));
|
|
|
|
render_frame_remote->FrameAttachedAck(/*allow=*/false);
|
2021-05-14 18:58:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserFrame::UpdateDraggableRegions(
|
2024-03-19 22:11:42 +01:00
|
|
|
std::optional<std::vector<cef::mojom::DraggableRegionEntryPtr>> regions) {
|
2024-04-17 18:01:26 +02:00
|
|
|
if (auto host = GetFrameHost(/*prefer_speculative=*/false)) {
|
2021-05-14 18:58:55 +02:00
|
|
|
host->UpdateDraggableRegions(std::move(regions));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 02:45:05 +02:00
|
|
|
CefRefPtr<CefFrameHostImpl> CefBrowserFrame::GetFrameHost(
|
2024-04-17 18:01:26 +02:00
|
|
|
bool prefer_speculative,
|
2024-04-24 23:23:47 +02:00
|
|
|
bool* is_excluded) const {
|
2024-04-17 18:01:26 +02:00
|
|
|
return CefBrowserInfoManager::GetFrameHost(
|
|
|
|
render_frame_host(), prefer_speculative,
|
2024-04-24 23:23:47 +02:00
|
|
|
/*browser_info=*/nullptr, is_excluded);
|
2021-05-14 18:58:55 +02:00
|
|
|
}
|