summaryrefslogtreecommitdiffstats
path: root/src/core/net/network_delegate_qt.cpp
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@qt.io>2019-02-01 12:01:26 +0100
committerMichal Klocek <michal.klocek@qt.io>2019-02-04 15:34:00 +0000
commit5e92adf5f85c4ec8340d5b7e92166a5e4f8e9883 (patch)
tree350d28ccf5de9a85cc26f520bd0dda2222bc1021 /src/core/net/network_delegate_qt.cpp
parenta8b48040243c95316a9dad92360f086cf6e537af (diff)
Move QWebEngineUrlRequestInterceptor::intercept to ui thread
Currently interceptor sufferers thread safety issues, when custom profiles are deleted, interceptor is set to be nullptr, however it can be still referenced in IO thread. Since profile was split to ui and io part, where io part can outlive the ui part, this can boost thread safety issues. Since QWebEngineUrlRequestInterceptor is living on ui thread simplify the logic move intercept call to ui thread. This fixes the issue of referencing interceptor in io thread. Add new method to install interceptor setUrlRequestInterceptor, and deprecate old one. Update interceptor install method name on page to match the profile one. Task-number: QTBUG-69844 Change-Id: I5dd2b6b734fd91906cccc6c1408ffbe7b1b4250c Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/core/net/network_delegate_qt.cpp')
-rw-r--r--src/core/net/network_delegate_qt.cpp53
1 files changed, 31 insertions, 22 deletions
diff --git a/src/core/net/network_delegate_qt.cpp b/src/core/net/network_delegate_qt.cpp
index d2b9f06b3..3641cb845 100644
--- a/src/core/net/network_delegate_qt.cpp
+++ b/src/core/net/network_delegate_qt.cpp
@@ -131,33 +131,41 @@ int NetworkDelegateQt::OnBeforeURLRequest(net::URLRequest *request, net::Complet
QByteArray::fromStdString(request->method()));
QWebEngineUrlRequestInfo requestInfo(infoPrivate);
- if (QWebEngineUrlRequestInterceptor* interceptor = m_profileIOData->acquireInterceptor()) {
- interceptor->interceptRequest(requestInfo);
- m_profileIOData->releaseInterceptor();
- if (requestInfo.changed()) {
- int result = infoPrivate->shouldBlockRequest ? net::ERR_BLOCKED_BY_CLIENT : net::OK;
-
- if (qUrl != infoPrivate->url)
- *newUrl = toGurl(infoPrivate->url);
-
- if (!infoPrivate->extraHeaders.isEmpty()) {
- auto end = infoPrivate->extraHeaders.constEnd();
- for (auto header = infoPrivate->extraHeaders.constBegin(); header != end; ++header)
- request->SetExtraRequestHeaderByName(header.key().toStdString(), header.value().toStdString(), /* overwrite */ true);
+ // Deprecated =begin
+ // quick peek if deprecated
+ QWebEngineUrlRequestInterceptor* profileInterceptor = m_profileIOData->requestInterceptor();
+ if (profileInterceptor && profileInterceptor->property("deprecated").toBool()) {
+ profileInterceptor = nullptr;
+ if (QWebEngineUrlRequestInterceptor* interceptor = m_profileIOData->acquireInterceptor()) {
+ interceptor->interceptRequest(requestInfo);
+ m_profileIOData->releaseInterceptor();
+ if (requestInfo.changed()) {
+ int result = infoPrivate->shouldBlockRequest ? net::ERR_BLOCKED_BY_CLIENT : net::OK;
+
+ if (qUrl != infoPrivate->url)
+ *newUrl = toGurl(infoPrivate->url);
+
+ if (!infoPrivate->extraHeaders.isEmpty()) {
+ auto end = infoPrivate->extraHeaders.constEnd();
+ for (auto header = infoPrivate->extraHeaders.constBegin(); header != end; ++header)
+ request->SetExtraRequestHeaderByName(header.key().toStdString(), header.value().toStdString(), /* overwrite */ true);
+ }
+
+ if (result != net::OK)
+ return result;
+
+ requestInfo.resetChanged();
}
-
- if (result != net::OK)
- return result;
-
- requestInfo.resetChanged();
+ } else {
+ m_profileIOData->releaseInterceptor();
}
- } else
- m_profileIOData->releaseInterceptor();
+ }
+ // Deprecated =cut
if (!resourceInfo)
return net::OK;
- if (!m_profileIOData->hasPageInterceptors() && !content::IsResourceTypeFrame(resourceType))
+ if (!m_profileIOData->hasPageInterceptors() && !profileInterceptor && !content::IsResourceTypeFrame(resourceType))
return net::OK;
auto webContentsGetter = resourceInfo->GetWebContentsGetterForRequest();
@@ -167,7 +175,8 @@ int NetworkDelegateQt::OnBeforeURLRequest(net::URLRequest *request, net::Complet
newUrl,
std::move(requestInfo),
webContentsGetter,
- std::move(callback)
+ std::move(callback),
+ profileInterceptor ? m_profileIOData->profileAdapter() : nullptr
);
// We'll run the callback after we notified the UI thread.