[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/kio/kio
From:       Dawit Alemayehu <adawit () kde ! org>
Date:       2010-10-13 7:38:39
Message-ID: 20101013073839.25C23AC895 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1185377 by adawit:

- Added functions to disable cookie storage. When this flag is set, all cookies will \
be converted  to session cookies so they do not get saved to a peristent storage, \
i.e. hard drive.

- Changed the external content restriction check to use KProtocolInfo to determine \
whether  the current request is a local one or not.

- Documentation update.

CCBUG:250122


 M  +37 -17    accessmanager.cpp  
 M  +28 -3     accessmanager.h  


--- trunk/KDE/kdelibs/kio/kio/accessmanager.cpp #1185376:1185377
@@ -30,8 +30,10 @@
 #include <kio/scheduler.h>
 #include <kconfiggroup.h>
 #include <ksharedconfig.h>
+#include <kprotocolinfo.h>
 
 #include <QtCore/QUrl>
+#include <QtCore/QWeakPointer>
 #include <QtDBus/QDBusInterface>
 #include <QtDBus/QDBusConnection>
 #include <QtDBus/QDBusReply>
@@ -44,14 +46,23 @@
 #define QL1S(x)   QLatin1String(x)
 #define QL1C(x)   QLatin1Char(x)
 
+static bool isLocalRequest(const QUrl& url)
+{
+    const QString scheme (url.scheme());
+    return (KProtocolInfo::isKnownProtocol(scheme) && 
+            KProtocolInfo::protocolClass(scheme).compare(QL1S(":local"), \
Qt::CaseInsensitive) == 0); +}
+
 namespace KIO {
 
 class AccessManager::AccessManagerPrivate
 {
 public:
-    AccessManagerPrivate():externalContentAllowed(true) {}
+    AccessManagerPrivate() 
+    : externalContentAllowed(true)
+    {}
+
     KIO::MetaData metaDataForRequest(QNetworkRequest request);
-    bool isRequestAllowed(const QUrl& url) const;
 
     bool externalContentAllowed;
     KIO::MetaData requestMetaData;
@@ -63,10 +74,15 @@
 class CookieJar::CookieJarPrivate
 {
 public:
-  CookieJarPrivate(): windowId((WId)-1), enabled(true) {}
+  CookieJarPrivate()
+    : windowId((WId)-1), 
+      isEnabled(true),
+      isStorageDisabled(false)
+  {}
 
   WId windowId;
-  bool enabled;
+  bool isEnabled;
+  bool isStorageDisabled;
 };
 
 }
@@ -130,7 +146,7 @@
     KIO::SimpleJob *kioJob = 0;
     const QUrl reqUrl (req.url());
 
-    if ( !d->isRequestAllowed(reqUrl) ) {
+    if (!d->externalContentAllowed && !isLocalRequest(reqUrl)) {
         kDebug( 7044 ) << "Blocked: " << reqUrl;
         /* if kioJob equals zero, the AccessManagerReply will block the request */
         return new KDEPrivate::AccessManagerReply(op, req, kioJob, this);
@@ -256,14 +272,7 @@
     return metaData;
 }
 
-bool AccessManager::AccessManagerPrivate::isRequestAllowed(const QUrl& url) const
-{
-    const QString scheme (url.scheme());
 
-    return (externalContentAllowed || scheme == QL1S("file")  || scheme == \
                QL1S("data"));
-}
-
-
 using namespace KIO::Integration;
 
 static QSsl::SslProtocol qSslProtocolFromString(const QString& str)
@@ -310,10 +319,14 @@
     return d->windowId;
 }
 
+bool CookieJar::isCookieStorageDisabled() const {
+   return d->isStorageDisabled;
+}
+
 QList<QNetworkCookie> CookieJar::cookiesForUrl(const QUrl &url) const {
     QList<QNetworkCookie> cookieList;
 
-    if (d->enabled) {
+    if (d->isEnabled) {
         QDBusInterface kcookiejar("org.kde.kded", "/modules/kcookiejar", \
                "org.kde.KCookieServer");
         QDBusReply<QString> reply = kcookiejar.call("findDOMCookies", \
url.toString(), (qlonglong)d->windowId);  
@@ -337,11 +350,15 @@
 }
 
 bool CookieJar::setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const \
                QUrl &url) {
-    if (d->enabled) {
+    if (d->isEnabled) {
         QDBusInterface kcookiejar("org.kde.kded", "/modules/kcookiejar", \
                "org.kde.KCookieServer");
-
         Q_FOREACH(const QNetworkCookie &cookie, cookieList) {
             QByteArray cookieHeader ("Set-Cookie: ");
+	    if (d->isStorageDisabled && !cookie.isSessionCookie()) {
+                QNetworkCookie sessionCookie(cookie);
+                sessionCookie.setExpirationDate(QDateTime());
+                cookieHeader += sessionCookie.toRawForm();
+            } else
             cookieHeader += cookie.toRawForm();
             kcookiejar.call("addCookies", url.toString(), cookieHeader, \
                (qlonglong)d->windowId);
             //kDebug(7044) << "[" << d->windowId << "]" << cookieHeader << " from " \
<< url; @@ -353,14 +370,17 @@
     return false;
 }
 
+void CookieJar::setDisableCookieStorage(bool disable) {
+    d->isStorageDisabled = disable;
+}
+
 void CookieJar::setWindowId(WId id) {
     d->windowId = id;
 }
 
 void CookieJar::reparseConfiguration() {
     KConfigGroup cfg = KSharedConfig::openConfig("kcookiejarrc", \
                KConfig::NoGlobals)->group("Cookie Policy");
-    d->enabled = cfg.readEntry("Cookies", true);
+    d->isEnabled = cfg.readEntry("Cookies", true);
 }
 
-
 #include "accessmanager.moc"
--- trunk/KDE/kdelibs/kio/kio/accessmanager.h #1185376:1185377
@@ -71,16 +71,22 @@
     Q_OBJECT
 public:
     /*!
-      Extensions to QNetworkRequest::Attribute enums.
-      @since 4.3.2
+     * Extensions to QNetworkRequest::Attribute enums.
+     * @since 4.3.2
     */
     enum Attribute {
         MetaData = QNetworkRequest::User, /** < Used to send KIO MetaData back and \
                forth. type: QVariant::Map. */
-        KioError /**< Used to send KIO error codes that cannot be mapped into \
QNetworkReply::NetworkError. type: QVariant::Int */ +        KioError, /**< Used to \
send KIO error codes that cannot be mapped into QNetworkReply::NetworkError. type: \
QVariant::Int */  };
 
+    /**
+     * Constructor
+     */
     AccessManager(QObject *parent);
 
+    /**
+     * Destructor
+     */
     virtual ~AccessManager();
 
     /**
@@ -265,6 +271,25 @@
      */
     bool setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl \
&url);  
+    /**
+     * Returns true if persistent caching of cookies is disabled.
+     * 
+     * @see setDisableCookieStorage
+     * @since 4.6
+     */
+    bool isCookieStorageDisabled() const;
+    
+    /**
+     * Prevent persistent storage of cookies.
+     * 
+     * Call this function if you do not want cookies to be stored locally for
+     * later access without disabling the cookiejar. All cookies will be discarded
+     * once the sessions that are using the cookie are done.
+     * 
+     * @since 4.6
+     */
+    void setDisableCookieStorage (bool disable);
+
 private:
     class CookieJarPrivate;
     CookieJarPrivate* const d;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic