mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Delete Alloy bootstrap (fixes #3685)
This commit is contained in:
@@ -1,599 +0,0 @@
|
||||
// Copyright (c) 2013 The Chromium Embedded Framework Authors.
|
||||
// Portions copyright (c) 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 "cef/libcef/renderer/alloy/alloy_content_renderer_client.h"
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "build/build_config.h"
|
||||
|
||||
// Enable deprecation warnings on Windows. See http://crbug.com/585142.
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
#if defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic error "-Wdeprecated-declarations"
|
||||
#else
|
||||
#pragma warning(push)
|
||||
#pragma warning(default : 4996)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "base/metrics/user_metrics_action.h"
|
||||
#include "base/path_service.h"
|
||||
#include "base/process/current_process.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "build/build_config.h"
|
||||
#include "cef/libcef/browser/alloy/alloy_content_browser_client.h"
|
||||
#include "cef/libcef/browser/context.h"
|
||||
#include "cef/libcef/common/alloy/alloy_content_client.h"
|
||||
#include "cef/libcef/common/app_manager.h"
|
||||
#include "cef/libcef/common/cef_switches.h"
|
||||
#include "cef/libcef/common/extensions/extensions_client.h"
|
||||
#include "cef/libcef/common/extensions/extensions_util.h"
|
||||
#include "cef/libcef/common/request_impl.h"
|
||||
#include "cef/libcef/features/runtime_checks.h"
|
||||
#include "cef/libcef/renderer/alloy/alloy_render_frame_observer.h"
|
||||
#include "cef/libcef/renderer/alloy/alloy_render_thread_observer.h"
|
||||
#include "cef/libcef/renderer/alloy/url_loader_throttle_provider_impl.h"
|
||||
#include "cef/libcef/renderer/browser_impl.h"
|
||||
#include "cef/libcef/renderer/extensions/extensions_renderer_client.h"
|
||||
#include "cef/libcef/renderer/render_manager.h"
|
||||
#include "cef/libcef/renderer/thread_util.h"
|
||||
#include "chrome/common/chrome_switches.h"
|
||||
#include "chrome/common/pdf_util.h"
|
||||
#include "chrome/common/url_constants.h"
|
||||
#include "chrome/renderer/browser_exposed_renderer_interfaces.h"
|
||||
#include "chrome/renderer/chrome_content_renderer_client.h"
|
||||
#include "chrome/renderer/extensions/chrome_extensions_renderer_client.h"
|
||||
#include "chrome/renderer/loadtimes_extension_bindings.h"
|
||||
#include "chrome/renderer/media/chrome_key_systems.h"
|
||||
#include "chrome/renderer/plugins/chrome_plugin_placeholder.h"
|
||||
#include "chrome/renderer/printing/chrome_print_render_frame_helper_delegate.h"
|
||||
#include "components/content_settings/core/common/content_settings_types.h"
|
||||
#include "components/nacl/common/nacl_constants.h"
|
||||
#include "components/pdf/common/constants.h"
|
||||
#include "components/pdf/common/pdf_util.h"
|
||||
#include "components/pdf/renderer/internal_plugin_renderer_helpers.h"
|
||||
#include "components/printing/renderer/print_render_frame_helper.h"
|
||||
#include "components/spellcheck/renderer/spellcheck.h"
|
||||
#include "components/spellcheck/renderer/spellcheck_provider.h"
|
||||
#include "components/visitedlink/renderer/visitedlink_reader.h"
|
||||
#include "components/web_cache/renderer/web_cache_impl.h"
|
||||
#include "content/public/browser/browser_task_traits.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/render_process_host.h"
|
||||
#include "content/public/child/child_thread.h"
|
||||
#include "content/public/common/content_constants.h"
|
||||
#include "content/public/common/content_paths.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "content/public/common/url_constants.h"
|
||||
#include "content/public/renderer/render_frame.h"
|
||||
#include "extensions/common/manifest_handlers/csp_info.h"
|
||||
#include "extensions/common/switches.h"
|
||||
#include "extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container_manager.h"
|
||||
#include "extensions/renderer/renderer_extension_registry.h"
|
||||
#include "ipc/ipc_sync_channel.h"
|
||||
#include "media/base/media.h"
|
||||
#include "mojo/public/cpp/bindings/binder_map.h"
|
||||
#include "mojo/public/cpp/bindings/generic_pending_receiver.h"
|
||||
#include "printing/print_settings.h"
|
||||
#include "services/network/public/cpp/is_potentially_trustworthy.h"
|
||||
#include "services/service_manager/public/cpp/connector.h"
|
||||
#include "services/service_manager/public/cpp/interface_provider.h"
|
||||
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
|
||||
#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
|
||||
#include "third_party/blink/public/platform/scheduler/web_renderer_process_type.h"
|
||||
#include "third_party/blink/public/platform/url_conversion.h"
|
||||
#include "third_party/blink/public/platform/web_runtime_features.h"
|
||||
#include "third_party/blink/public/platform/web_string.h"
|
||||
#include "third_party/blink/public/platform/web_url.h"
|
||||
#include "third_party/blink/public/web/web_console_message.h"
|
||||
#include "third_party/blink/public/web/web_element.h"
|
||||
#include "third_party/blink/public/web/web_frame.h"
|
||||
#include "third_party/blink/public/web/web_local_frame.h"
|
||||
#include "third_party/blink/public/web/web_script_controller.h"
|
||||
#include "third_party/blink/public/web/web_security_policy.h"
|
||||
#include "third_party/blink/public/web/web_view.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
#include "base/mac/mac_util.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#endif
|
||||
|
||||
AlloyContentRendererClient::AlloyContentRendererClient()
|
||||
: main_entry_time_(base::TimeTicks::Now()),
|
||||
render_manager_(new CefRenderManager) {
|
||||
if (extensions::ExtensionsEnabled()) {
|
||||
extensions_client_ = std::make_unique<extensions::CefExtensionsClient>();
|
||||
extensions::ExtensionsClient::Set(extensions_client_.get());
|
||||
extensions_renderer_client_ =
|
||||
std::make_unique<extensions::CefExtensionsRendererClient>(this);
|
||||
extensions::ExtensionsRendererClient::Set(
|
||||
extensions_renderer_client_.get());
|
||||
}
|
||||
}
|
||||
|
||||
AlloyContentRendererClient::~AlloyContentRendererClient() = default;
|
||||
|
||||
// static
|
||||
AlloyContentRendererClient* AlloyContentRendererClient::Get() {
|
||||
REQUIRE_ALLOY_RUNTIME();
|
||||
return static_cast<AlloyContentRendererClient*>(
|
||||
CefAppManager::Get()->GetContentClient()->renderer());
|
||||
}
|
||||
|
||||
scoped_refptr<base::SingleThreadTaskRunner>
|
||||
AlloyContentRendererClient::GetCurrentTaskRunner() {
|
||||
// Check if currently on the render thread.
|
||||
if (CEF_CURRENTLY_ON_RT()) {
|
||||
return render_task_runner_;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void AlloyContentRendererClient::RunSingleProcessCleanup() {
|
||||
DCHECK(content::RenderProcessHost::run_renderer_in_process());
|
||||
|
||||
// Make sure the render thread was actually started.
|
||||
if (!render_task_runner_.get()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
|
||||
RunSingleProcessCleanupOnUIThread();
|
||||
} else {
|
||||
CEF_POST_TASK(
|
||||
CEF_UIT,
|
||||
base::BindOnce(
|
||||
&AlloyContentRendererClient::RunSingleProcessCleanupOnUIThread,
|
||||
base::Unretained(this)));
|
||||
}
|
||||
|
||||
// Wait for the render thread cleanup to complete. Spin instead of using
|
||||
// base::WaitableEvent because calling Wait() is not allowed on the UI
|
||||
// thread.
|
||||
bool complete = false;
|
||||
do {
|
||||
{
|
||||
base::AutoLock lock_scope(single_process_cleanup_lock_);
|
||||
complete = single_process_cleanup_complete_;
|
||||
}
|
||||
if (!complete) {
|
||||
base::PlatformThread::YieldCurrentThread();
|
||||
}
|
||||
} while (!complete);
|
||||
}
|
||||
|
||||
void AlloyContentRendererClient::PostIOThreadCreated(
|
||||
base::SingleThreadTaskRunner*) {
|
||||
// TODO(cef): Enable these once the implementation supports it.
|
||||
blink::WebRuntimeFeatures::EnableNotifications(false);
|
||||
blink::WebRuntimeFeatures::EnablePushMessaging(false);
|
||||
}
|
||||
|
||||
void AlloyContentRendererClient::RenderThreadStarted() {
|
||||
const base::CommandLine* command_line =
|
||||
base::CommandLine::ForCurrentProcess();
|
||||
|
||||
render_task_runner_ = base::SingleThreadTaskRunner::GetCurrentDefault();
|
||||
observer_ = std::make_unique<AlloyRenderThreadObserver>();
|
||||
web_cache_impl_ = std::make_unique<web_cache::WebCacheImpl>();
|
||||
visited_link_slave_ = std::make_unique<visitedlink::VisitedLinkReader>();
|
||||
|
||||
content::RenderThread* thread = content::RenderThread::Get();
|
||||
|
||||
const bool is_extension = CefRenderManager::IsExtensionProcess();
|
||||
|
||||
thread->SetRendererProcessType(
|
||||
is_extension
|
||||
? blink::scheduler::WebRendererProcessType::kExtensionRenderer
|
||||
: blink::scheduler::WebRendererProcessType::kRenderer);
|
||||
|
||||
if (is_extension) {
|
||||
// The process name was set to "Renderer" in RendererMain(). Update it to
|
||||
// "Extension Renderer" to highlight that it's hosting an extension.
|
||||
base::CurrentProcess::GetInstance().SetProcessType(
|
||||
base::CurrentProcessType::PROCESS_RENDERER_EXTENSION);
|
||||
}
|
||||
|
||||
thread->AddObserver(observer_.get());
|
||||
|
||||
if (!command_line->HasSwitch(switches::kDisableSpellChecking)) {
|
||||
spellcheck_ = std::make_unique<SpellCheck>(this);
|
||||
}
|
||||
|
||||
if (content::RenderProcessHost::run_renderer_in_process()) {
|
||||
// When running in single-process mode register as a destruction observer
|
||||
// on the render thread's MessageLoop.
|
||||
base::CurrentThread::Get()->AddDestructionObserver(this);
|
||||
}
|
||||
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
{
|
||||
base::apple::ScopedCFTypeRef<CFStringRef> key(
|
||||
base::SysUTF8ToCFStringRef("NSScrollViewRubberbanding"));
|
||||
base::apple::ScopedCFTypeRef<CFStringRef> value;
|
||||
|
||||
// If the command-line switch is specified then set the value that will be
|
||||
// checked in RenderThreadImpl::Init(). Otherwise, remove the application-
|
||||
// level value.
|
||||
if (command_line->HasSwitch(switches::kDisableScrollBounce)) {
|
||||
value.reset(base::SysUTF8ToCFStringRef("false"));
|
||||
}
|
||||
|
||||
CFPreferencesSetAppValue(key.get(), value.get(),
|
||||
kCFPreferencesCurrentApplication);
|
||||
CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
|
||||
}
|
||||
#endif // BUILDFLAG(IS_MAC)
|
||||
|
||||
if (extensions::ExtensionsEnabled()) {
|
||||
extensions_renderer_client_->RenderThreadStarted();
|
||||
}
|
||||
}
|
||||
|
||||
void AlloyContentRendererClient::ExposeInterfacesToBrowser(
|
||||
mojo::BinderMap* binders) {
|
||||
auto task_runner = base::SequencedTaskRunner::GetCurrentDefault();
|
||||
|
||||
binders->Add<web_cache::mojom::WebCache>(
|
||||
base::BindRepeating(&web_cache::WebCacheImpl::BindReceiver,
|
||||
base::Unretained(web_cache_impl_.get())),
|
||||
task_runner);
|
||||
|
||||
binders->Add<visitedlink::mojom::VisitedLinkNotificationSink>(
|
||||
visited_link_slave_->GetBindCallback(), task_runner);
|
||||
|
||||
if (spellcheck_) {
|
||||
binders->Add<spellcheck::mojom::SpellChecker>(
|
||||
base::BindRepeating(
|
||||
[](SpellCheck* spellcheck,
|
||||
mojo::PendingReceiver<spellcheck::mojom::SpellChecker>
|
||||
receiver) { spellcheck->BindReceiver(std::move(receiver)); },
|
||||
base::Unretained(spellcheck_.get())),
|
||||
task_runner);
|
||||
}
|
||||
|
||||
render_manager_->ExposeInterfacesToBrowser(binders);
|
||||
}
|
||||
|
||||
void AlloyContentRendererClient::RenderThreadConnected() {
|
||||
// Register extensions last because it will trigger WebKit initialization.
|
||||
blink::WebScriptController::RegisterExtension(
|
||||
extensions_v8::LoadTimesExtension::Get());
|
||||
|
||||
render_manager_->RenderThreadConnected();
|
||||
}
|
||||
|
||||
void AlloyContentRendererClient::RenderFrameCreated(
|
||||
content::RenderFrame* render_frame) {
|
||||
auto render_frame_observer = new AlloyRenderFrameObserver(render_frame);
|
||||
|
||||
if (extensions::ExtensionsEnabled()) {
|
||||
extensions_renderer_client_->RenderFrameCreated(
|
||||
render_frame, render_frame_observer->registry());
|
||||
|
||||
render_frame_observer->associated_interfaces()
|
||||
->AddInterface<extensions::mojom::MimeHandlerViewContainerManager>(
|
||||
base::BindRepeating(
|
||||
&extensions::MimeHandlerViewContainerManager::BindReceiver,
|
||||
base::Unretained(render_frame)));
|
||||
}
|
||||
|
||||
const base::CommandLine* command_line =
|
||||
base::CommandLine::ForCurrentProcess();
|
||||
if (!command_line->HasSwitch(switches::kDisableSpellChecking)) {
|
||||
new SpellCheckProvider(render_frame, spellcheck_.get());
|
||||
}
|
||||
|
||||
bool browser_created;
|
||||
std::optional<bool> is_windowless;
|
||||
std::optional<bool> print_preview_enabled;
|
||||
render_manager_->RenderFrameCreated(render_frame, render_frame_observer,
|
||||
browser_created, is_windowless,
|
||||
print_preview_enabled);
|
||||
if (browser_created) {
|
||||
OnBrowserCreated(render_frame->GetWebView(), is_windowless);
|
||||
}
|
||||
|
||||
// |print_preview_enabled| may be empty, in which case the
|
||||
// kDisablePrintPreview command-line flag will be checked.
|
||||
new printing::PrintRenderFrameHelper(
|
||||
render_frame, std::make_unique<ChromePrintRenderFrameHelperDelegate>(
|
||||
print_preview_enabled));
|
||||
}
|
||||
|
||||
void AlloyContentRendererClient::WebViewCreated(
|
||||
blink::WebView* web_view,
|
||||
bool was_created_by_renderer,
|
||||
const url::Origin* outermost_origin) {
|
||||
bool browser_created;
|
||||
std::optional<bool> is_windowless;
|
||||
std::optional<bool> print_preview_enabled;
|
||||
render_manager_->WebViewCreated(web_view, browser_created, is_windowless,
|
||||
print_preview_enabled);
|
||||
if (browser_created) {
|
||||
OnBrowserCreated(web_view, is_windowless);
|
||||
}
|
||||
}
|
||||
|
||||
bool AlloyContentRendererClient::IsPluginHandledExternally(
|
||||
content::RenderFrame* render_frame,
|
||||
const blink::WebElement& plugin_element,
|
||||
const GURL& original_url,
|
||||
const std::string& mime_type) {
|
||||
if (!extensions::ExtensionsEnabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DCHECK(plugin_element.HasHTMLTagName("object") ||
|
||||
plugin_element.HasHTMLTagName("embed"));
|
||||
// Blink will next try to load a WebPlugin which would end up in
|
||||
// OverrideCreatePlugin, sending another IPC only to find out the plugin is
|
||||
// not supported. Here it suffices to return false but there should perhaps be
|
||||
// a more unified approach to avoid sending the IPC twice.
|
||||
chrome::mojom::PluginInfoPtr plugin_info = chrome::mojom::PluginInfo::New();
|
||||
mojo::AssociatedRemote<chrome::mojom::PluginInfoHost> plugin_info_host;
|
||||
render_frame->GetRemoteAssociatedInterfaces()->GetInterface(
|
||||
&plugin_info_host);
|
||||
plugin_info_host->GetPluginInfo(
|
||||
original_url, render_frame->GetWebFrame()->Top()->GetSecurityOrigin(),
|
||||
mime_type, &plugin_info);
|
||||
// TODO(ekaramad): Not continuing here due to a disallowed status should take
|
||||
// us to CreatePlugin. See if more in depths investigation of |status| is
|
||||
// necessary here (see https://crbug.com/965747). For now, returning false
|
||||
// should take us to CreatePlugin after HTMLPlugInElement which is called
|
||||
// through HTMLPlugInElement::LoadPlugin code path.
|
||||
if (plugin_info->status != chrome::mojom::PluginStatus::kAllowed &&
|
||||
plugin_info->status !=
|
||||
chrome::mojom::PluginStatus::kPlayImportantContent) {
|
||||
// We could get here when a MimeHandlerView is loaded inside a <webview>
|
||||
// which is using permissions API (see WebViewPluginTests).
|
||||
ChromeExtensionsRendererClient::DidBlockMimeHandlerViewForDisallowedPlugin(
|
||||
plugin_element);
|
||||
return false;
|
||||
}
|
||||
if (plugin_info->actual_mime_type == pdf::kInternalPluginMimeType) {
|
||||
// Only actually treat the internal PDF plugin as externally handled if
|
||||
// used within an origin allowed to create the internal PDF plugin;
|
||||
// otherwise, let Blink try to create the in-process PDF plugin.
|
||||
if (IsPdfInternalPluginAllowedOrigin(
|
||||
render_frame->GetWebFrame()->GetSecurityOrigin())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return ChromeExtensionsRendererClient::MaybeCreateMimeHandlerView(
|
||||
plugin_element, original_url, plugin_info->actual_mime_type,
|
||||
plugin_info->plugin);
|
||||
}
|
||||
|
||||
bool AlloyContentRendererClient::OverrideCreatePlugin(
|
||||
content::RenderFrame* render_frame,
|
||||
const blink::WebPluginParams& params,
|
||||
blink::WebPlugin** plugin) {
|
||||
std::string orig_mime_type = params.mime_type.Utf8();
|
||||
if (extensions::ExtensionsEnabled() &&
|
||||
!extensions_renderer_client_->OverrideCreatePlugin(render_frame,
|
||||
params)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
GURL url(params.url);
|
||||
chrome::mojom::PluginInfoPtr plugin_info = chrome::mojom::PluginInfo::New();
|
||||
mojo::AssociatedRemote<chrome::mojom::PluginInfoHost> plugin_info_host;
|
||||
render_frame->GetRemoteAssociatedInterfaces()->GetInterface(
|
||||
&plugin_info_host);
|
||||
plugin_info_host->GetPluginInfo(
|
||||
url, render_frame->GetWebFrame()->Top()->GetSecurityOrigin(),
|
||||
orig_mime_type, &plugin_info);
|
||||
*plugin = ChromeContentRendererClient::CreatePlugin(render_frame, params,
|
||||
*plugin_info);
|
||||
return true;
|
||||
}
|
||||
|
||||
void AlloyContentRendererClient::WillSendRequest(
|
||||
blink::WebLocalFrame* frame,
|
||||
ui::PageTransition transition_type,
|
||||
const blink::WebURL& url,
|
||||
const net::SiteForCookies& site_for_cookies,
|
||||
const url::Origin* initiator_origin,
|
||||
GURL* new_url) {
|
||||
if (extensions::ExtensionsEnabled()) {
|
||||
extensions_renderer_client_->WillSendRequest(frame, transition_type, url,
|
||||
site_for_cookies,
|
||||
initiator_origin, new_url);
|
||||
if (!new_url->is_empty()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t AlloyContentRendererClient::VisitedLinkHash(
|
||||
std::string_view canonical_url) {
|
||||
return visited_link_slave_->ComputeURLFingerprint(canonical_url);
|
||||
}
|
||||
|
||||
bool AlloyContentRendererClient::IsLinkVisited(uint64_t link_hash) {
|
||||
return visited_link_slave_->IsVisited(link_hash);
|
||||
}
|
||||
|
||||
bool AlloyContentRendererClient::IsOriginIsolatedPepperPlugin(
|
||||
const base::FilePath& plugin_path) {
|
||||
// Isolate all the plugins (including the PDF plugin).
|
||||
return true;
|
||||
}
|
||||
|
||||
std::unique_ptr<media::KeySystemSupportRegistration>
|
||||
AlloyContentRendererClient::GetSupportedKeySystems(
|
||||
content::RenderFrame* render_frame,
|
||||
media::GetSupportedKeySystemsCB cb) {
|
||||
return GetChromeKeySystems(render_frame, std::move(cb));
|
||||
}
|
||||
|
||||
void AlloyContentRendererClient::RunScriptsAtDocumentStart(
|
||||
content::RenderFrame* render_frame) {
|
||||
if (extensions::ExtensionsEnabled()) {
|
||||
extensions_renderer_client_->RunScriptsAtDocumentStart(render_frame);
|
||||
}
|
||||
}
|
||||
|
||||
void AlloyContentRendererClient::RunScriptsAtDocumentEnd(
|
||||
content::RenderFrame* render_frame) {
|
||||
if (extensions::ExtensionsEnabled()) {
|
||||
extensions_renderer_client_->RunScriptsAtDocumentEnd(render_frame);
|
||||
}
|
||||
}
|
||||
|
||||
void AlloyContentRendererClient::RunScriptsAtDocumentIdle(
|
||||
content::RenderFrame* render_frame) {
|
||||
if (extensions::ExtensionsEnabled()) {
|
||||
extensions_renderer_client_->RunScriptsAtDocumentIdle(render_frame);
|
||||
}
|
||||
}
|
||||
|
||||
void AlloyContentRendererClient::DevToolsAgentAttached() {
|
||||
// WebWorkers may be creating agents on a different thread.
|
||||
if (!render_task_runner_->BelongsToCurrentThread()) {
|
||||
render_task_runner_->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(&AlloyContentRendererClient::DevToolsAgentAttached,
|
||||
base::Unretained(this)));
|
||||
return;
|
||||
}
|
||||
|
||||
render_manager_->DevToolsAgentAttached();
|
||||
}
|
||||
|
||||
void AlloyContentRendererClient::DevToolsAgentDetached() {
|
||||
// WebWorkers may be creating agents on a different thread.
|
||||
if (!render_task_runner_->BelongsToCurrentThread()) {
|
||||
render_task_runner_->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(&AlloyContentRendererClient::DevToolsAgentDetached,
|
||||
base::Unretained(this)));
|
||||
return;
|
||||
}
|
||||
|
||||
render_manager_->DevToolsAgentDetached();
|
||||
}
|
||||
|
||||
std::unique_ptr<blink::URLLoaderThrottleProvider>
|
||||
AlloyContentRendererClient::CreateURLLoaderThrottleProvider(
|
||||
blink::URLLoaderThrottleProviderType provider_type) {
|
||||
return std::make_unique<CefURLLoaderThrottleProviderImpl>(provider_type,
|
||||
this);
|
||||
}
|
||||
|
||||
void AlloyContentRendererClient::AppendContentSecurityPolicy(
|
||||
const blink::WebURL& url,
|
||||
blink::WebVector<blink::WebContentSecurityPolicyHeader>* csp) {
|
||||
if (!extensions::ExtensionsEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't apply default CSP to PDF renderers.
|
||||
// TODO(crbug.com/1252096): Lock down the CSP once style and script are no
|
||||
// longer injected inline by `pdf::PluginResponseWriter`. That class may be a
|
||||
// better place to define such CSP, or we may continue doing so here.
|
||||
if (pdf::IsPdfRenderer()) {
|
||||
return;
|
||||
}
|
||||
|
||||
DCHECK(csp);
|
||||
GURL gurl(url);
|
||||
const extensions::Extension* extension =
|
||||
extensions::RendererExtensionRegistry::Get()->GetExtensionOrAppByURL(
|
||||
gurl);
|
||||
if (!extension) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Append a minimum CSP to ensure the extension can't relax the default
|
||||
// applied CSP through means like Service Worker.
|
||||
const std::string* default_csp =
|
||||
extensions::CSPInfo::GetMinimumCSPToAppend(*extension, gurl.path());
|
||||
if (!default_csp) {
|
||||
return;
|
||||
}
|
||||
|
||||
csp->push_back({blink::WebString::FromUTF8(*default_csp),
|
||||
network::mojom::ContentSecurityPolicyType::kEnforce,
|
||||
network::mojom::ContentSecurityPolicySource::kHTTP});
|
||||
}
|
||||
|
||||
void AlloyContentRendererClient::GetInterface(
|
||||
const std::string& interface_name,
|
||||
mojo::ScopedMessagePipeHandle interface_pipe) {
|
||||
// TODO(crbug.com/977637): Get rid of the use of this implementation of
|
||||
// |service_manager::LocalInterfaceProvider|. This was done only to avoid
|
||||
// churning spellcheck code while eliminating the "chrome" and
|
||||
// "chrome_renderer" services. Spellcheck is (and should remain) the only
|
||||
// consumer of this implementation.
|
||||
content::RenderThread::Get()->BindHostReceiver(
|
||||
mojo::GenericPendingReceiver(interface_name, std::move(interface_pipe)));
|
||||
}
|
||||
|
||||
void AlloyContentRendererClient::WillDestroyCurrentMessageLoop() {
|
||||
base::AutoLock lock_scope(single_process_cleanup_lock_);
|
||||
single_process_cleanup_complete_ = true;
|
||||
}
|
||||
|
||||
void AlloyContentRendererClient::OnBrowserCreated(
|
||||
blink::WebView* web_view,
|
||||
std::optional<bool> is_windowless) {
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
const bool windowless = is_windowless.has_value() && *is_windowless;
|
||||
|
||||
// FIXME: It would be better if this API would be a callback from the
|
||||
// WebKit layer, or if it would be exposed as an WebView instance method; the
|
||||
// current implementation uses a static variable, and WebKit needs to be
|
||||
// patched in order to make it work for each WebView instance
|
||||
web_view->SetUseExternalPopupMenusThisInstance(!windowless);
|
||||
#endif
|
||||
}
|
||||
|
||||
void AlloyContentRendererClient::RunSingleProcessCleanupOnUIThread() {
|
||||
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
|
||||
|
||||
// Clean up the single existing RenderProcessHost.
|
||||
content::RenderProcessHost* host = nullptr;
|
||||
content::RenderProcessHost::iterator iterator(
|
||||
content::RenderProcessHost::AllHostsIterator());
|
||||
if (!iterator.IsAtEnd()) {
|
||||
host = iterator.GetCurrentValue();
|
||||
host->Cleanup();
|
||||
iterator.Advance();
|
||||
DCHECK(iterator.IsAtEnd());
|
||||
}
|
||||
DCHECK(host);
|
||||
|
||||
// Clear the run_renderer_in_process() flag to avoid a DCHECK in the
|
||||
// RenderProcessHost destructor.
|
||||
content::RenderProcessHost::SetRunRendererInProcess(false);
|
||||
|
||||
// Deletion of the RenderProcessHost object will stop the render thread and
|
||||
// result in a call to WillDestroyCurrentMessageLoop.
|
||||
// Cleanup() will cause deletion to be posted as a task on the UI thread but
|
||||
// this task will only execute when running in multi-threaded message loop
|
||||
// mode (because otherwise the UI message loop has already stopped). Therefore
|
||||
// we need to explicitly delete the object when not running in this mode.
|
||||
if (!CefContext::Get()->settings().multi_threaded_message_loop) {
|
||||
delete host;
|
||||
}
|
||||
}
|
||||
|
||||
// Enable deprecation warnings on Windows. See http://crbug.com/585142.
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
#if defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#else
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
#endif
|
@@ -1,156 +0,0 @@
|
||||
// Copyright (c) 2013 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.
|
||||
|
||||
#ifndef CEF_LIBCEF_RENDERER_ALLOY_ALLOY_CONTENT_RENDERER_CLIENT_H_
|
||||
#define CEF_LIBCEF_RENDERER_ALLOY_ALLOY_CONTENT_RENDERER_CLIENT_H_
|
||||
#pragma once
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/task/current_thread.h"
|
||||
#include "base/task/single_thread_task_runner.h"
|
||||
#include "cef/libcef/renderer/browser_impl.h"
|
||||
#include "chrome/common/plugin.mojom.h"
|
||||
#include "content/public/renderer/content_renderer_client.h"
|
||||
#include "content/public/renderer/render_thread.h"
|
||||
#include "mojo/public/cpp/bindings/generic_pending_receiver.h"
|
||||
#include "services/service_manager/public/cpp/local_interface_provider.h"
|
||||
|
||||
namespace extensions {
|
||||
class CefExtensionsRendererClient;
|
||||
class Dispatcher;
|
||||
class ExtensionsClient;
|
||||
class ExtensionsRendererClient;
|
||||
class ResourceRequestPolicy;
|
||||
} // namespace extensions
|
||||
|
||||
namespace visitedlink {
|
||||
class VisitedLinkReader;
|
||||
}
|
||||
|
||||
namespace web_cache {
|
||||
class WebCacheImpl;
|
||||
}
|
||||
|
||||
class AlloyRenderThreadObserver;
|
||||
class CefRenderManager;
|
||||
class SpellCheck;
|
||||
|
||||
class AlloyContentRendererClient
|
||||
: public content::ContentRendererClient,
|
||||
public service_manager::LocalInterfaceProvider,
|
||||
public base::CurrentThread::DestructionObserver {
|
||||
public:
|
||||
AlloyContentRendererClient();
|
||||
|
||||
AlloyContentRendererClient(const AlloyContentRendererClient&) = delete;
|
||||
AlloyContentRendererClient& operator=(const AlloyContentRendererClient&) =
|
||||
delete;
|
||||
|
||||
~AlloyContentRendererClient() override;
|
||||
|
||||
// Returns the singleton AlloyContentRendererClient instance.
|
||||
// This method is deprecated and should not be used in new callsites.
|
||||
static AlloyContentRendererClient* Get();
|
||||
|
||||
// Render thread task runner.
|
||||
base::SingleThreadTaskRunner* render_task_runner() const {
|
||||
return render_task_runner_.get();
|
||||
}
|
||||
|
||||
// Returns the task runner for the current thread. Returns NULL if the current
|
||||
// thread is not the main render process thread.
|
||||
scoped_refptr<base::SingleThreadTaskRunner> GetCurrentTaskRunner();
|
||||
|
||||
// Perform cleanup work that needs to occur before shutdown when running in
|
||||
// single-process mode. Blocks until cleanup is complete.
|
||||
void RunSingleProcessCleanup();
|
||||
|
||||
// ContentRendererClient implementation.
|
||||
void PostIOThreadCreated(
|
||||
base::SingleThreadTaskRunner* io_thread_task_runner) override;
|
||||
void RenderThreadStarted() override;
|
||||
void ExposeInterfacesToBrowser(mojo::BinderMap* binders) override;
|
||||
void RenderThreadConnected() override;
|
||||
void RenderFrameCreated(content::RenderFrame* render_frame) override;
|
||||
void WebViewCreated(blink::WebView* web_view,
|
||||
bool was_created_by_renderer,
|
||||
const url::Origin* outermost_origin) override;
|
||||
bool IsPluginHandledExternally(content::RenderFrame* render_frame,
|
||||
const blink::WebElement& plugin_element,
|
||||
const GURL& original_url,
|
||||
const std::string& mime_type) override;
|
||||
bool OverrideCreatePlugin(content::RenderFrame* render_frame,
|
||||
const blink::WebPluginParams& params,
|
||||
blink::WebPlugin** plugin) override;
|
||||
void WillSendRequest(blink::WebLocalFrame* frame,
|
||||
ui::PageTransition transition_type,
|
||||
const blink::WebURL& url,
|
||||
const net::SiteForCookies& site_for_cookies,
|
||||
const url::Origin* initiator_origin,
|
||||
GURL* new_url) override;
|
||||
uint64_t VisitedLinkHash(std::string_view canonical_url) override;
|
||||
bool IsLinkVisited(uint64_t link_hash) override;
|
||||
bool IsOriginIsolatedPepperPlugin(const base::FilePath& plugin_path) override;
|
||||
std::unique_ptr<media::KeySystemSupportRegistration> GetSupportedKeySystems(
|
||||
content::RenderFrame* render_frame,
|
||||
media::GetSupportedKeySystemsCB cb) override;
|
||||
void RunScriptsAtDocumentStart(content::RenderFrame* render_frame) override;
|
||||
void RunScriptsAtDocumentEnd(content::RenderFrame* render_frame) override;
|
||||
void RunScriptsAtDocumentIdle(content::RenderFrame* render_frame) override;
|
||||
void DevToolsAgentAttached() override;
|
||||
void DevToolsAgentDetached() override;
|
||||
std::unique_ptr<blink::URLLoaderThrottleProvider>
|
||||
CreateURLLoaderThrottleProvider(
|
||||
blink::URLLoaderThrottleProviderType provider_type) override;
|
||||
void AppendContentSecurityPolicy(
|
||||
const blink::WebURL& url,
|
||||
blink::WebVector<blink::WebContentSecurityPolicyHeader>* csp) override;
|
||||
|
||||
// service_manager::LocalInterfaceProvider implementation.
|
||||
void GetInterface(const std::string& name,
|
||||
mojo::ScopedMessagePipeHandle request_handle) override;
|
||||
|
||||
// MessageLoopCurrent::DestructionObserver implementation.
|
||||
void WillDestroyCurrentMessageLoop() override;
|
||||
|
||||
AlloyRenderThreadObserver* GetAlloyObserver() const {
|
||||
return observer_.get();
|
||||
}
|
||||
|
||||
private:
|
||||
void OnBrowserCreated(blink::WebView* web_view,
|
||||
std::optional<bool> is_windowless);
|
||||
|
||||
// Perform cleanup work for single-process mode.
|
||||
void RunSingleProcessCleanupOnUIThread();
|
||||
|
||||
// Time at which this object was created. This is very close to the time at
|
||||
// which the RendererMain function was entered.
|
||||
base::TimeTicks main_entry_time_;
|
||||
|
||||
std::unique_ptr<CefRenderManager> render_manager_;
|
||||
|
||||
scoped_refptr<base::SingleThreadTaskRunner> render_task_runner_;
|
||||
std::unique_ptr<AlloyRenderThreadObserver> observer_;
|
||||
std::unique_ptr<web_cache::WebCacheImpl> web_cache_impl_;
|
||||
std::unique_ptr<SpellCheck> spellcheck_;
|
||||
std::unique_ptr<visitedlink::VisitedLinkReader> visited_link_slave_;
|
||||
|
||||
std::unique_ptr<extensions::ExtensionsClient> extensions_client_;
|
||||
std::unique_ptr<extensions::CefExtensionsRendererClient>
|
||||
extensions_renderer_client_;
|
||||
|
||||
// Used in single-process mode to test when cleanup is complete.
|
||||
// Access must be protected by |single_process_cleanup_lock_|.
|
||||
bool single_process_cleanup_complete_ = false;
|
||||
base::Lock single_process_cleanup_lock_;
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_RENDERER_ALLOY_ALLOY_CONTENT_RENDERER_CLIENT_H_
|
@@ -1,21 +0,0 @@
|
||||
// Copyright 2014 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 "cef/libcef/renderer/alloy/alloy_render_frame_observer.h"
|
||||
|
||||
AlloyRenderFrameObserver::AlloyRenderFrameObserver(
|
||||
content::RenderFrame* render_frame)
|
||||
: CefRenderFrameObserver(render_frame) {}
|
||||
|
||||
void AlloyRenderFrameObserver::OnInterfaceRequestForFrame(
|
||||
const std::string& interface_name,
|
||||
mojo::ScopedMessagePipeHandle* interface_pipe) {
|
||||
registry_.TryBindInterface(interface_name, interface_pipe);
|
||||
}
|
||||
|
||||
bool AlloyRenderFrameObserver::OnAssociatedInterfaceRequestForFrame(
|
||||
const std::string& interface_name,
|
||||
mojo::ScopedInterfaceEndpointHandle* handle) {
|
||||
return associated_interfaces_.TryBindInterface(interface_name, handle);
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
// Copyright 2014 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 LIBCEF_RENDERER_ALLOY_ALLOY_RENDER_FRAME_OBSERVER_H_
|
||||
#define LIBCEF_RENDERER_ALLOY_ALLOY_RENDER_FRAME_OBSERVER_H_
|
||||
|
||||
#include "cef/libcef/renderer/render_frame_observer.h"
|
||||
#include "services/service_manager/public/cpp/binder_registry.h"
|
||||
#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
|
||||
|
||||
class AlloyRenderFrameObserver : public CefRenderFrameObserver {
|
||||
public:
|
||||
explicit AlloyRenderFrameObserver(content::RenderFrame* render_frame);
|
||||
|
||||
AlloyRenderFrameObserver(const AlloyRenderFrameObserver&) = delete;
|
||||
AlloyRenderFrameObserver& operator=(const AlloyRenderFrameObserver&) = delete;
|
||||
|
||||
// RenderFrameObserver methods:
|
||||
void OnInterfaceRequestForFrame(
|
||||
const std::string& interface_name,
|
||||
mojo::ScopedMessagePipeHandle* interface_pipe) override;
|
||||
bool OnAssociatedInterfaceRequestForFrame(
|
||||
const std::string& interface_name,
|
||||
mojo::ScopedInterfaceEndpointHandle* handle) override;
|
||||
|
||||
service_manager::BinderRegistry* registry() { return ®istry_; }
|
||||
blink::AssociatedInterfaceRegistry* associated_interfaces() {
|
||||
return &associated_interfaces_;
|
||||
}
|
||||
|
||||
private:
|
||||
service_manager::BinderRegistry registry_;
|
||||
|
||||
// For interfaces which must be associated with some IPC::ChannelProxy,
|
||||
// meaning that messages on the interface retain FIFO with respect to legacy
|
||||
// Chrome IPC messages sent or dispatched on the channel.
|
||||
blink::AssociatedInterfaceRegistry associated_interfaces_;
|
||||
};
|
||||
|
||||
#endif // LIBCEF_RENDERER_ALLOY_ALLOY_RENDER_FRAME_OBSERVER_H_
|
@@ -1,67 +0,0 @@
|
||||
/// Copyright (c) 2013 The Chromium Embedded Framework Authors.
|
||||
// Portions (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 "cef/libcef/renderer/alloy/alloy_render_thread_observer.h"
|
||||
|
||||
#include "base/no_destructor.h"
|
||||
#include "cef/libcef/common/net/net_resource_provider.h"
|
||||
#include "chrome/common/renderer_configuration.mojom.h"
|
||||
#include "net/base/net_module.h"
|
||||
#include "services/service_manager/public/cpp/connector.h"
|
||||
#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
|
||||
|
||||
AlloyRenderThreadObserver::AlloyRenderThreadObserver() {
|
||||
net::NetModule::SetResourceProvider(NetResourceProvider);
|
||||
}
|
||||
|
||||
AlloyRenderThreadObserver::~AlloyRenderThreadObserver() = default;
|
||||
|
||||
chrome::mojom::DynamicParamsPtr AlloyRenderThreadObserver::GetDynamicParams()
|
||||
const {
|
||||
{
|
||||
base::AutoLock lock(dynamic_params_lock_);
|
||||
if (dynamic_params_) {
|
||||
return dynamic_params_.Clone();
|
||||
}
|
||||
}
|
||||
return chrome::mojom::DynamicParams::New();
|
||||
}
|
||||
|
||||
void AlloyRenderThreadObserver::RegisterMojoInterfaces(
|
||||
blink::AssociatedInterfaceRegistry* associated_interfaces) {
|
||||
associated_interfaces->AddInterface<chrome::mojom::RendererConfiguration>(
|
||||
base::BindRepeating(
|
||||
&AlloyRenderThreadObserver::OnRendererConfigurationAssociatedRequest,
|
||||
base::Unretained(this)));
|
||||
}
|
||||
|
||||
void AlloyRenderThreadObserver::UnregisterMojoInterfaces(
|
||||
blink::AssociatedInterfaceRegistry* associated_interfaces) {
|
||||
associated_interfaces->RemoveInterface(
|
||||
chrome::mojom::RendererConfiguration::Name_);
|
||||
}
|
||||
|
||||
void AlloyRenderThreadObserver::SetInitialConfiguration(
|
||||
bool is_incognito_process,
|
||||
mojo::PendingReceiver<chrome::mojom::ChromeOSListener>
|
||||
chromeos_listener_receiver,
|
||||
mojo::PendingRemote<content_settings::mojom::ContentSettingsManager>
|
||||
content_settings_manager,
|
||||
mojo::PendingRemote<chrome::mojom::BoundSessionRequestThrottledHandler>
|
||||
bound_session_request_throttled_handler) {
|
||||
is_incognito_process_ = is_incognito_process;
|
||||
}
|
||||
|
||||
void AlloyRenderThreadObserver::SetConfiguration(
|
||||
chrome::mojom::DynamicParamsPtr params) {
|
||||
base::AutoLock lock(dynamic_params_lock_);
|
||||
dynamic_params_ = std::move(params);
|
||||
}
|
||||
|
||||
void AlloyRenderThreadObserver::OnRendererConfigurationAssociatedRequest(
|
||||
mojo::PendingAssociatedReceiver<chrome::mojom::RendererConfiguration>
|
||||
receiver) {
|
||||
renderer_configuration_receivers_.Add(this, std::move(receiver));
|
||||
}
|
@@ -1,68 +0,0 @@
|
||||
// Copyright (c) 2013 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.
|
||||
|
||||
#ifndef CEF_LIBCEF_RENDERER_ALLOY_ALLOY_RENDER_THREAD_OBSERVER_H_
|
||||
#define CEF_LIBCEF_RENDERER_ALLOY_ALLOY_RENDER_THREAD_OBSERVER_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "base/synchronization/lock.h"
|
||||
#include "base/thread_annotations.h"
|
||||
#include "chrome/common/renderer_configuration.mojom.h"
|
||||
#include "components/content_settings/core/common/content_settings.h"
|
||||
#include "content/public/renderer/render_thread_observer.h"
|
||||
#include "mojo/public/cpp/bindings/associated_receiver_set.h"
|
||||
|
||||
// This class sends and receives control messages in the renderer process.
|
||||
class AlloyRenderThreadObserver : public content::RenderThreadObserver,
|
||||
public chrome::mojom::RendererConfiguration {
|
||||
public:
|
||||
AlloyRenderThreadObserver();
|
||||
|
||||
AlloyRenderThreadObserver(const AlloyRenderThreadObserver&) = delete;
|
||||
AlloyRenderThreadObserver& operator=(const AlloyRenderThreadObserver&) =
|
||||
delete;
|
||||
|
||||
~AlloyRenderThreadObserver() override;
|
||||
|
||||
bool IsIncognitoProcess() const { return is_incognito_process_; }
|
||||
|
||||
// Return a copy of the dynamic parameters - those that may change while the
|
||||
// render process is running.
|
||||
chrome::mojom::DynamicParamsPtr GetDynamicParams() const;
|
||||
|
||||
private:
|
||||
// content::RenderThreadObserver:
|
||||
void RegisterMojoInterfaces(
|
||||
blink::AssociatedInterfaceRegistry* associated_interfaces) override;
|
||||
void UnregisterMojoInterfaces(
|
||||
blink::AssociatedInterfaceRegistry* associated_interfaces) override;
|
||||
|
||||
// chrome::mojom::RendererConfiguration:
|
||||
void SetInitialConfiguration(
|
||||
bool is_incognito_process,
|
||||
mojo::PendingReceiver<chrome::mojom::ChromeOSListener>
|
||||
chromeos_listener_receiver,
|
||||
mojo::PendingRemote<content_settings::mojom::ContentSettingsManager>
|
||||
content_settings_manager,
|
||||
mojo::PendingRemote<chrome::mojom::BoundSessionRequestThrottledHandler>
|
||||
bound_session_request_throttled_handler) override;
|
||||
void SetConfiguration(chrome::mojom::DynamicParamsPtr params) override;
|
||||
|
||||
void OnRendererConfigurationAssociatedRequest(
|
||||
mojo::PendingAssociatedReceiver<chrome::mojom::RendererConfiguration>
|
||||
receiver);
|
||||
|
||||
bool is_incognito_process_ = false;
|
||||
|
||||
mojo::AssociatedReceiverSet<chrome::mojom::RendererConfiguration>
|
||||
renderer_configuration_receivers_;
|
||||
|
||||
chrome::mojom::DynamicParamsPtr dynamic_params_
|
||||
GUARDED_BY(dynamic_params_lock_);
|
||||
mutable base::Lock dynamic_params_lock_;
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_RENDERER_ALLOY_ALLOY_RENDER_THREAD_OBSERVER_H_
|
@@ -1,71 +0,0 @@
|
||||
// Copyright 2018 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 "cef/libcef/renderer/alloy/url_loader_throttle_provider_impl.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "base/feature_list.h"
|
||||
#include "cef/libcef/common/extensions/extensions_util.h"
|
||||
#include "cef/libcef/renderer/alloy/alloy_content_renderer_client.h"
|
||||
#include "cef/libcef/renderer/alloy/alloy_render_thread_observer.h"
|
||||
#include "chrome/common/google_url_loader_throttle.h"
|
||||
#include "components/signin/public/base/signin_buildflags.h"
|
||||
#include "content/public/common/content_features.h"
|
||||
#include "content/public/renderer/render_frame.h"
|
||||
#include "services/network/public/cpp/features.h"
|
||||
#include "third_party/blink/public/common/loader/resource_type_util.h"
|
||||
#include "third_party/blink/public/platform/web_url.h"
|
||||
|
||||
CefURLLoaderThrottleProviderImpl::CefURLLoaderThrottleProviderImpl(
|
||||
blink::URLLoaderThrottleProviderType type,
|
||||
AlloyContentRendererClient* alloy_content_renderer_client)
|
||||
: type_(type),
|
||||
alloy_content_renderer_client_(alloy_content_renderer_client) {
|
||||
DETACH_FROM_SEQUENCE(sequence_checker_);
|
||||
}
|
||||
|
||||
CefURLLoaderThrottleProviderImpl::~CefURLLoaderThrottleProviderImpl() {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
}
|
||||
|
||||
CefURLLoaderThrottleProviderImpl::CefURLLoaderThrottleProviderImpl(
|
||||
const CefURLLoaderThrottleProviderImpl& other)
|
||||
: type_(other.type_),
|
||||
alloy_content_renderer_client_(other.alloy_content_renderer_client_) {
|
||||
DETACH_FROM_SEQUENCE(sequence_checker_);
|
||||
}
|
||||
|
||||
std::unique_ptr<blink::URLLoaderThrottleProvider>
|
||||
CefURLLoaderThrottleProviderImpl::Clone() {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
return base::WrapUnique(new CefURLLoaderThrottleProviderImpl(*this));
|
||||
}
|
||||
|
||||
blink::WebVector<std::unique_ptr<blink::URLLoaderThrottle>>
|
||||
CefURLLoaderThrottleProviderImpl::CreateThrottles(
|
||||
base::optional_ref<const blink::LocalFrameToken> local_frame_token,
|
||||
const network::ResourceRequest& request) {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
|
||||
blink::WebVector<std::unique_ptr<blink::URLLoaderThrottle>> throttles;
|
||||
|
||||
// Some throttles have already been added in the browser for frame resources.
|
||||
// Don't add them for frame requests.
|
||||
bool is_frame_resource =
|
||||
blink::IsRequestDestinationFrame(request.destination);
|
||||
|
||||
DCHECK(!is_frame_resource ||
|
||||
type_ == blink::URLLoaderThrottleProviderType::kFrame);
|
||||
|
||||
throttles.emplace_back(std::make_unique<GoogleURLLoaderThrottle>(
|
||||
#if BUILDFLAG(ENABLE_BOUND_SESSION_CREDENTIALS)
|
||||
/*bound_session_request_throttled_listener=*/nullptr,
|
||||
#endif
|
||||
alloy_content_renderer_client_->GetAlloyObserver()->GetDynamicParams()));
|
||||
|
||||
return throttles;
|
||||
}
|
||||
|
||||
void CefURLLoaderThrottleProviderImpl::SetOnline(bool is_online) {}
|
@@ -1,49 +0,0 @@
|
||||
// Copyright 2018 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.
|
||||
|
||||
#ifndef CEF_LIBCEF_RENDERER_ALLOY_URL_LOADER_THROTTLE_PROVIDER_IMPL_H_
|
||||
#define CEF_LIBCEF_RENDERER_ALLOY_URL_LOADER_THROTTLE_PROVIDER_IMPL_H_
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "base/sequence_checker.h"
|
||||
#include "third_party/blink/public/platform/url_loader_throttle_provider.h"
|
||||
|
||||
class AlloyContentRendererClient;
|
||||
|
||||
// Instances must be constructed on the render thread, and then used and
|
||||
// destructed on a single thread, which can be different from the render thread.
|
||||
class CefURLLoaderThrottleProviderImpl
|
||||
: public blink::URLLoaderThrottleProvider {
|
||||
public:
|
||||
CefURLLoaderThrottleProviderImpl(
|
||||
blink::URLLoaderThrottleProviderType type,
|
||||
AlloyContentRendererClient* alloy_content_renderer_client);
|
||||
|
||||
CefURLLoaderThrottleProviderImpl& operator=(
|
||||
const CefURLLoaderThrottleProviderImpl&) = delete;
|
||||
|
||||
~CefURLLoaderThrottleProviderImpl() override;
|
||||
|
||||
// blink::URLLoaderThrottleProvider implementation.
|
||||
std::unique_ptr<blink::URLLoaderThrottleProvider> Clone() override;
|
||||
blink::WebVector<std::unique_ptr<blink::URLLoaderThrottle>> CreateThrottles(
|
||||
base::optional_ref<const blink::LocalFrameToken> local_frame_token,
|
||||
const network::ResourceRequest& request) override;
|
||||
void SetOnline(bool is_online) override;
|
||||
|
||||
private:
|
||||
// This copy constructor works in conjunction with Clone(), not intended for
|
||||
// general use.
|
||||
CefURLLoaderThrottleProviderImpl(
|
||||
const CefURLLoaderThrottleProviderImpl& other);
|
||||
|
||||
blink::URLLoaderThrottleProviderType type_;
|
||||
AlloyContentRendererClient* const alloy_content_renderer_client_;
|
||||
|
||||
SEQUENCE_CHECKER(sequence_checker_);
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_RENDERER_ALLOY_URL_LOADER_THROTTLE_PROVIDER_IMPL_H_
|
@@ -1,32 +0,0 @@
|
||||
// Copyright 2024 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "cef/libcef/renderer/extensions/extensions_renderer_api_provider.h"
|
||||
|
||||
#include "extensions/renderer/module_system.h"
|
||||
#include "extensions/renderer/script_context.h"
|
||||
|
||||
namespace extensions {
|
||||
|
||||
void CefExtensionsRendererAPIProvider::RegisterNativeHandlers(
|
||||
ModuleSystem* module_system,
|
||||
NativeExtensionBindingsSystem* bindings_system,
|
||||
V8SchemaRegistry* v8_schema_registry,
|
||||
ScriptContext* context) const {}
|
||||
|
||||
void CefExtensionsRendererAPIProvider::AddBindingsSystemHooks(
|
||||
Dispatcher* dispatcher,
|
||||
NativeExtensionBindingsSystem* bindings_system) const {}
|
||||
|
||||
void CefExtensionsRendererAPIProvider::PopulateSourceMap(
|
||||
ResourceBundleSourceMap* source_map) const {}
|
||||
|
||||
void CefExtensionsRendererAPIProvider::EnableCustomElementAllowlist() const {}
|
||||
|
||||
void CefExtensionsRendererAPIProvider::RequireWebViewModules(
|
||||
ScriptContext* context) const {
|
||||
context->module_system()->Require("extensionsWebViewElement");
|
||||
}
|
||||
|
||||
} // namespace extensions
|
@@ -1,37 +0,0 @@
|
||||
// Copyright 2024 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef CEF_LIBCEF_BROWSER_EXTENSIONS_EXTENSIONS_RENDERER_API_PROVIDER_H_
|
||||
#define CEF_LIBCEF_BROWSER_EXTENSIONS_EXTENSIONS_RENDERER_API_PROVIDER_H_
|
||||
|
||||
#include "extensions/renderer/extensions_renderer_api_provider.h"
|
||||
|
||||
namespace extensions {
|
||||
|
||||
// Provides capabilities for the set of extension APIs defined for the
|
||||
// extensions shell.
|
||||
class CefExtensionsRendererAPIProvider : public ExtensionsRendererAPIProvider {
|
||||
public:
|
||||
CefExtensionsRendererAPIProvider() = default;
|
||||
CefExtensionsRendererAPIProvider(const CefExtensionsRendererAPIProvider&) =
|
||||
delete;
|
||||
CefExtensionsRendererAPIProvider& operator=(
|
||||
const CefExtensionsRendererAPIProvider&) = delete;
|
||||
~CefExtensionsRendererAPIProvider() override = default;
|
||||
|
||||
void RegisterNativeHandlers(ModuleSystem* module_system,
|
||||
NativeExtensionBindingsSystem* bindings_system,
|
||||
V8SchemaRegistry* v8_schema_registry,
|
||||
ScriptContext* context) const override;
|
||||
void AddBindingsSystemHooks(
|
||||
Dispatcher* dispatcher,
|
||||
NativeExtensionBindingsSystem* bindings_system) const override;
|
||||
void PopulateSourceMap(ResourceBundleSourceMap* source_map) const override;
|
||||
void EnableCustomElementAllowlist() const override;
|
||||
void RequireWebViewModules(ScriptContext* context) const override;
|
||||
};
|
||||
|
||||
} // namespace extensions
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_EXTENSIONS_EXTENSIONS_RENDERER_API_PROVIDER_H_
|
@@ -1,152 +0,0 @@
|
||||
// Copyright 2014 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 "cef/libcef/renderer/extensions/extensions_renderer_client.h"
|
||||
|
||||
#include "base/stl_util.h"
|
||||
#include "cef/libcef/renderer/alloy/alloy_content_renderer_client.h"
|
||||
#include "cef/libcef/renderer/alloy/alloy_render_thread_observer.h"
|
||||
#include "cef/libcef/renderer/extensions/extensions_renderer_api_provider.h"
|
||||
#include "chrome/common/url_constants.h"
|
||||
#include "chrome/renderer/extensions/resource_request_policy.h"
|
||||
#include "content/public/common/content_constants.h"
|
||||
#include "content/public/renderer/render_frame.h"
|
||||
#include "content/public/renderer/render_thread.h"
|
||||
#include "extensions/common/constants.h"
|
||||
#include "extensions/common/permissions/permissions_data.h"
|
||||
#include "extensions/renderer/api/core_extensions_renderer_api_provider.h"
|
||||
#include "extensions/renderer/dispatcher.h"
|
||||
#include "extensions/renderer/extension_frame_helper.h"
|
||||
#include "extensions/renderer/extensions_render_frame_observer.h"
|
||||
#include "extensions/renderer/extensions_renderer_api_provider.h"
|
||||
#include "extensions/renderer/renderer_extension_registry.h"
|
||||
#include "extensions/renderer/script_context.h"
|
||||
#include "third_party/blink/public/web/web_document.h"
|
||||
#include "third_party/blink/public/web/web_local_frame.h"
|
||||
#include "third_party/blink/public/web/web_plugin_params.h"
|
||||
|
||||
namespace extensions {
|
||||
|
||||
namespace {
|
||||
|
||||
void IsGuestViewApiAvailableToScriptContext(
|
||||
bool* api_is_available,
|
||||
extensions::ScriptContext* context) {
|
||||
if (context->GetAvailability("guestViewInternal").is_available()) {
|
||||
*api_is_available = true;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
CefExtensionsRendererClient::CefExtensionsRendererClient(
|
||||
AlloyContentRendererClient* alloy_content_renderer_client)
|
||||
: alloy_content_renderer_client_(alloy_content_renderer_client) {
|
||||
AddAPIProvider(std::make_unique<CoreExtensionsRendererAPIProvider>());
|
||||
AddAPIProvider(std::make_unique<CefExtensionsRendererAPIProvider>());
|
||||
}
|
||||
|
||||
CefExtensionsRendererClient::~CefExtensionsRendererClient() = default;
|
||||
|
||||
bool CefExtensionsRendererClient::IsIncognitoProcess() const {
|
||||
return alloy_content_renderer_client_->GetAlloyObserver()
|
||||
->IsIncognitoProcess();
|
||||
}
|
||||
|
||||
int CefExtensionsRendererClient::GetLowestIsolatedWorldId() const {
|
||||
// CEF doesn't need to reserve world IDs for anything other than extensions,
|
||||
// so we always return 1. Note that 0 is reserved for the global world.
|
||||
return 1;
|
||||
}
|
||||
|
||||
extensions::Dispatcher* CefExtensionsRendererClient::GetDispatcher() {
|
||||
return extension_dispatcher_.get();
|
||||
}
|
||||
|
||||
void CefExtensionsRendererClient::OnExtensionLoaded(
|
||||
const extensions::Extension& extension) {
|
||||
resource_request_policy_->OnExtensionLoaded(extension);
|
||||
}
|
||||
|
||||
void CefExtensionsRendererClient::OnExtensionUnloaded(
|
||||
const extensions::ExtensionId& extension_id) {
|
||||
resource_request_policy_->OnExtensionUnloaded(extension_id);
|
||||
}
|
||||
|
||||
bool CefExtensionsRendererClient::ExtensionAPIEnabledForServiceWorkerScript(
|
||||
const GURL& scope,
|
||||
const GURL& script_url) const {
|
||||
// TODO(extensions): Implement to support background sevice worker scripts
|
||||
// in extensions
|
||||
return false;
|
||||
}
|
||||
|
||||
void CefExtensionsRendererClient::RenderThreadStarted() {
|
||||
content::RenderThread* thread = content::RenderThread::Get();
|
||||
|
||||
extension_dispatcher_ =
|
||||
std::make_unique<extensions::Dispatcher>(std::move(api_providers_));
|
||||
extension_dispatcher_->OnRenderThreadStarted(thread);
|
||||
resource_request_policy_ =
|
||||
std::make_unique<extensions::ResourceRequestPolicy>(
|
||||
extension_dispatcher_.get());
|
||||
|
||||
thread->AddObserver(extension_dispatcher_.get());
|
||||
}
|
||||
|
||||
void CefExtensionsRendererClient::RenderFrameCreated(
|
||||
content::RenderFrame* render_frame,
|
||||
service_manager::BinderRegistry* registry) {
|
||||
new extensions::ExtensionsRenderFrameObserver(render_frame, registry);
|
||||
new extensions::ExtensionFrameHelper(render_frame,
|
||||
extension_dispatcher_.get());
|
||||
extension_dispatcher_->OnRenderFrameCreated(render_frame);
|
||||
}
|
||||
|
||||
bool CefExtensionsRendererClient::OverrideCreatePlugin(
|
||||
content::RenderFrame* render_frame,
|
||||
const blink::WebPluginParams& params) {
|
||||
if (params.mime_type.Utf8() != content::kBrowserPluginMimeType) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool guest_view_api_available = false;
|
||||
extension_dispatcher_->script_context_set_iterator()->ForEach(
|
||||
render_frame, base::BindRepeating(&IsGuestViewApiAvailableToScriptContext,
|
||||
&guest_view_api_available));
|
||||
return !guest_view_api_available;
|
||||
}
|
||||
|
||||
void CefExtensionsRendererClient::WillSendRequest(
|
||||
blink::WebLocalFrame* frame,
|
||||
ui::PageTransition transition_type,
|
||||
const blink::WebURL& url,
|
||||
const net::SiteForCookies& site_for_cookies,
|
||||
const url::Origin* initiator_origin,
|
||||
GURL* new_url) {
|
||||
// Check whether the request should be allowed. If not allowed, we reset the
|
||||
// URL to something invalid to prevent the request and cause an error.
|
||||
if (url.ProtocolIs(extensions::kExtensionScheme) &&
|
||||
!resource_request_policy_->CanRequestResource(
|
||||
GURL(url), frame, transition_type, initiator_origin)) {
|
||||
*new_url = GURL(chrome::kExtensionInvalidRequestURL);
|
||||
}
|
||||
}
|
||||
|
||||
void CefExtensionsRendererClient::RunScriptsAtDocumentStart(
|
||||
content::RenderFrame* render_frame) {
|
||||
extension_dispatcher_->RunScriptsAtDocumentStart(render_frame);
|
||||
}
|
||||
|
||||
void CefExtensionsRendererClient::RunScriptsAtDocumentEnd(
|
||||
content::RenderFrame* render_frame) {
|
||||
extension_dispatcher_->RunScriptsAtDocumentEnd(render_frame);
|
||||
}
|
||||
|
||||
void CefExtensionsRendererClient::RunScriptsAtDocumentIdle(
|
||||
content::RenderFrame* render_frame) {
|
||||
extension_dispatcher_->RunScriptsAtDocumentIdle(render_frame);
|
||||
}
|
||||
|
||||
} // namespace extensions
|
@@ -1,91 +0,0 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
#ifndef CEF_LIBCEF_RENDERER_EXTENSIONS_EXTENSIONS_RENDERER_CLIENT_H_
|
||||
#define CEF_LIBCEF_RENDERER_EXTENSIONS_EXTENSIONS_RENDERER_CLIENT_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "extensions/renderer/extensions_renderer_client.h"
|
||||
#include "services/service_manager/public/cpp/binder_registry.h"
|
||||
#include "ui/base/page_transition_types.h"
|
||||
|
||||
class AlloyContentRendererClient;
|
||||
class GURL;
|
||||
|
||||
namespace blink {
|
||||
class WebFrame;
|
||||
class WebLocalFrame;
|
||||
struct WebPluginParams;
|
||||
class WebURL;
|
||||
} // namespace blink
|
||||
|
||||
namespace net {
|
||||
class SiteForCookies;
|
||||
}
|
||||
|
||||
namespace content {
|
||||
class BrowserPluginDelegate;
|
||||
class RenderFrame;
|
||||
struct WebPluginInfo;
|
||||
} // namespace content
|
||||
|
||||
namespace url {
|
||||
class Origin;
|
||||
}
|
||||
|
||||
namespace extensions {
|
||||
|
||||
class Dispatcher;
|
||||
class ResourceRequestPolicy;
|
||||
|
||||
class CefExtensionsRendererClient : public ExtensionsRendererClient {
|
||||
public:
|
||||
explicit CefExtensionsRendererClient(
|
||||
AlloyContentRendererClient* alloy_content_renderer_client);
|
||||
|
||||
CefExtensionsRendererClient(const CefExtensionsRendererClient&) = delete;
|
||||
CefExtensionsRendererClient& operator=(const CefExtensionsRendererClient&) =
|
||||
delete;
|
||||
|
||||
~CefExtensionsRendererClient() override;
|
||||
|
||||
// ExtensionsRendererClient implementation.
|
||||
void RenderThreadStarted() override;
|
||||
bool IsIncognitoProcess() const override;
|
||||
int GetLowestIsolatedWorldId() const override;
|
||||
extensions::Dispatcher* GetDispatcher() override;
|
||||
void OnExtensionLoaded(const extensions::Extension& extension) override;
|
||||
void OnExtensionUnloaded(
|
||||
const extensions::ExtensionId& extension_id) override;
|
||||
bool ExtensionAPIEnabledForServiceWorkerScript(
|
||||
const GURL& scope,
|
||||
const GURL& script_url) const override;
|
||||
|
||||
// See AlloyContentRendererClient methods with the same names.
|
||||
void RenderFrameCreated(content::RenderFrame* render_frame,
|
||||
service_manager::BinderRegistry* registry);
|
||||
bool OverrideCreatePlugin(content::RenderFrame* render_frame,
|
||||
const blink::WebPluginParams& params);
|
||||
void WillSendRequest(blink::WebLocalFrame* frame,
|
||||
ui::PageTransition transition_type,
|
||||
const blink::WebURL& url,
|
||||
const net::SiteForCookies& site_for_cookies,
|
||||
const url::Origin* initiator_origin,
|
||||
GURL* new_url);
|
||||
void RunScriptsAtDocumentStart(content::RenderFrame* render_frame);
|
||||
void RunScriptsAtDocumentEnd(content::RenderFrame* render_frame);
|
||||
void RunScriptsAtDocumentIdle(content::RenderFrame* render_frame);
|
||||
|
||||
private:
|
||||
AlloyContentRendererClient* const alloy_content_renderer_client_;
|
||||
|
||||
std::unique_ptr<extensions::Dispatcher> extension_dispatcher_;
|
||||
std::unique_ptr<extensions::ResourceRequestPolicy> resource_request_policy_;
|
||||
};
|
||||
|
||||
} // namespace extensions
|
||||
|
||||
#endif // CEF_LIBCEF_RENDERER_EXTENSIONS_EXTENSIONS_RENDERER_CLIENT_H_
|
Reference in New Issue
Block a user