1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

fixed caching in qml cookies

This commit is contained in:
Anmol Gautam 2018-08-03 11:37:03 +05:30
parent a2440585d8
commit caec5838b9
2 changed files with 9 additions and 10 deletions

View File

@ -95,8 +95,9 @@ QmlCookie *QmlCookieData::get(QNetworkCookie *cookie)
{ {
QmlCookie *qmlCookie = m_cookies.value(cookie); QmlCookie *qmlCookie = m_cookies.value(cookie);
if (!qmlCookie) { if (!qmlCookie) {
qmlCookie = new QmlCookie(cookie); QNetworkCookie *netCookie = new QNetworkCookie(*cookie);
m_cookies.insert(cookie, qmlCookie); qmlCookie = new QmlCookie(netCookie);
m_cookies.insert(netCookie, qmlCookie);
} }
return qmlCookie; return qmlCookie;
} }

View File

@ -27,7 +27,7 @@ QmlCookies::QmlCookies(QObject *parent)
{ {
connect(mApp->cookieJar(), &CookieJar::cookieAdded, this, [this](QNetworkCookie network_cookie){ connect(mApp->cookieJar(), &CookieJar::cookieAdded, this, [this](QNetworkCookie network_cookie){
// FIXME: improve this // FIXME: improve this
QmlCookie *cookie = cookieData->get(new QNetworkCookie(network_cookie)); QmlCookie *cookie = cookieData->get(&network_cookie);
QVariantMap map; QVariantMap map;
map.insert(QSL("cookie"), QVariant::fromValue(cookie)); map.insert(QSL("cookie"), QVariant::fromValue(cookie));
map.insert(QSL("removed"), false); map.insert(QSL("removed"), false);
@ -36,7 +36,7 @@ QmlCookies::QmlCookies(QObject *parent)
connect(mApp->cookieJar(), &CookieJar::cookieRemoved, this, [this](QNetworkCookie network_cookie){ connect(mApp->cookieJar(), &CookieJar::cookieRemoved, this, [this](QNetworkCookie network_cookie){
// FIXME: improve this // FIXME: improve this
QmlCookie *cookie = cookieData->get(new QNetworkCookie(network_cookie)); QmlCookie *cookie = cookieData->get(&network_cookie);
QVariantMap map; QVariantMap map;
map.insert(QSL("cookie"), QVariant::fromValue(cookie)); map.insert(QSL("cookie"), QVariant::fromValue(cookie));
map.insert(QSL("removed"), true); map.insert(QSL("removed"), true);
@ -53,10 +53,9 @@ QNetworkCookie *QmlCookies::getNetworkCookie(const QVariantMap &map)
const QString name = map.value(QSL("name")).toString(); const QString name = map.value(QSL("name")).toString();
const QString url = map.value(QSL("url")).toString(); const QString url = map.value(QSL("url")).toString();
QVector<QNetworkCookie> cookies = mApp->cookieJar()->getAllCookies(); QVector<QNetworkCookie> cookies = mApp->cookieJar()->getAllCookies();
for (const QNetworkCookie &cookie : cookies) { for (const QNetworkCookie &cookie : qAsConst(cookies)) {
if (cookie.name() == name && cookie.domain() == url) { if (cookie.name() == name && cookie.domain() == url) {
QNetworkCookie *netCookie = new QNetworkCookie(cookie); return new QNetworkCookie(cookie);
return netCookie;
} }
} }
return nullptr; return nullptr;
@ -105,14 +104,13 @@ QList<QObject*> QmlCookies::getAll(const QVariantMap &map)
const bool secure = map.value(QSL("secure")).toBool(); const bool secure = map.value(QSL("secure")).toBool();
const bool session = map.value(QSL("session")).toBool(); const bool session = map.value(QSL("session")).toBool();
QVector<QNetworkCookie> cookies = mApp->cookieJar()->getAllCookies(); QVector<QNetworkCookie> cookies = mApp->cookieJar()->getAllCookies();
for (QNetworkCookie cookie : cookies) { for (QNetworkCookie cookie : qAsConst(cookies)) {
if ((!map.contains(QSL("name")) || cookie.name() == name) if ((!map.contains(QSL("name")) || cookie.name() == name)
&& (!map.contains(QSL("url")) || cookie.domain() == url) && (!map.contains(QSL("url")) || cookie.domain() == url)
&& (!map.contains(QSL("path")) || cookie.path() == path) && (!map.contains(QSL("path")) || cookie.path() == path)
&& (!map.contains(QSL("secure")) || cookie.isSecure() == secure) && (!map.contains(QSL("secure")) || cookie.isSecure() == secure)
&& (!map.contains(QSL("session")) || cookie.isSessionCookie() == session)) { && (!map.contains(QSL("session")) || cookie.isSessionCookie() == session)) {
QNetworkCookie *netCookie = new QNetworkCookie(cookie); QmlCookie *qmlCookie = cookieData->get(&cookie);
QmlCookie *qmlCookie = cookieData->get(netCookie);
qmlCookies.append(qmlCookie); qmlCookies.append(qmlCookie);
} }
} }