diff --git a/src/core/api/qwebengineurlrequestinfo.cpp b/src/core/api/qwebengineurlrequestinfo.cpp index b769081f8a37293b8ccc0b2b41b6381e43c15b41..e8ce65be3d65006cbdf0fcecca279b6ecab048a5 100644 --- a/src/core/api/qwebengineurlrequestinfo.cpp +++ b/src/core/api/qwebengineurlrequestinfo.cpp @@ -119,11 +119,12 @@ ASSERT_ENUMS_MATCH(QtWebEngineCore::WebContentsAdapterClient::OtherNavigation, Q */ -QWebEngineUrlRequestInfoPrivate::QWebEngineUrlRequestInfoPrivate(QWebEngineUrlRequestInfo::ResourceType resource, QWebEngineUrlRequestInfo::NavigationType navigation, const QUrl &u, const QByteArray &m) +QWebEngineUrlRequestInfoPrivate::QWebEngineUrlRequestInfoPrivate(QWebEngineUrlRequestInfo::ResourceType resource, QWebEngineUrlRequestInfo::NavigationType navigation, const QUrl &u, const QUrl &fpu, const QByteArray &m) : resourceType(resource) , navigationType(navigation) , shouldBlockRequest(false) , url(u) + , firstPartyUrl(fpu) , method(m) { } @@ -218,6 +219,17 @@ QUrl QWebEngineUrlRequestInfo::requestUrl() const return d->url; } +/*! + Returns the first party URL of the request. + The first party URL is the URL of the page that issued the request. +*/ + +QUrl QWebEngineUrlRequestInfo::firstPartyUrl() const +{ + Q_D(const QWebEngineUrlRequestInfo); + return d->firstPartyUrl; +} + /*! Returns the HTTP method of the request (for example, GET or POST). diff --git a/src/core/api/qwebengineurlrequestinfo.h b/src/core/api/qwebengineurlrequestinfo.h index 7c016d20d9645b2ca31cba9ea904cca98b14edcb..e6e225051449869e041279d0b674d3b5dd329aac 100644 --- a/src/core/api/qwebengineurlrequestinfo.h +++ b/src/core/api/qwebengineurlrequestinfo.h @@ -86,6 +86,7 @@ public: NavigationType navigationType() const; QUrl requestUrl() const; + QUrl firstPartyUrl() const; QByteArray requestMethod() const; void block(bool shouldBlock); diff --git a/src/core/api/qwebengineurlrequestinfo_p.h b/src/core/api/qwebengineurlrequestinfo_p.h index b6a304a039cecf2b1f418785def2d085180d1bef..1b1279d2792546700b8600dcea4cf37e2dfe628a 100644 --- a/src/core/api/qwebengineurlrequestinfo_p.h +++ b/src/core/api/qwebengineurlrequestinfo_p.h @@ -58,6 +58,7 @@ public: QWebEngineUrlRequestInfoPrivate(QWebEngineUrlRequestInfo::ResourceType resource , QWebEngineUrlRequestInfo::NavigationType navigation , const QUrl &u + , const QUrl &fpu , const QByteArray &m); QWebEngineUrlRequestInfo::ResourceType resourceType; @@ -65,6 +66,7 @@ public: bool shouldBlockRequest; QUrl url; + QUrl firstPartyUrl; const QByteArray method; QHash<QByteArray, QByteArray> extraHeaders; diff --git a/src/core/network_delegate_qt.cpp b/src/core/network_delegate_qt.cpp index b8f1b68d0dc7ccbf1d446ea0b81228aef2ca4dca..3f67e7c0d39941f7c36eb5458d648d522ac76796 100644 --- a/src/core/network_delegate_qt.cpp +++ b/src/core/network_delegate_qt.cpp @@ -106,6 +106,7 @@ int NetworkDelegateQt::OnBeforeURLRequest(net::URLRequest *request, const net::C QWebEngineUrlRequestInfoPrivate *infoPrivate = new QWebEngineUrlRequestInfoPrivate(static_cast<QWebEngineUrlRequestInfo::ResourceType>(resourceType) , static_cast<QWebEngineUrlRequestInfo::NavigationType>(navigationType) , qUrl + , toQt(request->first_party_for_cookies()) , QByteArray::fromStdString(request->method())); QWebEngineUrlRequestInfo requestInfo(infoPrivate); if (interceptor->interceptRequest(requestInfo)) { diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/resources/firstparty.html b/tests/auto/core/qwebengineurlrequestinterceptor/resources/firstparty.html new file mode 100644 index 0000000000000000000000000000000000000000..8bc540c08d84118c5b6622f3e99db38c08e3dcc1 --- /dev/null +++ b/tests/auto/core/qwebengineurlrequestinterceptor/resources/firstparty.html @@ -0,0 +1,5 @@ +<html> +<body> +<iframe src="qrc:///resources/content.html"></iframe> +</body> +</html> diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp b/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp index a2f9e0c37dfcb2727bcc78b61bd3f6e8e21f1015..4891cafd0fc3a7c7b48269a3ea07046e6625c8d5 100644 --- a/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp +++ b/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp @@ -66,6 +66,7 @@ private Q_SLOTS: void ipv6HostEncoding(); void requestedUrl(); void setUrlSameUrl(); + void firstPartyUrl(); }; tst_QWebEngineUrlRequestInterceptor::tst_QWebEngineUrlRequestInterceptor() @@ -96,6 +97,7 @@ class TestRequestInterceptor : public QWebEngineUrlRequestInterceptor { public: QList<QUrl> observedUrls; + QList<QUrl> firstPartyUrls; bool shouldIntercept; bool interceptRequest(QWebEngineUrlRequestInfo &info) override @@ -105,6 +107,7 @@ public: info.redirect(QUrl("qrc:///resources/content.html")); observedUrls.append(info.requestUrl()); + firstPartyUrls.append(info.firstPartyUrl()); return shouldIntercept; } TestRequestInterceptor(bool intercept) @@ -253,5 +256,22 @@ void tst_QWebEngineUrlRequestInterceptor::setUrlSameUrl() QCOMPARE(spy.count(), 4); } +void tst_QWebEngineUrlRequestInterceptor::firstPartyUrl() +{ + QWebEnginePage page; + TestRequestInterceptor interceptor(/* intercept */ false); + page.profile()->setRequestInterceptor(&interceptor); + + QSignalSpy spy(&page, SIGNAL(loadFinished(bool))); + + page.setUrl(QUrl("qrc:///resources/firstparty.html")); + waitForSignal(&page, SIGNAL(loadFinished(bool))); + QCOMPARE(interceptor.observedUrls.at(0), QUrl("qrc:///resources/firstparty.html")); + QCOMPARE(interceptor.observedUrls.at(1), QUrl("qrc:///resources/content.html")); + QCOMPARE(interceptor.firstPartyUrls.at(0), QUrl("qrc:///resources/firstparty.html")); + QCOMPARE(interceptor.firstPartyUrls.at(1), QUrl("qrc:///resources/firstparty.html")); + QCOMPARE(spy.count(), 1); +} + QTEST_MAIN(tst_QWebEngineUrlRequestInterceptor) #include "tst_qwebengineurlrequestinterceptor.moc" diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.qrc b/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.qrc index afeae268ba0fb99221a7097e534343eba4b8d750..ca045e7fcc452aa54f76755db718b7130c3814cd 100644 --- a/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.qrc +++ b/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.qrc @@ -2,5 +2,6 @@ <qresource> <file>resources/index.html</file> <file>resources/content.html</file> + <file>resources/firstparty.html</file> </qresource> </RCC>