diff options
Diffstat (limited to 'src/core/api/qwebenginecookiestore.cpp')
-rw-r--r-- | src/core/api/qwebenginecookiestore.cpp | 35 |
1 files changed, 19 insertions, 16 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. |