[WebKit-devel] KDE/kdelibs/kdewebkit

Dawit Alemayehu adawit at kde.org
Mon Nov 30 21:24:21 CET 2009


SVN commit 1056771 by adawit:

- Added functions to remove cached form data from wallet.
- Added function to retreive cached form data for a frame.
- Renamed fillFormData to fillFormDataFromCache 
- Renamed saveFormData to saveFormDataFromCache

CCMAIL:webkit-devel at kde.org


 M  +98 -37    kwebwallet.cpp  
 M  +68 -16    kwebwallet.h  


--- trunk/KDE/kdelibs/kdewebkit/kwebwallet.cpp #1056770:1056771
@@ -36,7 +36,7 @@
 #define QL1C(x)   QLatin1Char(x)
 
 /**
- * Creates key used to store and retrieve form data.
+ * Creates key used to store and retreive form data.
  *
  */
 static QString walletKey(KWebWallet::WebForm form, bool useIndexOnEmptyName = false)
@@ -72,6 +72,7 @@
     KWebWallet::WebFormList parseFormData(QWebFrame* frame, bool fillform = true, bool ignorepasswd = false);
     void fillDataFromCache(KWebWallet::WebFormList &formList);
     void saveDataToCache(const QString &key);
+    void removeDataFromCache(const WebFormList &formList);
 
     // Private Q_SLOT...
     void _k_openWalletDone(bool);    
@@ -79,8 +80,8 @@
     WId wid;
     KWebWallet *q;
     QPointer<KWallet::Wallet> wallet;
+    KWebWallet::WebFormList pendingRemoveRequests;
     QHash<KUrl, FormsData> pendingFillRequests;
-    QHash<KUrl, KWebWallet::WebFormList> pendingRemoveRequests;
     QHash<QString, KWebWallet::WebFormList> pendingSaveRequests;
 };
 
@@ -163,24 +164,32 @@
         }
 
         if (wallet->writeMap(walletKey(form), values) == 0)
-          count++;
+            count++;
     }
 
     emit q->saveFormDataCompleted(url, (count == list.count()));
 }
 
+void KWebWallet::KWebWalletPrivate::removeDataFromCache(const WebFormList &formList)
+{
+    Q_ASSERT(wallet);
+
+    QListIterator<WebForm> formIt (formList);
+    while (formIt.hasNext()) {
+        wallet->removeEntry(walletKey(formIt.next()));
+    }
+}
+
 void KWebWallet::KWebWalletPrivate::_k_openWalletDone(bool ok)
 { 
-    if (!ok) {
-        delete wallet;
-        return;
-    }
+    Q_ASSERT (wallet);
 
-    if ((wallet->hasFolder(KWallet::Wallet::FormDataFolder()) ||
+    if (ok &&
+        (wallet->hasFolder(KWallet::Wallet::FormDataFolder()) ||
          wallet->createFolder(KWallet::Wallet::FormDataFolder())) &&
         wallet->setFolder(KWallet::Wallet::FormDataFolder())) {
 
-        // Save pending fill requests...
+        // Do pending fill requests...
         if (!pendingFillRequests.isEmpty()) {
             KUrl::List urlList;
             QMutableHashIterator<KUrl, FormsData> requestIt (pendingFillRequests);
@@ -188,22 +197,34 @@
                requestIt.next();
                KWebWallet::WebFormList list = requestIt.value().forms;
                fillDataFromCache(list);
-               q->fillForm(requestIt.key(), list);
+               q->fillWebForm(requestIt.key(), list);
             }
 
             pendingFillRequests.clear();
         }
 
-         // Save pending save requests...
+         // Do pending save requests...
         if (!pendingSaveRequests.isEmpty()) {
             QListIterator<QString> keysIt (pendingSaveRequests.keys());
             while (keysIt.hasNext())
-                saveDataToCache(keysIt.next());            
+                saveDataToCache(keysIt.next());
+
+            pendingSaveRequests.clear();
         }
+
+        // Do pending remove requests...
+        if (!pendingRemoveRequests.isEmpty()) {
+            removeDataFromCache(pendingRemoveRequests);
+            pendingRemoveRequests.clear();
+        }
+    } else {
+        // Delete the wallet if opening the wallet failed or we were unable
+        // to change to the folder we wanted to change to.
+        delete wallet;
     }
 }
 
-KWebWallet::KWebWallet(QObject *parent, WId wid)
+KWebWallet::KWebWallet(QObject *parent, qlonglong wid)
            :QObject(parent), d(new KWebWalletPrivate(this))
 {
     if (!wid) {
@@ -225,21 +246,18 @@
     delete d;
 }
 
-void KWebWallet::saveFormData(QWebFrame *frame, bool recursive, bool ignorePasswordFields)
-{  
-    WebFormList list = d->parseFormData(frame, false, ignorePasswordFields);
+KWebWallet::WebFormList KWebWallet::formsWithCachedData(QWebFrame* frame, bool recursive) const
+{
+    WebFormList list = d->parseFormData(frame);
+
     if (recursive) {
-        QListIterator<QWebFrame*> frameIt (frame->childFrames());
-        while (frameIt.hasNext()) {
-            list << d->parseFormData(frameIt.next(), false, ignorePasswordFields);
+        QListIterator <QWebFrame *> framesIt (frame->childFrames());
+        while (framesIt.hasNext()) {
+            list << d->parseFormData(framesIt.next());
         }
     }
 
-    if (!list.isEmpty()) {
-        const QString key = QString::number(qHash(frame->url().toString() + frame->frameName()), 16);
-        d->pendingSaveRequests.insert(key, list);
-        emit saveFormDataRequested(key, frame->url());
-    }
+    return list;
 }
 
 void KWebWallet::fillFormData(QWebFrame *frame, bool recursive)
@@ -281,13 +299,41 @@
         }
 
         if (!urlList.isEmpty())
-            fillFormData(urlList);
+            fillFormDataFromCache(urlList);
     }
 }
 
+void KWebWallet::saveFormData(QWebFrame *frame, bool recursive, bool ignorePasswordFields)
+{
+    WebFormList list = d->parseFormData(frame, false, ignorePasswordFields);
+    if (recursive) {
+        QListIterator<QWebFrame*> frameIt (frame->childFrames());
+        while (frameIt.hasNext()) {
+            list << d->parseFormData(frameIt.next(), false, ignorePasswordFields);
+        }
+    }
+
+    if (!list.isEmpty()) {
+        const QString key = QString::number(qHash(frame->url().toString() + frame->frameName()), 16);
+        d->pendingSaveRequests.insert(key, list);
+        emit saveFormDataRequested(key, frame->url());
+    }
+}
+
+void KWebWallet::removeFormData(QWebFrame *frame, bool recursive)
+{
+    removeFormDataFromCache(formsWithCachedData(frame, recursive));
+}
+
+void KWebWallet::removeFormData(const WebFormList &forms)
+{
+    d->pendingRemoveRequests << forms;
+    removeFormDataFromCache(forms);
+}
+
 void KWebWallet::acceptSaveFormDataRequest(const QString &key)
 {
-    saveFormData(key);
+    saveFormDataToCache(key);
 }
 
 void KWebWallet::rejectSaveFormDataRequest(const QString & key)
@@ -295,7 +341,7 @@
     d->pendingSaveRequests.remove(key);
 }
 
