From caec5838b97866d4f1c6a0ef37ed68b28bbe8623 Mon Sep 17 00:00:00 2001 From: Anmol Gautam Date: Fri, 3 Aug 2018 11:37:03 +0530 Subject: [PATCH] fixed caching in qml cookies --- src/lib/plugins/qml/api/cookies/qmlcookie.cpp | 5 +++-- src/lib/plugins/qml/api/cookies/qmlcookies.cpp | 14 ++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/lib/plugins/qml/api/cookies/qmlcookie.cpp b/src/lib/plugins/qml/api/cookies/qmlcookie.cpp index 608f65a58..33d9fcb3d 100644 --- a/src/lib/plugins/qml/api/cookies/qmlcookie.cpp +++ b/src/lib/plugins/qml/api/cookies/qmlcookie.cpp @@ -95,8 +95,9 @@ QmlCookie *QmlCookieData::get(QNetworkCookie *cookie) { QmlCookie *qmlCookie = m_cookies.value(cookie); if (!qmlCookie) { - qmlCookie = new QmlCookie(cookie); - m_cookies.insert(cookie, qmlCookie); + QNetworkCookie *netCookie = new QNetworkCookie(*cookie); + qmlCookie = new QmlCookie(netCookie); + m_cookies.insert(netCookie, qmlCookie); } return qmlCookie; } diff --git a/src/lib/plugins/qml/api/cookies/qmlcookies.cpp b/src/lib/plugins/qml/api/cookies/qmlcookies.cpp index ec409ebab..020956086 100644 --- a/src/lib/plugins/qml/api/cookies/qmlcookies.cpp +++ b/src/lib/plugins/qml/api/cookies/qmlcookies.cpp @@ -27,7 +27,7 @@ QmlCookies::QmlCookies(QObject *parent) { connect(mApp->cookieJar(), &CookieJar::cookieAdded, this, [this](QNetworkCookie network_cookie){ // FIXME: improve this - QmlCookie *cookie = cookieData->get(new QNetworkCookie(network_cookie)); + QmlCookie *cookie = cookieData->get(&network_cookie); QVariantMap map; map.insert(QSL("cookie"), QVariant::fromValue(cookie)); map.insert(QSL("removed"), false); @@ -36,7 +36,7 @@ QmlCookies::QmlCookies(QObject *parent) connect(mApp->cookieJar(), &CookieJar::cookieRemoved, this, [this](QNetworkCookie network_cookie){ // FIXME: improve this - QmlCookie *cookie = cookieData->get(new QNetworkCookie(network_cookie)); + QmlCookie *cookie = cookieData->get(&network_cookie); QVariantMap map; map.insert(QSL("cookie"), QVariant::fromValue(cookie)); 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 url = map.value(QSL("url")).toString(); QVector cookies = mApp->cookieJar()->getAllCookies(); - for (const QNetworkCookie &cookie : cookies) { + for (const QNetworkCookie &cookie : qAsConst(cookies)) { if (cookie.name() == name && cookie.domain() == url) { - QNetworkCookie *netCookie = new QNetworkCookie(cookie); - return netCookie; + return new QNetworkCookie(cookie); } } return nullptr; @@ -105,14 +104,13 @@ QList QmlCookies::getAll(const QVariantMap &map) const bool secure = map.value(QSL("secure")).toBool(); const bool session = map.value(QSL("session")).toBool(); QVector cookies = mApp->cookieJar()->getAllCookies(); - for (QNetworkCookie cookie : cookies) { + for (QNetworkCookie cookie : qAsConst(cookies)) { if ((!map.contains(QSL("name")) || cookie.name() == name) && (!map.contains(QSL("url")) || cookie.domain() == url) && (!map.contains(QSL("path")) || cookie.path() == path) && (!map.contains(QSL("secure")) || cookie.isSecure() == secure) && (!map.contains(QSL("session")) || cookie.isSessionCookie() == session)) { - QNetworkCookie *netCookie = new QNetworkCookie(cookie); - QmlCookie *qmlCookie = cookieData->get(netCookie); + QmlCookie *qmlCookie = cookieData->get(&cookie); qmlCookies.append(qmlCookie); } }