diff options
author | Michal Klocek <michal.klocek@qt.io> | 2020-08-27 15:25:07 +0200 |
---|---|---|
committer | Michal Klocek <michal.klocek@qt.io> | 2020-11-20 10:47:34 +0100 |
commit | 8f77aa42d2b5b67116a095c41040003265c820c7 (patch) | |
tree | e625adf9ae3840fcc340774e63761c001bce45ca | |
parent | 50218deafeb52419bb45a451bbecf4819dd3ed39 (diff) |
Remove deprecated url interoceptor setter from profile
Change-Id: I15c621da6da97b2ccdd57afdfad0d413302d3c24
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r-- | src/core/api/qwebengineprofile.cpp | 28 | ||||
-rw-r--r-- | src/core/net/proxying_url_loader_factory_qt.cpp | 23 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineprofile.cpp | 25 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineprofile.h | 3 | ||||
-rw-r--r-- | tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp | 139 |
5 files changed, 35 insertions, 183 deletions
diff --git a/src/core/api/qwebengineprofile.cpp b/src/core/api/qwebengineprofile.cpp index bc8f295d9..5704a139a 100644 --- a/src/core/api/qwebengineprofile.cpp +++ b/src/core/api/qwebengineprofile.cpp @@ -582,34 +582,6 @@ 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. - For a duration of this call ui thread is blocked. - Use setUrlRequestInterceptor instead. - - \since 5.6 - \sa QWebEngineUrlRequestInfo - -*/ -void QWebEngineProfile::setRequestInterceptor(QWebEngineUrlRequestInterceptor *interceptor) -{ - Q_D(QWebEngineProfile); - if (interceptor) - interceptor->setProperty("deprecated", true); - d->profileAdapter()->setRequestInterceptor(interceptor); - if (interceptor) - qDebug("Use of deprecated not thread-safe setter, use setUrlRequestInterceptor instead."); -} -#endif /*! Registers a request interceptor singleton \a interceptor to intercept URL requests. diff --git a/src/core/net/proxying_url_loader_factory_qt.cpp b/src/core/net/proxying_url_loader_factory_qt.cpp index d63659d2d..235079c26 100644 --- a/src/core/net/proxying_url_loader_factory_qt.cpp +++ b/src/core/net/proxying_url_loader_factory_qt.cpp @@ -144,7 +144,6 @@ public: private: void InterceptOnUIThread(); - void InterceptOnIOThread(base::WaitableEvent *event); void ContinueAfterIntercept(); // This is called when the original URLLoaderClient has a connection error. @@ -253,34 +252,14 @@ void InterceptedRequest::Restart() 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(); } -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_->property("deprecated").toBool()) + if (profile_request_interceptor_) profile_request_interceptor_->interceptRequest(request_info_); if (!request_info_.changed() && page_request_interceptor_) diff --git a/src/webengine/api/qquickwebengineprofile.cpp b/src/webengine/api/qquickwebengineprofile.cpp index 9e848691b..a8d036d1b 100644 --- a/src/webengine/api/qquickwebengineprofile.cpp +++ b/src/webengine/api/qquickwebengineprofile.cpp @@ -926,31 +926,6 @@ void QQuickWebEngineProfile::clearHttpCache() d->profileAdapter()->clearHttpCache(); } -#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. - - \sa QWebEngineUrlRequestInterceptor - -*/ -void QQuickWebEngineProfile::setRequestInterceptor(QWebEngineUrlRequestInterceptor *interceptor) -{ - Q_D(QQuickWebEngineProfile); - 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. diff --git a/src/webengine/api/qquickwebengineprofile.h b/src/webengine/api/qquickwebengineprofile.h index a0480b424..088e6b225 100644 --- a/src/webengine/api/qquickwebengineprofile.h +++ b/src/webengine/api/qquickwebengineprofile.h @@ -126,9 +126,6 @@ public: QWebEngineCookieStore *cookieStore() const; -#if QT_DEPRECATED_SINCE(5, 13) - void setRequestInterceptor(QWebEngineUrlRequestInterceptor *interceptor); -#endif void setUrlRequestInterceptor(QWebEngineUrlRequestInterceptor *interceptor); const QWebEngineUrlSchemeHandler *urlSchemeHandler(const QByteArray &) const; diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp b/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp index e149e75d8..88f0166c4 100644 --- a/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp +++ b/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp @@ -37,8 +37,6 @@ #include <httpserver.h> #include <httpreqrep.h> -typedef void (QWebEngineProfile::*InterceptorSetter)(QWebEngineUrlRequestInterceptor *interceptor); -Q_DECLARE_METATYPE(InterceptorSetter) class tst_QWebEngineUrlRequestInterceptor : public QObject { Q_OBJECT @@ -54,27 +52,20 @@ public Q_SLOTS: private Q_SLOTS: void initTestCase(); void cleanupTestCase(); - void interceptRequest_data(); void interceptRequest(); - void ipv6HostEncoding_data(); void ipv6HostEncoding(); void requestedUrl_data(); void requestedUrl(); void setUrlSameUrl_data(); void setUrlSameUrl(); - void firstPartyUrl_data(); void firstPartyUrl(); void firstPartyUrlNestedIframes_data(); void firstPartyUrlNestedIframes(); void requestInterceptorByResourceType_data(); void requestInterceptorByResourceType(); - void firstPartyUrlHttp_data(); void firstPartyUrlHttp(); - void passRefererHeader_data(); void passRefererHeader(); - void initiator_data(); void initiator(); - void jsServiceWorker_data(); void jsServiceWorker(); }; @@ -130,8 +121,7 @@ public: void interceptRequest(QWebEngineUrlRequestInfo &info) override { - QCOMPARE(QThread::currentThread() == QCoreApplication::instance()->thread(), !property("deprecated").toBool()); - + QVERIFY(QThread::currentThread() == QCoreApplication::instance()->thread()); // Since 63 we also intercept some unrelated blob requests.. if (info.requestUrl().scheme() == QLatin1String("blob")) return; @@ -220,20 +210,12 @@ public: QStringList sourceIDs; }; -void tst_QWebEngineUrlRequestInterceptor::interceptRequest_data() -{ - QTest::addColumn<InterceptorSetter>("setter"); - QTest::newRow("ui") << &QWebEngineProfile::setUrlRequestInterceptor; - QTest::newRow("io") << &QWebEngineProfile::setRequestInterceptor; -} - void tst_QWebEngineUrlRequestInterceptor::interceptRequest() { - QFETCH(InterceptorSetter, setter); QWebEngineProfile profile; profile.settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, false); TestRequestInterceptor interceptor(/* intercept */ false); - (profile.*setter)(&interceptor); + profile.setUrlRequestInterceptor(&interceptor); QWebEnginePage page(&profile); QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool))); @@ -263,7 +245,7 @@ void tst_QWebEngineUrlRequestInterceptor::interceptRequest() // Make sure that registering an observer does not modify the request. TestRequestInterceptor observer(/* intercept */ false); - (profile.*setter)(&observer); + profile.setUrlRequestInterceptor(&observer); page.load(QUrl("qrc:///resources/__placeholder__")); QTRY_COMPARE(loadSpy.count(), 1); success = loadSpy.takeFirst().takeFirst(); @@ -292,17 +274,11 @@ public: QList<QUrl> requestedUrls; }; -void tst_QWebEngineUrlRequestInterceptor::ipv6HostEncoding_data() -{ - interceptRequest_data(); -} - void tst_QWebEngineUrlRequestInterceptor::ipv6HostEncoding() { - QFETCH(InterceptorSetter, setter); QWebEngineProfile profile; LocalhostContentProvider contentProvider; - (profile.*setter)(&contentProvider); + profile.setUrlRequestInterceptor(&contentProvider); QWebEnginePage page(&profile); QSignalSpy spyLoadFinished(&page, SIGNAL(loadFinished(bool))); @@ -322,23 +298,20 @@ void tst_QWebEngineUrlRequestInterceptor::ipv6HostEncoding() void tst_QWebEngineUrlRequestInterceptor::requestedUrl_data() { - QTest::addColumn<InterceptorSetter>("setter"); QTest::addColumn<bool>("interceptInPage"); - QTest::newRow("ui profile intercept") << &QWebEngineProfile::setUrlRequestInterceptor << false; - QTest::newRow("ui page intercept") << &QWebEngineProfile::setUrlRequestInterceptor << true; - QTest::newRow("io profile intercept") << &QWebEngineProfile::setRequestInterceptor << false; + QTest::newRow("profile intercept") << false; + QTest::newRow("page intercept") << true; } void tst_QWebEngineUrlRequestInterceptor::requestedUrl() { - QFETCH(InterceptorSetter, setter); QFETCH(bool, interceptInPage); QWebEngineProfile profile; profile.settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, false); TestRequestInterceptor interceptor(/* intercept */ true); if (!interceptInPage) - (profile.*setter)(&interceptor); + profile.setUrlRequestInterceptor(&interceptor); QWebEnginePage page(&profile); if (interceptInPage) @@ -377,13 +350,12 @@ void tst_QWebEngineUrlRequestInterceptor::setUrlSameUrl_data() void tst_QWebEngineUrlRequestInterceptor::setUrlSameUrl() { - QFETCH(InterceptorSetter, setter); QFETCH(bool, interceptInPage); QWebEngineProfile profile; TestRequestInterceptor interceptor(/* intercept */ true); if (!interceptInPage) - (profile.*setter)(&interceptor); + profile.setUrlRequestInterceptor(&interceptor); QWebEnginePage page(&profile); if (interceptInPage) @@ -412,17 +384,11 @@ void tst_QWebEngineUrlRequestInterceptor::setUrlSameUrl() QCOMPARE(spy.count(), 4); } -void tst_QWebEngineUrlRequestInterceptor::firstPartyUrl_data() -{ - interceptRequest_data(); -} - void tst_QWebEngineUrlRequestInterceptor::firstPartyUrl() { - QFETCH(InterceptorSetter, setter); QWebEngineProfile profile; TestRequestInterceptor interceptor(/* intercept */ false); - (profile.*setter)(&interceptor); + profile.setUrlRequestInterceptor(&interceptor); QWebEnginePage page(&profile); QSignalSpy spy(&page, SIGNAL(loadFinished(bool))); @@ -440,19 +406,13 @@ void tst_QWebEngineUrlRequestInterceptor::firstPartyUrl() void tst_QWebEngineUrlRequestInterceptor::firstPartyUrlNestedIframes_data() { QUrl url = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebengineurlrequestinterceptor/resources/iframe.html")); - QTest::addColumn<InterceptorSetter>("setter"); QTest::addColumn<QUrl>("requestUrl"); - QTest::newRow("ui file") << &QWebEngineProfile::setUrlRequestInterceptor << url; - QTest::newRow("io file") << &QWebEngineProfile::setRequestInterceptor << url; - QTest::newRow("ui qrc") << &QWebEngineProfile::setUrlRequestInterceptor - << QUrl("qrc:///resources/iframe.html"); - QTest::newRow("io qrc") << &QWebEngineProfile::setRequestInterceptor - << QUrl("qrc:///resources/iframe.html"); + QTest::newRow("ui file") << url; + QTest::newRow("ui qrc") << QUrl("qrc:///resources/iframe.html"); } void tst_QWebEngineUrlRequestInterceptor::firstPartyUrlNestedIframes() { - QFETCH(InterceptorSetter, setter); QFETCH(QUrl, requestUrl); if (requestUrl.scheme() == "file" && !QDir(TESTS_SOURCE_DIR).exists()) @@ -462,7 +422,7 @@ void tst_QWebEngineUrlRequestInterceptor::firstPartyUrlNestedIframes() QWebEngineProfile profile; TestRequestInterceptor interceptor(/* intercept */ false); - (profile.*setter)(&interceptor); + profile.setUrlRequestInterceptor(&interceptor); QWebEnginePage page(&profile); QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool))); @@ -502,47 +462,40 @@ void tst_QWebEngineUrlRequestInterceptor::requestInterceptorByResourceType_data( QUrl faviconFirstPartyUrl = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebengineurlrequestinterceptor/resources/favicon.html")); QUrl faviconRequestUrl = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebengineurlrequestinterceptor/resources/icons/favicon.png")); - QTest::addColumn<InterceptorSetter>("setter"); QTest::addColumn<QUrl>("requestUrl"); QTest::addColumn<QUrl>("firstPartyUrl"); QTest::addColumn<int>("resourceType"); - QStringList name = { "ui", "io" }; - QList<InterceptorSetter> setters = { &QWebEngineProfile::setUrlRequestInterceptor, - &QWebEngineProfile::setRequestInterceptor }; - for (int i = 0; i < 2; i++) { - QTest::newRow(qPrintable(name[i] + "StyleSheet")) - << setters[i] << styleRequestUrl << firstPartyUrl - << static_cast<int>(QWebEngineUrlRequestInfo::ResourceTypeStylesheet); - QTest::newRow(qPrintable(name[i] + "Script")) << setters[i] << scriptRequestUrl << firstPartyUrl - << static_cast<int>(QWebEngineUrlRequestInfo::ResourceTypeScript); - QTest::newRow(qPrintable(name[i] + "Image")) << setters[i] << imageRequestUrl << imageFirstPartyUrl - << static_cast<int>(QWebEngineUrlRequestInfo::ResourceTypeImage); - QTest::newRow(qPrintable(name[i] + "FontResource")) - << setters[i] << fontRequestUrl << firstPartyUrl - << static_cast<int>(QWebEngineUrlRequestInfo::ResourceTypeFontResource); - QTest::newRow(qPrintable(name[i] + "Media")) << setters[i] << mediaRequestUrl << mediaFirstPartyUrl - << static_cast<int>(QWebEngineUrlRequestInfo::ResourceTypeMedia); - QTest::newRow(qPrintable(name[i] + "Favicon")) - << setters[i] << faviconRequestUrl << faviconFirstPartyUrl - << static_cast<int>(QWebEngineUrlRequestInfo::ResourceTypeFavicon); - QTest::newRow(qPrintable(name[i] + "Xhr")) << setters[i] << xhrRequestUrl << firstPartyUrl - << static_cast<int>(QWebEngineUrlRequestInfo::ResourceTypeXhr); - } + QTest::newRow("StyleSheet") + << styleRequestUrl << firstPartyUrl + << static_cast<int>(QWebEngineUrlRequestInfo::ResourceTypeStylesheet); + QTest::newRow("Script") << scriptRequestUrl << firstPartyUrl + << static_cast<int>(QWebEngineUrlRequestInfo::ResourceTypeScript); + QTest::newRow("Image") << imageRequestUrl << imageFirstPartyUrl + << static_cast<int>(QWebEngineUrlRequestInfo::ResourceTypeImage); + QTest::newRow("FontResource") + << fontRequestUrl << firstPartyUrl + << static_cast<int>(QWebEngineUrlRequestInfo::ResourceTypeFontResource); + QTest::newRow(qPrintable("Media")) << mediaRequestUrl << mediaFirstPartyUrl + << static_cast<int>(QWebEngineUrlRequestInfo::ResourceTypeMedia); + QTest::newRow("Favicon") + << faviconRequestUrl << faviconFirstPartyUrl + << static_cast<int>(QWebEngineUrlRequestInfo::ResourceTypeFavicon); + QTest::newRow(qPrintable("Xhr")) << xhrRequestUrl << firstPartyUrl + << static_cast<int>(QWebEngineUrlRequestInfo::ResourceTypeXhr); } void tst_QWebEngineUrlRequestInterceptor::requestInterceptorByResourceType() { if (!QDir(TESTS_SOURCE_DIR).exists()) W_QSKIP(QString("This test requires access to resources found in '%1'").arg(TESTS_SOURCE_DIR).toLatin1().constData(), SkipAll); - QFETCH(InterceptorSetter, setter); QFETCH(QUrl, requestUrl); QFETCH(QUrl, firstPartyUrl); QFETCH(int, resourceType); QWebEngineProfile profile; TestRequestInterceptor interceptor(/* intercept */ false); - (profile.*setter)(&interceptor); + profile.setUrlRequestInterceptor(&interceptor); QWebEnginePage page(&profile); QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool))); @@ -557,17 +510,11 @@ void tst_QWebEngineUrlRequestInterceptor::requestInterceptorByResourceType() QCOMPARE(infos.at(0).resourceType, resourceType); } -void tst_QWebEngineUrlRequestInterceptor::firstPartyUrlHttp_data() -{ - interceptRequest_data(); -} - void tst_QWebEngineUrlRequestInterceptor::firstPartyUrlHttp() { - QFETCH(InterceptorSetter, setter); QWebEngineProfile profile; TestRequestInterceptor interceptor(/* intercept */ false); - (profile.*setter)(&interceptor); + profile.setUrlRequestInterceptor(&interceptor); QWebEnginePage page(&profile); QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool))); @@ -627,14 +574,8 @@ void tst_QWebEngineUrlRequestInterceptor::firstPartyUrlHttp() QCOMPARE(info.firstPartyUrl, firstPartyUrl); } -void tst_QWebEngineUrlRequestInterceptor::passRefererHeader_data() -{ - interceptRequest_data(); -} - void tst_QWebEngineUrlRequestInterceptor::passRefererHeader() { - QFETCH(InterceptorSetter, setter); // Create HTTP Server to parse the request. HttpServer httpServer; @@ -652,7 +593,7 @@ void tst_QWebEngineUrlRequestInterceptor::passRefererHeader() QWebEngineProfile profile; TestRequestInterceptor interceptor(false); interceptor.headers.insert(kHttpHeaderRefererName, kHttpHeaderReferrerValue); - (profile.*setter)(&interceptor); + profile.setUrlRequestInterceptor(&interceptor); QWebEnginePage page(&profile); QSignalSpy spy(&page, SIGNAL(loadFinished(bool))); @@ -666,17 +607,11 @@ void tst_QWebEngineUrlRequestInterceptor::passRefererHeader() QVERIFY(succeeded); } -void tst_QWebEngineUrlRequestInterceptor::initiator_data() -{ - interceptRequest_data(); -} - void tst_QWebEngineUrlRequestInterceptor::initiator() { - QFETCH(InterceptorSetter, setter); QWebEngineProfile profile; TestRequestInterceptor interceptor(/* intercept */ false); - (profile.*setter)(&interceptor); + profile.setUrlRequestInterceptor(&interceptor); QWebEnginePage page(&profile); QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool))); @@ -736,14 +671,8 @@ void tst_QWebEngineUrlRequestInterceptor::initiator() QVERIFY(interceptor.requestInitiatorUrls[info.requestUrl].contains(info.initiator)); } -void tst_QWebEngineUrlRequestInterceptor::jsServiceWorker_data() -{ - interceptRequest_data(); -} - void tst_QWebEngineUrlRequestInterceptor::jsServiceWorker() { - QFETCH(InterceptorSetter, setter); HttpServer server; server.setResourceDirs({ TESTS_SOURCE_DIR "qwebengineurlrequestinterceptor/resources" }); @@ -753,7 +682,7 @@ void tst_QWebEngineUrlRequestInterceptor::jsServiceWorker() std::unique_ptr<ConsolePage> page; page.reset(new ConsolePage(&profile)); TestRequestInterceptor interceptor(/* intercept */ false); - (profile.*setter)(&interceptor); + profile.setUrlRequestInterceptor(&interceptor); QVERIFY(loadSync(page.get(), server.url("/sw.html"))); // We expect only one message here, because logging of services workers is not exposed in our API. |