Changeset View
Changeset View
Standalone View
Standalone View
webenginepart/src/webenginepartcookiejar.cpp
Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Line(s) | |||||
65 | { | 65 | { | ||
66 | prof->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies); | 66 | prof->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies); | ||
67 | connect(qApp, &QApplication::lastWindowClosed, this, &WebEnginePartCookieJar::deleteSessionCookies); | 67 | connect(qApp, &QApplication::lastWindowClosed, this, &WebEnginePartCookieJar::deleteSessionCookies); | ||
68 | connect(m_cookieStore, &QWebEngineCookieStore::cookieAdded, this, &WebEnginePartCookieJar::addCookie); | 68 | connect(m_cookieStore, &QWebEngineCookieStore::cookieAdded, this, &WebEnginePartCookieJar::addCookie); | ||
69 | connect(m_cookieStore, &QWebEngineCookieStore::cookieRemoved, this, &WebEnginePartCookieJar::removeCookie); | 69 | connect(m_cookieStore, &QWebEngineCookieStore::cookieRemoved, this, &WebEnginePartCookieJar::removeCookie); | ||
70 | if(!m_cookieServer.isValid()){ | 70 | if(!m_cookieServer.isValid()){ | ||
71 | qDebug() << "Couldn't connect to KCookieServer"; | 71 | qDebug() << "Couldn't connect to KCookieServer"; | ||
72 | } | 72 | } | ||
73 | | ||||
73 | loadKIOCookies(); | 74 | loadKIOCookies(); | ||
74 | 75 | | |||
75 | //QWebEngineCookieStore::setCookieFilter only exists from Qt 5.11.0 | 76 | //QWebEngineCookieStore::setCookieFilter only exists from Qt 5.11.0 | ||
76 | #if QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5,11,0) | 77 | #if QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5,11,0) | ||
77 | auto filter = [this](const QWebEngineCookieStore::FilterRequest &req){return filterCookie(req);}; | 78 | auto filter = [this](const QWebEngineCookieStore::FilterRequest &req){return filterCookie(req);}; | ||
78 | m_cookieStore->setCookieFilter(filter); | 79 | m_cookieStore->setCookieFilter(filter); | ||
79 | #endif //QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5,11,0) | 80 | #endif //QTWEBENGINE_VERSION >= QT_VERSION_CHECK(5,11,0) | ||
80 | } | 81 | } | ||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | 142 | { | |||
143 | //we're loading the cookie from KCookieServer (from the call to loadKIOCookies | 144 | //we're loading the cookie from KCookieServer (from the call to loadKIOCookies | ||
144 | //in the constructor (QWebEngineCookieStore::setCookie is asynchronous, though, | 145 | //in the constructor (QWebEngineCookieStore::setCookie is asynchronous, though, | ||
145 | //so we're not in the constructor anymore)), so don't attempt to add | 146 | //so we're not in the constructor anymore)), so don't attempt to add | ||
146 | //the cookie back to KCookieServer; instead, remove it from the list. | 147 | //the cookie back to KCookieServer; instead, remove it from the list. | ||
147 | if (m_cookiesLoadedFromKCookieServer.removeOne(_cookie)) { | 148 | if (m_cookiesLoadedFromKCookieServer.removeOne(_cookie)) { | ||
148 | return; | 149 | return; | ||
149 | } | 150 | } | ||
150 | 151 | | |||
152 | #ifdef BUILD_TESTING | ||||
153 | m_testCookies.clear(); | ||||
154 | #endif | ||||
155 | | ||||
151 | QNetworkCookie cookie(_cookie); | 156 | QNetworkCookie cookie(_cookie); | ||
152 | CookieIdentifier id(cookie); | 157 | CookieIdentifier id(cookie); | ||
153 | 158 | | |||
154 | if (!m_cookieServer.isValid()) { | 159 | if (!m_cookieServer.isValid()) { | ||
155 | return; | 160 | return; | ||
156 | } | 161 | } | ||
157 | 162 | | |||
158 | if (cookie.expirationDate().isValid()) { | 163 | if (cookie.expirationDate().isValid()) { | ||
▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Line(s) | 290 | { | |||
286 | CookieList cookies = findKIOCookies(); | 291 | CookieList cookies = findKIOCookies(); | ||
287 | foreach(const QNetworkCookie& cookie, cookies){ | 292 | foreach(const QNetworkCookie& cookie, cookies){ | ||
288 | QDateTime currentTime = QDateTime::currentDateTime(); | 293 | QDateTime currentTime = QDateTime::currentDateTime(); | ||
289 | //Don't attempt to add expired cookies | 294 | //Don't attempt to add expired cookies | ||
290 | if (cookie.expirationDate().isValid() && cookie.expirationDate() < currentTime) { | 295 | if (cookie.expirationDate().isValid() && cookie.expirationDate() < currentTime) { | ||
291 | continue; | 296 | continue; | ||
292 | } | 297 | } | ||
293 | m_cookiesLoadedFromKCookieServer << cookie; | 298 | m_cookiesLoadedFromKCookieServer << cookie; | ||
299 | #ifdef BUILD_TESTING | ||||
300 | m_testCookies << cookie; | ||||
dfaure: Should this be cleared at some point? For users of a debug build... | |||||
Unfortunately, it's quite difficult to find out when to do so. Of course it can't be done in the constructor because it is needed by the test method after the constructor has finished. Maybe we could use a timer, but we can't know how much time the test needs. Two options come to my mind:
stefanocrocco: Unfortunately, it's quite difficult to find out when to do so. Of course it can't be done in… | |||||
301 | #endif | ||||
294 | m_cookieStore->setCookie(cookie); | 302 | m_cookieStore->setCookie(cookie); | ||
295 | } | 303 | } | ||
296 | } | 304 | } | ||
297 | 305 | | |||
298 | WebEnginePartCookieJar::CookieList WebEnginePartCookieJar::findKIOCookies() | 306 | WebEnginePartCookieJar::CookieList WebEnginePartCookieJar::findKIOCookies() | ||
299 | { | 307 | { | ||
300 | CookieList res; | 308 | CookieList res; | ||
301 | if (!m_cookieServer.isValid()) { | 309 | if (!m_cookieServer.isValid()) { | ||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |
Should this be cleared at some point? For users of a debug build...