diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-02-15 14:57:23 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-02-17 09:12:12 +0100 |
commit | cd12379d43f8c2df14b19ebced316aa94b3f6043 (patch) | |
tree | f8ff1ac93a1a5502e60c243c32c54f80b1bd332d /src/core/content_browser_client_qt.cpp | |
parent | 4e6e907001d4cf0833465407f8a0fa68e6ce564b (diff) | |
parent | 4c94370394ccf1e00233669df01599cb6141a5dc (diff) |
Merge remote-tracking branch 'origin/5.15' into dev
Change-Id: Idee0142b0e33fdf8ca663f1ef1bcd8b932985043
Diffstat (limited to 'src/core/content_browser_client_qt.cpp')
-rw-r--r-- | src/core/content_browser_client_qt.cpp | 173 |
1 files changed, 90 insertions, 83 deletions
diff --git a/src/core/content_browser_client_qt.cpp b/src/core/content_browser_client_qt.cpp index 0c1c8b111..b70f8a290 100644 --- a/src/core/content_browser_client_qt.cpp +++ b/src/core/content_browser_client_qt.cpp @@ -39,69 +39,38 @@ #include "content_browser_client_qt.h" -#include "base/memory/ptr_util.h" #include "base/optional.h" -#include "base/path_service.h" -#include "base/strings/utf_string_conversions.h" #include "base/task/post_task.h" -#include "base/threading/thread_restrictions.h" #include "chrome/browser/custom_handlers/protocol_handler_registry.h" #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" -#if QT_CONFIG(webengine_spellchecker) -#include "chrome/browser/spellchecker/spell_check_host_chrome_impl.h" -#endif -#include "components/guest_view/browser/guest_view_base.h" +#include "chrome/browser/tab_contents/form_interaction_tab_helper.h" #include "components/navigation_interception/intercept_navigation_throttle.h" #include "components/navigation_interception/navigation_params.h" #include "components/network_hints/browser/simple_network_hints_handler_impl.h" #include "components/performance_manager/embedder/performance_manager_registry.h" #include "components/performance_manager/public/performance_manager.h" -#include "components/spellcheck/spellcheck_buildflags.h" -#include "content/browser/renderer_host/render_view_host_delegate.h" #include "content/browser/web_contents/web_contents_impl.h" -#include "content/common/url_schemes.h" #include "content/public/browser/browser_main_runner.h" -#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/child_process_security_policy.h" #include "content/public/browser/client_certificate_delegate.h" #include "content/public/browser/file_url_loader.h" #include "content/public/browser/media_observer.h" -#include "content/public/browser/network_service_instance.h" #include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/shared_cors_origin_access_list.h" -#include "content/public/browser/storage_partition.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_user_data.h" #include "content/public/browser/web_ui_url_loader_factory.h" #include "content/public/common/content_switches.h" #include "content/public/common/main_function_params.h" -#include "content/public/common/service_manager_connection.h" #include "content/public/common/service_names.mojom.h" -#include "content/public/common/url_constants.h" #include "content/public/common/user_agent.h" -#include "media/media_buildflags.h" #include "extensions/buildflags/buildflags.h" -#include "extensions/browser/extension_protocols.h" -#include "extensions/browser/guest_view/web_view/web_view_guest.h" -#include "extensions/browser/process_map.h" -#include "mojo/public/cpp/bindings/binding.h" -#include "mojo/public/cpp/bindings/binding_set.h" -#include "mojo/public/cpp/bindings/remote.h" -#include "printing/buildflags/buildflags.h" -#include "qtwebengine/browser/qtwebengine_content_browser_overlay_manifest.h" -#include "qtwebengine/browser/qtwebengine_content_renderer_overlay_manifest.h" #include "net/ssl/client_cert_identity.h" #include "net/ssl/client_cert_store.h" -#include "sandbox/policy/switches.h" #include "services/network/network_service.h" -#include "services/network/public/cpp/features.h" -#include "services/service_manager/switches.h" -#include "services/service_manager/public/cpp/connector.h" -#include "services/service_manager/public/cpp/service.h" -#include "storage/browser/quota/quota_settings.h" #include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h" #include "third_party/blink/public/common/loader/url_loader_throttle.h" #include "third_party/blink/public/mojom/insecure_input/insecure_input_service.mojom.h" @@ -109,6 +78,8 @@ #include "ui/base/ui_base_switches.h" #include "url/url_util_qt.h" +#include "qtwebengine/browser/qtwebengine_content_browser_overlay_manifest.h" +#include "qtwebengine/browser/qtwebengine_content_renderer_overlay_manifest.h" #include "qtwebengine/common/renderer_configuration.mojom.h" #include "qtwebengine/grit/qt_webengine_resources.h" @@ -124,12 +95,9 @@ #include "net/custom_url_loader_factory.h" #include "net/proxying_restricted_cookie_manager_qt.h" #include "net/proxying_url_loader_factory_qt.h" -#include "net/qrc_url_scheme_handler.h" #include "net/system_network_context_manager.h" +#include "ozone/gl_share_context_qt.h" #include "platform_notification_service_qt.h" -#if QT_CONFIG(webengine_printing_and_pdf) -#include "printing/printing_message_filter_qt.h" -#endif #include "profile_qt.h" #include "profile_io_data_qt.h" #include "quota_permission_context_qt.h" @@ -138,16 +106,20 @@ #include "web_contents_adapter_client.h" #include "web_contents_adapter.h" #include "web_contents_delegate_qt.h" -#include "web_engine_context.h" #include "web_contents_view_qt.h" +#include "web_engine_context.h" #include "web_engine_library_info.h" #include "api/qwebenginecookiestore.h" #include "api/qwebenginecookiestore_p.h" -#include "api/qwebengineurlscheme.h" -#include "ozone/gl_share_context_qt.h" -#if defined(Q_OS_LINUX) -#include "global_descriptors_qt.h" -#include "ui/base/resource/resource_bundle.h" + +#if QT_CONFIG(opengl) +#include <QOpenGLContext> +#include <QOpenGLExtraFunctions> +#endif + +#if QT_CONFIG(webengine_geolocation) +#include "base/memory/ptr_util.h" +#include "location_provider_qt.h" #endif #if QT_CONFIG(webengine_pepper_plugins) @@ -156,22 +128,36 @@ #include "renderer_host/pepper/pepper_host_factory_qt.h" #endif -#if QT_CONFIG(webengine_geolocation) -#include "location_provider_qt.h" +#if QT_CONFIG(webengine_printing_and_pdf) +#include "printing/printing_message_filter_qt.h" +#endif + +#if QT_CONFIG(webengine_spellchecker) +#include "chrome/browser/spellchecker/spell_check_host_chrome_impl.h" +#include "components/spellcheck/common/spellcheck.mojom.h" +#endif + +#if QT_CONFIG(webengine_webrtc) && QT_CONFIG(webengine_extensions) +#include "chrome/browser/media/webrtc/webrtc_logging_controller.h" +#endif + +#if defined(Q_OS_LINUX) +#include "global_descriptors_qt.h" #endif #if BUILDFLAG(ENABLE_EXTENSIONS) -#include "content/public/browser/file_url_loader.h" +#include "common/extensions/extensions_client_qt.h" +#include "components/guest_view/browser/guest_view_base.h" #include "extensions/browser/api/mime_handler_private/mime_handler_private.h" #include "extensions/browser/extension_message_filter.h" -#include "extensions/browser/extension_registry.h" +#include "extensions/browser/extension_protocols.h" #include "extensions/browser/extension_registry.h" #include "extensions/browser/guest_view/extensions_guest_view_message_filter.h" #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h" +#include "extensions/browser/guest_view/web_view/web_view_guest.h" +#include "extensions/browser/process_map.h" #include "extensions/browser/url_loader_factory_manager.h" #include "extensions/common/constants.h" - -#include "common/extensions/extensions_client_qt.h" #include "extensions/extension_web_contents_observer_qt.h" #include "extensions/extensions_browser_client_qt.h" #include "net/plugin_response_interceptor_url_loader_throttle.h" @@ -182,14 +168,13 @@ #include "media/mojo/services/media_service_factory.h" #endif -#if BUILDFLAG(ENABLE_SPELLCHECK) -#include "chrome/browser/spellchecker/spell_check_host_chrome_impl.h" -#include "components/spellcheck/common/spellcheck.mojom.h" -#endif - #include <QGuiApplication> -#include <QLocale> #include <QStandardPaths> +#include <qpa/qplatformnativeinterface.h> + +QT_BEGIN_NAMESPACE +Q_GUI_EXPORT QOpenGLContext *qt_gl_global_share_context(); +QT_END_NAMESPACE // Implement IsHandledProtocol as declared in //url/url_util_qt.h. namespace url { @@ -248,6 +233,10 @@ void ContentBrowserClientQt::RenderProcessWillLaunch(content::RenderProcessHost const int id = host->GetID(); Profile *profile = Profile::FromBrowserContext(host->GetBrowserContext()); +#if QT_CONFIG(webengine_webrtc) && QT_CONFIG(webengine_extensions) + WebRtcLoggingController::AttachToRenderProcessHost(host, WebEngineContext::current()->webRtcLogUploader()); +#endif + // Allow requesting custom schemes. const auto policy = content::ChildProcessSecurityPolicy::GetInstance(); const auto profileAdapter = static_cast<ProfileQt *>(profile)->profileAdapter(); @@ -478,12 +467,12 @@ WEB_CONTENTS_USER_DATA_KEY_IMPL(ServiceDriver) void ContentBrowserClientQt::BindHostReceiverForRenderer(content::RenderProcessHost *render_process_host, mojo::GenericPendingReceiver receiver) { -#if BUILDFLAG(ENABLE_SPELLCHECK) +#if QT_CONFIG(webengine_spellchecker) if (auto host_receiver = receiver.As<spellcheck::mojom::SpellCheckHost>()) { SpellCheckHostChromeImpl::Create(render_process_host->GetID(), std::move(host_receiver)); return; } -#endif // BUILDFLAG(ENABLE_SPELLCHECK) +#endif } static void BindNetworkHintsHandler(content::RenderFrameHost *frame_host, @@ -747,7 +736,6 @@ bool ContentBrowserClientQt::HandleExternalProtocol(const GURL &url, const base::Optional<url::Origin> &initiating_origin, mojo::PendingRemote<network::mojom::URLLoaderFactory> *out_factory) { -// Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); Q_UNUSED(child_id); Q_UNUSED(navigation_data); Q_UNUSED(initiating_origin); @@ -945,6 +933,16 @@ bool ContentBrowserClientQt::ShouldTreatURLSchemeAsFirstPartyWhenTopLevel(base:: #endif } +bool ContentBrowserClientQt::DoesSchemeAllowCrossOriginSharedWorker(const std::string &scheme) +{ +#if BUILDFLAG(ENABLE_EXTENSIONS) + // Extensions are allowed to start cross-origin shared workers. + return scheme == extensions::kExtensionScheme; +#else + return false; +#endif +} + void ContentBrowserClientQt::OverrideURLLoaderFactoryParams(content::BrowserContext *browser_context, const url::Origin &origin, bool is_for_isolated_world, @@ -1042,6 +1040,24 @@ void ContentBrowserClientQt::RegisterNonNetworkWorkerMainResourceURLLoaderFactor for (const QByteArray &scheme : profileAdapter->customUrlSchemes()) factories->emplace(scheme.toStdString(), CreateCustomURLLoaderFactory(profileAdapter)); + +#if BUILDFLAG(ENABLE_EXTENSIONS) + factories->emplace( + extensions::kExtensionScheme, + extensions::CreateExtensionWorkerMainResourceURLLoaderFactory(browser_context)); +#endif // BUILDFLAG(ENABLE_EXTENSIONS) +} + +void ContentBrowserClientQt::RegisterNonNetworkServiceWorkerUpdateURLLoaderFactories(content::BrowserContext* browser_context, + NonNetworkURLLoaderFactoryMap* factories) +{ + DCHECK(browser_context); + DCHECK(factories); +#if BUILDFLAG(ENABLE_EXTENSIONS) + factories->emplace( + extensions::kExtensionScheme, + extensions::CreateExtensionServiceWorkerScriptURLLoaderFactory(browser_context)); +#endif // BUILDFLAG(ENABLE_EXTENSIONS) } void ContentBrowserClientQt::RegisterNonNetworkSubresourceURLLoaderFactories(int render_process_id, int render_frame_id, @@ -1135,32 +1151,14 @@ bool ContentBrowserClientQt::WillCreateURLLoaderFactory( bool *disable_secure_dns, network::mojom::URLLoaderFactoryOverridePtr *factory_override) { - auto *web_contents = content::WebContents::FromRenderFrameHost(frame); - ProfileQt *profile = static_cast<ProfileQt *>(browser_context); - - QWebEngineUrlRequestInterceptor *profile_interceptor = profile->profileAdapter()->requestInterceptor(); - QWebEngineUrlRequestInterceptor *page_interceptor = nullptr; - - if (web_contents) { - WebContentsAdapterClient *client = - WebContentsViewQt::from(static_cast<content::WebContentsImpl *>(web_contents)->GetView())->client(); - if (!client) - return false; - - page_interceptor = client->webContentsAdapter()->requestInterceptor(); - } - - if (profile_interceptor || page_interceptor) { - int process_id = type == URLLoaderFactoryType::kNavigation ? 0 : render_process_id; - auto proxied_receiver = std::move(*factory_receiver); - mojo::PendingRemote<network::mojom::URLLoaderFactory> pending_url_loader_factory; - *factory_receiver = pending_url_loader_factory.InitWithNewPipeAndPassReceiver(); - // Will manage its own lifetime - new ProxyingURLLoaderFactoryQt(process_id, profile_interceptor, page_interceptor, std::move(proxied_receiver), - std::move(pending_url_loader_factory)); - return true; - } - return false; + auto adapter = static_cast<ProfileQt *>(browser_context)->profileAdapter(); + int process_id = type == URLLoaderFactoryType::kNavigation ? 0 : render_process_id; + auto proxied_receiver = std::move(*factory_receiver); + mojo::PendingRemote<network::mojom::URLLoaderFactory> pending_url_loader_factory; + *factory_receiver = pending_url_loader_factory.InitWithNewPipeAndPassReceiver(); + // Will manage its own lifetime + new ProxyingURLLoaderFactoryQt(adapter, process_id, std::move(proxied_receiver), std::move(pending_url_loader_factory)); + return true; } void ContentBrowserClientQt::SiteInstanceGotProcess(content::SiteInstance *site_instance) @@ -1195,4 +1193,13 @@ void ContentBrowserClientQt::SiteInstanceDeleting(content::SiteInstance *site_in #endif } +content::WebContentsViewDelegate *ContentBrowserClientQt::GetWebContentsViewDelegate(content::WebContents *web_contents) +{ + FormInteractionTabHelper::CreateForWebContents(web_contents); + if (auto *registry = performance_manager::PerformanceManagerRegistry::GetInstance()) + registry->MaybeCreatePageNodeForWebContents(web_contents); + + return nullptr; +} + } // namespace QtWebEngineCore |