diff options
Diffstat (limited to 'src/core/content_browser_client_qt.cpp')
-rw-r--r-- | src/core/content_browser_client_qt.cpp | 443 |
1 files changed, 172 insertions, 271 deletions
diff --git a/src/core/content_browser_client_qt.cpp b/src/core/content_browser_client_qt.cpp index a1fc7116e..0a51cc261 100644 --- a/src/core/content_browser_client_qt.cpp +++ b/src/core/content_browser_client_qt.cpp @@ -41,18 +41,13 @@ #include "base/json/json_reader.h" #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) +#include "base/strings/utf_string_conversions.h" +#if QT_CONFIG(webengine_spellchecker) #include "chrome/browser/spellchecker/spell_check_host_chrome_impl.h" -#if BUILDFLAG(USE_BROWSER_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" #include "content/public/browser/browser_thread.h" #include "content/public/browser/child_process_security_policy.h" #include "content/public/browser/client_certificate_delegate.h" @@ -61,71 +56,83 @@ #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/service.h" #include "services/proxy_resolver/proxy_resolver_service.h" -#include "third_party/WebKit/public/platform/modules/insecure_input/insecure_input_service.mojom.h" +#include "services/service_manager/public/cpp/connector.h" +#include "services/service_manager/public/cpp/service.h" +#include "services/service_manager/sandbox/switches.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" #include "ui/gl/gl_context.h" #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 "qtwebengine/grit/qt_webengine_resources.h" -#include "browser_context_adapter.h" -#include "browser_context_qt.h" +#include "profile_adapter.h" +#include "browser_main_parts_qt.h" #include "browser_message_filter_qt.h" #include "certificate_error_controller.h" #include "certificate_error_controller_p.h" -#include "desktop_screen_qt.h" +#include "client_cert_select_controller.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 "service/service_qt.h" #include "type_conversion.h" #include "web_contents_delegate_qt.h" #include "web_engine_context.h" #include "web_engine_library_info.h" -#if defined(Q_OS_WIN) -#include "ui/display/win/screen_win.h" -#endif - #if defined(Q_OS_LINUX) #include "global_descriptors_qt.h" #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,157 +149,6 @@ QT_END_NAMESPACE 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) { - if (from.is_null()) - return -1; - - // Be careful here. TimeDelta has a precision of microseconds, but we want a - // value in milliseconds. If there are 5.5ms left, should the delay be 5 or - // 6? It should be 6 to avoid executing delayed work too early. - int delay = static_cast<int>( - ceil((from - base::TimeTicks::Now()).InMillisecondsF())); - - // If this value is negative, then we need to run delayed work soon. - return delay < 0 ? 0 : delay; -} - -class MessagePumpForUIQt : public QObject, - public base::MessagePump -{ -public: - MessagePumpForUIQt() - // Usually this gets passed through Run, but since we have - // our own event loop, attach it explicitly ourselves. - : m_delegate(base::MessageLoopForUI::current()) - , m_explicitLoop(0) - , m_timerId(0) - { - } - - void Run(Delegate *delegate) override - { - Q_ASSERT(delegate == m_delegate); - // This is used only when MessagePumpForUIQt is used outside of the GUI thread. - QEventLoop loop; - m_explicitLoop = &loop; - loop.exec(); - m_explicitLoop = 0; - } - - void Quit() override - { - Q_ASSERT(m_explicitLoop); - m_explicitLoop->quit(); - } - - void ScheduleWork() override - { - QCoreApplication::postEvent(this, new QEvent(QEvent::User)); - } - - void ScheduleDelayedWork(const base::TimeTicks &delayed_work_time) override - { - if (delayed_work_time.is_null()) { - killTimer(m_timerId); - m_timerId = 0; - m_timerScheduledTime = base::TimeTicks(); - } else if (!m_timerId || delayed_work_time < m_timerScheduledTime) { - killTimer(m_timerId); - m_timerId = startTimer(GetTimeIntervalMilliseconds(delayed_work_time)); - m_timerScheduledTime = delayed_work_time; - } - } - -protected: - void customEvent(QEvent *ev) override - { - if (handleScheduledWork()) - QCoreApplication::postEvent(this, new QEvent(QEvent::User)); - } - - void timerEvent(QTimerEvent *ev) override - { - Q_ASSERT(m_timerId == ev->timerId()); - killTimer(m_timerId); - m_timerId = 0; - m_timerScheduledTime = base::TimeTicks(); - - base::TimeTicks next_delayed_work_time; - m_delegate->DoDelayedWork(&next_delayed_work_time); - ScheduleDelayedWork(next_delayed_work_time); - } - -private: - bool handleScheduledWork() { - bool more_work_is_plausible = m_delegate->DoWork(); - - base::TimeTicks delayed_work_time; - more_work_is_plausible |= m_delegate->DoDelayedWork(&delayed_work_time); - - if (more_work_is_plausible) - return true; - - more_work_is_plausible |= m_delegate->DoIdleWork(); - if (!more_work_is_plausible) - ScheduleDelayedWork(delayed_work_time); - - return more_work_is_plausible; - } - - Delegate *m_delegate; - QEventLoop *m_explicitLoop; - int m_timerId; - base::TimeTicks m_timerScheduledTime; -}; - -std::unique_ptr<base::MessagePump> messagePumpFactory() -{ - return base::WrapUnique(new MessagePumpForUIQt); -} - -} // anonymous namespace - -class BrowserMainPartsQt : public content::BrowserMainParts -{ -public: - BrowserMainPartsQt() - : content::BrowserMainParts() - { } - - void PreMainMessageLoopStart() override - { - base::MessageLoop::InitMessagePumpForUIFactory(messagePumpFactory); - } - - void PostMainMessageLoopRun() override - { - // The BrowserContext's destructor uses the MessageLoop so it should be deleted - // right before the RenderProcessHostImpl's destructor destroys it. - WebEngineContext::current()->destroyBrowserContext(); - } - - int PreCreateThreads() override - { - base::ThreadRestrictions::SetIOAllowed(true); - // Like ChromeBrowserMainExtraPartsViews::PreCreateThreads does. -#if defined(Q_OS_WIN) - display::Screen::SetScreenInstance(new display::win::ScreenWin); -#else - display::Screen::SetScreenInstance(new DesktopScreenQt); -#endif - return 0; - } - -private: - DISALLOW_COPY_AND_ASSIGN(BrowserMainPartsQt); -}; - class QtShareGLContext : public gl::GLContext { public: QtShareGLContext(QOpenGLContext *qtContext) @@ -334,14 +190,13 @@ public: bool MakeCurrent(gl::GLSurface *) override { Q_UNREACHABLE(); return false; } void ReleaseCurrent(gl::GLSurface *) override { Q_UNREACHABLE(); } bool IsCurrent(gl::GLSurface *) override { Q_UNREACHABLE(); return false; } - void OnSetSwapInterval(int) override { Q_UNREACHABLE(); } scoped_refptr<gl::GPUTimingClient> CreateGPUTimingClient() override { return nullptr; } - const gl::ExtensionSet& GetExtensions() override + const gfx::ExtensionSet& GetExtensions() override { - static const gl::ExtensionSet s_emptySet; + static const gfx::ExtensionSet s_emptySet; return s_emptySet; } void ResetExtensions() override @@ -376,18 +231,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&) @@ -396,25 +243,38 @@ 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); + content::ChildProcessSecurityPolicy::GetInstance()->GrantRequestScheme(id, url::kFileScheme); + 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) - 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()); } @@ -463,6 +323,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: @@ -500,12 +361,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() @@ -515,15 +402,17 @@ 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) + if (processType == service_manager::switches::kZygoteProcess) command_line->AppendSwitchASCII(switches::kLang, GetApplicationLocale()); } @@ -532,12 +421,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) { @@ -554,7 +437,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( @@ -617,8 +500,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)); } @@ -633,59 +516,17 @@ 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) +void ContentBrowserClientQt::RegisterInProcessServices(StaticServiceMap* services, content::ServiceManagerConnection* connection) { service_manager::EmbeddedServiceInfo info; - info.factory = base::Bind(&ServiceQt::Create); + info.factory = ServiceQt::GetInstance()->CreateServiceQtFactory(); services->insert(std::make_pair("qtwebengine", info)); } void ContentBrowserClientQt::RegisterOutOfProcessServices(content::ContentBrowserClient::OutOfProcessServiceMap *services) { - (*services)[proxy_resolver::mojom::kProxyResolverServiceName] = toString16(QLatin1String("V8 Proxy Resolver")); + (*services)[proxy_resolver::mojom::kProxyResolverServiceName] = + base::BindRepeating(&base::ASCIIToUTF16, "V8 Proxy Resolver"); } std::unique_ptr<base::Value> ContentBrowserClientQt::GetServiceManifestOverlay(base::StringPiece name) @@ -706,6 +547,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, @@ -748,28 +596,31 @@ bool ContentBrowserClientQt::CanCreateWindow( return (settings && settings->getJavaScriptCanOpenWindowsAutomatically()) || user_gesture; } +#if QT_CONFIG(webengine_geolocation) std::unique_ptr<device::LocationProvider> ContentBrowserClientQt::OverrideSystemLocationProvider() { -#if defined(QT_USE_POSITIONING) return base::WrapUnique(new LocationProviderQt()); -#else - return nullptr; -#endif } +#endif 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( - base::OnceCallback<void(scoped_refptr<net::URLRequestContextGetter>)> callback) +void ContentBrowserClientQt::AddNetworkHintsMessageFilter(int render_process_id, net::URLRequestContext *context) { - content::BrowserThread::PostTaskAndReplyWithResult( - content::BrowserThread::UI, FROM_HERE, - base::BindOnce(&GetSystemRequestContextOnUIThread), std::move(callback)); + 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, @@ -789,8 +640,7 @@ bool ContentBrowserClientQt::AllowSetCookie(const GURL &url, const net::CanonicalCookie& /*cookie*/, content::ResourceContext *context, int /*render_process_id*/, - int /*render_frame_id*/, - const net::CookieOptions& /*options*/) + int /*render_frame_id*/) { DCHECK_CURRENTLY_ON(content::BrowserThread::IO); NetworkDelegateQt *networkDelegate = static_cast<NetworkDelegateQt *>(context->GetRequestContext()->network_delegate()); @@ -839,6 +689,57 @@ 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, + const content::GlobalRequestID &request_id, + bool /*is_main_frame*/, + const GURL &url, + scoped_refptr<net::HttpResponseHeaders> response_headers, + bool first_auth_attempt, + LoginAuthRequiredCallback auth_required_callback) +{ + return base::MakeRefCounted<LoginDelegateQt>(authInfo, web_contents_getter, url, first_auth_attempt, std::move(auth_required_callback)); +} + } // namespace QtWebEngineCore DEFINE_WEB_CONTENTS_USER_DATA_KEY(QtWebEngineCore::ServiceDriver); |