diff --git a/BUILD.gn b/BUILD.gn index a04169014..ced3aa5cf 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -598,6 +598,8 @@ static_library("libcef_static") { "libcef/renderer/render_urlrequest_impl.cc", "libcef/renderer/render_urlrequest_impl.h", "libcef/renderer/thread_util.h", + "libcef/renderer/url_loader_throttle_provider_impl.cc", + "libcef/renderer/url_loader_throttle_provider_impl.h", "libcef/renderer/v8_impl.cc", "libcef/renderer/v8_impl.h", "libcef/utility/content_utility_client.cc", diff --git a/libcef/browser/extensions/extension_system.cc b/libcef/browser/extensions/extension_system.cc index d67498a95..2fdfb3ed5 100644 --- a/libcef/browser/extensions/extension_system.cc +++ b/libcef/browser/extensions/extension_system.cc @@ -199,7 +199,7 @@ void CefExtensionSystem::Init() { // mime_handler_private.idl), and returns the unique View ID via the // |payload| argument. // 5. The unique View ID arrives in the renderer process via - // ResourceLoader::didReceiveData and triggers creation of a new Document. + // ResourceLoader::DidReceiveData and triggers creation of a new Document. // DOMImplementation::createDocument indirectly calls // RendererBlinkPlatformImpl::getPluginList to retrieve the list of // supported plugins from the browser process. If a plugin supports the diff --git a/libcef/common/main_delegate.cc b/libcef/common/main_delegate.cc index e0e3d2c96..e10b0d055 100644 --- a/libcef/common/main_delegate.cc +++ b/libcef/common/main_delegate.cc @@ -566,6 +566,13 @@ bool CefMainDelegate::BasicStartupComplete(int* exit_code) { } } + if (features::kMimeHandlerViewInCrossProcessFrame.default_state == + base::FEATURE_ENABLED_BY_DEFAULT) { + // TODO: Add support for cross-process mime handler view (see issue #2727) + disable_features.push_back( + features::kMimeHandlerViewInCrossProcessFrame.name); + } + if (!disable_features.empty()) { DCHECK(!base::FeatureList::GetInstance()); std::string disable_features_str = diff --git a/libcef/renderer/content_renderer_client.cc b/libcef/renderer/content_renderer_client.cc index 7e7b2cb4e..9357610fa 100644 --- a/libcef/renderer/content_renderer_client.cc +++ b/libcef/renderer/content_renderer_client.cc @@ -37,6 +37,7 @@ #include "libcef/renderer/render_message_filter.h" #include "libcef/renderer/render_thread_observer.h" #include "libcef/renderer/thread_util.h" +#include "libcef/renderer/url_loader_throttle_provider_impl.h" #include "libcef/renderer/v8_impl.h" #include "base/command_line.h" @@ -623,6 +624,12 @@ void CefContentRendererClient::CreateRendererService( service_binding_.Bind(std::move(service_request)); } +std::unique_ptr +CefContentRendererClient::CreateURLLoaderThrottleProvider( + content::URLLoaderThrottleProviderType provider_type) { + return std::make_unique(provider_type); +} + void CefContentRendererClient::OnBindInterface( const service_manager::BindSourceInfo& remote_info, const std::string& name, diff --git a/libcef/renderer/content_renderer_client.h b/libcef/renderer/content_renderer_client.h index 1c3a0253e..3f05d25dd 100644 --- a/libcef/renderer/content_renderer_client.h +++ b/libcef/renderer/content_renderer_client.h @@ -138,6 +138,9 @@ class CefContentRendererClient void DevToolsAgentDetached() override; void CreateRendererService( service_manager::mojom::ServiceRequest service_request) override; + std::unique_ptr + CreateURLLoaderThrottleProvider( + content::URLLoaderThrottleProviderType provider_type) override; // service_manager::Service implementation. void OnBindInterface(const service_manager::BindSourceInfo& remote_info, diff --git a/libcef/renderer/url_loader_throttle_provider_impl.cc b/libcef/renderer/url_loader_throttle_provider_impl.cc new file mode 100644 index 000000000..b85e42b9e --- /dev/null +++ b/libcef/renderer/url_loader_throttle_provider_impl.cc @@ -0,0 +1,78 @@ +// 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 "libcef/renderer/url_loader_throttle_provider_impl.h" + +#include "libcef/common/extensions/extensions_util.h" + +#include + +#include "base/feature_list.h" +#include "content/public/common/content_features.h" +#include "content/public/renderer/render_frame.h" +#include "extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.h" +#include "services/network/public/cpp/features.h" +#include "third_party/blink/public/platform/web_url.h" + +CefURLLoaderThrottleProviderImpl::CefURLLoaderThrottleProviderImpl( + content::URLLoaderThrottleProviderType type) + : type_(type) { + DETACH_FROM_THREAD(thread_checker_); +} + +CefURLLoaderThrottleProviderImpl::~CefURLLoaderThrottleProviderImpl() { + DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); +} + +CefURLLoaderThrottleProviderImpl::CefURLLoaderThrottleProviderImpl( + const CefURLLoaderThrottleProviderImpl& other) + : type_(other.type_) { + DETACH_FROM_THREAD(thread_checker_); +} + +std::unique_ptr +CefURLLoaderThrottleProviderImpl::Clone() { + DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); + return base::WrapUnique(new CefURLLoaderThrottleProviderImpl(*this)); +} + +std::vector> +CefURLLoaderThrottleProviderImpl::CreateThrottles( + int render_frame_id, + const blink::WebURLRequest& request, + content::ResourceType resource_type) { + DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); + + std::vector> throttles; + + bool network_service_enabled = + base::FeatureList::IsEnabled(network::features::kNetworkService); + // Some throttles have already been added in the browser for frame resources. + // Don't add them for frame requests. + bool is_frame_resource = content::IsResourceTypeFrame(resource_type); + + DCHECK(!is_frame_resource || + type_ == content::URLLoaderThrottleProviderType::kFrame); + + if (extensions::ExtensionsEnabled() && network_service_enabled && + type_ == content::URLLoaderThrottleProviderType::kFrame && + resource_type == content::ResourceType::kObject) { + content::RenderFrame* render_frame = + content::RenderFrame::FromRoutingID(render_frame_id); + auto mime_handlers = + extensions::MimeHandlerViewContainer::FromRenderFrame(render_frame); + GURL gurl(request.Url()); + for (auto* handler : mime_handlers) { + auto throttle = handler->MaybeCreatePluginThrottle(gurl); + if (throttle) { + throttles.push_back(std::move(throttle)); + break; + } + } + } + + return throttles; +} + +void CefURLLoaderThrottleProviderImpl::SetOnline(bool is_online) {} diff --git a/libcef/renderer/url_loader_throttle_provider_impl.h b/libcef/renderer/url_loader_throttle_provider_impl.h new file mode 100644 index 000000000..a1269f4e9 --- /dev/null +++ b/libcef/renderer/url_loader_throttle_provider_impl.h @@ -0,0 +1,45 @@ +// 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_URL_LOADER_THROTTLE_PROVIDER_IMPL_H_ +#define CEF_LIBCEF_RENDERER_URL_LOADER_THROTTLE_PROVIDER_IMPL_H_ + +#include +#include + +#include "base/threading/thread_checker.h" +#include "content/public/renderer/url_loader_throttle_provider.h" + +// 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 content::URLLoaderThrottleProvider { + public: + explicit CefURLLoaderThrottleProviderImpl( + content::URLLoaderThrottleProviderType type); + + ~CefURLLoaderThrottleProviderImpl() override; + + // content::URLLoaderThrottleProvider implementation. + std::unique_ptr Clone() override; + std::vector> CreateThrottles( + int render_frame_id, + const blink::WebURLRequest& request, + content::ResourceType resource_type) 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); + + content::URLLoaderThrottleProviderType type_; + + THREAD_CHECKER(thread_checker_); + + DISALLOW_ASSIGN(CefURLLoaderThrottleProviderImpl); +}; + +#endif // CEF_LIBCEF_RENDERER_URL_LOADER_THROTTLE_PROVIDER_IMPL_H_