diff options
-rw-r--r-- | src/core/api/qwebenginecookiestoreclient.cpp | 23 | ||||
-rw-r--r-- | src/core/api/qwebenginecookiestoreclient.h | 2 | ||||
-rw-r--r-- | src/core/api/qwebenginecookiestoreclient_p.h | 2 | ||||
-rw-r--r-- | src/core/cookie_monster_delegate_qt.cpp | 8 | ||||
-rw-r--r-- | src/core/cookie_monster_delegate_qt.h | 1 | ||||
-rw-r--r-- | src/core/network_delegate_qt.cpp | 3 |
6 files changed, 38 insertions, 1 deletions
diff --git a/src/core/api/qwebenginecookiestoreclient.cpp b/src/core/api/qwebenginecookiestoreclient.cpp index 25480c1b3..61d38099d 100644 --- a/src/core/api/qwebenginecookiestoreclient.cpp +++ b/src/core/api/qwebenginecookiestoreclient.cpp @@ -171,6 +171,12 @@ void QWebEngineCookieStoreClientPrivate::onCookieChanged(const QNetworkCookie &c Q_EMIT q->cookieAdded(cookie); } +bool QWebEngineCookieStoreClientPrivate::canSetCookie(const QUrl &firstPartyUrl, const QByteArray &cookieLine, const QUrl &url) +{ + Q_Q(QWebEngineCookieStoreClient); + return q->acceptCookie(firstPartyUrl, cookieLine, url); +} + /*! \class QWebEngineCookieStoreClient \inmodule QtWebEngineCore @@ -346,4 +352,21 @@ void QWebEngineCookieStoreClient::deleteAllCookies() deleteAllCookiesWithCallback(QWebEngineCallback<int>()); } +/*! + This virtual function is called before a new cookie is added to the cookie store. + By overriding this function and returning \c false the user can decide to deny + from \a firstPartyUrl the cookie \a cookieLine with the source \a cookieSource. + The request's \a firstPartyUrl can be used to identify a third-party cookie. + This function should not be used to execute heavy tasks since it is running on the + IO thread and therefore blocks the Chromium networking. +*/ + +bool QWebEngineCookieStoreClient::acceptCookie(const QUrl &firstPartyUrl, const QByteArray &cookieLine, const QUrl &cookieSource) +{ + Q_UNUSED(firstPartyUrl); + Q_UNUSED(cookieLine); + Q_UNUSED(cookieSource); + return true; +} + QT_END_NAMESPACE diff --git a/src/core/api/qwebenginecookiestoreclient.h b/src/core/api/qwebenginecookiestoreclient.h index 5dae3bf59..3c01f927d 100644 --- a/src/core/api/qwebenginecookiestoreclient.h +++ b/src/core/api/qwebenginecookiestoreclient.h @@ -74,6 +74,8 @@ public: void deleteSessionCookies(); void deleteAllCookies(); + virtual bool acceptCookie(const QUrl &firstPartyUrl, const QByteArray &cookieLine, const QUrl &cookieSource); + Q_SIGNALS: void cookieAdded(const QNetworkCookie &cookie); void cookieRemoved(const QNetworkCookie &cookie); diff --git a/src/core/api/qwebenginecookiestoreclient_p.h b/src/core/api/qwebenginecookiestoreclient_p.h index ba7914d94..dbb49c81f 100644 --- a/src/core/api/qwebenginecookiestoreclient_p.h +++ b/src/core/api/qwebenginecookiestoreclient_p.h @@ -90,6 +90,8 @@ public: void deleteAllCookies(); void getAllCookies(); + bool canSetCookie(const QUrl &firstPartyUrl, const QByteArray &cookieLine, const QUrl &url); + void onGetAllCallbackResult(qint64 callbackId, const QByteArray &cookieList); void onSetCallbackResult(qint64 callbackId, bool success); void onDeleteCallbackResult(qint64 callbackId, int numCookies); diff --git a/src/core/cookie_monster_delegate_qt.cpp b/src/core/cookie_monster_delegate_qt.cpp index 6b808e76c..7838617ba 100644 --- a/src/core/cookie_monster_delegate_qt.cpp +++ b/src/core/cookie_monster_delegate_qt.cpp @@ -158,6 +158,14 @@ void CookieMonsterDelegateQt::setClient(QWebEngineCookieStoreClient *client) m_client->d_func()->processPendingUserCookies(); } +bool CookieMonsterDelegateQt::canSetCookie(const QUrl &firstPartyUrl, const QByteArray &cookieLine, const QUrl &url) +{ + if (!m_client) + return true; + + return m_client->d_ptr->canSetCookie(firstPartyUrl, cookieLine, url); +} + void CookieMonsterDelegateQt::OnCookieChanged(const net::CanonicalCookie& cookie, bool removed, ChangeCause cause) { if (!m_client) diff --git a/src/core/cookie_monster_delegate_qt.h b/src/core/cookie_monster_delegate_qt.h index e5e295853..7592d57fa 100644 --- a/src/core/cookie_monster_delegate_qt.h +++ b/src/core/cookie_monster_delegate_qt.h @@ -80,6 +80,7 @@ public: void setCookieMonster(net::CookieMonster* monster); void setClient(QWebEngineCookieStoreClient *client); + bool canSetCookie(const QUrl &firstPartyUrl, const QByteArray &cookieLine, const QUrl &url); void OnCookieChanged(const net::CanonicalCookie& cookie, bool removed, ChangeCause cause) override; }; diff --git a/src/core/network_delegate_qt.cpp b/src/core/network_delegate_qt.cpp index d79f6e609..38fd3c710 100644 --- a/src/core/network_delegate_qt.cpp +++ b/src/core/network_delegate_qt.cpp @@ -221,7 +221,8 @@ bool NetworkDelegateQt::OnCanSetCookie(const net::URLRequest& request, const std::string& cookie_line, net::CookieOptions*) { - return true; + Q_ASSERT(m_requestContextGetter); + return m_requestContextGetter->m_cookieDelegate->canSetCookie(toQt(request.first_party_for_cookies()), QByteArray::fromStdString(cookie_line), toQt(request.url())); } void NetworkDelegateQt::OnResolveProxy(const GURL&, int, const net::ProxyService&, net::ProxyInfo*) |