-void KWebWallet::fillForm(const KUrl &url, const KWebWallet::WebFormList &forms)
+void KWebWallet::fillWebForm(const KUrl &url, const KWebWallet::WebFormList &forms)
 {
     QWebFrame *frame = d->pendingFillRequests.value(url).frame;
     if (frame) {
@@ -339,7 +385,7 @@
                                              walletKey(form));
 }
 
-void KWebWallet::saveFormData(const QString &key)
+void KWebWallet::fillFormDataFromCache(const KUrl::List &urlList)
 {
     if (!d->wallet) {
         d->wallet = KWallet::Wallet::openWallet(KWallet::Wallet::NetworkWallet(),
@@ -349,10 +395,18 @@
         return;
     }
 
-    d->saveDataToCache(key);
+    QListIterator<KUrl> urlIt (urlList);
+    while (urlIt.hasNext()) {
+        const KUrl url = urlIt.next();
+        WebFormList list = formsToFill(url);
+        d->fillDataFromCache(list);
+        fillWebForm(url, list);
+    }
+
+    d->pendingFillRequests.clear();
 }
 
-void KWebWallet::fillFormData(const KUrl::List &urlList)
+void KWebWallet::saveFormDataToCache(const QString &key)
 {
     if (!d->wallet) {
         d->wallet = KWallet::Wallet::openWallet(KWallet::Wallet::NetworkWallet(),
@@ -362,15 +416,22 @@
         return;
     }
 
-    QListIterator<KUrl> urlIt (urlList);
-    while (urlIt.hasNext()) {
-        const KUrl url = urlIt.next();
-        WebFormList list = formsToFill(url);
-        d->fillDataFromCache(list);
-        fillForm(url, list);
+    d->saveDataToCache(key);
+    d->pendingSaveRequests.clear();
+}
+
+void KWebWallet::removeFormDataFromCache(const WebFormList &forms)
+{
+    if (!d->wallet) {
+        d->wallet = KWallet::Wallet::openWallet(KWallet::Wallet::NetworkWallet(),
+                                                d->wid, KWallet::Wallet::Asynchronous);
+        connect(d->wallet, SIGNAL(walletOpened(bool)),
+                this, SLOT(_k_openWalletDone(bool)));
+        return;
     }
 
-    d->pendingFillRequests.clear();
+    d->removeDataFromCache(forms);
+    d->pendingRemoveRequests.clear();
 }
 
 #include "kwebwallet.moc"
--- trunk/KDE/kdelibs/kdewebkit/kwebwallet.h #1056770:1056771
@@ -30,7 +30,6 @@
 #include <QtCore/QString>
 #include <QtCore/QList>
 #include <QtCore/QPair>
-#include <QtGui/QWidget>
 #include <QtGlobal>
 
 class QWebFrame;
@@ -76,7 +75,7 @@
     /**
      * Constructs a KWebWallet with @p parent as its parent.
      */
-    explicit KWebWallet(QObject* parent = 0, WId wid = 0);
+    explicit KWebWallet(QObject* parent = 0, qlonglong wid = 0);
 
     /**
      * Destructor
@@ -84,6 +83,24 @@
     virtual ~KWebWallet();
 
     /**
+     * Returns a list of forms in @p frame that have cached data in the
+     * peristent storage.
+     *
+     * If @p recursive is set to true, the default, then this function will
+     * will also return the cached form data for all the children frames of
+     * @p frame.
+     *
+     * If the site currently rendered in @p frame does not contain any forms
+     * or there is not cached data for the forms found in @p frame, then this
+     * function will return an empty list.
+     *
+     * Note that this function will only return the information about the forms
+     * in @p frame and not their cached data, i.e. the fields member variable in
+     * the returned @ref WebForm list will always be empty.
+     */
+    WebFormList formsWithCachedData(QWebFrame* frame, bool recursive = true) const;
+
+    /**
      * Attempts to save the form data from @p frame and its children frames.
      *
      * If @p recursive is set to true, the default, then form data from all
@@ -94,8 +111,6 @@
      * @ref rejectSaveFormDataRequest or @ref acceptSaveFormDataRequest signals
      * in order to complete the save request. Otherwise, you request will simply
      * be ignored.
-     *
-     * @see saveFormDataRequested
      */
     void saveFormData(QWebFrame *frame, bool recursive = true, bool ignorePasswordFields = false);
 
@@ -105,11 +120,33 @@
      * If @p recursive is set to true, the default, then this function will
      * attempt to fill out forms in the specified frame and all its children
      * frames.
-     *
-     * @see restoreFormData
      */
     void fillFormData(QWebFrame *frame, bool recursive = true);
 
+    /**
+     * Removes the form data specified by @p forms from the persistent storage.
+     *
+     * This function is provided for convenience and simply calls @ref formsWithCachedData
+     * and @ref removeFormData. Note that this function will remove all cached
+     * data for forms found in @p frame. If @p recursive is set to true, then
+     * all cached data for all of the child frames of @p frame will be removed
+     * from the persistent storage as well.
+     *
+     * @see formsWithCachedData
+     * @see removeFormData
+     */
+    void removeFormData (QWebFrame *frame, bool recursive);
+
+    /**
+     * Removes the form data specified by @p forms from the persistent storage.
+     *
+     * Call @ref formsWithCachedData to obtain a list of forms with data cached
+     * in persistent storage.
+     *
+     * @see formsWithCachedData
+     */
+    void removeFormData(const WebFormList &forms);
+
 public Q_SLOTS:
     /**
      * Accepts the save form data request associated with @p key.
@@ -179,40 +216,55 @@
     WebFormList formsToSave(const QString &key) const;
 
     /**
+     * Returns forms to be removed from persistent storage.
+     */
+    WebFormList formsToDelete() const;
+
+    /**
      * Returns true when there is data associated with @p form in the
-     * persistent cache.
+     * persistent storage.
      */
     virtual bool hasCachedFormData(const WebForm &form) const;
 
     /**
-     * Fills the QWebFrame that is showing @p url with data from @p forms.
+     * Fills the web forms in frame that point to @p url with data from @p forms.
      *
-     * @see fillFormData.
+     * @see fillFormDataFromCache.
      */
-    void fillForm(const KUrl &url, const WebFormList &forms);
+    void fillWebForm(const KUrl &url, const WebFormList &forms);
 
     /**
-     * Fills form data from persistent cache.
+     * Fills form data from persistent storage.
      *
      * If you reimplement this function, call @ref formsToFill to obtain
      * the list of forms pending to be filled. Once you fill the list with
-     * the cached data from the persistent storage, you must call @p fillForm
+     * the cached data from the persistent storage, you must call @p fillWebForm
      * to fill out the actual web forms.
      *
      * @see formsToFill
      */
-    virtual void fillFormData(const KUrl::List &list);
+    virtual void fillFormDataFromCache(const KUrl::List &list);
 
     /**
-     * Stores form data associated with @p key to a persistent cache.
+     * Stores form data associated with @p key to a persistent storage.
      *
      * If you reimplement this function, call @ref formsToSave to obtain the
-     * list of forms data pending to be saved to persistent cache.
+     * list of form data pending to be saved to persistent storage.
      *
      *@see formsToSave
      */
-    virtual void saveFormData(const QString &key);
+    virtual void saveFormDataToCache(const QString &key);
 
+    /**
+     * Removes all cached form data associated with @p forms from persistent storage.
+     *
+     * If you reimplement this function, call @ref formsToDelete to obtain the
+     * list of form data pending to be removed from persistent storage.
+     *
+     *@see formsToDelete
+     */
+    virtual void removeFormDataFromCache(const WebFormList &forms);
+
 private:
     class KWebWalletPrivate;
     friend class KWebWalletPrivate;


More information about the WebKit-devel mailing list