2013-01-03 18:24:24 +01:00
|
|
|
// Copyright (c) 2013 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright (c) 2012 The Chromium Authors. All rights reserved.
|
2012-04-03 03:34:16 +02:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
#include "libcef/renderer/alloy/alloy_content_renderer_client.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
#include <utility>
|
|
|
|
|
2022-02-21 23:23:40 +01:00
|
|
|
#include "build/build_config.h"
|
2016-03-16 03:55:59 +01:00
|
|
|
|
2018-10-02 14:14:11 +02:00
|
|
|
// Enable deprecation warnings on Windows. See http://crbug.com/585142.
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2018-10-02 14:14:11 +02:00
|
|
|
#if defined(__clang__)
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic error "-Wdeprecated-declarations"
|
|
|
|
#else
|
2016-03-16 03:55:59 +01:00
|
|
|
#pragma warning(push)
|
2017-05-17 11:29:28 +02:00
|
|
|
#pragma warning(default : 4996)
|
2016-03-16 03:55:59 +01:00
|
|
|
#endif
|
2018-10-02 14:14:11 +02:00
|
|
|
#endif
|
2016-03-16 03:55:59 +01:00
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
#include "libcef/browser/alloy/alloy_content_browser_client.h"
|
2013-02-02 01:21:59 +01:00
|
|
|
#include "libcef/browser/context.h"
|
2020-06-28 20:29:44 +02:00
|
|
|
#include "libcef/common/alloy/alloy_content_client.h"
|
2020-06-28 23:05:36 +02:00
|
|
|
#include "libcef/common/app_manager.h"
|
2012-12-31 11:41:15 +01:00
|
|
|
#include "libcef/common/cef_switches.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "libcef/common/extensions/extensions_client.h"
|
|
|
|
#include "libcef/common/extensions/extensions_util.h"
|
2013-11-21 21:59:28 +01:00
|
|
|
#include "libcef/common/request_impl.h"
|
2020-06-28 23:05:36 +02:00
|
|
|
#include "libcef/features/runtime_checks.h"
|
2020-09-25 03:40:47 +02:00
|
|
|
#include "libcef/renderer/alloy/alloy_render_thread_observer.h"
|
|
|
|
#include "libcef/renderer/alloy/url_loader_throttle_provider_impl.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/renderer/browser_impl.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "libcef/renderer/extensions/extensions_renderer_client.h"
|
2017-09-06 23:40:58 +02:00
|
|
|
#include "libcef/renderer/extensions/print_render_frame_helper_delegate.h"
|
2021-05-14 18:58:55 +02:00
|
|
|
#include "libcef/renderer/render_frame_observer.h"
|
|
|
|
#include "libcef/renderer/render_manager.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/renderer/thread_util.h"
|
|
|
|
|
2012-12-31 11:41:15 +01:00
|
|
|
#include "base/command_line.h"
|
2016-04-27 22:38:52 +02:00
|
|
|
#include "base/memory/ptr_util.h"
|
2015-09-09 16:05:39 +02:00
|
|
|
#include "base/metrics/user_metrics_action.h"
|
2012-12-31 11:41:15 +01:00
|
|
|
#include "base/path_service.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "base/stl_util.h"
|
2014-04-04 18:50:38 +02:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2016-01-06 20:20:54 +01:00
|
|
|
#include "build/build_config.h"
|
2015-09-09 16:05:39 +02:00
|
|
|
#include "chrome/common/chrome_switches.h"
|
2021-11-23 21:28:12 +01:00
|
|
|
#include "chrome/common/pdf_util.h"
|
2015-10-12 20:13:13 +02:00
|
|
|
#include "chrome/common/url_constants.h"
|
2020-02-10 18:10:17 +01:00
|
|
|
#include "chrome/renderer/browser_exposed_renderer_interfaces.h"
|
2017-12-07 22:44:24 +01:00
|
|
|
#include "chrome/renderer/chrome_content_renderer_client.h"
|
2019-07-24 23:12:00 +02:00
|
|
|
#include "chrome/renderer/extensions/chrome_extensions_renderer_client.h"
|
2013-04-04 20:10:17 +02:00
|
|
|
#include "chrome/renderer/loadtimes_extension_bindings.h"
|
2022-03-26 02:12:30 +01:00
|
|
|
#include "chrome/renderer/media/chrome_key_systems.h"
|
2017-12-07 22:44:24 +01:00
|
|
|
#include "chrome/renderer/plugins/chrome_plugin_placeholder.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "components/content_settings/core/common/content_settings_types.h"
|
2015-09-09 16:05:39 +02:00
|
|
|
#include "components/nacl/common/nacl_constants.h"
|
2021-11-23 21:28:12 +01:00
|
|
|
#include "components/pdf/common/internal_plugin_helpers.h"
|
|
|
|
#include "components/pdf/renderer/internal_plugin_renderer_helpers.h"
|
2017-09-06 23:40:58 +02:00
|
|
|
#include "components/printing/renderer/print_render_frame_helper.h"
|
2016-08-31 13:25:56 +02:00
|
|
|
#include "components/spellcheck/renderer/spellcheck.h"
|
|
|
|
#include "components/spellcheck/renderer/spellcheck_provider.h"
|
2020-02-10 18:10:17 +01:00
|
|
|
#include "components/visitedlink/renderer/visitedlink_reader.h"
|
2016-05-25 01:35:43 +02:00
|
|
|
#include "components/web_cache/renderer/web_cache_impl.h"
|
2018-10-02 14:14:11 +02:00
|
|
|
#include "content/public/browser/browser_task_traits.h"
|
2013-02-02 01:21:59 +01:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
|
|
|
#include "content/public/browser/render_process_host.h"
|
2015-03-04 02:00:13 +01:00
|
|
|
#include "content/public/child/child_thread.h"
|
2013-06-24 18:40:40 +02:00
|
|
|
#include "content/public/common/content_constants.h"
|
2014-01-14 18:37:02 +01:00
|
|
|
#include "content/public/common/content_paths.h"
|
2015-11-10 21:18:16 +01:00
|
|
|
#include "content/public/common/content_switches.h"
|
2020-02-10 18:10:17 +01:00
|
|
|
#include "content/public/common/url_constants.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "content/public/renderer/render_view.h"
|
2014-10-07 22:44:33 +02:00
|
|
|
#include "content/public/renderer/render_view_visitor.h"
|
2022-02-21 23:23:40 +01:00
|
|
|
#include "extensions/common/manifest_handlers/csp_info.h"
|
2017-09-06 23:40:58 +02:00
|
|
|
#include "extensions/common/switches.h"
|
2020-01-23 22:58:01 +01:00
|
|
|
#include "extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container_manager.h"
|
2015-11-10 21:18:16 +01:00
|
|
|
#include "extensions/renderer/renderer_extension_registry.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "ipc/ipc_sync_channel.h"
|
2012-12-31 11:41:15 +01:00
|
|
|
#include "media/base/media.h"
|
2020-02-10 18:10:17 +01:00
|
|
|
#include "mojo/public/cpp/bindings/binder_map.h"
|
2019-10-01 15:55:16 +02:00
|
|
|
#include "mojo/public/cpp/bindings/generic_pending_receiver.h"
|
2015-12-09 17:10:16 +01:00
|
|
|
#include "printing/print_settings.h"
|
2019-04-16 16:38:48 +02:00
|
|
|
#include "services/network/public/cpp/is_potentially_trustworthy.h"
|
2017-12-07 22:44:24 +01:00
|
|
|
#include "services/service_manager/public/cpp/connector.h"
|
|
|
|
#include "services/service_manager/public/cpp/interface_provider.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
|
2020-01-23 22:58:01 +01:00
|
|
|
#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
|
2018-11-30 23:21:07 +01:00
|
|
|
#include "third_party/blink/public/platform/scheduler/web_renderer_process_type.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#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"
|
2022-06-17 15:28:55 +02:00
|
|
|
#include "third_party/blink/public/web/web_script_controller.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "third_party/blink/public/web/web_security_policy.h"
|
|
|
|
#include "third_party/blink/public/web/web_view.h"
|
2020-09-02 21:06:45 +02:00
|
|
|
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
|
2015-09-09 16:05:39 +02:00
|
|
|
#include "ui/base/l10n/l10n_util.h"
|
2012-04-24 20:01:48 +02:00
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2015-04-08 15:16:17 +02:00
|
|
|
#include "base/mac/mac_util.h"
|
|
|
|
#include "base/strings/sys_string_conversions.h"
|
|
|
|
#endif
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
AlloyContentRendererClient::AlloyContentRendererClient()
|
2018-03-20 21:15:08 +01:00
|
|
|
: main_entry_time_(base::TimeTicks::Now()),
|
2021-05-14 18:58:55 +02:00
|
|
|
render_manager_(new CefRenderManager) {
|
2015-11-10 21:18:16 +01:00
|
|
|
if (extensions::ExtensionsEnabled()) {
|
|
|
|
extensions_client_.reset(new extensions::CefExtensionsClient);
|
|
|
|
extensions::ExtensionsClient::Set(extensions_client_.get());
|
|
|
|
extensions_renderer_client_.reset(
|
|
|
|
new extensions::CefExtensionsRendererClient);
|
|
|
|
extensions::ExtensionsRendererClient::Set(
|
|
|
|
extensions_renderer_client_.get());
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
AlloyContentRendererClient::~AlloyContentRendererClient() {}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// static
|
2020-06-28 20:29:44 +02:00
|
|
|
AlloyContentRendererClient* AlloyContentRendererClient::Get() {
|
2020-06-28 23:05:36 +02:00
|
|
|
REQUIRE_ALLOY_RUNTIME();
|
2020-06-28 20:29:44 +02:00
|
|
|
return static_cast<AlloyContentRendererClient*>(
|
2020-06-28 23:05:36 +02:00
|
|
|
CefAppManager::Get()->GetContentClient()->renderer());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2017-09-21 13:57:40 +02:00
|
|
|
scoped_refptr<base::SingleThreadTaskRunner>
|
2020-06-28 20:29:44 +02:00
|
|
|
AlloyContentRendererClient::GetCurrentTaskRunner() {
|
2013-01-03 18:24:24 +01:00
|
|
|
// Check if currently on the render thread.
|
|
|
|
if (CEF_CURRENTLY_ON_RT())
|
|
|
|
return render_task_runner_;
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2013-01-03 18:24:24 +01:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyContentRendererClient::RunSingleProcessCleanup() {
|
2013-02-02 01:21:59 +01:00
|
|
|
DCHECK(content::RenderProcessHost::run_renderer_in_process());
|
|
|
|
|
|
|
|
// Make sure the render thread was actually started.
|
2014-09-27 01:48:19 +02:00
|
|
|
if (!render_task_runner_.get())
|
2013-02-02 01:21:59 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
|
|
|
|
RunSingleProcessCleanupOnUIThread();
|
|
|
|
} else {
|
2022-05-19 12:28:44 +02:00
|
|
|
CEF_POST_TASK(
|
|
|
|
CEF_UIT,
|
2021-06-04 03:34:56 +02:00
|
|
|
base::BindOnce(
|
2020-06-28 20:29:44 +02:00
|
|
|
&AlloyContentRendererClient::RunSingleProcessCleanupOnUIThread,
|
|
|
|
base::Unretained(this)));
|
2013-02-02 01:21:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2020-07-20 20:16:48 +02:00
|
|
|
void AlloyContentRendererClient::PostIOThreadCreated(
|
2020-08-29 00:39:23 +02:00
|
|
|
base::SingleThreadTaskRunner*) {
|
2020-07-20 20:16:48 +02:00
|
|
|
// TODO(cef): Enable these once the implementation supports it.
|
|
|
|
blink::WebRuntimeFeatures::EnableNotifications(false);
|
|
|
|
blink::WebRuntimeFeatures::EnablePushMessaging(false);
|
2020-09-02 21:06:45 +02:00
|
|
|
blink::RuntimeEnabledFeatures::SetBadgingEnabled(false);
|
2020-07-20 20:16:48 +02:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyContentRendererClient::RenderThreadStarted() {
|
2014-10-07 22:44:33 +02:00
|
|
|
const base::CommandLine* command_line =
|
|
|
|
base::CommandLine::ForCurrentProcess();
|
|
|
|
|
2015-07-24 02:06:56 +02:00
|
|
|
render_task_runner_ = base::ThreadTaskRunnerHandle::Get();
|
2020-09-25 03:40:47 +02:00
|
|
|
observer_ = std::make_unique<AlloyRenderThreadObserver>();
|
2020-02-10 18:10:17 +01:00
|
|
|
web_cache_impl_ = std::make_unique<web_cache::WebCacheImpl>();
|
|
|
|
visited_link_slave_ = std::make_unique<visitedlink::VisitedLinkReader>();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
content::RenderThread* thread = content::RenderThread::Get();
|
2017-09-06 23:40:58 +02:00
|
|
|
|
2021-11-29 20:58:09 +01:00
|
|
|
const bool is_extension = CefRenderManager::IsExtensionProcess();
|
2021-11-23 21:28:12 +01:00
|
|
|
|
2017-09-06 23:40:58 +02:00
|
|
|
thread->SetRendererProcessType(
|
2021-11-23 21:28:12 +01:00
|
|
|
is_extension
|
2018-11-30 23:21:07 +01:00
|
|
|
? blink::scheduler::WebRendererProcessType::kExtensionRenderer
|
|
|
|
: blink::scheduler::WebRendererProcessType::kRenderer);
|
2017-09-06 23:40:58 +02:00
|
|
|
|
2021-11-23 21:28:12 +01:00
|
|
|
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::trace_event::TraceLog::GetInstance()->set_process_name(
|
|
|
|
"Extension Renderer");
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
thread->AddObserver(observer_.get());
|
|
|
|
|
2014-10-07 22:44:33 +02:00
|
|
|
if (!command_line->HasSwitch(switches::kDisableSpellChecking)) {
|
2020-02-10 18:10:17 +01:00
|
|
|
spellcheck_ = std::make_unique<SpellCheck>(this);
|
2014-10-07 22:44:33 +02:00
|
|
|
}
|
|
|
|
|
2013-02-02 01:21:59 +01:00
|
|
|
if (content::RenderProcessHost::run_renderer_in_process()) {
|
|
|
|
// When running in single-process mode register as a destruction observer
|
|
|
|
// on the render thread's MessageLoop.
|
2020-08-29 00:39:23 +02:00
|
|
|
base::CurrentThread::Get()->AddDestructionObserver(this);
|
2013-02-02 01:21:59 +01:00
|
|
|
}
|
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2016-05-25 01:35:43 +02:00
|
|
|
{
|
2015-04-08 15:16:17 +02:00
|
|
|
base::ScopedCFTypeRef<CFStringRef> key(
|
|
|
|
base::SysUTF8ToCFStringRef("NSScrollViewRubberbanding"));
|
|
|
|
base::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, value, kCFPreferencesCurrentApplication);
|
|
|
|
CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
|
|
|
|
}
|
2022-01-24 18:58:02 +01:00
|
|
|
#endif // BUILDFLAG(IS_MAC)
|
2015-04-08 15:16:17 +02:00
|
|
|
|
2015-11-10 21:18:16 +01:00
|
|
|
if (extensions::ExtensionsEnabled())
|
|
|
|
extensions_renderer_client_->RenderThreadStarted();
|
2017-05-31 17:33:30 +02:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyContentRendererClient::ExposeInterfacesToBrowser(
|
2020-02-10 18:10:17 +01:00
|
|
|
mojo::BinderMap* binders) {
|
|
|
|
auto task_runner = base::SequencedTaskRunnerHandle::Get();
|
|
|
|
|
|
|
|
binders->Add(base::BindRepeating(&web_cache::WebCacheImpl::BindReceiver,
|
|
|
|
base::Unretained(web_cache_impl_.get())),
|
|
|
|
task_runner);
|
|
|
|
|
|
|
|
binders->Add(visited_link_slave_->GetBindCallback(), task_runner);
|
|
|
|
|
|
|
|
if (spellcheck_) {
|
|
|
|
binders->Add(
|
|
|
|
base::BindRepeating(
|
|
|
|
[](SpellCheck* spellcheck,
|
|
|
|
mojo::PendingReceiver<spellcheck::mojom::SpellChecker>
|
|
|
|
receiver) { spellcheck->BindReceiver(std::move(receiver)); },
|
|
|
|
base::Unretained(spellcheck_.get())),
|
|
|
|
task_runner);
|
|
|
|
}
|
2021-05-14 18:58:55 +02:00
|
|
|
|
|
|
|
render_manager_->ExposeInterfacesToBrowser(binders);
|
2020-02-10 18:10:17 +01:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyContentRendererClient::RenderThreadConnected() {
|
2015-08-14 16:41:08 +02:00
|
|
|
// Register extensions last because it will trigger WebKit initialization.
|
2022-06-17 15:28:55 +02:00
|
|
|
blink::WebScriptController::RegisterExtension(
|
|
|
|
extensions_v8::LoadTimesExtension::Get());
|
2016-04-27 22:38:52 +02:00
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
render_manager_->RenderThreadConnected();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyContentRendererClient::RenderFrameCreated(
|
2014-01-02 23:41:11 +01:00
|
|
|
content::RenderFrame* render_frame) {
|
2021-05-14 18:58:55 +02:00
|
|
|
auto render_frame_observer = new CefRenderFrameObserver(render_frame);
|
2017-09-06 23:40:58 +02:00
|
|
|
|
2020-01-23 22:58:01 +01:00
|
|
|
if (extensions::ExtensionsEnabled()) {
|
2021-05-14 18:58:55 +02:00
|
|
|
extensions_renderer_client_->RenderFrameCreated(
|
|
|
|
render_frame, render_frame_observer->registry());
|
2015-07-16 23:40:01 +02:00
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
render_frame_observer->associated_interfaces()->AddInterface(
|
|
|
|
base::BindRepeating(
|
|
|
|
&extensions::MimeHandlerViewContainerManager::BindReceiver,
|
|
|
|
render_frame->GetRoutingID()));
|
2020-01-23 22:58:01 +01:00
|
|
|
}
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
const base::CommandLine* command_line =
|
|
|
|
base::CommandLine::ForCurrentProcess();
|
2017-12-07 22:44:24 +01:00
|
|
|
if (!command_line->HasSwitch(switches::kDisableSpellChecking)) {
|
2018-02-15 01:12:09 +01:00
|
|
|
new SpellCheckProvider(render_frame, spellcheck_.get(), this);
|
2017-12-07 22:44:24 +01:00
|
|
|
}
|
2017-04-20 21:28:17 +02:00
|
|
|
|
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-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 (browser_created) {
|
|
|
|
OnBrowserCreated(render_frame->GetRenderView(), is_windowless);
|
2019-05-24 22:23:43 +02:00
|
|
|
}
|
2019-10-15 13:52:26 +02:00
|
|
|
|
|
|
|
if (is_windowless.has_value()) {
|
|
|
|
new printing::PrintRenderFrameHelper(
|
|
|
|
render_frame,
|
|
|
|
base::WrapUnique(
|
|
|
|
new extensions::CefPrintRenderFrameHelperDelegate(*is_windowless)));
|
|
|
|
}
|
2014-01-02 23:41:11 +01:00
|
|
|
}
|
|
|
|
|
2021-07-23 18:40:13 +02:00
|
|
|
void AlloyContentRendererClient::WebViewCreated(blink::WebView* web_view) {
|
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 (browser_created) {
|
2021-07-23 18:40:13 +02:00
|
|
|
auto render_view = content::RenderView::FromWebView(web_view);
|
|
|
|
CHECK(render_view);
|
2020-09-25 03:40:47 +02:00
|
|
|
OnBrowserCreated(render_view, is_windowless);
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
bool AlloyContentRendererClient::IsPluginHandledExternally(
|
2019-07-24 23:12:00 +02:00
|
|
|
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();
|
|
|
|
ChromeContentRendererClient::GetPluginInfoHost()->GetPluginInfo(
|
2022-02-21 23:23:40 +01:00
|
|
|
original_url, render_frame->GetWebFrame()->Top()->GetSecurityOrigin(),
|
|
|
|
mime_type, &plugin_info);
|
2019-07-24 23:12:00 +02:00
|
|
|
// 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;
|
|
|
|
}
|
2022-03-26 02:12:30 +01:00
|
|
|
if (plugin_info->actual_mime_type == pdf::kInternalPluginMimeType) {
|
2021-11-23 21:28:12 +01:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
2019-07-24 23:12:00 +02:00
|
|
|
return ChromeExtensionsRendererClient::MaybeCreateMimeHandlerView(
|
|
|
|
plugin_element, original_url, plugin_info->actual_mime_type,
|
|
|
|
plugin_info->plugin);
|
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
bool AlloyContentRendererClient::OverrideCreatePlugin(
|
2014-07-01 00:30:29 +02:00
|
|
|
content::RenderFrame* render_frame,
|
|
|
|
const blink::WebPluginParams& params,
|
|
|
|
blink::WebPlugin** plugin) {
|
2017-04-20 21:28:17 +02:00
|
|
|
std::string orig_mime_type = params.mime_type.Utf8();
|
2015-11-10 21:18:16 +01:00
|
|
|
if (extensions::ExtensionsEnabled() &&
|
|
|
|
!extensions_renderer_client_->OverrideCreatePlugin(render_frame,
|
|
|
|
params)) {
|
|
|
|
return false;
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
GURL url(params.url);
|
2017-12-07 22:44:24 +01:00
|
|
|
chrome::mojom::PluginInfoPtr plugin_info = chrome::mojom::PluginInfo::New();
|
|
|
|
ChromeContentRendererClient::GetPluginInfoHost()->GetPluginInfo(
|
2022-02-21 23:23:40 +01:00
|
|
|
url, render_frame->GetWebFrame()->Top()->GetSecurityOrigin(),
|
|
|
|
orig_mime_type, &plugin_info);
|
2017-12-07 22:44:24 +01:00
|
|
|
*plugin = ChromeContentRendererClient::CreatePlugin(render_frame, params,
|
|
|
|
*plugin_info);
|
2015-07-16 23:40:01 +02:00
|
|
|
return true;
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyContentRendererClient::WillSendRequest(
|
2017-01-23 18:36:54 +01:00
|
|
|
blink::WebLocalFrame* frame,
|
2015-10-12 20:13:13 +02:00
|
|
|
ui::PageTransition transition_type,
|
2016-11-23 21:54:29 +01:00
|
|
|
const blink::WebURL& url,
|
2020-03-04 01:29:39 +01:00
|
|
|
const net::SiteForCookies& site_for_cookies,
|
2018-04-19 17:44:42 +02:00
|
|
|
const url::Origin* initiator_origin,
|
2021-01-28 00:13:12 +01:00
|
|
|
GURL* new_url) {
|
2015-10-12 20:13:13 +02:00
|
|
|
if (extensions::ExtensionsEnabled()) {
|
2021-01-28 00:13:12 +01:00
|
|
|
extensions_renderer_client_->WillSendRequest(frame, transition_type, url,
|
|
|
|
site_for_cookies,
|
|
|
|
initiator_origin, new_url);
|
2018-04-19 17:44:42 +02:00
|
|
|
if (!new_url->is_empty())
|
|
|
|
return;
|
2015-10-12 20:13:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
uint64_t AlloyContentRendererClient::VisitedLinkHash(const char* canonical_url,
|
|
|
|
size_t length) {
|
2020-02-10 18:10:17 +01:00
|
|
|
return visited_link_slave_->ComputeURLFingerprint(canonical_url, length);
|
2016-01-12 01:19:51 +01:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
bool AlloyContentRendererClient::IsLinkVisited(uint64_t link_hash) {
|
2020-02-10 18:10:17 +01:00
|
|
|
return visited_link_slave_->IsVisited(link_hash);
|
2016-01-12 01:19:51 +01:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
bool AlloyContentRendererClient::IsOriginIsolatedPepperPlugin(
|
2018-04-19 17:44:42 +02:00
|
|
|
const base::FilePath& plugin_path) {
|
2021-01-28 00:13:12 +01:00
|
|
|
// Isolate all the plugins (including the PDF plugin).
|
|
|
|
return true;
|
2018-04-19 17:44:42 +02:00
|
|
|
}
|
|
|
|
|
2022-02-21 23:23:40 +01:00
|
|
|
void AlloyContentRendererClient::GetSupportedKeySystems(
|
|
|
|
media::GetSupportedKeySystemsCB cb) {
|
2022-03-26 02:12:30 +01:00
|
|
|
GetChromeKeySystems(std::move(cb));
|
2015-08-31 13:28:07 +02:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyContentRendererClient::RunScriptsAtDocumentStart(
|
2016-04-27 22:38:52 +02:00
|
|
|
content::RenderFrame* render_frame) {
|
|
|
|
if (extensions::ExtensionsEnabled())
|
|
|
|
extensions_renderer_client_->RunScriptsAtDocumentStart(render_frame);
|
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyContentRendererClient::RunScriptsAtDocumentEnd(
|
2016-04-27 22:38:52 +02:00
|
|
|
content::RenderFrame* render_frame) {
|
|
|
|
if (extensions::ExtensionsEnabled())
|
|
|
|
extensions_renderer_client_->RunScriptsAtDocumentEnd(render_frame);
|
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyContentRendererClient::RunScriptsAtDocumentIdle(
|
2017-04-20 21:28:17 +02:00
|
|
|
content::RenderFrame* render_frame) {
|
|
|
|
if (extensions::ExtensionsEnabled())
|
|
|
|
extensions_renderer_client_->RunScriptsAtDocumentIdle(render_frame);
|
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyContentRendererClient::DevToolsAgentAttached() {
|
2019-07-26 15:47:11 +02:00
|
|
|
// WebWorkers may be creating agents on a different thread.
|
|
|
|
if (!render_task_runner_->BelongsToCurrentThread()) {
|
|
|
|
render_task_runner_->PostTask(
|
|
|
|
FROM_HERE,
|
2020-06-28 20:29:44 +02:00
|
|
|
base::BindOnce(&AlloyContentRendererClient::DevToolsAgentAttached,
|
2019-07-26 15:47:11 +02:00
|
|
|
base::Unretained(this)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
render_manager_->DevToolsAgentAttached();
|
2013-02-02 01:21:59 +01:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyContentRendererClient::DevToolsAgentDetached() {
|
2019-07-26 15:47:11 +02:00
|
|
|
// WebWorkers may be creating agents on a different thread.
|
|
|
|
if (!render_task_runner_->BelongsToCurrentThread()) {
|
|
|
|
render_task_runner_->PostTask(
|
|
|
|
FROM_HERE,
|
2020-06-28 20:29:44 +02:00
|
|
|
base::BindOnce(&AlloyContentRendererClient::DevToolsAgentDetached,
|
2019-07-26 15:47:11 +02:00
|
|
|
base::Unretained(this)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
render_manager_->DevToolsAgentDetached();
|
2017-12-07 22:44:24 +01:00
|
|
|
}
|
2015-09-09 16:05:39 +02:00
|
|
|
|
2021-04-21 00:52:34 +02:00
|
|
|
std::unique_ptr<blink::URLLoaderThrottleProvider>
|
2020-06-28 20:29:44 +02:00
|
|
|
AlloyContentRendererClient::CreateURLLoaderThrottleProvider(
|
2021-04-21 00:52:34 +02:00
|
|
|
blink::URLLoaderThrottleProviderType provider_type) {
|
2019-07-24 23:12:00 +02:00
|
|
|
return std::make_unique<CefURLLoaderThrottleProviderImpl>(provider_type);
|
|
|
|
}
|
|
|
|
|
2022-02-21 23:23:40 +01:00
|
|
|
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;
|
|
|
|
|
2022-05-19 12:28:44 +02:00
|
|
|
// Append a minimum CSP to ensure the extension can't relax the default
|
2022-02-21 23:23:40 +01:00
|
|
|
// applied CSP through means like Service Worker.
|
|
|
|
const std::string* default_csp =
|
2022-05-19 12:28:44 +02:00
|
|
|
extensions::CSPInfo::GetMinimumCSPToAppend(*extension, gurl.path());
|
2022-02-21 23:23:40 +01:00
|
|
|
if (!default_csp)
|
|
|
|
return;
|
|
|
|
|
|
|
|
csp->push_back({blink::WebString::FromUTF8(*default_csp),
|
|
|
|
network::mojom::ContentSecurityPolicyType::kEnforce,
|
|
|
|
network::mojom::ContentSecurityPolicySource::kHTTP});
|
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyContentRendererClient::GetInterface(
|
2017-12-07 22:44:24 +01:00
|
|
|
const std::string& interface_name,
|
|
|
|
mojo::ScopedMessagePipeHandle interface_pipe) {
|
2019-10-01 15:55:16 +02:00
|
|
|
// 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)));
|
2017-12-07 22:44:24 +01:00
|
|
|
}
|
2015-09-09 16:05:39 +02:00
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyContentRendererClient::WillDestroyCurrentMessageLoop() {
|
2017-12-07 22:44:24 +01:00
|
|
|
base::AutoLock lock_scope(single_process_cleanup_lock_);
|
|
|
|
single_process_cleanup_complete_ = true;
|
2015-09-09 16:05:39 +02:00
|
|
|
}
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
void AlloyContentRendererClient::OnBrowserCreated(
|
2014-01-02 23:41:11 +01:00
|
|
|
content::RenderView* render_view,
|
2021-06-04 03:34:56 +02:00
|
|
|
absl::optional<bool> is_windowless) {
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2020-09-25 03:40:47 +02:00
|
|
|
const bool windowless = is_windowless.has_value() && *is_windowless;
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
// 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
|
2020-09-25 03:40:47 +02:00
|
|
|
render_view->GetWebView()->SetUseExternalPopupMenusThisInstance(!windowless);
|
2014-07-01 00:30:29 +02:00
|
|
|
#endif
|
2014-01-02 23:41:11 +01:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyContentRendererClient::RunSingleProcessCleanupOnUIThread() {
|
2013-02-02 01:21:59 +01:00
|
|
|
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
|
|
|
|
|
|
|
|
// Clean up the single existing RenderProcessHost.
|
2020-01-15 14:36:24 +01:00
|
|
|
content::RenderProcessHost* host = nullptr;
|
2013-02-02 01:21:59 +01:00
|
|
|
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.
|
2013-09-03 20:06:25 +02:00
|
|
|
if (!CefContext::Get()->settings().multi_threaded_message_loop)
|
2013-02-02 01:21:59 +01:00
|
|
|
delete host;
|
|
|
|
}
|
2016-03-16 03:55:59 +01:00
|
|
|
|
2018-10-02 14:14:11 +02:00
|
|
|
// Enable deprecation warnings on Windows. See http://crbug.com/585142.
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2018-10-02 14:14:11 +02:00
|
|
|
#if defined(__clang__)
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
#else
|
2016-03-16 03:55:59 +01:00
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
2018-10-02 14:14:11 +02:00
|
|
|
#endif
|