Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/Source/WebCore/WebCore.pri b/Source/WebCore/WebCore.pri
- index 0ff4763..0dbd829 100644
- --- a/Source/WebCore/WebCore.pri
- +++ b/Source/WebCore/WebCore.pri
- @@ -6,7 +6,7 @@ include(features.pri)
- # We enable TextureMapper by default; remove this line to enable GraphicsLayerQt.
- CONFIG += texmap
- -QT *= network
- +QT *= network sql
- SOURCE_DIR = $$replace(PWD, /WebCore, "")
- diff --git a/Source/WebCore/WebCore.pro b/Source/WebCore/WebCore.pro
- index 300ecc7..db2a89b 100644
- --- a/Source/WebCore/WebCore.pro
- +++ b/Source/WebCore/WebCore.pro
- @@ -1939,6 +1939,7 @@ HEADERS += \
- platform/AsyncFileStream.h \
- platform/ContentType.h \
- platform/ContextMenu.h \
- + platform/Cookie.h \
- platform/CrossThreadCopier.h \
- platform/DateComponents.h \
- platform/DefaultLocalizationStrategy.h \
- @@ -2083,6 +2084,7 @@ HEADERS += \
- platform/PlatformTouchPoint.h \
- platform/PopupMenu.h \
- platform/qt/ClipboardQt.h \
- + platform/qt/CookieJarQt.h \
- platform/qt/QWebPageClient.h \
- platform/qt/QtStyleOptionWebComboBox.h \
- platform/qt/RenderThemeQt.h \
- diff --git a/Source/WebCore/platform/Cookie.h b/Source/WebCore/platform/Cookie.h
- index 4eea7d2..257a2fa 100644
- --- a/Source/WebCore/platform/Cookie.h
- +++ b/Source/WebCore/platform/Cookie.h
- @@ -29,12 +29,23 @@
- #include "PlatformString.h"
- #include <wtf/text/StringHash.h>
- -namespace WebCore {
- +#if PLATFORM(QT)
- +QT_BEGIN_NAMESPACE
- +class QNetworkCookie;
- +QT_END_NAMESPACE
- +#endif
- - // This struct is currently only used to provide more cookies information
- - // to the Web Inspector.
- +namespace WebCore {
- struct Cookie {
- + Cookie()
- + : expires(0)
- + , httpOnly(false)
- + , secure(false)
- + , session(false)
- + {
- + }
- +
- Cookie(const String& name, const String& value, const String& domain,
- const String& path, double expires, bool httpOnly, bool secure,
- bool session)
- @@ -57,6 +68,11 @@ namespace WebCore {
- bool httpOnly;
- bool secure;
- bool session;
- +
- +#if PLATFORM(QT)
- + Cookie(const QNetworkCookie&);
- + operator QNetworkCookie() const;
- +#endif
- };
- struct CookieHash {
- diff --git a/Source/WebCore/platform/qt/CookieJarQt.cpp b/Source/WebCore/platform/qt/CookieJarQt.cpp
- index 6dcd66b..a4f9a7c 100644
- --- a/Source/WebCore/platform/qt/CookieJarQt.cpp
- +++ b/Source/WebCore/platform/qt/CookieJarQt.cpp
- @@ -26,6 +26,8 @@
- */
- #include "config.h"
- +#include "CookieJarQt.h"
- +
- #include "CookieJar.h"
- #include "Cookie.h"
- @@ -38,12 +40,17 @@
- #include "qwebframe.h"
- #include "qwebpage.h"
- #include "qwebsettings.h"
- +#include <QDateTime>
- +#include <QDir>
- #include <QNetworkAccessManager>
- #include <QNetworkCookie>
- +#include <QSqlQuery>
- #include <QStringList>
- namespace WebCore {
- +static WebKit2SharedCookieJar* webKit2SharedCookieJar = 0;
- +
- static QNetworkCookieJar *cookieJar(const Document *document)
- {
- if (!document)
- @@ -144,19 +151,164 @@ void deleteCookie(const Document*, const KURL&, const String&)
- void getHostnamesWithCookies(HashSet<String>& hostnames)
- {
- - // FIXME: Not yet implemented
- + WebKit2SharedCookieJar::shared()->getHostnamesWithCookies(hostnames);
- }
- void deleteCookiesForHostname(const String& hostname)
- {
- - // FIXME: Not yet implemented
- + WebKit2SharedCookieJar::shared()->deleteCookiesForHostname(hostname);
- }
- void deleteAllCookies()
- {
- - // FIXME: Not yet implemented
- + WebKit2SharedCookieJar::shared()->deleteAllCookies();
- +}
- +
- +Cookie::Cookie(const QNetworkCookie& cookie)
- + : name(cookie.name().constData())
- + , value(cookie.value().constData())
- + , domain(cookie.domain())
- + , path(cookie.path())
- + , expires(cookie.expirationDate().toMSecsSinceEpoch())
- + , httpOnly(cookie.isHttpOnly())
- + , secure(cookie.isSecure())
- + , session(cookie.isSessionCookie())
- +{
- +}
- +
- +Cookie::operator QNetworkCookie() const
- +{
- + QNetworkCookie result(QString(name).toAscii(), QString(value).toAscii());
- + result.setDomain(domain);
- + result.setPath(path);
- + if (session) {
- + QDateTime expirationDate;
- + expirationDate.setMSecsSinceEpoch(expires);
- + result.setExpirationDate(expirationDate);
- + }
- + result.setHttpOnly(httpOnly);
- + result.setSecure(secure);
- + return result;
- +}
- +
- +WebKit2SharedCookieJar* sharedCookieJar()
- +{
- + return WebKit2SharedCookieJar::shared();
- }
- +WebKit2SharedCookieJar* WebKit2SharedCookieJar::shared()
- +{
- + if (!webKit2SharedCookieJar)
- + webKit2SharedCookieJar = new WebKit2SharedCookieJar();
- + return webKit2SharedCookieJar;
- +}
- +
- +void WebKit2SharedCookieJar::destroy()
- +{
- + delete webKit2SharedCookieJar;
- + webKit2SharedCookieJar = 0;
- +}
- +
- +void WebKit2SharedCookieJar::getHostnamesWithCookies(HashSet<String>& hostnames)
- +{
- + QList<QNetworkCookie> cookies = allCookies();
- + foreach (QNetworkCookie networkCookie, cookies)
- + hostnames.add(networkCookie.domain());
- +}
- +
- +void WebKit2SharedCookieJar::deleteCookiesForHostname(const QString& hostname)
- +{
- + QList<QNetworkCookie> cookies = allCookies();
- + QList<QNetworkCookie>::Iterator it = cookies.begin();
- + QList<QNetworkCookie>::Iterator end = cookies.end();
- + const QLatin1String deletionQuery("DELETE FROM cookies WHERE domain=:domainvalue");
- + QSqlQuery sqlQuery(m_database);
- + sqlQuery.prepare(deletionQuery);
- + sqlQuery.bindValue(QLatin1String(":domainvalue"), hostname);
- + sqlQuery.exec();
- + while (it != end) {
- + if (it->domain() == hostname)
- + it = cookies.erase(it);
- + else
- + it++;
- + }
- + setAllCookies(cookies);
- +}
- +
- +void WebKit2SharedCookieJar::deleteAllCookies()
- +{
- + QSqlQuery sqlQuery(m_database);
- + const QLatin1String deletionQuery("DELETE * FROM cookies");
- + sqlQuery.prepare(deletionQuery);
- + sqlQuery.exec();
- + setAllCookies(QList<QNetworkCookie>());
- +}
- +
- +WebKit2SharedCookieJar::WebKit2SharedCookieJar()
- +{
- + m_database = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"));
- +}
- +
- +WebKit2SharedCookieJar::~WebKit2SharedCookieJar()
- +{
- +}
- +
- +bool WebKit2SharedCookieJar::setCookiesFromUrl(const QList<QNetworkCookie>& cookieList, const QUrl& url)
- +{
- + bool status = QNetworkCookieJar::setCookiesFromUrl(cookieList, url);
- + QSqlQuery sqlQuery(m_database);
- + // Delete old cookies for this domain.
- + sqlQuery.prepare(QLatin1String("DELETE FROM cookies WHERE domain=:domainvalue"));
- + sqlQuery.bindValue(QLatin1String(":domainvalue"), url.host());
- + sqlQuery.exec();
- +
- + sqlQuery.prepare(QLatin1String("INSERT INTO cookies (cookie, domain) VALUES (:cookievalue, :domainvalue)"));
- + foreach (const QNetworkCookie &cookie, cookiesForUrl(url)) {
- + if (!cookie.isSessionCookie()) {
- + sqlQuery.bindValue(QLatin1String(":cookievalue"), cookie.toRawForm());
- + sqlQuery.bindValue(QLatin1String(":domainvalue"), url.host());
- + sqlQuery.exec();
- + }
- + }
- + return status;
- +}
- +
- +void WebKit2SharedCookieJar::ensureDatabaseTable()
- +{
- + if (!m_database.open()) {
- + qWarning("Can't open cookie database");
- + return;
- + }
- +
- + const QLatin1String creationQuery("CREATE TABLE IF NOT EXISTS cookies (id INTEGER PRIMARY KEY AUTOINCREMENT,"
- + "cookie BLOB, domain VARCHAR);");
- + QSqlQuery sqlQuery(creationQuery);
- + sqlQuery.exec();
- +}
- +
- +void WebKit2SharedCookieJar::setStoragePath(const String& path)
- +{
- + m_path = path;
- + QDir().mkpath(m_path + QLatin1String(".QtWebKit/"));
- + const QString dataBaseName = m_path + QLatin1String(".QtWebKit/cookies.db");
- + m_database.setDatabaseName(dataBaseName);
- + ensureDatabaseTable();
- + loadCookies();
- +}
- +
- +void WebKit2SharedCookieJar::loadCookies()
- +{
- + QList<QNetworkCookie> cookies;
- + QSqlQuery sqlQuery(m_database);
- + sqlQuery.prepare(QLatin1String("SELECT cookie FROM cookies"));
- + sqlQuery.exec();
- + while (sqlQuery.next())
- + cookies.append(QNetworkCookie::parseCookies(sqlQuery.value(0).toByteArray()));
- + setAllCookies(cookies);
- +}
- +
- +#include "moc_CookieJarQt.cpp"
- +
- }
- // vim: ts=4 sw=4 et
- diff --git a/Source/WebCore/platform/qt/CookieJarQt.h b/Source/WebCore/platform/qt/CookieJarQt.h
- new file mode 100644
- index 0000000..1b474dc
- --- /dev/null
- +++ b/Source/WebCore/platform/qt/CookieJarQt.h
- @@ -0,0 +1,61 @@
- +/*
- + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
- + *
- + * This library is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU Library General Public
- + * License as published by the Free Software Foundation; either
- + * version 2 of the License, or (at your option) any later version.
- + *
- + * This library is distributed in the hope that it will be useful,
- + * but WITHOUT ANY WARRANTY; without even the implied warranty of
- + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- + * Library General Public License for more details.
- + *
- + * You should have received a copy of the GNU Library General Public License
- + * along with this library; see the file COPYING.LIB. If not, write to
- + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- + * Boston, MA 02110-1301, USA.
- + *
- + */
- +
- +#ifndef CookieJarQt_h
- +#define CookieJarQt_h
- +
- +#include <QtCore/QFile>
- +#include <QtCore/QObject>
- +#include <QtCore/QTimer>
- +#include <QtCore/QTimerEvent>
- +#include <QtNetwork/QNetworkCookieJar>
- +#include <QtSql/QSqlDatabase>
- +
- +#include <wtf/HashSet.h>
- +#include <wtf/text/WTFString.h>
- +
- +namespace WebCore {
- +
- +class WebKit2SharedCookieJar : public QNetworkCookieJar {
- + Q_OBJECT
- +public:
- + static WebKit2SharedCookieJar* shared();
- + void destroy();
- +
- + void getHostnamesWithCookies(HashSet<String>& hostnames);
- + void deleteCookiesForHostname(const QString& hostname);
- + void deleteAllCookies();
- + void setStoragePath(const String&);
- + bool setCookiesFromUrl(const QList<QNetworkCookie>&, const QUrl&);
- + void loadCookies();
- +
- +private:
- + WebKit2SharedCookieJar();
- + ~WebKit2SharedCookieJar();
- + void ensureDatabaseTable();
- +
- + QSqlDatabase m_database;
- + QString m_path;
- +};
- +
- +WebKit2SharedCookieJar* sharedCookieJar();
- +}
- +
- +#endif
- diff --git a/Source/WebKit2/Shared/WebProcessCreationParameters.cpp b/Source/WebKit2/Shared/WebProcessCreationParameters.cpp
- index de52716..5d2374b 100644
- --- a/Source/WebKit2/Shared/WebProcessCreationParameters.cpp
- +++ b/Source/WebKit2/Shared/WebProcessCreationParameters.cpp
- @@ -53,6 +53,9 @@ void WebProcessCreationParameters::encode(CoreIPC::ArgumentEncoder* encoder) con
- encoder->encode(applicationCacheDirectory);
- encoder->encode(databaseDirectory);
- encoder->encode(localStorageDirectory);
- +#if PLATFORM(QT)
- + encoder->encode(cookieStorageDirectory);
- +#endif
- encoder->encode(urlSchemesRegistererdAsEmptyDocument);
- encoder->encode(urlSchemesRegisteredAsSecure);
- encoder->encode(urlSchemesForWhichDomainRelaxationIsForbidden);
- @@ -105,6 +108,10 @@ bool WebProcessCreationParameters::decode(CoreIPC::ArgumentDecoder* decoder, Web
- return false;
- if (!decoder->decode(parameters.localStorageDirectory))
- return false;
- +#if PLATFORM(QT)
- + if (!decoder->decode(parameters.cookieStorageDirectory))
- + return false;
- +#endif
- if (!decoder->decode(parameters.urlSchemesRegistererdAsEmptyDocument))
- return false;
- if (!decoder->decode(parameters.urlSchemesRegisteredAsSecure))
- diff --git a/Source/WebKit2/Shared/WebProcessCreationParameters.h b/Source/WebKit2/Shared/WebProcessCreationParameters.h
- index 0396cfb..16ac6b2 100644
- --- a/Source/WebKit2/Shared/WebProcessCreationParameters.h
- +++ b/Source/WebKit2/Shared/WebProcessCreationParameters.h
- @@ -56,6 +56,9 @@ struct WebProcessCreationParameters {
- String applicationCacheDirectory;
- String databaseDirectory;
- String localStorageDirectory;
- +#if PLATFORM(QT)
- + String cookieStorageDirectory;
- +#endif
- Vector<String> urlSchemesRegistererdAsEmptyDocument;
- Vector<String> urlSchemesRegisteredAsSecure;
- Vector<String> urlSchemesForWhichDomainRelaxationIsForbidden;
- diff --git a/Source/WebKit2/UIProcess/qt/WebContextQt.cpp b/Source/WebKit2/UIProcess/qt/WebContextQt.cpp
- index b46587e..5c6bdad 100644
- --- a/Source/WebKit2/UIProcess/qt/WebContextQt.cpp
- +++ b/Source/WebKit2/UIProcess/qt/WebContextQt.cpp
- @@ -29,6 +29,7 @@
- #include "ApplicationCacheStorage.h"
- #include "WebProcessCreationParameters.h"
- +#include <QDesktopServices>
- #include <QProcess>
- namespace WebKit {
- @@ -42,9 +43,10 @@ String WebContext::applicationCacheDirectory()
- #endif
- }
- -void WebContext::platformInitializeWebProcess(WebProcessCreationParameters&)
- +void WebContext::platformInitializeWebProcess(WebProcessCreationParameters& parameters)
- {
- qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus");
- + parameters.cookieStorageDirectory = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
- }
- void WebContext::platformInvalidateContext()
- diff --git a/Source/WebKit2/WebProcess/qt/WebProcessQt.cpp b/Source/WebKit2/WebProcess/qt/WebProcessQt.cpp
- index 919044e..917794e 100644
- --- a/Source/WebKit2/WebProcess/qt/WebProcessQt.cpp
- +++ b/Source/WebKit2/WebProcess/qt/WebProcessQt.cpp
- @@ -29,6 +29,8 @@
- #include "WebProcessCreationParameters.h"
- #include <WebCore/RuntimeEnabledFeatures.h>
- #include <QNetworkAccessManager>
- +#include <QNetworkCookieJar>
- +#include <WebCore/CookieJarQt.h>
- namespace WebKit {
- @@ -44,6 +46,10 @@ void WebProcess::platformClearResourceCaches(ResourceCachesToClear)
- void WebProcess::platformInitializeWebProcess(const WebProcessCreationParameters& parameters, CoreIPC::ArgumentDecoder* arguments)
- {
- m_networkAccessManager = new QNetworkAccessManager;
- + WebCore::WebKit2SharedCookieJar* jar = WebCore::sharedCookieJar();
- + jar->setStoragePath(parameters.cookieStorageDirectory);
- + m_networkAccessManager->setCookieJar(jar);
- + jar->setParent(0);
- // Disable runtime enabled features that have no WebKit2 implementation yet.
- #if ENABLE(DEVICE_ORIENTATION)
- @@ -57,6 +63,7 @@ void WebProcess::platformInitializeWebProcess(const WebProcessCreationParameters
- void WebProcess::platformTerminate()
- {
- + WebCore::sharedCookieJar()->destroy();
- delete m_networkAccessManager;
- m_networkAccessManager = 0;
- }
Add Comment
Please, Sign In to add comment