Changeset 95568 in webkit
- Timestamp:
- Sep 20, 2011 2:01:12 PM (13 years ago)
- Location:
- trunk/Source
- Files:
-
- 1 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r95567 r95568 1 2011-09-20 Alexis Menard <alexis.menard@openbossa.org> 2 3 [Qt] [WK2] Implement a persistent cookie storage. 4 https://bugs.webkit.org/show_bug.cgi?id=65309 5 6 Reviewed by Chang Shu. 7 8 Implement a cookie storage for the Qt port on WebKit2. 9 The implementation is using a SQLite database to store the cookies 10 and restore them. It uses a static object as CookieJar is not an 11 object but a set of global functions. The actual saving/restoring is on 12 the WebProcess side where our network stack lives. 13 14 Existing tests cover the new implementation. Unfortunately there is one 15 case that we can't easily simulate : login in a website, make sure that the webprocess 16 is not running and then going back to this website and see that we are logged. 17 18 * WebCore.pri: 19 * WebCore.pro: 20 * platform/qt/CookieJarQt.cpp: 21 (WebCore::getHostnamesWithCookies): 22 (WebCore::deleteCookiesForHostname): 23 (WebCore::deleteAllCookies): 24 (WebCore::SharedCookieJarQt::shared): 25 (WebCore::SharedCookieJarQt::create): 26 (WebCore::SharedCookieJarQt::destroy): 27 (WebCore::SharedCookieJarQt::getHostnamesWithCookies): 28 (WebCore::SharedCookieJarQt::deleteCookiesForHostname): 29 (WebCore::SharedCookieJarQt::deleteAllCookies): 30 (WebCore::SharedCookieJarQt::SharedCookieJarQt): 31 (WebCore::SharedCookieJarQt::~SharedCookieJarQt): 32 (WebCore::SharedCookieJarQt::setCookiesFromUrl): 33 (WebCore::SharedCookieJarQt::ensureDatabaseTable): 34 (WebCore::SharedCookieJarQt::loadCookies): 35 * platform/qt/CookieJarQt.h: Added. 36 1 37 2011-09-20 David Hyatt <hyatt@apple.com> 2 38 -
trunk/Source/WebCore/WebCore.pri
r94890 r95568 6 6 CONFIG += texmap 7 7 8 QT *= network 8 QT *= network sql 9 9 10 10 SOURCE_DIR = $$replace(PWD, /WebCore, "") -
trunk/Source/WebCore/WebCore.pro
r95551 r95568 2097 2097 platform/PopupMenu.h \ 2098 2098 platform/qt/ClipboardQt.h \ 2099 platform/qt/CookieJarQt.h \ 2099 2100 platform/qt/QWebPageClient.h \ 2100 2101 platform/qt/QtStyleOptionWebComboBox.h \ -
trunk/Source/WebCore/platform/qt/CookieJarQt.cpp
r90341 r95568 1 1 /* 2 2 * Copyright (C) 2006 George Staikos <staikos@kde.org> 3 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies) 3 4 * 4 5 * All rights reserved. … … 27 28 28 29 #include "config.h" 30 #include "CookieJarQt.h" 31 29 32 #include "CookieJar.h" 30 33 … … 39 42 #include "qwebpage.h" 40 43 #include "qwebsettings.h" 44 #include <QDateTime> 45 #include <QDir> 41 46 #include <QNetworkAccessManager> 42 47 #include <QNetworkCookie> 48 #include <QSqlQuery> 43 49 #include <QStringList> 44 50 45 51 namespace WebCore { 52 53 static SharedCookieJarQt* s_sharedCookieJarQt = 0; 46 54 47 55 static QNetworkCookieJar *cookieJar(const Document *document) … … 145 153 void getHostnamesWithCookies(HashSet<String>& hostnames) 146 154 { 147 // FIXME: Not yet implemented 155 SharedCookieJarQt* jar = SharedCookieJarQt::shared(); 156 if (jar) 157 jar->getHostnamesWithCookies(hostnames); 148 158 } 149 159 150 160 void deleteCookiesForHostname(const String& hostname) 151 161 { 152 // FIXME: Not yet implemented 162 SharedCookieJarQt* jar = SharedCookieJarQt::shared(); 163 if (jar) 164 jar->deleteCookiesForHostname(hostname); 153 165 } 154 166 155 167 void deleteAllCookies() 156 168 { 157 // FIXME: Not yet implemented 158 } 169 SharedCookieJarQt* jar = SharedCookieJarQt::shared(); 170 if (jar) 171 jar->deleteAllCookies(); 172 } 173 174 SharedCookieJarQt* SharedCookieJarQt::shared() 175 { 176 return s_sharedCookieJarQt; 177 } 178 179 SharedCookieJarQt* SharedCookieJarQt::create(const String& cookieStorageDirectory) 180 { 181 if (!s_sharedCookieJarQt) 182 s_sharedCookieJarQt = new SharedCookieJarQt(cookieStorageDirectory); 183 184 return s_sharedCookieJarQt; 185 } 186 187 void SharedCookieJarQt::destroy() 188 { 189 delete s_sharedCookieJarQt; 190 s_sharedCookieJarQt = 0; 191 } 192 193 void SharedCookieJarQt::getHostnamesWithCookies(HashSet<String>& hostnames) 194 { 195 QList<QNetworkCookie> cookies = allCookies(); 196 foreach (const QNetworkCookie& networkCookie, cookies) 197 hostnames.add(networkCookie.domain()); 198 } 199 200 void SharedCookieJarQt::deleteCookiesForHostname(const String& hostname) 201 { 202 QList<QNetworkCookie> cookies = allCookies(); 203 QList<QNetworkCookie>::Iterator it = cookies.begin(); 204 QList<QNetworkCookie>::Iterator end = cookies.end(); 205 QSqlQuery sqlQuery(m_database); 206 sqlQuery.prepare(QLatin1String("DELETE FROM cookies WHERE cookieId=:cookieIdvalue")); 207 while (it != end) { 208 if (it->domain() == QString(hostname)) { 209 sqlQuery.bindValue(QLatin1String(":cookieIdvalue"), it->domain().append(QLatin1String(it->name()))); 210 sqlQuery.exec(); 211 it = cookies.erase(it); 212 } else 213 it++; 214 } 215 setAllCookies(cookies); 216 } 217 218 void SharedCookieJarQt::deleteAllCookies() 219 { 220 QSqlQuery sqlQuery(m_database); 221 sqlQuery.prepare(QLatin1String("DELETE * FROM cookies")); 222 sqlQuery.exec(); 223 setAllCookies(QList<QNetworkCookie>()); 224 } 225 226 SharedCookieJarQt::SharedCookieJarQt(const String& cookieStorageDirectory) 227 { 228 m_database = QSqlDatabase::addDatabase(QLatin1String("QSQLITE")); 229 const QString cookieStoragePath = cookieStorageDirectory; 230 QDir().mkpath(cookieStoragePath + QLatin1String(".QtWebKit/")); 231 const QString dataBaseName = cookieStoragePath + QLatin1String(".QtWebKit/cookies.db"); 232 m_database.setDatabaseName(dataBaseName); 233 ensureDatabaseTable(); 234 loadCookies(); 235 } 236 237 SharedCookieJarQt::~SharedCookieJarQt() 238 { 239 m_database.close(); 240 } 241 242 bool SharedCookieJarQt::setCookiesFromUrl(const QList<QNetworkCookie>& cookieList, const QUrl& url) 243 { 244 if (!QNetworkCookieJar::setCookiesFromUrl(cookieList, url)) 245 return false; 246 QSqlQuery sqlQuery(m_database); 247 sqlQuery.prepare(QLatin1String("INSERT OR REPLACE INTO cookies (cookieId, cookie) VALUES (:cookieIdvalue, :cookievalue)")); 248 QVariantList cookiesIds; 249 QVariantList cookiesValues; 250 foreach (const QNetworkCookie &cookie, cookiesForUrl(url)) { 251 if (cookie.isSessionCookie()) 252 continue; 253 cookiesIds.append(cookie.domain().append(QLatin1String(cookie.name()))); 254 cookiesValues.append(cookie.toRawForm()); 255 } 256 sqlQuery.bindValue(QLatin1String(":cookieIdvalue"), cookiesIds); 257 sqlQuery.bindValue(QLatin1String(":cookievalue"), cookiesValues); 258 sqlQuery.execBatch(); 259 return true; 260 } 261 262 void SharedCookieJarQt::ensureDatabaseTable() 263 { 264 if (!m_database.open()) { 265 qWarning("Can't open cookie database"); 266 return; 267 } 268 QSqlQuery sqlQuery(m_database); 269 sqlQuery.prepare(QLatin1String("CREATE TABLE IF NOT EXISTS cookies (cookieId VARCHAR PRIMARY KEY, cookie BLOB);")); 270 sqlQuery.exec(); 271 } 272 273 void SharedCookieJarQt::loadCookies() 274 { 275 QList<QNetworkCookie> cookies; 276 QSqlQuery sqlQuery(m_database); 277 sqlQuery.prepare(QLatin1String("SELECT cookie FROM cookies")); 278 sqlQuery.exec(); 279 while (sqlQuery.next()) 280 cookies.append(QNetworkCookie::parseCookies(sqlQuery.value(0).toByteArray())); 281 setAllCookies(cookies); 282 } 283 284 #include "moc_CookieJarQt.cpp" 159 285 160 286 } -
trunk/Source/WebKit2/ChangeLog
r95565 r95568 1 2011-09-20 Alexis Menard <alexis.menard@openbossa.org> 2 3 [Qt] [WK2] Implement a persistent cookie storage. 4 https://bugs.webkit.org/show_bug.cgi?id=65309 5 6 Reviewed by Chang Shu. 7 8 Add parameter to the WebProcess creation to specify where cookies should be saved. 9 It also use the new cookie storage implementation and set it to our network stack 10 so cookies are used when using it. 11 12 * Shared/WebProcessCreationParameters.cpp: 13 (WebKit::WebProcessCreationParameters::encode): 14 (WebKit::WebProcessCreationParameters::decode): 15 * Shared/WebProcessCreationParameters.h: 16 * UIProcess/qt/WebContextQt.cpp: 17 (WebKit::WebContext::platformInitializeWebProcess): 18 * WebProcess/qt/WebProcessQt.cpp: 19 (WebKit::WebProcess::platformInitializeWebProcess): 20 (WebKit::WebProcess::platformTerminate): 21 1 22 2011-09-20 Nayan Kumar K <nayankk@motorola.com> 2 23 -
trunk/Source/WebKit2/Shared/WebProcessCreationParameters.cpp
r92713 r95568 92 92 #endif // USE(CFURLSTORAGESESSIONS) 93 93 #endif 94 #if PLATFORM(QT) 95 encoder->encode(cookieStorageDirectory); 96 #endif 94 97 } 95 98 … … 173 176 #endif 174 177 178 #if PLATFORM(QT) 179 if (!decoder->decode(parameters.cookieStorageDirectory)) 180 return false; 181 #endif 182 175 183 return true; 176 184 } -
trunk/Source/WebKit2/Shared/WebProcessCreationParameters.h
r92713 r95568 112 112 #endif // USE(CFURLSTORAGESESSIONS) 113 113 #endif // PLATFORM(WIN) 114 #if PLATFORM(QT) 115 String cookieStorageDirectory; 116 #endif 114 117 }; 115 118 -
trunk/Source/WebKit2/UIProcess/qt/WebContextQt.cpp
r81274 r95568 30 30 #include "ApplicationCacheStorage.h" 31 31 #include "WebProcessCreationParameters.h" 32 #include <QDesktopServices> 32 33 #include <QProcess> 33 34 … … 43 44 } 44 45 45 void WebContext::platformInitializeWebProcess(WebProcessCreationParameters& )46 void WebContext::platformInitializeWebProcess(WebProcessCreationParameters& parameters) 46 47 { 47 48 qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus"); 49 parameters.cookieStorageDirectory = QDesktopServices::storageLocation(QDesktopServices::DataLocation); 48 50 } 49 51 -
trunk/Source/WebKit2/WebProcess/qt/WebProcessQt.cpp
r80753 r95568 30 30 #include <WebCore/RuntimeEnabledFeatures.h> 31 31 #include <QNetworkAccessManager> 32 #include <QNetworkCookieJar> 33 #include <WebCore/CookieJarQt.h> 32 34 33 35 namespace WebKit { … … 45 47 { 46 48 m_networkAccessManager = new QNetworkAccessManager; 49 ASSERT(!parameters.cookieStorageDirectory.isEmpty() && !parameters.cookieStorageDirectory.isNull()); 50 WebCore::SharedCookieJarQt* jar = WebCore::SharedCookieJarQt::create(parameters.cookieStorageDirectory); 51 m_networkAccessManager->setCookieJar(jar); 52 // Do not let QNetworkAccessManager delete the jar. 53 jar->setParent(0); 47 54 48 55 // Disable runtime enabled features that have no WebKit2 implementation yet. … … 60 67 delete m_networkAccessManager; 61 68 m_networkAccessManager = 0; 69 WebCore::SharedCookieJarQt::shared()->destroy(); 62 70 } 63 71
Note: See TracChangeset
for help on using the changeset viewer.