summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core/api/qwebenginecallback_p.h6
-rw-r--r--src/core/api/qwebenginecookiestoreclient.cpp59
-rw-r--r--src/core/api/qwebenginecookiestoreclient.h16
-rw-r--r--src/core/api/qwebenginecookiestoreclient_p.h1
-rw-r--r--src/core/browser_context_adapter.cpp9
-rw-r--r--src/core/browser_context_adapter.h3
-rw-r--r--src/webengine/api/qquickwebengineprofile.cpp10
-rw-r--r--src/webengine/api/qquickwebengineprofile_p.h2
-rw-r--r--src/webenginewidgets/api/qwebengineprofile.cpp13
-rw-r--r--src/webenginewidgets/api/qwebengineprofile.h1
-rw-r--r--tests/auto/core/qwebenginecookiestoreclient/tst_qwebenginecookiestoreclient.cpp48
-rw-r--r--tests/quicktestbrowser/main.cpp29
12 files changed, 103 insertions, 94 deletions
diff --git a/src/core/api/qwebenginecallback_p.h b/src/core/api/qwebenginecallback_p.h
index 44d9ceb14..f0c25fe9e 100644
--- a/src/core/api/qwebenginecallback_p.h
+++ b/src/core/api/qwebenginecallback_p.h
@@ -98,6 +98,12 @@ public:
FOR_EACH_TYPE(DEFINE_INVOKE_FOR_TYPE)
#undef DEFINE_INVOKE_FOR_TYPE
+ template <typename A>
+ void invokeDirectly(const QWebEngineCallback<A> &callback, const A &argument)
+ {
+ return callback.d.data()->operator()(std::forward<const A&>(argument));
+ }
+
private:
struct CallbackSharedDataPointerBase {
virtual ~CallbackSharedDataPointerBase() { }
diff --git a/src/core/api/qwebenginecookiestoreclient.cpp b/src/core/api/qwebenginecookiestoreclient.cpp
index 3a003ff3e..167b3f68c 100644
--- a/src/core/api/qwebenginecookiestoreclient.cpp
+++ b/src/core/api/qwebenginecookiestoreclient.cpp
@@ -175,8 +175,16 @@ void QWebEngineCookieStoreClientPrivate::onCookieChanged(const QNetworkCookie &c
bool QWebEngineCookieStoreClientPrivate::canSetCookie(const QUrl &firstPartyUrl, const QByteArray &cookieLine, const QUrl &url)
{
- Q_Q(QWebEngineCookieStoreClient);
- return q->acceptCookie(firstPartyUrl, cookieLine, url);
+ if (filterCallback) {
+ QWebEngineCookieStoreClient::FilterRequest request;
+ request.accepted = true;
+ request.firstPartyUrl = firstPartyUrl;
+ request.cookieLine = cookieLine;
+ request.cookieSource = url;
+ callbackDirectory.invokeDirectly<const QWebEngineCookieStoreClient::FilterRequest&>(filterCallback, request);
+ return request.accepted;
+ }
+ return true;
}
/*!
@@ -185,8 +193,7 @@ bool QWebEngineCookieStoreClientPrivate::canSetCookie(const QUrl &firstPartyUrl,
\since 5.6
\brief The QWebEngineCookieStoreClient class provides access to Chromium's cookies.
- By subclassing the QWebEngineCookieStoreClient and installing it on the profile, the user can
- access HTTP cookies of Chromium.
+ The class allows to access HTTP cookies of Chromium for a specific profile.
It can be used to synchronize cookies of Chromium and the QNetworkAccessManager, as well as
to set, delete, and intercept cookies during navigation.
Because cookie operations are asynchronous, the user can choose to provide a callback function
@@ -196,6 +203,27 @@ bool QWebEngineCookieStoreClientPrivate::canSetCookie(const QUrl &firstPartyUrl,
*/
/*!
+ \class QWebEngineCookieStoreClient::FilterRequest
+ \inmodule QtWebEngineCore
+ \since 5.6
+
+ The structure specifies properties of a cookie, and whether it should accepted or not. It is
+ used as an argument to a filter installed via setCookieFilter().
+*/
+
+/*!
+ \variable QWebEngineCookieStoreClient::FilterRequest::accepted
+ Whether the cookie shall be accepted. The default is \c true.
+ \variable QWebEngineCookieStoreClient::FilterRequest::firstPartyUrl
+ URL of page that triggered the setting of the cookie.
+ \variable QWebEngineCookieStoreClient::FilterRequest::cookieLine
+ Content of the cookie.
+ \variable QWebEngineCookieStoreClient::FilterRequest::cookieSource
+ URL of site that sets the cookie.
+*/
+
+
+/*!
\fn void QWebEngineCookieStoreClient::cookieAdded(const QNetworkCookie &cookie)
This signal is emitted whenever a new \a cookie is added to the cookie store.
@@ -355,20 +383,21 @@ void QWebEngineCookieStoreClient::deleteAllCookies()
}
/*!
- 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
+ \fn void QWebEngineCookieStoreClient::setCookieFilter(FunctorOrLambda filterCallback)
+
+ Installs a cookie filter that can reject cookies before they are added to the cookie store.
+ The \a filterCallback must be a lambda or functor taking FilterRequest structure. If the
+ cookie is to be rejected, the filter can set FilterRequest::accepted to \c false.
+
+ The callback 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)
+ \sa deleteAllCookiesWithCallback(), getAllCookies()
+*/
+void QWebEngineCookieStoreClient::setCookieFilter(const QWebEngineCallback<const QWebEngineCookieStoreClient::FilterRequest&> &filter)
{
- Q_UNUSED(firstPartyUrl);
- Q_UNUSED(cookieLine);
- Q_UNUSED(cookieSource);
- return true;
+ Q_D(QWebEngineCookieStoreClient);
+ d->filterCallback = filter;
}
QT_END_NAMESPACE
diff --git a/src/core/api/qwebenginecookiestoreclient.h b/src/core/api/qwebenginecookiestoreclient.h
index 3a6f54ea7..8bdb988e2 100644
--- a/src/core/api/qwebenginecookiestoreclient.h
+++ b/src/core/api/qwebenginecookiestoreclient.h
@@ -46,6 +46,7 @@
#include <QtNetwork/qnetworkcookie.h>
namespace QtWebEngineCore {
+class BrowserContextAdapter;
class CookieMonsterDelegateQt;
}
@@ -54,8 +55,15 @@ QT_BEGIN_NAMESPACE
class QWebEngineCookieStoreClientPrivate;
class QWEBENGINE_EXPORT QWebEngineCookieStoreClient : public QObject {
Q_OBJECT
+
public:
- explicit QWebEngineCookieStoreClient(QObject *parent = 0);
+ struct FilterRequest {
+ bool accepted;
+
+ QUrl firstPartyUrl;
+ QByteArray cookieLine;
+ QUrl cookieSource;
+ };
virtual ~QWebEngineCookieStoreClient();
#ifdef Q_QDOC
@@ -63,24 +71,26 @@ public:
void deleteSessionCookiesWithCallback(FunctorOrLambda resultCallback);
void deleteAllCookiesWithCallback(FunctorOrLambda resultCallback);
void getAllCookies(FunctorOrLambda resultCallback);
+ void setCookieFilter(FunctorOrLambda filterCallback);
#else
void setCookieWithCallback(const QNetworkCookie &cookie, const QWebEngineCallback<bool> &resultCallback, const QUrl &origin = QUrl());
void deleteSessionCookiesWithCallback(const QWebEngineCallback<int> &resultCallback);
void deleteAllCookiesWithCallback(const QWebEngineCallback<int> &resultCallback);
void getAllCookies(const QWebEngineCallback<const QByteArray&> &resultCallback);
+ void setCookieFilter(const QWebEngineCallback<const FilterRequest&> &filterCallback);
#endif
void setCookie(const QNetworkCookie &cookie, const QUrl &origin = QUrl());
void deleteCookie(const QNetworkCookie &cookie, const QUrl &origin = QUrl());
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);
private:
+ explicit QWebEngineCookieStoreClient(QObject *parent = 0);
+ friend class QtWebEngineCore::BrowserContextAdapter;
friend class QtWebEngineCore::CookieMonsterDelegateQt;
Q_DISABLE_COPY(QWebEngineCookieStoreClient)
Q_DECLARE_PRIVATE(QWebEngineCookieStoreClient)
diff --git a/src/core/api/qwebenginecookiestoreclient_p.h b/src/core/api/qwebenginecookiestoreclient_p.h
index a5b0a7068..43652fba6 100644
--- a/src/core/api/qwebenginecookiestoreclient_p.h
+++ b/src/core/api/qwebenginecookiestoreclient_p.h
@@ -74,6 +74,7 @@ class QWEBENGINE_PRIVATE_EXPORT QWebEngineCookieStoreClientPrivate {
public:
Q_DECLARE_PUBLIC(QWebEngineCookieStoreClient)
QtWebEngineCore::CallbackDirectory callbackDirectory;
+ QWebEngineCallback<const QWebEngineCookieStoreClient::FilterRequest&> filterCallback;
QList<CookieData> m_pendingUserCookies;
quint64 m_nextCallbackId;
bool m_deleteSessionCookiesPending;
diff --git a/src/core/browser_context_adapter.cpp b/src/core/browser_context_adapter.cpp
index fc5dc8c21..b5fdf2ce0 100644
--- a/src/core/browser_context_adapter.cpp
+++ b/src/core/browser_context_adapter.cpp
@@ -138,16 +138,11 @@ DownloadManagerDelegateQt *BrowserContextAdapter::downloadManagerDelegate()
QWebEngineCookieStoreClient *BrowserContextAdapter::cookieStoreClient()
{
+ if (!m_cookieStoreClient)
+ m_cookieStoreClient.reset(new QWebEngineCookieStoreClient);
return m_cookieStoreClient.data();
}
-void BrowserContextAdapter::setCookieStoreClient(QWebEngineCookieStoreClient *client)
-{
- m_cookieStoreClient = client;
- if (m_browserContext->url_request_getter_.get())
- m_browserContext->url_request_getter_->updateStorageSettings();
-}
-
QWebEngineUrlRequestInterceptor *BrowserContextAdapter::requestInterceptor()
{
return m_requestInterceptor.data();
diff --git a/src/core/browser_context_adapter.h b/src/core/browser_context_adapter.h
index 6d42f0b06..818dfda3d 100644
--- a/src/core/browser_context_adapter.h
+++ b/src/core/browser_context_adapter.h
@@ -74,7 +74,6 @@ public:
DownloadManagerDelegateQt *downloadManagerDelegate();
QWebEngineCookieStoreClient *cookieStoreClient();
- void setCookieStoreClient(QWebEngineCookieStoreClient *client);
QWebEngineUrlRequestInterceptor* requestInterceptor();
void setRequestInterceptor(QWebEngineUrlRequestInterceptor *interceptor);
@@ -165,7 +164,7 @@ private:
QScopedPointer<WebEngineVisitedLinksManager> m_visitedLinksManager;
QScopedPointer<DownloadManagerDelegateQt> m_downloadManagerDelegate;
QScopedPointer<UserScriptControllerHost> m_userScriptController;
- QPointer<QWebEngineCookieStoreClient> m_cookieStoreClient;
+ QScopedPointer<QWebEngineCookieStoreClient> m_cookieStoreClient;
QPointer<QWebEngineUrlRequestInterceptor> m_requestInterceptor;
QString m_dataPath;
diff --git a/src/webengine/api/qquickwebengineprofile.cpp b/src/webengine/api/qquickwebengineprofile.cpp
index b06345b83..a678fe5fa 100644
--- a/src/webengine/api/qquickwebengineprofile.cpp
+++ b/src/webengine/api/qquickwebengineprofile.cpp
@@ -419,16 +419,16 @@ QQuickWebEngineProfile *QQuickWebEngineProfile::defaultProfile()
return profile;
}
-QQuickWebEngineSettings *QQuickWebEngineProfile::settings() const
+QWebEngineCookieStoreClient *QQuickWebEngineProfile::cookieStoreClient() const
{
const Q_D(QQuickWebEngineProfile);
- return d->settings();
+ return d->browserContext()->cookieStoreClient();
}
-void QQuickWebEngineProfile::setCookieStoreClient(QWebEngineCookieStoreClient* client)
+QQuickWebEngineSettings *QQuickWebEngineProfile::settings() const
{
- Q_D(QQuickWebEngineProfile);
- d->browserContext()->setCookieStoreClient(client);
+ const Q_D(QQuickWebEngineProfile);
+ return d->settings();
}
QT_END_NAMESPACE
diff --git a/src/webengine/api/qquickwebengineprofile_p.h b/src/webengine/api/qquickwebengineprofile_p.h
index af5762032..2cd43caad 100644
--- a/src/webengine/api/qquickwebengineprofile_p.h
+++ b/src/webengine/api/qquickwebengineprofile_p.h
@@ -122,7 +122,7 @@ public:
static QQuickWebEngineProfile *defaultProfile();
- Q_REVISION(1) Q_INVOKABLE void setCookieStoreClient(QWebEngineCookieStoreClient* client);
+ Q_REVISION(1) Q_INVOKABLE QWebEngineCookieStoreClient *cookieStoreClient() const;
signals:
void storageNameChanged();
diff --git a/src/webenginewidgets/api/qwebengineprofile.cpp b/src/webenginewidgets/api/qwebengineprofile.cpp
index 0d9e400ed..2edebdfeb 100644
--- a/src/webenginewidgets/api/qwebengineprofile.cpp
+++ b/src/webenginewidgets/api/qwebengineprofile.cpp
@@ -443,19 +443,6 @@ QWebEngineCookieStoreClient* QWebEngineProfile::cookieStoreClient()
return d->browserContext()->cookieStoreClient();
}
-/*!
- Registers a cookie store client singleton \a client to access Chromium's cookies.
-
- The profile does not take ownership of the pointer.
-
- \sa QWebEngineCookieStoreClient
-*/
-
-void QWebEngineProfile::setCookieStoreClient(QWebEngineCookieStoreClient *client)
-{
- Q_D(QWebEngineProfile);
- d->browserContext()->setCookieStoreClient(client);
-}
/*!
Registers a request interceptor singleton \a interceptor to intercept URL requests.
diff --git a/src/webenginewidgets/api/qwebengineprofile.h b/src/webenginewidgets/api/qwebengineprofile.h
index 4bed186fb..7e03c065c 100644
--- a/src/webenginewidgets/api/qwebengineprofile.h
+++ b/src/webenginewidgets/api/qwebengineprofile.h
@@ -100,7 +100,6 @@ public:
void setHttpCacheMaximumSize(int maxSize);
QWebEngineCookieStoreClient* cookieStoreClient();
- void setCookieStoreClient(QWebEngineCookieStoreClient *client);
void setRequestInterceptor(QWebEngineUrlRequestInterceptor *interceptor);
void clearAllVisitedLinks();
diff --git a/tests/auto/core/qwebenginecookiestoreclient/tst_qwebenginecookiestoreclient.cpp b/tests/auto/core/qwebenginecookiestoreclient/tst_qwebenginecookiestoreclient.cpp
index 0f007d643..d78a81c21 100644
--- a/tests/auto/core/qwebenginecookiestoreclient/tst_qwebenginecookiestoreclient.cpp
+++ b/tests/auto/core/qwebenginecookiestoreclient/tst_qwebenginecookiestoreclient.cpp
@@ -94,13 +94,11 @@ void tst_QWebEngineCookieStoreClient::cleanupTestCase()
void tst_QWebEngineCookieStoreClient::cookieSignals()
{
QWebEngineView view;
- QWebEngineCookieStoreClient client;
+ QWebEngineCookieStoreClient *client = view.page()->profile()->cookieStoreClient();
QSignalSpy loadSpy(&view, SIGNAL(loadFinished(bool)));
- QSignalSpy cookieAddedSpy(&client, SIGNAL(cookieAdded(const QNetworkCookie &)));
- QSignalSpy cookieRemovedSpy(&client, SIGNAL(cookieRemoved(const QNetworkCookie &)));
-
- view.page()->profile()->setCookieStoreClient(&client);
+ QSignalSpy cookieAddedSpy(client, SIGNAL(cookieAdded(const QNetworkCookie &)));
+ QSignalSpy cookieRemovedSpy(client, SIGNAL(cookieRemoved(const QNetworkCookie &)));
view.load(QUrl("qrc:///resources/index.html"));
@@ -111,24 +109,24 @@ void tst_QWebEngineCookieStoreClient::cookieSignals()
// try whether updating a cookie to be expired results in that cookie being removed.
QNetworkCookie expiredCookie(QNetworkCookie::parseCookies(QByteArrayLiteral("SessionCookie=delete; expires=Thu, 01-Jan-1970 00:00:00 GMT; path=///resources")).first());
- client.setCookie(expiredCookie, QUrl("qrc:///resources/index.html"));
+ client->setCookie(expiredCookie, QUrl("qrc:///resources/index.html"));
QTRY_COMPARE(cookieRemovedSpy.count(), 1);
cookieRemovedSpy.clear();
// try removing the other cookie.
QNetworkCookie nonSessionCookie(QNetworkCookie::parseCookies(QByteArrayLiteral("CookieWithExpiresField=QtWebEngineCookieTest; path=///resources")).first());
- client.deleteCookie(nonSessionCookie, QUrl("qrc:///resources/index.html"));
+ client->deleteCookie(nonSessionCookie, QUrl("qrc:///resources/index.html"));
QTRY_COMPARE(cookieRemovedSpy.count(), 1);
}
void tst_QWebEngineCookieStoreClient::setAndDeleteCookie()
{
QWebEngineView view;
- QWebEngineCookieStoreClient client;
+ QWebEngineCookieStoreClient *client = view.page()->profile()->cookieStoreClient();
QSignalSpy loadSpy(&view, SIGNAL(loadFinished(bool)));
- QSignalSpy cookieAddedSpy(&client, SIGNAL(cookieAdded(const QNetworkCookie &)));
- QSignalSpy cookieRemovedSpy(&client, SIGNAL(cookieRemoved(const QNetworkCookie &)));
+ QSignalSpy cookieAddedSpy(client, SIGNAL(cookieAdded(const QNetworkCookie &)));
+ QSignalSpy cookieRemovedSpy(client, SIGNAL(cookieRemoved(const QNetworkCookie &)));
QNetworkCookie cookie1(QNetworkCookie::parseCookies(QByteArrayLiteral("khaos=I9GX8CWI; Domain=.example.com; Path=/docs")).first());
QNetworkCookie cookie2(QNetworkCookie::parseCookies(QByteArrayLiteral("Test%20Cookie=foobar; domain=example.com; Path=/")).first());
@@ -136,11 +134,10 @@ void tst_QWebEngineCookieStoreClient::setAndDeleteCookie()
QNetworkCookie expiredCookie3(QNetworkCookie::parseCookies(QByteArrayLiteral("SessionCookie=delete; expires=Thu, 01-Jan-1970 00:00:00 GMT; path=///resources")).first());
// check if pending cookies are set and removed
- client.setCookieWithCallback(cookie1, [](bool success) { QVERIFY(success); });
- client.setCookieWithCallback(cookie2, [](bool success) { QVERIFY(success); });
- client.deleteCookie(cookie1);
+ client->setCookieWithCallback(cookie1, [](bool success) { QVERIFY(success); });
+ client->setCookieWithCallback(cookie2, [](bool success) { QVERIFY(success); });
+ client->deleteCookie(cookie1);
- view.page()->profile()->setCookieStoreClient(&client);
view.load(QUrl("qrc:///resources/content.html"));
QTRY_COMPARE(loadSpy.count(), 1);
@@ -151,10 +148,10 @@ void tst_QWebEngineCookieStoreClient::setAndDeleteCookie()
cookieAddedSpy.clear();
cookieRemovedSpy.clear();
- client.setCookieWithCallback(cookie3, [](bool success) { QVERIFY(success); });
+ client->setCookieWithCallback(cookie3, [](bool success) { QVERIFY(success); });
// updating a cookie with an expired 'expires' field should remove the cookie with the same name
- client.setCookieWithCallback(expiredCookie3, [](bool success) { QVERIFY(success); });
- client.deleteCookie(cookie2);
+ client->setCookieWithCallback(expiredCookie3, [](bool success) { QVERIFY(success); });
+ client->deleteCookie(cookie2);
QTRY_COMPARE(cookieAddedSpy.count(), 1);
QTRY_COMPARE(cookieRemovedSpy.count(), 2);
}
@@ -162,21 +159,20 @@ void tst_QWebEngineCookieStoreClient::setAndDeleteCookie()
void tst_QWebEngineCookieStoreClient::batchCookieTasks()
{
QWebEngineView view;
- QWebEngineCookieStoreClient client;
+ QWebEngineCookieStoreClient *client = view.page()->profile()->cookieStoreClient();
QSignalSpy loadSpy(&view, SIGNAL(loadFinished(bool)));
- QSignalSpy cookieAddedSpy(&client, SIGNAL(cookieAdded(const QNetworkCookie &)));
- QSignalSpy cookieRemovedSpy(&client, SIGNAL(cookieRemoved(const QNetworkCookie &)));
+ QSignalSpy cookieAddedSpy(client, SIGNAL(cookieAdded(const QNetworkCookie &)));
+ QSignalSpy cookieRemovedSpy(client, SIGNAL(cookieRemoved(const QNetworkCookie &)));
QNetworkCookie cookie1(QNetworkCookie::parseCookies(QByteArrayLiteral("khaos=I9GX8CWI; Domain=.example.com; Path=/docs")).first());
QNetworkCookie cookie2(QNetworkCookie::parseCookies(QByteArrayLiteral("Test%20Cookie=foobar; domain=example.com; Path=/")).first());
int capture = 0;
- client.setCookieWithCallback(cookie1, [&capture](bool success) { QVERIFY(success); ++capture; });
- client.setCookieWithCallback(cookie2, [&capture](bool success) { QVERIFY(success); ++capture; });
+ client->setCookieWithCallback(cookie1, [&capture](bool success) { QVERIFY(success); ++capture; });
+ client->setCookieWithCallback(cookie2, [&capture](bool success) { QVERIFY(success); ++capture; });
- view.page()->profile()->setCookieStoreClient(&client);
view.load(QUrl("qrc:///resources/index.html"));
QTRY_COMPARE(loadSpy.count(), 1);
@@ -190,17 +186,17 @@ void tst_QWebEngineCookieStoreClient::batchCookieTasks()
cookieAddedSpy.clear();
cookieRemovedSpy.clear();
- client.getAllCookies([&capture](const QByteArray& cookieLine) {
+ client->getAllCookies([&capture](const QByteArray& cookieLine) {
++capture;
QCOMPARE(QNetworkCookie::parseCookies(cookieLine).count(), 4);
});
- client.deleteSessionCookiesWithCallback([&capture](int numDeleted) {
+ client->deleteSessionCookiesWithCallback([&capture](int numDeleted) {
++capture;
QCOMPARE(numDeleted, 3);
});
- client.deleteAllCookiesWithCallback([&capture](int numDeleted) {
+ client->deleteAllCookiesWithCallback([&capture](int numDeleted) {
++capture;
QCOMPARE(numDeleted, 1);
});
diff --git a/tests/quicktestbrowser/main.cpp b/tests/quicktestbrowser/main.cpp
index 166da4d5b..167f67dc3 100644
--- a/tests/quicktestbrowser/main.cpp
+++ b/tests/quicktestbrowser/main.cpp
@@ -69,24 +69,6 @@ static QUrl startupUrl()
return QUrl(QStringLiteral("http://qt.io/"));
}
-class CookieClient: public QWebEngineCookieStoreClient
-{
- QMetaProperty m_settingProperty;
- const QObject *m_object;
-public:
- CookieClient(const QObject *object)
- : m_object(object)
- {
- const QMetaObject *rootMeta = object->metaObject();
- int index = rootMeta->indexOfProperty("thirdPartyCookiesEnabled");
- Q_ASSERT(index != -1);
- m_settingProperty = rootMeta->property(index);
- }
- virtual bool acceptCookieFromUrl(const QByteArray &, const QUrl &) {
- return m_settingProperty.read(m_object).toBool();
- }
-};
-
int main(int argc, char **argv)
{
Application app(argc, argv);
@@ -110,10 +92,15 @@ int main(int argc, char **argv)
"}")
, QUrl());
QObject *profile = component.create();
- CookieClient client(rootObject);
- QMetaObject::invokeMethod(profile, "setCookieStoreClient", Q_ARG(QWebEngineCookieStoreClient*, &client));
const QMetaObject *rootMeta = rootObject->metaObject();
- int index = rootMeta->indexOfProperty("testProfile");
+ QWebEngineCookieStoreClient *client = 0;
+ QMetaObject::invokeMethod(profile, "cookieStoreClient", Q_RETURN_ARG(QWebEngineCookieStoreClient*, client));
+ int index = rootMeta->indexOfProperty("thirdPartyCookiesEnabled");
+ Q_ASSERT(index != -1);
+ QMetaProperty thirdPartyCookiesProperty = rootMeta->property(index);
+ client->setCookieFilter([rootObject,&thirdPartyCookiesProperty](const QWebEngineCookieStoreClient::FilterRequest&){ return thirdPartyCookiesProperty.read(rootObject).toBool(); });
+
+ index = rootMeta->indexOfProperty("testProfile");
Q_ASSERT(index != -1);
QMetaProperty profileProperty = rootMeta->property(index);
profileProperty.write(rootObject, qVariantFromValue(profile));