summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@theqtcompany.com>2015-12-02 19:38:33 +0100
committerMichal Klocek <michal.klocek@theqtcompany.com>2016-01-15 22:06:53 +0000
commit09ff58b1a91a1472b4aa4c644686fb2e46a3b1ca (patch)
treed3c77a3034e4ddc349150f5e38a686fd569457dd
parent50c423267ee54020a7ddbe3a0f56ddca4653c40a (diff)
Remove callback functions from qwebenginecookiestore
Remove all callback api calls, rename getAllCookies to loadCookies, update documentation. New function name reflects the fact the cookieAdded signal is always emitted when cookies are loaded from the store. Change-Id: Iab7bb04871c7396d2e23306a10084d425426a19f Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
-rw-r--r--src/core/api/qwebenginecookiestore.cpp108
-rw-r--r--src/core/api/qwebenginecookiestore.h9
-rw-r--r--tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp44
3 files changed, 52 insertions, 109 deletions
diff --git a/src/core/api/qwebenginecookiestore.cpp b/src/core/api/qwebenginecookiestore.cpp
index 2938eddbd..ab2612803 100644
--- a/src/core/api/qwebenginecookiestore.cpp
+++ b/src/core/api/qwebenginecookiestore.cpp
@@ -268,41 +268,26 @@ QWebEngineCookieStore::~QWebEngineCookieStore()
}
/*!
- \fn void setCookieWithCallback(const QNetworkCookie &cookie, FunctorOrLambda resultCallback, const QUrl &origin = QUrl())
-
- Adds \a cookie to the cookie store. When the operation finishes, \a resultCallback will be executed
- on the caller thread.
- It is possible to provide an optional \a origin URL argument to limit the scope of the cookie.
- The provided URL should also include the scheme.
-
- \sa setCookie()
-*/
-
-void QWebEngineCookieStore::setCookieWithCallback(const QNetworkCookie &cookie, const QWebEngineCallback<bool> &resultCallback, const QUrl &origin)
-{
- Q_D(QWebEngineCookieStore);
- d->setCookie(resultCallback, cookie, origin);
-}
-
-/*!
- Adds \a cookie to the cookie store. This function is provided for convenience and is
- equivalent to calling setCookieWithCallback() with an empty callback.
+ Adds \a cookie to the cookie store.
It is possible to provide an optional \a origin URL argument to limit the scope of the cookie.
The provided URL should also include the scheme.
- \sa setCookieWithCallback()
+ \note This operation is asynchronous.
*/
void QWebEngineCookieStore::setCookie(const QNetworkCookie &cookie, const QUrl &origin)
{
- setCookieWithCallback(cookie, QWebEngineCallback<bool>(), origin);
+ //TODO: use callbacks or delete dummy ones
+ Q_D(QWebEngineCookieStore);
+ d->setCookie(QWebEngineCallback<bool>(), cookie, origin);
}
/*!
Deletes \a cookie from the cookie store.
It is possible to provide an optional \a origin URL argument to limit the scope of the
cookie to be deleted.
- The provided URL should also include the scheme.
+
+ \note This operation is asynchronous.
*/
void QWebEngineCookieStore::deleteCookie(const QNetworkCookie &cookie, const QUrl &origin)
@@ -312,89 +297,60 @@ void QWebEngineCookieStore::deleteCookie(const QNetworkCookie &cookie, const QUr
}
/*!
- \fn void QWebEngineCookieStore::getAllCookies(FunctorOrLambda resultCallback)
+ Loads all the cookies into the cookie store. The cookieAdded() signal is emitted on every
+ loaded cookie. Cookies are loaded automatically when the store gets initialized, which
+ in most cases happens on loading the first URL. However, calling this function is useful
+ if cookies should be listed before entering the web content.
- Requests all the cookies in the cookie store. When the asynchronous operation finishes,
- \a resultCallback will be called with a QByteArray as the argument containing the cookies.
- This QByteArray can be parsed using QNetworkCookie::parseCookies().
-
- \sa deleteCookie()
+ \note This operation is asynchronous.
*/
-void QWebEngineCookieStore::getAllCookies(const QWebEngineCallback<const QByteArray&> &resultCallback)
+void QWebEngineCookieStore::loadAllCookies()
{
+ //TODO: use callbacks or delete dummy ones
Q_D(QWebEngineCookieStore);
- if (d->m_getAllCookiesPending) {
- d->callbackDirectory.invokeEmpty(resultCallback);
+ if (d->m_getAllCookiesPending)
return;
- }
- d->callbackDirectory.registerCallback(CallbackDirectory::GetAllCookiesCallbackId, resultCallback);
+ d->callbackDirectory.registerCallback(CallbackDirectory::GetAllCookiesCallbackId, QWebEngineCallback<const QByteArray&>());
+ //this will trigger cookieAdded signal
d->getAllCookies();
}
/*!
- \fn void QWebEngineCookieStore::deleteSessionCookiesWithCallback(FunctorOrLambda resultCallback)
-
Deletes all the session cookies in the cookie store. Session cookies do not have an
expiration date assigned to them.
- When the asynchronous operation finishes, \a resultCallback will be called with the
- number of cookies deleted as the argument.
+
+ \note This operation is asynchronous.
+ \sa loadAllCookies()
*/
-void QWebEngineCookieStore::deleteSessionCookiesWithCallback(const QWebEngineCallback<int> &resultCallback)
+void QWebEngineCookieStore::deleteSessionCookies()
{
+ //TODO: use callbacks or delete dummy ones
Q_D(QWebEngineCookieStore);
- if (d->m_deleteAllCookiesPending || d->m_deleteSessionCookiesPending) {
- d->callbackDirectory.invokeEmpty(resultCallback);
+ if (d->m_deleteAllCookiesPending || d->m_deleteSessionCookiesPending)
return;
- }
- d->callbackDirectory.registerCallback(CallbackDirectory::DeleteSessionCookiesCallbackId, resultCallback);
+ d->callbackDirectory.registerCallback(CallbackDirectory::DeleteSessionCookiesCallbackId, QWebEngineCallback<int>());
d->deleteSessionCookies();
}
/*!
- \fn void QWebEngineCookieStore::deleteAllCookiesWithCallback(FunctorOrLambda resultCallback)
-
- Deletes all the cookies in the cookie store. When the asynchronous operation finishes,
- \a resultCallback will be called with the number of cookies deleted as the argument.
-
- \sa deleteSessionCookiesWithCallback(), getAllCookies()
+ Deletes all the cookies in the cookie store.
+ \note This operation is asynchronous.
+ \sa loadAllCookies()
*/
-void QWebEngineCookieStore::deleteAllCookiesWithCallback(const QWebEngineCallback<int> &resultCallback)
+void QWebEngineCookieStore::deleteAllCookies()
{
+ //TODO: use callbacks or delete dummy ones
Q_D(QWebEngineCookieStore);
- if (d->m_deleteAllCookiesPending) {
- d->callbackDirectory.invokeEmpty(resultCallback);
+ if (d->m_deleteAllCookiesPending)
return;
- }
- d->callbackDirectory.registerCallback(CallbackDirectory::DeleteAllCookiesCallbackId, resultCallback);
+ d->callbackDirectory.registerCallback(CallbackDirectory::DeleteAllCookiesCallbackId, QWebEngineCallback<int>());
d->deleteAllCookies();
}
/*!
- Deletes all the session cookies in the cookie store.
-
- \sa deleteSessionCookiesWithCallback()
-*/
-
-void QWebEngineCookieStore::deleteSessionCookies()
-{
- deleteSessionCookiesWithCallback(QWebEngineCallback<int>());
-}
-
-/*!
- Deletes all the cookies in the cookie store.
-
- \sa deleteAllCookiesWithCallback(), getAllCookies()
-*/
-
-void QWebEngineCookieStore::deleteAllCookies()
-{
- deleteAllCookiesWithCallback(QWebEngineCallback<int>());
-}
-
-/*!
\fn void QWebEngineCookieStore::setCookieFilter(FunctorOrLambda filterCallback)
Installs a cookie filter that can reject cookies before they are added to the cookie store.
@@ -404,7 +360,7 @@ void QWebEngineCookieStore::deleteAllCookies()
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 deleteAllCookiesWithCallback(), getAllCookies()
+ \sa deleteAllCookies(), loadAllCookies()
*/
void QWebEngineCookieStore::setCookieFilter(const QWebEngineCallback<QWebEngineCookieStore::FilterRequest&> &filter)
{
diff --git a/src/core/api/qwebenginecookiestore.h b/src/core/api/qwebenginecookiestore.h
index b78f885ef..3a52a2025 100644
--- a/src/core/api/qwebenginecookiestore.h
+++ b/src/core/api/qwebenginecookiestore.h
@@ -67,22 +67,15 @@ public:
virtual ~QWebEngineCookieStore();
#ifdef Q_QDOC
- void setCookieWithCallback(const QNetworkCookie &cookie, FunctorOrLambda resultCallback, const QUrl &origin = QUrl());
- 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<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();
+ void loadAllCookies();
Q_SIGNALS:
void cookieAdded(const QNetworkCookie &cookie);
diff --git a/tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp b/tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp
index 9436b093e..7cf55427e 100644
--- a/tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp
+++ b/tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp
@@ -95,6 +95,7 @@ void tst_QWebEngineCookieStore::cookieSignals()
{
QWebEngineView view;
QWebEngineCookieStore *client = view.page()->profile()->cookieStore();
+ client->deleteAllCookies();
QSignalSpy loadSpy(&view, SIGNAL(loadFinished(bool)));
QSignalSpy cookieAddedSpy(client, SIGNAL(cookieAdded(const QNetworkCookie &)));
@@ -110,6 +111,7 @@ void tst_QWebEngineCookieStore::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"));
+
QTRY_COMPARE(cookieRemovedSpy.count(), 1);
cookieRemovedSpy.clear();
@@ -123,6 +125,7 @@ void tst_QWebEngineCookieStore::setAndDeleteCookie()
{
QWebEngineView view;
QWebEngineCookieStore *client = view.page()->profile()->cookieStore();
+ client->deleteAllCookies();
QSignalSpy loadSpy(&view, SIGNAL(loadFinished(bool)));
QSignalSpy cookieAddedSpy(client, SIGNAL(cookieAdded(const QNetworkCookie &)));
@@ -134,8 +137,10 @@ void tst_QWebEngineCookieStore::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->setCookie(cookie1);
+ QTRY_COMPARE(cookieAddedSpy.count(),1);
+ client->setCookie(cookie2);
+ QTRY_COMPARE(cookieAddedSpy.count(),2);
client->deleteCookie(cookie1);
view.load(QUrl("qrc:///resources/content.html"));
@@ -148,9 +153,10 @@ void tst_QWebEngineCookieStore::setAndDeleteCookie()
cookieAddedSpy.clear();
cookieRemovedSpy.clear();
- client->setCookieWithCallback(cookie3, [](bool success) { QVERIFY(success); });
+ client->setCookie(cookie3);
+ QTRY_COMPARE(cookieAddedSpy.count(), 1);
// updating a cookie with an expired 'expires' field should remove the cookie with the same name
- client->setCookieWithCallback(expiredCookie3, [](bool success) { QVERIFY(success); });
+ client->setCookie(expiredCookie3);
client->deleteCookie(cookie2);
QTRY_COMPARE(cookieAddedSpy.count(), 1);
QTRY_COMPARE(cookieRemovedSpy.count(), 2);
@@ -160,6 +166,7 @@ void tst_QWebEngineCookieStore::batchCookieTasks()
{
QWebEngineView view;
QWebEngineCookieStore *client = view.page()->profile()->cookieStore();
+ client->deleteAllCookies();
QSignalSpy loadSpy(&view, SIGNAL(loadFinished(bool)));
QSignalSpy cookieAddedSpy(client, SIGNAL(cookieAdded(const QNetworkCookie &)));
@@ -168,10 +175,10 @@ void tst_QWebEngineCookieStore::batchCookieTasks()
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->setCookie(cookie1);
+ QTRY_COMPARE(cookieAddedSpy.count(), 1);
+ client->setCookie(cookie2);
+ QTRY_COMPARE(cookieAddedSpy.count(), 2);
view.load(QUrl("qrc:///resources/index.html"));
@@ -180,28 +187,15 @@ void tst_QWebEngineCookieStore::batchCookieTasks()
QVERIFY(success.toBool());
QTRY_COMPARE(cookieAddedSpy.count(), 4);
QTRY_COMPARE(cookieRemovedSpy.count(), 0);
- QTRY_COMPARE(capture, 2);
- capture = 0;
cookieAddedSpy.clear();
cookieRemovedSpy.clear();
- client->getAllCookies([&capture](const QByteArray& cookieLine) {
- ++capture;
- QCOMPARE(QNetworkCookie::parseCookies(cookieLine).count(), 4);
- });
-
- client->deleteSessionCookiesWithCallback([&capture](int numDeleted) {
- ++capture;
- QCOMPARE(numDeleted, 3);
- });
-
- client->deleteAllCookiesWithCallback([&capture](int numDeleted) {
- ++capture;
- QCOMPARE(numDeleted, 1);
- });
+ client->deleteSessionCookies();
+ QTRY_COMPARE(cookieRemovedSpy.count(), 3);
- QTRY_COMPARE(capture, 3);
+ client->deleteAllCookies();
+ QTRY_COMPARE(cookieRemovedSpy.count(), 4);
}
QTEST_MAIN(tst_QWebEngineCookieStore)