diff options
author | Michal Klocek <michal.klocek@qt.io> | 2019-02-01 12:01:26 +0100 |
---|---|---|
committer | Michal Klocek <michal.klocek@qt.io> | 2019-02-04 15:34:00 +0000 |
commit | 5e92adf5f85c4ec8340d5b7e92166a5e4f8e9883 (patch) | |
tree | 350d28ccf5de9a85cc26f520bd0dda2222bc1021 /src/webenginewidgets/api | |
parent | a8b48040243c95316a9dad92360f086cf6e537af (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/webenginewidgets/api')
-rw-r--r-- | src/webenginewidgets/api/qwebenginepage.cpp | 2 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginepage.h | 2 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebengineprofile.cpp | 28 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebengineprofile.h | 3 |
4 files changed, 31 insertions, 4 deletions
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index 06a708672..5940319c3 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -1802,7 +1802,7 @@ void QWebEnginePagePrivate::printRequested() \sa QWebEngineUrlRequestInfo, QWebEngineProfile::setRequestInterceptor() */ -void QWebEnginePage::setRequestInterceptor(QWebEngineUrlRequestInterceptor *interceptor) +void QWebEnginePage::setUrlRequestInterceptor(QWebEngineUrlRequestInterceptor *interceptor) { Q_D(QWebEnginePage); bool hadInterceptorChanged = bool(d->requestInterceptor) != bool(interceptor); diff --git a/src/webenginewidgets/api/qwebenginepage.h b/src/webenginewidgets/api/qwebenginepage.h index 5eda8c72f..55450e438 100644 --- a/src/webenginewidgets/api/qwebenginepage.h +++ b/src/webenginewidgets/api/qwebenginepage.h @@ -304,7 +304,7 @@ public: void setDevToolsPage(QWebEnginePage *page); QWebEnginePage *devToolsPage() const; - void setRequestInterceptor(QWebEngineUrlRequestInterceptor *interceptor); + void setUrlRequestInterceptor(QWebEngineUrlRequestInterceptor *interceptor); const QWebEngineContextMenuData &contextMenuData() const; diff --git a/src/webenginewidgets/api/qwebengineprofile.cpp b/src/webenginewidgets/api/qwebengineprofile.cpp index 7e80f9720..e9703ffe8 100644 --- a/src/webenginewidgets/api/qwebengineprofile.cpp +++ b/src/webenginewidgets/api/qwebengineprofile.cpp @@ -550,19 +550,43 @@ QWebEngineCookieStore* QWebEngineProfile::cookieStore() return d->profileAdapter()->cookieStore(); } - +#if QT_DEPRECATED_SINCE(5, 13) /*! Registers a request interceptor singleton \a interceptor to intercept URL requests. The profile does not take ownership of the pointer. + \obsolete + + Interceptors installed with this method will call + QWebEngineUrlRequestInterceptor::interceptRequest on the I/O thread. Therefore + the user has to provide thread-safe interaction with the other user classes. + Use setUrlRequestInterceptor instead. + \since 5.6 \sa QWebEngineUrlRequestInfo -*/ +*/ void QWebEngineProfile::setRequestInterceptor(QWebEngineUrlRequestInterceptor *interceptor) { Q_D(QWebEngineProfile); + interceptor->setProperty("deprecated", true); + d->profileAdapter()->setRequestInterceptor(interceptor); + qWarning("Use of deprecated not tread-safe setter, use setUrlRequestInterceptor instead."); +} +#endif +/*! + Registers a request interceptor singleton \a interceptor to intercept URL requests. + + The profile does not take ownership of the pointer. + + \since 5.13 + \sa QWebEngineUrlRequestInfo QWebEngineUrlRequestInterceptor +*/ + +void QWebEngineProfile::setUrlRequestInterceptor(QWebEngineUrlRequestInterceptor *interceptor) +{ + Q_D(QWebEngineProfile); d->profileAdapter()->setRequestInterceptor(interceptor); } diff --git a/src/webenginewidgets/api/qwebengineprofile.h b/src/webenginewidgets/api/qwebengineprofile.h index 9fc509851..79e83c377 100644 --- a/src/webenginewidgets/api/qwebengineprofile.h +++ b/src/webenginewidgets/api/qwebengineprofile.h @@ -106,7 +106,10 @@ public: void setHttpCacheMaximumSize(int maxSize); QWebEngineCookieStore* cookieStore(); +#if QT_DEPRECATED_SINCE(5, 13) void setRequestInterceptor(QWebEngineUrlRequestInterceptor *interceptor); +#endif + void setUrlRequestInterceptor(QWebEngineUrlRequestInterceptor *interceptor); void clearAllVisitedLinks(); void clearVisitedLinks(const QList<QUrl> &urls); |