diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-03-16 11:16:48 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-03-16 18:26:29 +0000 |
commit | 327fcc7fd3396219a29a6c8d38dc4774e410c1e9 (patch) | |
tree | 12d594340295fe58efe0a35a7ab266bf09f2990d /src/core/api | |
parent | 29a9f9d6e4ad9ffee62d3633edb17c1be335203e (diff) |
Switch cookie-filter API to std::function
Allows us to use return value instead of magic properties
Task-number: QTBUG-66825
Change-Id: I55202a7aca2e662bc214b05caf767d2da496f026
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'src/core/api')
-rw-r--r-- | src/core/api/qwebenginecookiestore.cpp | 35 | ||||
-rw-r--r-- | src/core/api/qwebenginecookiestore.h | 14 | ||||
-rw-r--r-- | src/core/api/qwebenginecookiestore_p.h | 2 |
3 files changed, 27 insertions, 24 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; |