From a05bb73747620dd8f0294a57ff690a4f4202884e Mon Sep 17 00:00:00 2001 From: Michal Klocek Date: Thu, 16 Apr 2020 13:20:04 +0200 Subject: Move request interceptor to ui thread We use now network service avoid io-ui-io-ui hops, pipe proxying url loader factory directly to ui thread. This solves thread safty issues. Add deprecated request interceptor test cases. Task-number: QTBUG-83082 Task-number: QTBUG-82999 Change-Id: I38778cf1a70789c5e92e04c93d1c93e2cc4c765a Reviewed-by: Allan Sandfeld Jensen --- src/core/api/qwebengineurlrequestinfo.cpp | 5 +- src/core/api/qwebengineurlrequestinfo_p.h | 2 +- src/core/content_browser_client_qt.cpp | 35 ++-- src/core/net/proxying_url_loader_factory_qt.cpp | 226 +++++++++--------------- src/core/net/proxying_url_loader_factory_qt.h | 21 ++- src/core/web_contents_adapter.cpp | 10 ++ src/core/web_contents_adapter.h | 5 + src/core/web_contents_adapter_client.h | 3 +- 8 files changed, 143 insertions(+), 164 deletions(-) (limited to 'src/core') diff --git a/src/core/api/qwebengineurlrequestinfo.cpp b/src/core/api/qwebengineurlrequestinfo.cpp index 3816f08ca..5ed729f5e 100644 --- a/src/core/api/qwebengineurlrequestinfo.cpp +++ b/src/core/api/qwebengineurlrequestinfo.cpp @@ -131,10 +131,12 @@ ASSERT_ENUMS_MATCH(QtWebEngineCore::WebContentsAdapterClient::RedirectNavigation QWebEngineUrlRequestInfoPrivate::QWebEngineUrlRequestInfoPrivate(QWebEngineUrlRequestInfo::ResourceType resource, QWebEngineUrlRequestInfo::NavigationType navigation, - const QUrl &u, const QUrl &fpu, const QUrl &i, const QByteArray &m) + const QUrl &u, const QUrl &fpu, const QUrl &i, + const QByteArray &m) : resourceType(resource) , navigationType(navigation) , shouldBlockRequest(false) + , shouldRedirectRequest(false) , url(u) , firstPartyUrl(fpu) , initiator(i) @@ -310,6 +312,7 @@ void QWebEngineUrlRequestInfo::redirect(const QUrl &url) { d_ptr->changed = true; d_ptr->url = url; + d_ptr->shouldRedirectRequest = true; } /*! diff --git a/src/core/api/qwebengineurlrequestinfo_p.h b/src/core/api/qwebengineurlrequestinfo_p.h index 35b5610be..206104ec9 100644 --- a/src/core/api/qwebengineurlrequestinfo_p.h +++ b/src/core/api/qwebengineurlrequestinfo_p.h @@ -75,7 +75,7 @@ public: QWebEngineUrlRequestInfo::ResourceType resourceType; QWebEngineUrlRequestInfo::NavigationType navigationType; bool shouldBlockRequest; - + bool shouldRedirectRequest; QUrl url; QUrl firstPartyUrl; QUrl initiator; diff --git a/src/core/content_browser_client_qt.cpp b/src/core/content_browser_client_qt.cpp index 22dbc173b..cac392182 100644 --- a/src/core/content_browser_client_qt.cpp +++ b/src/core/content_browser_client_qt.cpp @@ -57,6 +57,7 @@ #include "components/network_hints/browser/simple_network_hints_handler_impl.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_task_traits.h" #include "content/public/browser/browser_thread.h" @@ -136,8 +137,10 @@ #include "renderer_host/user_resource_controller_host.h" #include "type_conversion.h" #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_library_info.h" #include "api/qwebenginecookiestore.h" #include "api/qwebenginecookiestore_p.h" @@ -1205,17 +1208,29 @@ bool ContentBrowserClientQt::WillCreateURLLoaderFactory( bool *bypass_redirect_checks, network::mojom::URLLoaderFactoryOverridePtr *factory_override) { - auto proxied_receiver = std::move(*factory_receiver); - network::mojom::URLLoaderFactoryPtrInfo target_factory_info; - *factory_receiver = mojo::MakeRequest(&target_factory_info); - int process_id = (type == URLLoaderFactoryType::kNavigation) ? 0 : render_process_id; + auto *web_contents = content::WebContents::FromRenderFrameHost(frame); + ProfileQt *profile = static_cast(browser_context); - base::PostTask(FROM_HERE, { content::BrowserThread::IO }, - base::BindOnce(&ProxyingURLLoaderFactoryQt::CreateProxy, process_id, - browser_context->GetResourceContext(), - std::move(proxied_receiver), - std::move(target_factory_info))); - return true; + QWebEngineUrlRequestInterceptor *profile_interceptor = profile->profileAdapter()->requestInterceptor(); + QWebEngineUrlRequestInterceptor *page_interceptor = nullptr; + + if (web_contents) { + WebContentsAdapterClient *client = + WebContentsViewQt::from(static_cast(web_contents)->GetView())->client(); + 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 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; } } // namespace QtWebEngineCore diff --git a/src/core/net/proxying_url_loader_factory_qt.cpp b/src/core/net/proxying_url_loader_factory_qt.cpp index a7dc8a48c..b42aa64bb 100644 --- a/src/core/net/proxying_url_loader_factory_qt.cpp +++ b/src/core/net/proxying_url_loader_factory_qt.cpp @@ -59,7 +59,7 @@ #include "net/http/http_util.h" #include "api/qwebengineurlrequestinfo_p.h" -#include "profile_io_data_qt.h" +#include "profile_qt.h" #include "type_conversion.h" #include "web_contents_adapter_client.h" #include "web_contents_view_qt.h" @@ -96,15 +96,14 @@ public: InterceptedRequest(int process_id, uint64_t request_id, int32_t routing_id, uint32_t options, const network::ResourceRequest &request, const net::MutableNetworkTrafficAnnotationTag &traffic_annotation, - ProfileIODataQt *profileData, + QWebEngineUrlRequestInterceptor *profile_request_interceptor, + QWebEngineUrlRequestInterceptor *page_request_interceptor, mojo::PendingReceiver loader, mojo::PendingRemote client, mojo::PendingRemote target_factory); ~InterceptedRequest() override; - void Start(); void Restart(); - void InterceptOnUIThread(); // network::mojom::URLLoaderClient void OnReceiveResponse(network::mojom::URLResponseHeadPtr head) override; @@ -122,9 +121,11 @@ public: void PauseReadingBodyFromNet() override; void ResumeReadingBodyFromNet() override; +private: + void InterceptOnUIThread(); + void InterceptOnIOThread(base::WaitableEvent *event); void ContinueAfterIntercept(); -private: // This is called when the original URLLoaderClient has a connection error. void OnURLLoaderClientError(); @@ -149,32 +150,29 @@ private: // That way the destructor can send it to OnReceivedError if safe browsing // error didn't occur. int error_status_ = net::OK; - QUrl m_originalUrl; - GURL m_topDocumentUrl; - network::ResourceRequest request_; network::ResourceResponseHead current_response_; const net::MutableNetworkTrafficAnnotationTag traffic_annotation_; - QWebEngineUrlRequestInfo m_requestInfo; - ProfileIODataQt *m_profileData; + QWebEngineUrlRequestInfo request_info_; + QPointer profile_request_interceptor_; + QPointer page_request_interceptor_; mojo::Receiver proxied_loader_receiver_; mojo::Remote target_client_; - mojo::Receiver proxied_client_receiver_{this}; mojo::Remote target_loader_; mojo::Remote target_factory_; - base::WeakPtrFactory m_weakFactory; - base::WeakPtr m_weakPtr; + base::WeakPtrFactory weak_factory_; DISALLOW_COPY_AND_ASSIGN(InterceptedRequest); }; InterceptedRequest::InterceptedRequest(int process_id, uint64_t request_id, int32_t routing_id, uint32_t options, const network::ResourceRequest &request, const net::MutableNetworkTrafficAnnotationTag &traffic_annotation, - ProfileIODataQt *profileData, + QWebEngineUrlRequestInterceptor *profile_request_interceptor, + QWebEngineUrlRequestInterceptor *page_request_interceptor, mojo::PendingReceiver loader_receiver, mojo::PendingRemote client, mojo::PendingRemote target_factory) @@ -184,128 +182,105 @@ InterceptedRequest::InterceptedRequest(int process_id, uint64_t request_id, int3 , options_(options) , request_(request) , traffic_annotation_(traffic_annotation) - , m_profileData(profileData) + , profile_request_interceptor_(profile_request_interceptor) + , page_request_interceptor_(page_request_interceptor) , proxied_loader_receiver_(this, std::move(loader_receiver)) , target_client_(std::move(client)) , target_factory_(std::move(target_factory)) - , m_weakFactory(this) - , m_weakPtr(m_weakFactory.GetWeakPtr()) + , weak_factory_(this) { // If there is a client error, clean up the request. target_client_.set_disconnect_handler( - base::BindOnce(&InterceptedRequest::OnURLLoaderClientError, m_weakFactory.GetWeakPtr())); + base::BindOnce(&InterceptedRequest::OnURLLoaderClientError, weak_factory_.GetWeakPtr())); proxied_loader_receiver_.set_disconnect_with_reason_handler( - base::BindOnce(&InterceptedRequest::OnURLLoaderError, m_weakFactory.GetWeakPtr())); + base::BindOnce(&InterceptedRequest::OnURLLoaderError, weak_factory_.GetWeakPtr())); } InterceptedRequest::~InterceptedRequest() { - m_weakFactory.InvalidateWeakPtrs(); + weak_factory_.InvalidateWeakPtrs(); } -void InterceptedRequest::Start() +void InterceptedRequest::Restart() { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + content::ResourceType resourceType = content::ResourceType(request_.resource_type); + WebContentsAdapterClient::NavigationType navigationType = + pageTransitionToNavigationType(ui::PageTransition(request_.transition_type)); + + const QUrl originalUrl = toQt(request_.url); + const QUrl initiator = request_.request_initiator.has_value() ? toQt(request_.request_initiator->GetURL()) : QUrl(); content::WebContents *webContents = nullptr; if (process_id_) { content::RenderFrameHost *frameHost = content::RenderFrameHost::FromID(process_id_, request_.render_frame_id); webContents = content::WebContents::FromRenderFrameHost(frameHost); - } else + } else { webContents = content::WebContents::FromFrameTreeNodeId(request_.render_frame_id); + } - if (webContents) - m_topDocumentUrl = static_cast(webContents)->GetLastCommittedURL(); - - base::PostTask(FROM_HERE, {content::BrowserThread::IO}, - base::BindOnce(&InterceptedRequest::Restart, m_weakPtr)); -} - -void InterceptedRequest::Restart() -{ - DCHECK_CURRENTLY_ON(content::BrowserThread::IO); - - content::ResourceType resourceType = content::ResourceType(request_.resource_type); - WebContentsAdapterClient::NavigationType navigationType = - pageTransitionToNavigationType(ui::PageTransition(request_.transition_type)); - - m_originalUrl = toQt(request_.url); - - const QUrl initiator = request_.request_initiator.has_value() ? toQt(request_.request_initiator->GetURL()) : QUrl(); - + GURL top_document_url = webContents ? webContents->GetLastCommittedURL() : GURL(); QUrl firstPartyUrl; - if (!m_topDocumentUrl.is_empty()) - firstPartyUrl = toQt(m_topDocumentUrl); + if (!top_document_url.is_empty()) + firstPartyUrl = toQt(top_document_url); else firstPartyUrl = toQt(request_.site_for_cookies); // m_topDocumentUrl can be empty for the main-frame. QWebEngineUrlRequestInfoPrivate *infoPrivate = - new QWebEngineUrlRequestInfoPrivate(toQt(resourceType), toQt(navigationType), - m_originalUrl, firstPartyUrl, initiator, - QByteArray::fromStdString(request_.method)); - m_requestInfo = QWebEngineUrlRequestInfo(infoPrivate); - - if (m_profileData && m_profileData->isInterceptorDeprecated()) { - QWebEngineUrlRequestInterceptor *interceptor = m_profileData->acquireInterceptor(); - if (interceptor && m_profileData->isInterceptorDeprecated()) - interceptor->interceptRequest(m_requestInfo); - m_profileData->releaseInterceptor(); + new QWebEngineUrlRequestInfoPrivate(toQt(resourceType), toQt(navigationType), originalUrl, firstPartyUrl, + initiator, QByteArray::fromStdString(request_.method)); + request_info_ = QWebEngineUrlRequestInfo(infoPrivate); + + // TODO: remove for Qt6 + if (profile_request_interceptor_ && profile_request_interceptor_->property("deprecated").toBool()) { + // sync call supports depracated call of an interceptor on io thread + base::WaitableEvent event; + base::PostTask(FROM_HERE, { content::BrowserThread::IO }, + base::BindOnce(&InterceptedRequest::InterceptOnIOThread, base::Unretained(this), &event)); + event.Wait(); + if (request_info_.changed()) { + ContinueAfterIntercept(); + return; + } } + InterceptOnUIThread(); + ContinueAfterIntercept(); +} - if (m_requestInfo.changed()) { - ContinueAfterIntercept(); - } else { - // FIXME: unretained post? - base::PostTask(FROM_HERE, {content::BrowserThread::UI}, - base::BindOnce(&InterceptedRequest::InterceptOnUIThread, base::Unretained(this))); - } +void InterceptedRequest::InterceptOnIOThread(base::WaitableEvent *event) +{ + DCHECK_CURRENTLY_ON(content::BrowserThread::IO); + if (profile_request_interceptor_) + profile_request_interceptor_->interceptRequest(request_info_); + event->Signal(); } void InterceptedRequest::InterceptOnUIThread() { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + if (profile_request_interceptor_) + profile_request_interceptor_->interceptRequest(request_info_); - content::WebContents *webContents = nullptr; - if (process_id_) { - content::RenderFrameHost *frameHost = content::RenderFrameHost::FromID(process_id_, request_.render_frame_id); - webContents = content::WebContents::FromRenderFrameHost(frameHost); - } else - webContents = content::WebContents::FromFrameTreeNodeId(request_.render_frame_id); - - if (webContents) { - if (m_profileData) { - QWebEngineUrlRequestInterceptor *interceptor = m_profileData->requestInterceptor(); - if (interceptor && !interceptor->property("deprecated").toBool()) - interceptor->interceptRequest(m_requestInfo); - } - - WebContentsAdapterClient *client = - WebContentsViewQt::from(static_cast(webContents)->GetView())->client(); - - if (!m_requestInfo.changed()) - client->interceptRequest(m_requestInfo); - } - base::PostTask(FROM_HERE, {content::BrowserThread::IO}, - base::BindOnce(&InterceptedRequest::ContinueAfterIntercept, m_weakPtr)); + if (!request_info_.changed() && page_request_interceptor_) + page_request_interceptor_->interceptRequest(request_info_); } void InterceptedRequest::ContinueAfterIntercept() { - DCHECK_CURRENTLY_ON(content::BrowserThread::IO); + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - if (m_requestInfo.changed()) { - if (m_requestInfo.d_ptr->shouldBlockRequest) + if (request_info_.changed()) { + if (request_info_.d_ptr->shouldBlockRequest) return SendErrorAndCompleteImmediately(net::ERR_BLOCKED_BY_CLIENT); - if (m_requestInfo.requestUrl() != m_originalUrl) { + if (request_info_.d_ptr->shouldRedirectRequest) { net::URLRequest::FirstPartyURLPolicy first_party_url_policy = request_.update_first_party_url_on_redirect ? net::URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT : net::URLRequest::NEVER_CHANGE_FIRST_PARTY_URL; - net::RedirectInfo redirectInfo = net::RedirectInfo::ComputeRedirectInfo(request_.method, request_.url, - request_.site_for_cookies, - first_party_url_policy, request_.referrer_policy, - request_.referrer.spec(), net::HTTP_TEMPORARY_REDIRECT, - toGurl(m_requestInfo.requestUrl()), base::nullopt, - false /*insecure_scheme_was_upgraded*/); + net::RedirectInfo redirectInfo = net::RedirectInfo::ComputeRedirectInfo( + request_.method, request_.url, request_.site_for_cookies, + first_party_url_policy, request_.referrer_policy, request_.referrer.spec(), + net::HTTP_TEMPORARY_REDIRECT, toGurl(request_info_.requestUrl()), base::nullopt, + false /*insecure_scheme_was_upgraded*/); // FIXME: Should probably create a new header. current_response_.encoded_data_length = 0; @@ -320,9 +295,9 @@ void InterceptedRequest::ContinueAfterIntercept() return; } - if (!m_requestInfo.d_ptr->extraHeaders.isEmpty()) { - auto end = m_requestInfo.d_ptr->extraHeaders.constEnd(); - for (auto header = m_requestInfo.d_ptr->extraHeaders.constBegin(); header != end; ++header) { + if (!request_info_.d_ptr->extraHeaders.isEmpty()) { + auto end = request_info_.d_ptr->extraHeaders.constEnd(); + for (auto header = request_info_.d_ptr->extraHeaders.constBegin(); header != end; ++header) { std::string h = header.key().toStdString(); if (base::LowerCaseEqualsASCII(h, "referer")) { request_.referrer = GURL(header.value().toStdString()); @@ -443,7 +418,7 @@ void InterceptedRequest::OnURLLoaderError(uint32_t custom_reason, const std::str void InterceptedRequest::CallOnComplete(const network::URLLoaderCompletionStatus &status, bool wait_for_loader_error) { - DCHECK_CURRENTLY_ON(content::BrowserThread::IO); + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); // Save an error status so that we call onReceiveError at destruction if there // was no safe browsing error. if (status.error_code != net::OK) @@ -467,7 +442,7 @@ void InterceptedRequest::CallOnComplete(const network::URLLoaderCompletionStatus // In case there are pending checks as to whether this request should be // intercepted, we don't want that causing |target_client_| to be used // later. - m_weakFactory.InvalidateWeakPtrs(); + weak_factory_.InvalidateWeakPtrs(); } else { delete this; } @@ -475,22 +450,21 @@ void InterceptedRequest::CallOnComplete(const network::URLLoaderCompletionStatus void InterceptedRequest::SendErrorAndCompleteImmediately(int error_code) { - DCHECK_CURRENTLY_ON(content::BrowserThread::IO); + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); auto status = network::URLLoaderCompletionStatus(error_code); target_client_->OnComplete(status); delete this; } -ProxyingURLLoaderFactoryQt::ProxyingURLLoaderFactoryQt(int process_id, - content::ResourceContext *resourceContext, +ProxyingURLLoaderFactoryQt::ProxyingURLLoaderFactoryQt(int process_id, QWebEngineUrlRequestInterceptor *profile, QWebEngineUrlRequestInterceptor *page, mojo::PendingReceiver loader_receiver, - network::mojom::URLLoaderFactoryPtrInfo target_factory_info) - : m_processId(process_id), m_resourceContext(resourceContext), m_weakFactory(this) + mojo::PendingRemote target_factory_info) + : m_processId(process_id), m_profileRequestInterceptor(profile), m_pageRequestInterceptor(page), m_weakFactory(this) { - DCHECK_CURRENTLY_ON(content::BrowserThread::IO); + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); if (target_factory_info) { m_targetFactory.Bind(std::move(target_factory_info)); - m_targetFactory.set_connection_error_handler( + m_targetFactory.set_disconnect_handler( base::BindOnce(&ProxyingURLLoaderFactoryQt::OnTargetFactoryError, m_weakFactory.GetWeakPtr())); } m_proxyReceivers.Add(this, std::move(loader_receiver)); @@ -503,47 +477,21 @@ ProxyingURLLoaderFactoryQt::~ProxyingURLLoaderFactoryQt() m_weakFactory.InvalidateWeakPtrs(); } -// static -void ProxyingURLLoaderFactoryQt::CreateProxy(int process_id, - content::ResourceContext *resourceContext, - mojo::PendingReceiver loader_receiver, - network::mojom::URLLoaderFactoryPtrInfo target_factory_info) -{ - DCHECK_CURRENTLY_ON(content::BrowserThread::IO); - - // Will manage its own lifetime - new ProxyingURLLoaderFactoryQt(process_id, resourceContext, std::move(loader_receiver), std::move(target_factory_info)); -} - -void ProxyingURLLoaderFactoryQt::CreateLoaderAndStart(mojo::PendingReceiver loader, - int32_t routing_id, int32_t request_id, uint32_t options, - const network::ResourceRequest &request, - mojo::PendingRemote client, +void ProxyingURLLoaderFactoryQt::CreateLoaderAndStart(mojo::PendingReceiver loader, int32_t routing_id, + int32_t request_id, uint32_t options, const network::ResourceRequest &request, + mojo::PendingRemote url_loader_client, const net::MutableNetworkTrafficAnnotationTag &traffic_annotation) { - DCHECK_CURRENTLY_ON(content::BrowserThread::IO); - - ProfileIODataQt *profileIOData = ProfileIODataQt::FromResourceContext(m_resourceContext); - - QWebEngineUrlRequestInterceptor *profileInterceptor = profileIOData ? profileIOData->requestInterceptor() : nullptr; - if (!profileIOData || !(profileInterceptor || profileIOData->hasPageInterceptors())) { - m_targetFactory->CreateLoaderAndStart( - std::move(loader), routing_id, request_id, options, request, - std::move(client), traffic_annotation); - return; - } - + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); mojo::PendingRemote target_factory_clone; if (m_targetFactory) m_targetFactory->Clone(target_factory_clone.InitWithNewPipeAndPassReceiver()); // Will manage its own lifetime - InterceptedRequest *req = new InterceptedRequest(m_processId, request_id, routing_id, options, request, - traffic_annotation, profileIOData, - std::move(loader), std::move(client), - std::move(target_factory_clone)); - base::PostTask(FROM_HERE, {content::BrowserThread::UI}, - base::BindOnce(&InterceptedRequest::Start, base::Unretained(req))); + InterceptedRequest *req = new InterceptedRequest(m_processId, request_id, routing_id, options, request, traffic_annotation, + m_profileRequestInterceptor, m_pageRequestInterceptor, std::move(loader), + std::move(url_loader_client), std::move(target_factory_clone)); + req->Restart(); } void ProxyingURLLoaderFactoryQt::OnTargetFactoryError() @@ -559,7 +507,7 @@ void ProxyingURLLoaderFactoryQt::OnProxyBindingError() void ProxyingURLLoaderFactoryQt::Clone(mojo::PendingReceiver receiver) { - DCHECK_CURRENTLY_ON(content::BrowserThread::IO); + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); m_proxyReceivers.Add(this, std::move(receiver)); } diff --git a/src/core/net/proxying_url_loader_factory_qt.h b/src/core/net/proxying_url_loader_factory_qt.h index ba19bab97..3d77856cc 100644 --- a/src/core/net/proxying_url_loader_factory_qt.h +++ b/src/core/net/proxying_url_loader_factory_qt.h @@ -54,11 +54,14 @@ #include "services/network/public/mojom/url_loader_factory.mojom.h" #include "url/gurl.h" +#include // based on aw_proxying_url_loader_factory.h: // 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. +QT_FORWARD_DECLARE_CLASS(QWebEngineUrlRequestInterceptor) + namespace content { class ResourceContext; } @@ -68,16 +71,13 @@ namespace QtWebEngineCore { class ProxyingURLLoaderFactoryQt : public network::mojom::URLLoaderFactory { public: - ProxyingURLLoaderFactoryQt(int process_id, content::ResourceContext *resourceContext, + ProxyingURLLoaderFactoryQt(int processId, QWebEngineUrlRequestInterceptor *profile, + QWebEngineUrlRequestInterceptor *page, mojo::PendingReceiver loader_receiver, - network::mojom::URLLoaderFactoryPtrInfo target_factory_info); + mojo::PendingRemote pending_target_factory_remote); ~ProxyingURLLoaderFactoryQt() override; - static void CreateProxy(int process_id, content::ResourceContext *resourceContext, - mojo::PendingReceiver loader_receiver, - network::mojom::URLLoaderFactoryPtrInfo target_factory_info); - void CreateLoaderAndStart(mojo::PendingReceiver loader, int32_t routing_id, int32_t request_id, uint32_t options, const network::ResourceRequest &request, @@ -90,12 +90,11 @@ private: void OnTargetFactoryError(); void OnProxyBindingError(); - const int m_processId; + int m_processId; mojo::ReceiverSet m_proxyReceivers; - network::mojom::URLLoaderFactoryPtr m_targetFactory; - - content::ResourceContext *m_resourceContext; - + mojo::Remote m_targetFactory; + QPointer m_profileRequestInterceptor; + QPointer m_pageRequestInterceptor; base::WeakPtrFactory m_weakFactory; DISALLOW_COPY_AND_ASSIGN(ProxyingURLLoaderFactoryQt); diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index a97db169b..2d559bb38 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -1014,6 +1014,16 @@ ProfileAdapter* WebContentsAdapter::profileAdapter() static_cast(m_webContents->GetBrowserContext())->profileAdapter() : nullptr; } +void WebContentsAdapter::setRequestInterceptor(QWebEngineUrlRequestInterceptor *interceptor) +{ + m_requestInterceptor = interceptor; +} + +QWebEngineUrlRequestInterceptor* WebContentsAdapter::requestInterceptor() const +{ + return m_requestInterceptor; +} + #ifndef QT_NO_ACCESSIBILITY QAccessibleInterface *WebContentsAdapter::browserAccessible() { diff --git a/src/core/web_contents_adapter.h b/src/core/web_contents_adapter.h index 1a76cd3c1..cc041ed55 100644 --- a/src/core/web_contents_adapter.h +++ b/src/core/web_contents_adapter.h @@ -61,6 +61,7 @@ #include #include #include +#include namespace content { class WebContents; @@ -79,6 +80,7 @@ class QPageLayout; class QString; class QTemporaryDir; class QWebChannel; +class QWebEngineUrlRequestInterceptor; QT_END_NAMESPACE namespace QtWebEngineCore { @@ -235,6 +237,8 @@ public: void initialize(content::SiteInstance *site); content::WebContents *webContents() const; void updateRecommendedState(); + void setRequestInterceptor(QWebEngineUrlRequestInterceptor *interceptor); + QWebEngineUrlRequestInterceptor* requestInterceptor() const; private: Q_DISABLE_COPY(WebContentsAdapter) @@ -274,6 +278,7 @@ private: LifecycleState m_lifecycleState = LifecycleState::Active; LifecycleState m_recommendedState = LifecycleState::Active; bool m_inspector = false; + QPointer m_requestInterceptor; }; } // namespace QtWebEngineCore diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h index 04df0450c..250801f51 100644 --- a/src/core/web_contents_adapter_client.h +++ b/src/core/web_contents_adapter_client.h @@ -70,6 +70,7 @@ QT_FORWARD_DECLARE_CLASS(QWebEngineFindTextResult) QT_FORWARD_DECLARE_CLASS(QWebEngineQuotaRequest) QT_FORWARD_DECLARE_CLASS(QWebEngineRegisterProtocolHandlerRequest) QT_FORWARD_DECLARE_CLASS(QWebEngineUrlRequestInfo) +QT_FORWARD_DECLARE_CLASS(QWebEngineUrlRequestInterceptor) namespace content { struct DropData; @@ -514,7 +515,6 @@ public: virtual ClientType clientType() = 0; virtual void printRequested() = 0; virtual void widgetChanged(RenderWidgetHostViewQtDelegate *newWidget) = 0; - virtual void interceptRequest(QWebEngineUrlRequestInfo &) { } virtual TouchHandleDrawableClient *createTouchHandle(const QMap &images) = 0; virtual void showTouchSelectionMenu(TouchSelectionMenuController *menuController, const QRect &bounds, const QSize &handleSize) = 0; virtual void hideTouchSelectionMenu() = 0; @@ -523,7 +523,6 @@ public: virtual ProfileAdapter *profileAdapter() = 0; virtual WebContentsAdapter* webContentsAdapter() = 0; virtual void releaseProfile() = 0; - }; } // namespace QtWebEngineCore -- cgit v1.2.3