diff options
author | Andras Becsi <andras.becsi@theqtcompany.com> | 2015-05-26 13:58:38 +0200 |
---|---|---|
committer | Andras Becsi <andras.becsi@theqtcompany.com> | 2015-07-08 13:16:57 +0000 |
commit | f7c4bab9157e25758ba526a6dce9a86fd4d1674e (patch) | |
tree | 512e88aeb9ea236f1c6cabd2e2fc47a43a450759 /src/core/cookie_monster_delegate_qt.cpp | |
parent | 5d56127cb7dbe38f552ac8858a5a7185c997911b (diff) |
Add support for batch tasks to the cookie client
This patch adds support for deleteSessionCookies, deleteAllCookies
and getAllCookies to make these features directly accessible without
the need of subclassing QWebEngineCookieStoreClient and having to
implement a less efficient equivalent.
Change-Id: I6645bee7fcef38d00dccfaa81f4e9ada86c491df
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
Diffstat (limited to 'src/core/cookie_monster_delegate_qt.cpp')
-rw-r--r-- | src/core/cookie_monster_delegate_qt.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/core/cookie_monster_delegate_qt.cpp b/src/core/cookie_monster_delegate_qt.cpp index d40abf13e..6b808e76c 100644 --- a/src/core/cookie_monster_delegate_qt.cpp +++ b/src/core/cookie_monster_delegate_qt.cpp @@ -44,6 +44,8 @@ #include "api/qwebenginecookiestoreclient_p.h" #include "type_conversion.h" +#include <QStringBuilder> + namespace QtWebEngineCore { static GURL sourceUrlForCookie(const QNetworkCookie &cookie) { @@ -55,6 +57,18 @@ static void onSetCookieCallback(QWebEngineCookieStoreClientPrivate *client, qint client->onSetCallbackResult(callbackId, success); } +static void onDeleteCookiesCallback(QWebEngineCookieStoreClientPrivate *client, qint64 callbackId, int numCookies) { + client->onDeleteCallbackResult(callbackId, numCookies); +} + +static void onGetAllCookiesCallback(QWebEngineCookieStoreClientPrivate *client, qint64 callbackId, const net::CookieList& cookies) { + QByteArray rawCookies; + for (auto&& cookie: cookies) + rawCookies += toQt(cookie).toRawForm() % QByteArrayLiteral("\n"); + + client->onGetAllCallbackResult(callbackId, rawCookies); +} + CookieMonsterDelegateQt::CookieMonsterDelegateQt() : m_client(0) , m_cookieMonster(0) @@ -72,6 +86,12 @@ bool CookieMonsterDelegateQt::hasCookieMonster() return m_cookieMonster.get(); } +void CookieMonsterDelegateQt::getAllCookies(quint64 callbackId) +{ + net::CookieMonster::GetCookieListCallback callback = base::Bind(&onGetAllCookiesCallback, m_client->d_func(), callbackId); + m_cookieMonster->GetAllCookiesAsync(callback); +} + void CookieMonsterDelegateQt::setCookie(quint64 callbackId, const QNetworkCookie &cookie, const QUrl &origin) { Q_ASSERT(hasCookieMonster()); @@ -99,6 +119,24 @@ void CookieMonsterDelegateQt::deleteCookie(const QNetworkCookie &cookie, const Q m_cookieMonster->DeleteCookieAsync(gurl, cookie.name().toStdString(), base::Closure()); } +void CookieMonsterDelegateQt::deleteSessionCookies(quint64 callbackId) +{ + Q_ASSERT(hasCookieMonster()); + Q_ASSERT(m_client); + + net::CookieMonster::DeleteCallback callback = base::Bind(&onDeleteCookiesCallback, m_client->d_func(), callbackId); + m_cookieMonster->DeleteSessionCookiesAsync(callback); +} + +void CookieMonsterDelegateQt::deleteAllCookies(quint64 callbackId) +{ + Q_ASSERT(hasCookieMonster()); + Q_ASSERT(m_client); + + net::CookieMonster::DeleteCallback callback = base::Bind(&onDeleteCookiesCallback, m_client->d_func(), callbackId); + m_cookieMonster->DeleteAllAsync(callback); +} + void CookieMonsterDelegateQt::setCookieMonster(net::CookieMonster* monster) { m_cookieMonster = monster; |