summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core/api/qwebenginecookiestore.cpp35
-rw-r--r--src/core/api/qwebenginecookiestore.h14
-rw-r--r--src/core/api/qwebenginecookiestore_p.h2
-rw-r--r--tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp4
-rw-r--r--tests/quicktestbrowser/main.cpp4
5 files changed, 31 insertions, 28 deletions
diff --git a/src/core/api/qwebenginecookiestore.cpp b/src/core/api/qwebenginecookiestore.cpp
index 583ca1df8..691fab8ab 100644
--- a/src/core/api/qwebenginecookiestore.cpp
+++ b/src/core/api/qwebenginecookiestore.cpp
@@ -192,9 +192,8 @@ bool QWebEngineCookieStorePrivate::canAccessCookies(const QUrl &firstPartyUrl, c
toGurl(firstPartyUrl),
net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
- QWebEngineCookieStore::FilterRequest request = { true, thirdParty, firstPartyUrl, url };
- callbackDirectory.invokeDirectly<QWebEngineCookieStore::FilterRequest&>(filterCallback, request);
- return request.accepted;
+ QWebEngineCookieStore::FilterRequest request = { thirdParty, firstPartyUrl, url };
+ return filterCallback(request);
}
/*!
@@ -337,28 +336,39 @@ void QWebEngineCookieStore::deleteAllCookies()
Installs a cookie filter that can prevent sites and resources from using cookies.
The \a filter must be a lambda or functor taking a FilterRequest structure. If the
- cookie is to be rejected, the filter can set FilterRequest::accepted to \c false.
+ cookie access is to be accepted, the filter function should return \c true; otherwise
+ it should return \c false.
The following code snippet illustrates how to set a cookie filter:
\code
profile->setCookieFilter(
- [&allowThirdPartyCookiesSetting](QWebEngineCookieStore::FilterRequest &request)
- { request.accepted = !request.thirdParty || allowThirdPartyCookiesSetting; }
+ [&allowThirdPartyCookies](const QWebEngineCookieStore::FilterRequest &request)
+ { return !request.thirdParty || allowThirdPartyCookies; }
);
\endcode
- You can unset the filter with a nullptr argument.
+ You can unset the filter with a \c nullptr argument.
The callback should not be used to execute heavy tasks since it is running on the
IO thread and therefore blocks the Chromium networking.
\sa deleteAllCookies(), loadAllCookies()
*/
-void QWebEngineCookieStore::setCookieFilter(const QWebEngineCallback<QWebEngineCookieStore::FilterRequest&> &filter)
+void QWebEngineCookieStore::setCookieFilter(const std::function<bool(const FilterRequest &)> &filterCallback)
{
Q_D(QWebEngineCookieStore);
- d->filterCallback = filter;
+ d->filterCallback = filterCallback;
+}
+
+/*!
+ \since 5.11
+ \overload
+*/
+void QWebEngineCookieStore::setCookieFilter(std::function<bool(const FilterRequest &)> &&filterCallback)
+{
+ Q_D(QWebEngineCookieStore);
+ d->filterCallback = std::move(filterCallback);
}
/*!
@@ -373,13 +383,6 @@ void QWebEngineCookieStore::setCookieFilter(const QWebEngineCallback<QWebEngineC
*/
/*!
- \variable QWebEngineCookieStore::FilterRequest::accepted
- \brief Whether the cookie access should be accepted or not. Defaults to \c true.
-
- Can be set to \c false by the filter to block the cookie access.
-*/
-
-/*!
\variable QWebEngineCookieStore::FilterRequest::firstPartyUrl
\brief The URL that was navigated to.
diff --git a/src/core/api/qwebenginecookiestore.h b/src/core/api/qwebenginecookiestore.h
index 0e839f73c..a62765f77 100644
--- a/src/core/api/qwebenginecookiestore.h
+++ b/src/core/api/qwebenginecookiestore.h
@@ -41,13 +41,14 @@
#define QWEBENGINECOOKIESTORE_H
#include <QtWebEngineCore/qtwebenginecoreglobal.h>
-#include <QtWebEngineCore/qwebenginecallback.h>
#include <QtCore/qobject.h>
#include <QtCore/qscopedpointer.h>
#include <QtCore/qurl.h>
#include <QtNetwork/qnetworkcookie.h>
+#include <functional>
+
namespace QtWebEngineCore {
class BrowserContextAdapter;
class CookieMonsterDelegateQt;
@@ -61,15 +62,14 @@ class QWEBENGINE_EXPORT QWebEngineCookieStore : public QObject {
public:
struct FilterRequest {
- bool accepted;
- const bool thirdParty;
-
- const QUrl firstPartyUrl;
- const QUrl origin;
+ bool thirdParty;
+ QUrl firstPartyUrl;
+ QUrl origin;
};
virtual ~QWebEngineCookieStore();
- void setCookieFilter(const QWebEngineCallback<FilterRequest&> &filterCallback);
+ void setCookieFilter(const std::function<bool(const FilterRequest &)> &filterCallback);
+ void setCookieFilter(std::function<bool(const FilterRequest &)> &&filterCallback);
void setCookie(const QNetworkCookie &cookie, const QUrl &origin = QUrl());
void deleteCookie(const QNetworkCookie &cookie, const QUrl &origin = QUrl());
void deleteSessionCookies();
diff --git a/src/core/api/qwebenginecookiestore_p.h b/src/core/api/qwebenginecookiestore_p.h
index 809aa39b0..e44a80f53 100644
--- a/src/core/api/qwebenginecookiestore_p.h
+++ b/src/core/api/qwebenginecookiestore_p.h
@@ -78,7 +78,7 @@ class QWEBENGINE_PRIVATE_EXPORT QWebEngineCookieStorePrivate
QWebEngineCookieStore *q_ptr;
public:
QtWebEngineCore::CallbackDirectory callbackDirectory;
- QWebEngineCallback<QWebEngineCookieStore::FilterRequest&> filterCallback;
+ std::function<bool(const QWebEngineCookieStore::FilterRequest&)> filterCallback;
QVector<CookieData> m_pendingUserCookies;
quint64 m_nextCallbackId;
bool m_deleteSessionCookiesPending;
diff --git a/tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp b/tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp
index 913614df2..4350575ab 100644
--- a/tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp
+++ b/tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp
@@ -193,7 +193,7 @@ void tst_QWebEngineCookieStore::basicFilter()
QWebEngineCookieStore *client = m_profile.cookieStore();
QAtomicInt accessTested = 0;
- client->setCookieFilter([&](QWebEngineCookieStore::FilterRequest &){ ++accessTested; });
+ client->setCookieFilter([&](const QWebEngineCookieStore::FilterRequest &){ ++accessTested; return true;});
QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool)));
QSignalSpy cookieAddedSpy(client, SIGNAL(cookieAdded(const QNetworkCookie &)));
@@ -209,7 +209,7 @@ void tst_QWebEngineCookieStore::basicFilter()
client->deleteAllCookies();
QTRY_COMPARE(cookieRemovedSpy.count(), 2);
- client->setCookieFilter([&](QWebEngineCookieStore::FilterRequest &request){ ++accessTested; request.accepted = false; });
+ client->setCookieFilter([&](const QWebEngineCookieStore::FilterRequest &){ ++accessTested; return false; });
page.triggerAction(QWebEnginePage::ReloadAndBypassCache);
QTRY_COMPARE(loadSpy.count(), 1);
QVERIFY(loadSpy.takeFirst().takeFirst().toBool());
diff --git a/tests/quicktestbrowser/main.cpp b/tests/quicktestbrowser/main.cpp
index d56841974..45661b5d4 100644
--- a/tests/quicktestbrowser/main.cpp
+++ b/tests/quicktestbrowser/main.cpp
@@ -80,9 +80,9 @@ int main(int argc, char **argv)
Q_ASSERT(index != -1);
QMetaProperty thirdPartyCookiesProperty = rootMeta->property(index);
profile->cookieStore()->setCookieFilter(
- [rootObject,&thirdPartyCookiesProperty](QWebEngineCookieStore::FilterRequest &request)
+ [rootObject,&thirdPartyCookiesProperty](const QWebEngineCookieStore::FilterRequest &request)
{
- request.accepted = !request.thirdParty || thirdPartyCookiesProperty.read(rootObject).toBool();
+ return !request.thirdParty || thirdPartyCookiesProperty.read(rootObject).toBool();
});
index = rootMeta->indexOfProperty("testProfile");