diff options
Diffstat (limited to 'src/core/content_browser_client_qt.cpp')
-rw-r--r-- | src/core/content_browser_client_qt.cpp | 258 |
1 files changed, 168 insertions, 90 deletions
diff --git a/src/core/content_browser_client_qt.cpp b/src/core/content_browser_client_qt.cpp index 3878bd1bf..393b0aee1 100644 --- a/src/core/content_browser_client_qt.cpp +++ b/src/core/content_browser_client_qt.cpp @@ -43,13 +43,13 @@ #include "base/memory/ptr_util.h" #include "base/message_loop/message_loop.h" #include "base/threading/thread_restrictions.h" -#include "components/spellcheck/spellcheck_build_features.h" -#if BUILDFLAG(ENABLE_SPELLCHECK) +#if QT_CONFIG(webengine_spellchecker) #include "chrome/browser/spellchecker/spell_check_host_chrome_impl.h" -#if BUILDFLAG(USE_BROWSER_SPELLCHECKER) +#if QT_CONFIG(webengine_native_spellchecker) #include "components/spellcheck/browser/spellcheck_message_filter_platform.h" #endif #endif +#include "components/network_hints/browser/network_hints_message_filter.h" #include "content/browser/renderer_host/render_view_host_delegate.h" #include "content/common/url_schemes.h" #include "content/public/browser/browser_main_parts.h" @@ -61,22 +61,24 @@ #include "content/public/browser/render_process_host.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/resource_dispatcher_host.h" +#include "content/public/browser/resource_dispatcher_host_delegate.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/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 "device/geolocation/public/cpp/location_provider.h" +#include "media/media_buildflags.h" #include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding_set.h" -#include "printing/features/features.h" +#include "printing/buildflags/buildflags.h" #include "net/ssl/client_cert_identity.h" -#include "services/service_manager/public/cpp/bind_source_info.h" -#include "services/service_manager/public/cpp/binder_registry.h" +#include "services/service_manager/public/cpp/connector.h" #include "services/service_manager/public/cpp/service.h" -#include "third_party/WebKit/public/platform/modules/insecure_input/insecure_input_service.mojom.h" +#include "third_party/blink/public/platform/modules/insecure_input/insecure_input_service.mojom.h" #include "ui/base/resource/resource_bundle.h" #include "ui/base/ui_base_switches.h" #include "ui/display/screen.h" @@ -84,26 +86,30 @@ #include "ui/gl/gl_implementation.h" #include "ui/gl/gl_share_group.h" #include "ui/gl/gpu_timing.h" +#include "url/url_util_qt.h" +#include "service/service_qt.h" #include "qtwebengine/grit/qt_webengine_resources.h" -#include "browser_context_adapter.h" -#include "browser_context_qt.h" +#include "profile_adapter.h" #include "browser_message_filter_qt.h" #include "certificate_error_controller.h" #include "certificate_error_controller_p.h" +#include "client_cert_select_controller.h" #include "desktop_screen_qt.h" #include "devtools_manager_delegate_qt.h" +#include "login_delegate_qt.h" #include "media_capture_devices_dispatcher.h" #include "net/network_delegate_qt.h" #include "net/qrc_protocol_handler_qt.h" #include "net/url_request_context_getter_qt.h" -#if BUILDFLAG(ENABLE_BASIC_PRINTING) +#if QT_CONFIG(webengine_printing_and_pdf) #include "printing/printing_message_filter_qt.h" -#endif // BUILDFLAG(ENABLE_BASIC_PRINTING) +#endif +#include "profile_qt.h" #include "quota_permission_context_qt.h" -#include "renderer_host/resource_dispatcher_host_delegate_qt.h" #include "renderer_host/user_resource_controller_host.h" +#include "type_conversion.h" #include "web_contents_delegate_qt.h" #include "web_engine_context.h" #include "web_engine_library_info.h" @@ -117,13 +123,25 @@ #include "ui/base/resource/resource_bundle.h" #endif -#if BUILDFLAG(ENABLE_PLUGINS) +#if defined(USE_NSS_CERTS) +#include "net/ssl/client_cert_store_nss.h" +#endif + +#if defined(OS_WIN) +#include "net/ssl/client_cert_store_win.h" +#endif + +#if defined(OS_MACOSX) +#include "net/ssl/client_cert_store_mac.h" +#endif + +#if QT_CONFIG(webengine_pepper_plugins) #include "content/public/browser/browser_ppapi_host.h" #include "ppapi/host/ppapi_host.h" #include "renderer_host/pepper/pepper_host_factory_qt.h" #endif -#if defined(QT_USE_POSITIONING) +#if QT_CONFIG(webengine_geolocation) #include "location_provider_qt.h" #endif @@ -142,8 +160,6 @@ namespace QtWebEngineCore { namespace { -ContentBrowserClientQt* gBrowserClient = 0; // Owned by ContentMainDelegateQt. - // Return a timeout suitable for the glib loop, -1 to block forever, // 0 to return right away, or a timeout in milliseconds from now. int GetTimeIntervalMilliseconds(const base::TimeTicks& from) { @@ -286,6 +302,11 @@ public: #endif return 0; } + void ServiceManagerConnectionStarted(content::ServiceManagerConnection *connection) override + { + ServiceQt::GetInstance()->InitConnector(); + connection->GetConnector()->StartService(service_manager::Identity("qtwebengine")); + } private: DISALLOW_COPY_AND_ASSIGN(BrowserMainPartsQt); @@ -374,18 +395,10 @@ void ShareGroupQtQuick::AboutToAddFirstContext() ContentBrowserClientQt::ContentBrowserClientQt() : m_browserMainParts(0) { - Q_ASSERT(!gBrowserClient); - gBrowserClient = this; } ContentBrowserClientQt::~ContentBrowserClientQt() { - gBrowserClient = 0; -} - -ContentBrowserClientQt *ContentBrowserClientQt::Get() -{ - return gBrowserClient; } content::BrowserMainParts *ContentBrowserClientQt::CreateBrowserMainParts(const content::MainFunctionParams&) @@ -394,25 +407,41 @@ content::BrowserMainParts *ContentBrowserClientQt::CreateBrowserMainParts(const return m_browserMainParts; } -void ContentBrowserClientQt::RenderProcessWillLaunch(content::RenderProcessHost* host) +void ContentBrowserClientQt::RenderProcessWillLaunch(content::RenderProcessHost* host, + service_manager::mojom::ServiceRequest *service_request) { const int id = host->GetID(); Profile *profile = Profile::FromBrowserContext(host->GetBrowserContext()); + content::BrowserThread::PostTaskAndReplyWithResult( + content::BrowserThread::IO, FROM_HERE, + base::Bind(&net::URLRequestContextGetter::GetURLRequestContext, base::Unretained(profile->GetRequestContext())), + base::Bind(&ContentBrowserClientQt::AddNetworkHintsMessageFilter, base::Unretained(this), id)); + // FIXME: Add a settings variable to enable/disable the file scheme. content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme(id, url::kFileScheme); - static_cast<BrowserContextQt*>(host->GetBrowserContext())->m_adapter->userResourceController()->renderProcessStartedWithHost(host); + static_cast<ProfileQt*>(host->GetBrowserContext())->m_profileAdapter->userResourceController()->renderProcessStartedWithHost(host); host->AddFilter(new BrowserMessageFilterQt(id, profile)); -#if defined(Q_OS_MACOS) && BUILDFLAG(ENABLE_SPELLCHECK) && BUILDFLAG(USE_BROWSER_SPELLCHECKER) +#if defined(Q_OS_MACOS) && QT_CONFIG(webengine_spellchecker) && QT_CONFIG(webengine_native_spellchecker) host->AddFilter(new SpellCheckMessageFilterPlatform(id)); #endif -#if BUILDFLAG(ENABLE_BASIC_PRINTING) +#if QT_CONFIG(webengine_printing_and_pdf) host->AddFilter(new PrintingMessageFilterQt(host->GetID())); -#endif // BUILDFLAG(ENABLE_BASIC_PRINTING) +#endif + + service_manager::mojom::ServicePtr service; + *service_request = mojo::MakeRequest(&service); + service_manager::mojom::PIDReceiverPtr pid_receiver; + service_manager::Identity renderer_identity = host->GetChildIdentity(); + ServiceQt::GetInstance()->connector()->StartService( + service_manager::Identity("qtwebengine_renderer", + renderer_identity.user_id(), + renderer_identity.instance()), + std::move(service), mojo::MakeRequest(&pid_receiver)); } void ContentBrowserClientQt::ResourceDispatcherHostCreated() { - m_resourceDispatcherHostDelegate.reset(new ResourceDispatcherHostDelegateQt); + m_resourceDispatcherHostDelegate.reset(new content::ResourceDispatcherHostDelegate); content::ResourceDispatcherHost::Get()->SetDelegate(m_resourceDispatcherHostDelegate.get()); } @@ -461,6 +490,7 @@ static int IsCertErrorFatal(int cert_error) case net::ERR_CERT_NAME_CONSTRAINT_VIOLATION: case net::ERR_CERT_VALIDITY_TOO_LONG: case net::ERR_CERTIFICATE_TRANSPARENCY_REQUIRED: + case net::ERR_CERT_SYMANTEC_LEGACY: return false; case net::ERR_CERT_CONTAINS_ERRORS: case net::ERR_CERT_REVOKED: @@ -498,12 +528,38 @@ void ContentBrowserClientQt::AllowCertificateError(content::WebContents *webCont contentsDelegate->allowCertificateError(errorController); } -void ContentBrowserClientQt::SelectClientCertificate(content::WebContents * /*webContents*/, - net::SSLCertRequestInfo * /*certRequestInfo*/, - net::ClientCertIdentityList /*client_certs*/, +void ContentBrowserClientQt::SelectClientCertificate(content::WebContents *webContents, + net::SSLCertRequestInfo *certRequestInfo, + net::ClientCertIdentityList clientCerts, std::unique_ptr<content::ClientCertificateDelegate> delegate) { - delegate->ContinueWithCertificate(nullptr, nullptr); + if (!clientCerts.empty()) { + WebContentsDelegateQt* contentsDelegate = static_cast<WebContentsDelegateQt*>(webContents->GetDelegate()); + + QSharedPointer<ClientCertSelectController> certSelectController( + new ClientCertSelectController(certRequestInfo, std::move(clientCerts), std::move(delegate))); + + contentsDelegate->selectClientCert(certSelectController); + } else { + delegate->ContinueWithCertificate(nullptr, nullptr); + } +} + +std::unique_ptr<net::ClientCertStore> ContentBrowserClientQt::CreateClientCertStore(content::ResourceContext *resource_context) +{ + if (!resource_context) + return nullptr; +#if defined(USE_NSS_CERTS) + // FIXME: Give it a proper callback for a password delegate. + return std::unique_ptr<net::ClientCertStore>( + new net::ClientCertStoreNSS(net::ClientCertStoreNSS::PasswordDelegateFactory())); +#elif defined(OS_WIN) + return std::unique_ptr<net::ClientCertStore>(new net::ClientCertStoreWin()); +#elif defined(OS_MACOSX) + return std::unique_ptr<net::ClientCertStore>(new net::ClientCertStoreMac()); +#else + return nullptr; +#endif } std::string ContentBrowserClientQt::GetApplicationLocale() @@ -513,13 +569,15 @@ std::string ContentBrowserClientQt::GetApplicationLocale() std::string ContentBrowserClientQt::GetAcceptLangs(content::BrowserContext *context) { - return static_cast<BrowserContextQt*>(context)->adapter()->httpAcceptLanguage().toStdString(); + return static_cast<ProfileQt*>(context)->profileAdapter()->httpAcceptLanguage().toStdString(); } void ContentBrowserClientQt::AppendExtraCommandLineSwitches(base::CommandLine* command_line, int child_process_id) { Q_UNUSED(child_process_id); + url::CustomScheme::SaveSchemes(command_line); + std::string processType = command_line->GetSwitchValueASCII(switches::kProcessType); if (processType == switches::kZygoteProcess) command_line->AppendSwitchASCII(switches::kLang, GetApplicationLocale()); @@ -530,12 +588,6 @@ void ContentBrowserClientQt::GetAdditionalWebUISchemes(std::vector<std::string>* additional_schemes->push_back(content::kChromeDevToolsScheme); } -void ContentBrowserClientQt::GetAdditionalViewSourceSchemes(std::vector<std::string>* additional_schemes) -{ - GetAdditionalWebUISchemes(additional_schemes); - additional_schemes->push_back(kQrcSchemeQt); -} - #if defined(Q_OS_LINUX) void ContentBrowserClientQt::GetAdditionalMappedFilesForChildProcess(const base::CommandLine& command_line, int child_process_id, content::PosixFileDescriptorInfo* mappings) { @@ -552,7 +604,7 @@ void ContentBrowserClientQt::GetAdditionalMappedFilesForChildProcess(const base: } #endif -#if BUILDFLAG(ENABLE_PLUGINS) +#if QT_CONFIG(webengine_pepper_plugins) void ContentBrowserClientQt::DidCreatePpapiPlugin(content::BrowserPpapiHost* browser_host) { browser_host->GetPpapiHost()->AddHostFactoryFilter( @@ -615,8 +667,8 @@ private: void ContentBrowserClientQt::InitFrameInterfaces() { - m_frameInterfaces = base::MakeUnique<service_manager::BinderRegistry>(); - m_frameInterfacesParameterized = base::MakeUnique<service_manager::BinderRegistryWithArgs<content::RenderFrameHost*>>(); + m_frameInterfaces = std::make_unique<service_manager::BinderRegistry>(); + m_frameInterfacesParameterized = std::make_unique<service_manager::BinderRegistryWithArgs<content::RenderFrameHost*>>(); m_frameInterfacesParameterized->AddInterface(base::Bind(&ServiceDriver::BindInsecureInputService)); } @@ -631,53 +683,10 @@ void ContentBrowserClientQt::BindInterfaceRequestFromFrame(content::RenderFrameH m_frameInterfaces->TryBindInterface(interface_name, &interface_pipe); } -class ServiceQt : public service_manager::Service { -public: - ServiceQt(); - - static std::unique_ptr<service_manager::Service> Create() - { - return base::MakeUnique<ServiceQt>(); - } - -private: - // service_manager::Service: - void OnBindInterface(const service_manager::BindSourceInfo& remote_info, - const std::string& name, - mojo::ScopedMessagePipeHandle handle) override; - - service_manager::BinderRegistry m_registry; - service_manager::BinderRegistryWithArgs<const service_manager::BindSourceInfo&> m_registry_with_source_info; - - DISALLOW_COPY_AND_ASSIGN(ServiceQt); -}; - -ServiceQt::ServiceQt() -{ - DCHECK_CURRENTLY_ON(content::BrowserThread::IO); -#if BUILDFLAG(ENABLE_SPELLCHECK) - m_registry_with_source_info.AddInterface( - base::Bind(&SpellCheckHostChromeImpl::Create), - content::BrowserThread::GetTaskRunnerForThread(content::BrowserThread::UI)); -#endif -} - -void ServiceQt::OnBindInterface(const service_manager::BindSourceInfo& remote_info, - const std::string& name, - mojo::ScopedMessagePipeHandle handle) -{ - content::OverrideOnBindInterface(remote_info, name, &handle); - if (!handle.is_valid()) - return; - - if (!m_registry.TryBindInterface(name, &handle)) - m_registry_with_source_info.TryBindInterface(name, &handle, remote_info); -} - void ContentBrowserClientQt::RegisterInProcessServices(StaticServiceMap* services) { service_manager::EmbeddedServiceInfo info; - info.factory = base::Bind(&ServiceQt::Create); + info.factory = ServiceQt::GetInstance()->CreateServiceQtFactory(); services->insert(std::make_pair("qtwebengine", info)); } @@ -697,6 +706,13 @@ std::unique_ptr<base::Value> ContentBrowserClientQt::GetServiceManifestOverlay(b return base::JSONReader::Read(manifest_contents); } +std::vector<content::ContentBrowserClient::ServiceManifestInfo> ContentBrowserClientQt::GetExtraServiceManifests() +{ + return std::vector<content::ContentBrowserClient::ServiceManifestInfo>({ + {"qtwebengine_renderer", IDR_QTWEBENGINE_RENDERER_SERVICE_MANIFEST}, + }); +} + bool ContentBrowserClientQt::CanCreateWindow( content::RenderFrameHost* opener, const GURL& opener_url, @@ -741,7 +757,7 @@ bool ContentBrowserClientQt::CanCreateWindow( std::unique_ptr<device::LocationProvider> ContentBrowserClientQt::OverrideSystemLocationProvider() { -#if defined(QT_USE_POSITIONING) +#if QT_CONFIG(webengine_geolocation) return base::WrapUnique(new LocationProviderQt()); #else return nullptr; @@ -752,7 +768,7 @@ scoped_refptr<net::URLRequestContextGetter> GetSystemRequestContextOnUIThread() { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); return scoped_refptr<net::URLRequestContextGetter>( - BrowserContextAdapter::defaultContext()->browserContext()->GetRequestContext()); + ProfileAdapter::createDefaultProfileAdapter()->profile()->GetRequestContext()); } void ContentBrowserClientQt::GetGeolocationRequestContext( @@ -763,6 +779,19 @@ void ContentBrowserClientQt::GetGeolocationRequestContext( base::BindOnce(&GetSystemRequestContextOnUIThread), std::move(callback)); } +void ContentBrowserClientQt::AddNetworkHintsMessageFilter(int render_process_id, net::URLRequestContext *context) +{ + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + + content::RenderProcessHost* host = content::RenderProcessHost::FromID(render_process_id); + if (!host) + return; + + content::BrowserMessageFilter *network_hints_message_filter( + new network_hints::NetworkHintsMessageFilter(context->host_resolver())); + host->AddFilter(network_hints_message_filter); +} + bool ContentBrowserClientQt::AllowGetCookie(const GURL &url, const GURL &first_party, const net::CookieList & /*cookie_list*/, @@ -830,6 +859,55 @@ bool ContentBrowserClientQt::AllowWorkerIndexedDB(const GURL &url, return networkDelegate->canSetCookies(url, url, std::string()); } +static void LaunchURL(const GURL& url, + const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, + ui::PageTransition page_transition, bool is_main_frame, bool has_user_gesture) +{ + Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); + content::WebContents* webContents = web_contents_getter.Run(); + if (!webContents) + return; + WebContentsDelegateQt *contentsDelegate = static_cast<WebContentsDelegateQt*>(webContents->GetDelegate()); + contentsDelegate->launchExternalURL(toQt(url), page_transition, is_main_frame, has_user_gesture); +} + + +bool ContentBrowserClientQt::HandleExternalProtocol( + const GURL &url, + content::ResourceRequestInfo::WebContentsGetter web_contents_getter, + int child_id, + content::NavigationUIData *navigation_data, + bool is_main_frame, + ui::PageTransition page_transition, + bool has_user_gesture) +{ + Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); + Q_UNUSED(child_id); + Q_UNUSED(navigation_data); + + content::BrowserThread::PostTask( + content::BrowserThread::UI, + FROM_HERE, + base::BindOnce(&LaunchURL, + url, + web_contents_getter, + page_transition, + is_main_frame, + has_user_gesture)); + return true; +} + +scoped_refptr<content::LoginDelegate> ContentBrowserClientQt::CreateLoginDelegate( + net::AuthChallengeInfo *authInfo, + content::ResourceRequestInfo::WebContentsGetter web_contents_getter, + bool /*is_main_frame*/, + const GURL &url, + bool first_auth_attempt, + const base::Callback<void(const base::Optional<net::AuthCredentials>&)>&auth_required_callback) +{ + return base::MakeRefCounted<LoginDelegateQt>(authInfo, web_contents_getter, url, first_auth_attempt, auth_required_callback); +} + } // namespace QtWebEngineCore DEFINE_WEB_CONTENTS_USER_DATA_KEY(QtWebEngineCore::ServiceDriver); |