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.
|
|
|
|
|
|
|
|
#include "libcef/browser/browser_frame.h"
|
|
|
|
|
|
|
|
#include "libcef/browser/browser_host_base.h"
|
|
|
|
#include "libcef/browser/thread_util.h"
|
|
|
|
|
|
|
|
#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,
|
|
|
|
base::ReadOnlySharedMemoryRegion region) {
|
|
|
|
// 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.
|
|
|
|
if (auto host = GetFrameHost(/*prefer_speculative=*/true)) {
|
2022-02-10 22:52:36 +01:00
|
|
|
host->FrameAttached(std::move(render_frame), reattached);
|
2021-05-14 18:58:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserFrame::UpdateDraggableRegions(
|
2021-06-04 03:34:56 +02:00
|
|
|
absl::optional<std::vector<cef::mojom::DraggableRegionEntryPtr>> regions) {
|
2021-05-14 18:58:55 +02:00
|
|
|
if (auto host = GetFrameHost()) {
|
|
|
|
host->UpdateDraggableRegions(std::move(regions));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 02:45:05 +02:00
|
|
|
CefRefPtr<CefFrameHostImpl> CefBrowserFrame::GetFrameHost(
|
|
|
|
bool prefer_speculative) const {
|
2021-05-14 18:58:55 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
auto rfh = render_frame_host();
|
|
|
|
if (auto browser = CefBrowserHostBase::GetBrowserForHost(rfh)) {
|
2021-05-19 02:45:05 +02:00
|
|
|
return browser->browser_info()->GetFrameForHost(rfh, nullptr,
|
|
|
|
prefer_speculative);
|
2021-05-14 18:58:55 +02:00
|
|
|
}
|
2023-05-08 17:22:46 +02:00
|
|
|
DCHECK(false);
|
2021-05-14 18:58:55 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|