diff options
author | Andras Becsi <andras.becsi@theqtcompany.com> | 2015-08-17 17:21:03 +0200 |
---|---|---|
committer | Andras Becsi <becsi.andras@gmail.com> | 2015-08-27 12:40:28 +0000 |
commit | 8cd47a6df005ae61dbc366b884bebeb0ec49e889 (patch) | |
tree | 123e2357c7c666a61f6e13a6deed95488f73a24d /src/core/api | |
parent | 93d3a21009b601d9fcee1c9faa2324625d3b5ed1 (diff) |
Add support for blocking cookies
This patch adds acceptCookie virtual function that is
called when a request wants to set a new cookie and
can be overridden to intercept or block these cookies.
Change-Id: I8b932d4176ffc3c0ac48b1656486d5492cabaefd
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
Diffstat (limited to 'src/core/api')
-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 |
3 files changed, 27 insertions, 0 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); |