summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2009-08-05 17:24:13 +0200
committerAndrea Diamantini <adjam7@gmail.com>2009-08-05 17:24:13 +0200
commit3e46acd2391fd37821dbbaad641100426e58f3e5 (patch)
tree8a2fc6bd1db21f7c0089b4fe8a932f9f40f2f0a7 /src
parentFixing Licensing issue (diff)
downloadrekonq-3e46acd2391fd37821dbbaad641100426e58f3e5.tar.xz
Initial porting to KCookieJar
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt6
-rw-r--r--src/cookiejar.cpp322
-rw-r--r--src/cookiejar.h108
-rw-r--r--src/mainwindow.cpp4
-rw-r--r--src/networkaccessmanager.cpp3
-rw-r--r--src/networkaccessmanager.h7
-rw-r--r--src/settings.cpp12
-rw-r--r--src/webpage.cpp3
-rw-r--r--src/webpage.h3
9 files changed, 64 insertions, 404 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index a0bcbfb1..c782864f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -7,7 +7,7 @@ SET( rekonq_SRCS
mainwindow.cpp
mainview.cpp
tabbar.cpp
- cookiejar.cpp
+ cookiejar.cpp
edittableview.cpp
edittreeview.cpp
history.cpp
@@ -24,8 +24,8 @@ SET( rekonq_SRCS
lineedit.cpp
stackedurlbar.cpp
webpage.cpp
- cookiedialog.cpp
- cookieexceptiondialog.cpp
+# cookiedialog.cpp
+# cookieexceptiondialog.cpp
)
diff --git a/src/cookiejar.cpp b/src/cookiejar.cpp
index 28a77120..df3140f5 100644
--- a/src/cookiejar.cpp
+++ b/src/cookiejar.cpp
@@ -49,325 +49,69 @@
#include <QtGui/QSortFilterProxyModel>
#include <QtGui/QCompleter>
+#include <QtDBus>
-static const unsigned int JAR_VERSION = 23;
-
-static const char cookieFileName[] = "cookies";
-
-
-CookieJar::CookieJar(QObject *parent)
- : QNetworkCookieJar(parent)
- , m_acceptCookies(AcceptOnlyFromSitesNavigatedTo)
+CookieJar::CookieJar(QObject* parent)
+ : QNetworkCookieJar(parent)
+ , m_windowId(-1)
{
- // load cookies and exceptions
- QString filepath = KStandardDirs::locateLocal("appdata", cookieFileName);
- KConfig iniconfig(filepath);
-
- KConfigGroup inigroup1 = iniconfig.group("cookielist");
-
- QStringList cookieStringList = inigroup1.readEntry( QString("cookies"), QStringList() );
- QList<QNetworkCookie> cookieNetworkList;
- foreach( QString str, cookieStringList )
- {
- cookieNetworkList << QNetworkCookie( str.toLocal8Bit() );
- }
- setAllCookies( cookieNetworkList );
-
- KConfigGroup inigroup2 = iniconfig.group("exceptions");
- m_exceptions_block = inigroup2.readEntry( QString("block") , QStringList() );
- m_exceptions_allow = inigroup2.readEntry( QString("allow"), QStringList() );
- m_exceptions_allowForSession = inigroup2.readEntry( QString("allowForSession"), QStringList() );
-
- qSort( m_exceptions_block.begin(), m_exceptions_block.end() );
- qSort( m_exceptions_allow.begin(), m_exceptions_allow.end() );
- qSort( m_exceptions_allowForSession.begin(), m_exceptions_allowForSession.end() );
-
- loadSettings();
}
CookieJar::~CookieJar()
{
- if (m_keepCookies == KeepUntilExit)
- clear();
-
- save();
-}
-
-
-void CookieJar::clear()
-{
- setAllCookies(QList<QNetworkCookie>());
-
- save();
-
- emit cookiesChanged();
-}
-
-
-void CookieJar::loadSettings()
-{
- int canAcceptCookies = ReKonfig::acceptCookies();
-
- switch (canAcceptCookies)
- {
- case 0:
- m_acceptCookies = AcceptAlways;
- break;
- case 1:
- m_acceptCookies = AcceptNever;
- break;
- case 2:
- default:
- m_acceptCookies = AcceptOnlyFromSitesNavigatedTo;
- break;
- }
-
- int canKeepCookiesUntil = ReKonfig::keepCookiesUntil();
-
- switch (canKeepCookiesUntil)
- {
- default:
- case 0:
- m_keepCookies = KeepUntilExpire;
- break;
- case 1:
- m_keepCookies = KeepUntilExit;
- setAllCookies(QList<QNetworkCookie>());
- break;
- case 2:
- m_keepCookies = KeepUntilTimeLimit;
- break;
- }
-
- emit cookiesChanged();
}
-void CookieJar::save()
+QList<QNetworkCookie> CookieJar::cookiesForUrl(const QUrl & url) const
{
- purgeOldCookies();
+ QList<QNetworkCookie> cookieList;
- QString filepath = KStandardDirs::locateLocal("appdata", cookieFileName);
- KConfig iniconfig( filepath );
-
- KConfigGroup inigroup1 = iniconfig.group("cookielist");
- QList<QNetworkCookie> cookies = allCookies();
- for (int i = cookies.count() - 1; i >= 0; --i)
+ if ( true ) // FIXME WebKitSettings::self()->isCookieJarEnabled())
{
- if (cookies.at(i).isSessionCookie())
- cookies.removeAt(i);
- }
+ QDBusInterface kcookiejar("org.kde.kded", "/modules/kcookiejar", "org.kde.KCookieServer");
+ QDBusReply<QString> reply = kcookiejar.call("findCookies", url.toString(), m_windowId);
- QStringList cookieStringList;
- foreach( QNetworkCookie cookie, cookies )
- {
- cookieStringList << QString( cookie.toRawForm() );
- }
- inigroup1.writeEntry( QString("cookies"), cookieStringList );
-
- KConfigGroup inigroup2 = iniconfig.group("exceptions");
- inigroup2.writeEntry( QString("block"), m_exceptions_block );
- inigroup2.writeEntry( QString("allow"), m_exceptions_allow );
- inigroup2.writeEntry( QString("allowForSession"), m_exceptions_allowForSession );
-
- // save cookie settings
- int n;
- switch (m_acceptCookies)
- {
- case AcceptAlways:
- n = 0;
- break;
- case AcceptNever:
- n = 1;
- break;
- case AcceptOnlyFromSitesNavigatedTo:
- default:
- n = 2;
- break;
+ if (reply.isValid())
+ {
+ cookieList << reply.value().toUtf8();
+ //kDebug() << reply.value();
+ }
+ else
+ {
+ kWarning() << "Unable to communicate with the cookiejar!";
+ }
}
- ReKonfig::setAcceptCookies(n);
-
- switch (m_keepCookies)
- {
- default:
- case KeepUntilExpire:
- n = 0;
- break;
- case KeepUntilExit:
- n = 1;
- break;
- case KeepUntilTimeLimit:
- n = 2;
- break;
- }
- ReKonfig::setKeepCookiesUntil(n);
+ return cookieList;
}
-void CookieJar::purgeOldCookies()
+bool CookieJar::setCookiesFromUrl(const QList<QNetworkCookie> & cookieList, const QUrl & url)
{
- QList<QNetworkCookie> cookies = allCookies();
- if (cookies.isEmpty())
- return;
- int oldCount = cookies.count();
- QDateTime now = QDateTime::currentDateTime();
- for (int i = cookies.count() - 1; i >= 0; --i)
- {
- if (!cookies.at(i).isSessionCookie() && cookies.at(i).expirationDate() < now)
- cookies.removeAt(i);
- }
- if (oldCount == cookies.count())
- return;
- setAllCookies(cookies);
- emit cookiesChanged();
-}
-
-
-QList<QNetworkCookie> CookieJar::cookiesForUrl(const QUrl &url) const
-{
- QWebSettings *globalSettings = QWebSettings::globalSettings();
- if (globalSettings->testAttribute(QWebSettings::PrivateBrowsingEnabled))
+ if ( true ) // FIXME WebKitSettings::self()->isCookieJarEnabled())
{
- QList<QNetworkCookie> noCookies;
- return noCookies;
- }
+ QDBusInterface kcookiejar("org.kde.kded", "/modules/kcookiejar", "org.kde.KCookieServer");
- return QNetworkCookieJar::cookiesForUrl(url);
-}
-
-
-bool CookieJar::setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url)
-{
- QWebSettings *globalSettings = QWebSettings::globalSettings();
- if (globalSettings->testAttribute(QWebSettings::PrivateBrowsingEnabled))
- return false;
-
- QString host = url.host();
- bool eBlock = qBinaryFind(m_exceptions_block.begin(), m_exceptions_block.end(), host) != m_exceptions_block.end();
- bool eAllow = qBinaryFind(m_exceptions_allow.begin(), m_exceptions_allow.end(), host) != m_exceptions_allow.end();
- bool eAllowSession = qBinaryFind(m_exceptions_allowForSession.begin(), m_exceptions_allowForSession.end(), host) != m_exceptions_allowForSession.end();
-
- bool addedCookies = false;
- // pass exceptions
- bool acceptInitially = (m_acceptCookies != AcceptNever);
- if ((acceptInitially && !eBlock) || (!acceptInitially && (eAllow || eAllowSession)))
- {
- // pass url domain == cookie domain
- QDateTime soon = QDateTime::currentDateTime();
- soon = soon.addDays(90);
- foreach(QNetworkCookie cookie, cookieList)
+ QByteArray cookieHeader;
+ Q_FOREACH(const QNetworkCookie& cookie, cookieList)
{
- QList<QNetworkCookie> lst;
- if (m_keepCookies == KeepUntilTimeLimit
- && !cookie.isSessionCookie()
- && cookie.expirationDate() > soon)
- {
- cookie.setExpirationDate(soon);
- }
- lst += cookie;
- if (QNetworkCookieJar::setCookiesFromUrl(lst, url))
- {
- addedCookies = true;
- }
- else
- {
- // finally force it in if wanted
- if (m_acceptCookies == AcceptAlways)
- {
- QList<QNetworkCookie> cookies = allCookies();
- cookies += cookie;
- setAllCookies(cookies);
- addedCookies = true;
- }
- }
+ cookieHeader = "Set-Cookie: ";
+ cookieHeader += cookie.toRawForm();
+ kcookiejar.call("addCookies", url.toString(), cookieHeader, m_windowId);
+ //kDebug() << "url: " << url.host() << ", cookie: " << cookieHeader;
}
- }
- if (addedCookies)
- {
- save();
- emit cookiesChanged();
+ return !kcookiejar.lastError().isValid();
}
- return addedCookies;
-}
-
-
-CookieJar::AcceptPolicy CookieJar::acceptPolicy() const
-{
- return m_acceptCookies;
+
+ return false;
}
-void CookieJar::setAcceptPolicy(AcceptPolicy policy)
+void CookieJar::setWindowId(qlonglong id)
{
- if (policy == m_acceptCookies)
- return;
- m_acceptCookies = policy;
-
- save();
-}
-
-
-CookieJar::KeepPolicy CookieJar::keepPolicy() const
-{
- return m_keepCookies;
-}
-
-
-void CookieJar::setKeepPolicy(KeepPolicy policy)
-{
- if (policy == m_keepCookies)
- return;
- m_keepCookies = policy;
-
- save();
-}
-
-
-QStringList CookieJar::blockedCookies() const
-{
- return m_exceptions_block;
-}
-
-
-QStringList CookieJar::allowedCookies() const
-{
- return m_exceptions_allow;
-}
-
-
-QStringList CookieJar::allowForSessionCookies() const
-{
- return m_exceptions_allowForSession;
-}
-
-
-void CookieJar::setBlockedCookies(const QStringList &list)
-{
- m_exceptions_block = list;
- qSort(m_exceptions_block.begin(), m_exceptions_block.end());
-
- save();
-}
-
-
-void CookieJar::setAllowedCookies(const QStringList &list)
-{
- m_exceptions_allow = list;
- qSort(m_exceptions_allow.begin(), m_exceptions_allow.end());
-
- save();
-}
-
-
-void CookieJar::setAllowForSessionCookies(const QStringList &list)
-{
- m_exceptions_allowForSession = list;
- qSort(m_exceptions_allowForSession.begin(), m_exceptions_allowForSession.end());
-
- save();
+ m_windowId = id;
}
diff --git a/src/cookiejar.h b/src/cookiejar.h
index cc3e81d0..d98d5af9 100644
--- a/src/cookiejar.h
+++ b/src/cookiejar.h
@@ -1,111 +1,29 @@
-/* ============================================================
-*
-* This file is a part of the rekonq project
-*
-* Copyright (C) 2007-2008 Trolltech ASA. All rights reserved
-* Copyright (C) 2008-2009 by Andrea Diamantini <adjam7 at gmail dot com>
-* Copyright (C) 2009 by Domrachev Alexandr <alexandr.domrachev@gmail.com>
-*
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License as
-* published by the Free Software Foundation; either version 2 of
-* the License or (at your option) version 3 or any later version
-* accepted by the membership of KDE e.V. (or its successor approved
-* by the membership of KDE e.V.), which shall act as a proxy
-* defined in Section 14 of version 3 of the license.
-*
-* This program 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 General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see <http://www.gnu.org/licenses/>.
-*
-* ============================================================ */
-#ifndef COOKIEJAR_H
-#define COOKIEJAR_H
+#ifndef RECOOKIEJAR_H
+#define RECOOKIEJAR_H
// Qt Includes
-#include <QtCore/QStringList>
#include <QtNetwork/QNetworkCookieJar>
// Forward Declarations
class QUrl;
-
class CookieJar : public QNetworkCookieJar
{
- friend class CookieModel;
- Q_OBJECT
-
- Q_PROPERTY(AcceptPolicy acceptPolicy READ acceptPolicy WRITE setAcceptPolicy)
- Q_PROPERTY(KeepPolicy keepPolicy READ keepPolicy WRITE setKeepPolicy)
- Q_PROPERTY(QStringList blockedCookies READ blockedCookies WRITE setBlockedCookies)
- Q_PROPERTY(QStringList allowedCookies READ allowedCookies WRITE setAllowedCookies)
- Q_PROPERTY(QStringList allowForSessionCookies READ allowForSessionCookies WRITE setAllowForSessionCookies)
-
- Q_ENUMS(KeepPolicy)
- Q_ENUMS(AcceptPolicy)
-
-signals:
- void cookiesChanged();
-
public:
- enum AcceptPolicy
- {
- AcceptAlways,
- AcceptNever,
- AcceptOnlyFromSitesNavigatedTo
- };
-
- enum KeepPolicy
- {
- KeepUntilExpire,
- KeepUntilExit,
- KeepUntilTimeLimit
- };
-
- CookieJar(QObject *parent = 0);
- ~CookieJar();
-
- QList<QNetworkCookie> cookiesForUrl(const QUrl &url) const;
- bool setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url);
-
- AcceptPolicy acceptPolicy() const;
- void setAcceptPolicy(AcceptPolicy policy);
-
- KeepPolicy keepPolicy() const;
- void setKeepPolicy(KeepPolicy policy);
-
- QStringList blockedCookies() const;
- QStringList allowedCookies() const;
- QStringList allowForSessionCookies() const;
-
- void setBlockedCookies(const QStringList &list);
- void setAllowedCookies(const QStringList &list);
- void setAllowForSessionCookies(const QStringList &list);
-
-public slots:
- void clear();
- void loadSettings();
-
-private slots:
- void save();
-
+ CookieJar(QObject* parent = 0);
+ virtual ~CookieJar();
+
+ virtual QList<QNetworkCookie> cookiesForUrl(const QUrl & url) const;
+
+ virtual bool setCookiesFromUrl(const QList<QNetworkCookie> & cookieList, const QUrl & url);
+
+ void setWindowId(qlonglong id);
+
private:
- void purgeOldCookies();
-
- AcceptPolicy m_acceptCookies;
- KeepPolicy m_keepCookies;
-
- QStringList m_exceptions_block;
- QStringList m_exceptions_allow;
- QStringList m_exceptions_allowForSession;
+ qlonglong m_windowId;
};
-#endif // COOKIEJAR_H
+#endif // RECOOKIEJAR_H
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index a4b78114..7de20c6e 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -450,7 +450,7 @@ void MainWindow::slotUpdateConfiguration()
// ====== load Settings on main classes
Application::networkAccessManager()->loadSettings();
- Application::cookieJar()->loadSettings();
+// FIXME (?) Application::cookieJar()->loadSettings();
Application::historyManager()->loadSettings();
}
@@ -972,7 +972,7 @@ void MainWindow::clearPrivateData()
if(clearWidget.clearCookies->isChecked())
{
- Application::cookieJar()->clear();
+ // FIXME (!) Application::cookieJar()->clear();
}
if(clearWidget.clearCachedPages->isChecked())
diff --git a/src/networkaccessmanager.cpp b/src/networkaccessmanager.cpp
index 1b589b27..fa554838 100644
--- a/src/networkaccessmanager.cpp
+++ b/src/networkaccessmanager.cpp
@@ -54,8 +54,9 @@
#include <QtNetwork/QNetworkDiskCache>
+
NetworkAccessManager::NetworkAccessManager(QObject *parent)
- : QNetworkAccessManager(parent)
+ : KIO::AccessManager(parent)
, m_diskCache(0)
{
connect(this, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)),
diff --git a/src/networkaccessmanager.h b/src/networkaccessmanager.h
index 348143b8..d42559a9 100644
--- a/src/networkaccessmanager.h
+++ b/src/networkaccessmanager.h
@@ -27,14 +27,14 @@
#ifndef NETWORKMANAGER_H
#define NETWORKMANAGER_H
-// Qt Includes
-#include <QtNetwork/QNetworkAccessManager>
+// KDE Includes
+#include <KIO/AccessManager>
// Forward Declarations
class QNetworkDiskCache;
-class NetworkAccessManager : public QNetworkAccessManager
+class NetworkAccessManager : public KIO::AccessManager
{
Q_OBJECT
@@ -56,7 +56,6 @@ private slots:
private:
QNetworkDiskCache *m_diskCache;
-
};
#endif // NETWORKMANAGER_H
diff --git a/src/settings.cpp b/src/settings.cpp
index 2d7d7c01..61056a71 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -216,17 +216,17 @@ bool SettingsDialog::hasChanged()
void SettingsDialog::showCookies()
{
- QPointer<CookiesDialog> dialog = new CookiesDialog(Application::cookieJar(), this);
- dialog->exec();
- delete dialog;
+// QPointer<CookiesDialog> dialog = new CookiesDialog(Application::cookieJar(), this);
+// dialog->exec();
+// delete dialog;
}
void SettingsDialog::showExceptions()
{
- QPointer<CookiesExceptionsDialog> dialog = new CookiesExceptionsDialog(Application::cookieJar(), this);
- dialog->exec();
- delete dialog;
+// QPointer<CookiesExceptionsDialog> dialog = new CookiesExceptionsDialog(Application::cookieJar(), this);
+// dialog->exec();
+// delete dialog;
}
diff --git a/src/webpage.cpp b/src/webpage.cpp
index 498ab7ba..160294e2 100644
--- a/src/webpage.cpp
+++ b/src/webpage.cpp
@@ -65,10 +65,9 @@
#include <QtGui/QClipboard>
#include <QtGui/QKeyEvent>
-
-
#include <QUiLoader>
+
WebPage::WebPage(QObject *parent)
: QWebPage(parent)
, m_keyboardModifiers(Qt::NoModifier)
diff --git a/src/webpage.h b/src/webpage.h
index aefd9bcd..d21fc44d 100644
--- a/src/webpage.h
+++ b/src/webpage.h
@@ -77,8 +77,7 @@ protected:
const QUrl &url,
const QStringList &paramNames,
const QStringList &paramValues);
-
-
+
protected Q_SLOTS:
virtual void slotHandleUnsupportedContent(QNetworkReply *reply);
virtual void slotDownloadRequested(const QNetworkRequest &request);