2020-09-25 03:40:47 +02:00
|
|
|
// Copyright 2020 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright 2012 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/chrome/chrome_content_renderer_client_cef.h"
|
|
|
|
|
|
|
|
#include "libcef/renderer/render_frame_observer.h"
|
2021-05-14 18:58:55 +02:00
|
|
|
#include "libcef/renderer/render_manager.h"
|
2020-09-25 03:40:47 +02:00
|
|
|
#include "libcef/renderer/thread_util.h"
|
|
|
|
|
|
|
|
#include "content/public/renderer/render_thread.h"
|
|
|
|
|
|
|
|
ChromeContentRendererClientCef::ChromeContentRendererClientCef()
|
2021-05-14 18:58:55 +02:00
|
|
|
: render_manager_(new CefRenderManager) {}
|
2020-09-25 03:40:47 +02:00
|
|
|
|
|
|
|
ChromeContentRendererClientCef::~ChromeContentRendererClientCef() = default;
|
|
|
|
|
|
|
|
scoped_refptr<base::SingleThreadTaskRunner>
|
|
|
|
ChromeContentRendererClientCef::GetCurrentTaskRunner() {
|
|
|
|
// Check if currently on the render thread.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (CEF_CURRENTLY_ON_RT()) {
|
2020-09-25 03:40:47 +02:00
|
|
|
return render_task_runner_;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-09-25 03:40:47 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChromeContentRendererClientCef::RenderThreadStarted() {
|
|
|
|
ChromeContentRendererClient::RenderThreadStarted();
|
|
|
|
|
2023-01-30 18:43:54 +01:00
|
|
|
render_task_runner_ = base::SingleThreadTaskRunner::GetCurrentDefault();
|
2020-09-25 03:40:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChromeContentRendererClientCef::RenderThreadConnected() {
|
|
|
|
ChromeContentRendererClient::RenderThreadConnected();
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
render_manager_->RenderThreadConnected();
|
2020-09-25 03:40:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChromeContentRendererClientCef::RenderFrameCreated(
|
|
|
|
content::RenderFrame* render_frame) {
|
|
|
|
ChromeContentRendererClient::RenderFrameCreated(render_frame);
|
|
|
|
|
|
|
|
// Will delete itself when no longer needed.
|
|
|
|
CefRenderFrameObserver* render_frame_observer =
|
|
|
|
new CefRenderFrameObserver(render_frame);
|
|
|
|
|
|
|
|
bool browser_created;
|
2021-06-04 03:34:56 +02:00
|
|
|
absl::optional<bool> is_windowless;
|
2021-05-14 18:58:55 +02:00
|
|
|
render_manager_->RenderFrameCreated(render_frame, render_frame_observer,
|
|
|
|
browser_created, is_windowless);
|
2020-09-25 03:40:47 +02:00
|
|
|
if (is_windowless.has_value() && *is_windowless) {
|
|
|
|
LOG(ERROR) << "The chrome runtime does not support windowless browsers";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-25 19:49:32 +02:00
|
|
|
void ChromeContentRendererClientCef::WebViewCreated(
|
|
|
|
blink::WebView* web_view,
|
2022-09-26 21:30:45 +02:00
|
|
|
bool was_created_by_renderer,
|
|
|
|
const url::Origin* outermost_origin) {
|
|
|
|
ChromeContentRendererClient::WebViewCreated(web_view, was_created_by_renderer,
|
|
|
|
outermost_origin);
|
2020-09-25 03:40:47 +02:00
|
|
|
|
|
|
|
bool browser_created;
|
2021-06-04 03:34:56 +02:00
|
|
|
absl::optional<bool> is_windowless;
|
2021-07-23 18:40:13 +02:00
|
|
|
render_manager_->WebViewCreated(web_view, browser_created, is_windowless);
|
2020-09-25 03:40:47 +02:00
|
|
|
if (is_windowless.has_value() && *is_windowless) {
|
|
|
|
LOG(ERROR) << "The chrome runtime does not support windowless browsers";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChromeContentRendererClientCef::DevToolsAgentAttached() {
|
|
|
|
// WebWorkers may be creating agents on a different thread.
|
|
|
|
if (!render_task_runner_->BelongsToCurrentThread()) {
|
|
|
|
render_task_runner_->PostTask(
|
|
|
|
FROM_HERE,
|
|
|
|
base::BindOnce(&ChromeContentRendererClientCef::DevToolsAgentAttached,
|
|
|
|
base::Unretained(this)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
render_manager_->DevToolsAgentAttached();
|
2020-09-25 03:40:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChromeContentRendererClientCef::DevToolsAgentDetached() {
|
|
|
|
// WebWorkers may be creating agents on a different thread.
|
|
|
|
if (!render_task_runner_->BelongsToCurrentThread()) {
|
|
|
|
render_task_runner_->PostTask(
|
|
|
|
FROM_HERE,
|
|
|
|
base::BindOnce(&ChromeContentRendererClientCef::DevToolsAgentDetached,
|
|
|
|
base::Unretained(this)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
render_manager_->DevToolsAgentDetached();
|
2020-09-25 03:40:47 +02:00
|
|
|
}
|
2021-05-14 18:58:55 +02:00
|
|
|
|
|
|
|
void ChromeContentRendererClientCef::ExposeInterfacesToBrowser(
|
|
|
|
mojo::BinderMap* binders) {
|
|
|
|
ChromeContentRendererClient::ExposeInterfacesToBrowser(binders);
|
|
|
|
|
|
|
|
render_manager_->ExposeInterfacesToBrowser(binders);
|
|
|
|
}
|