From 6cf3cb637c7442345edc92de92f24b9ea8a9420b Mon Sep 17 00:00:00 2001 From: nowrep Date: Mon, 25 Feb 2013 15:03:53 +0100 Subject: [PATCH] [AutoFill] Show key icon only when password was actually filled in page. If you have saved multiple passwords eg. for gmail.com, it will now only show key icon when trying to login, instead of showing it all the time on gmail.com (even after logging in). --- src/lib/autofill/autofill.cpp | 8 +++++++- src/lib/autofill/pageformcompleter.cpp | 12 ++++++------ src/lib/autofill/pageformcompleter.h | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/lib/autofill/autofill.cpp b/src/lib/autofill/autofill.cpp index 767b6e431..a53a0aa31 100644 --- a/src/lib/autofill/autofill.cpp +++ b/src/lib/autofill/autofill.cpp @@ -254,8 +254,10 @@ void AutoFill::updateEntry(const PageFormData &formData, const AutoFillData &upd mApp->dbWriter()->executeQuery(query); } +// If password was filled in the page, returns all saved passwords on this page QList AutoFill::completePage(WebPage* page) { + bool completed = false; QList list; if (!page) { @@ -273,7 +275,11 @@ QList AutoFill::completePage(WebPage* page) const AutoFillData data = getFirstFormData(pageUrl); PageFormCompleter completer(page); - completer.completePage(data.postData); + completed = completer.completePage(data.postData); + } + + if (!completed) { + list.clear(); } return list; diff --git a/src/lib/autofill/pageformcompleter.cpp b/src/lib/autofill/pageformcompleter.cpp index 58be19d40..34482d507 100644 --- a/src/lib/autofill/pageformcompleter.cpp +++ b/src/lib/autofill/pageformcompleter.cpp @@ -90,8 +90,10 @@ PageFormData PageFormCompleter::extractFormData(const QByteArray &postData) cons return formData; } -void PageFormCompleter::completePage(const QByteArray &data) const +// Returns if any data was actually filled in page +bool PageFormCompleter::completePage(const QByteArray &data) const { + bool completed = false; const QueryItems &queryItems = createQueryItems(data); // Input types that are being completed @@ -105,11 +107,6 @@ void PageFormCompleter::completePage(const QByteArray &data) const const QString &key = queryItems.at(i).first; const QString &value = queryItems.at(i).second; - /* Is it really necessary? - key = QUrl::fromEncoded(key.toUtf8()).toString(); - value = QUrl::fromEncoded(value.toUtf8()).toString(); - */ - for (int i = 0; i < inputs.count(); i++) { QWebElement element = inputs.at(i); const QString &typeAttr = element.attribute("type"); @@ -119,10 +116,13 @@ void PageFormCompleter::completePage(const QByteArray &data) const } if (key == element.attribute("name")) { + completed = true; element.setAttribute("value", value); } } } + + return completed; } bool PageFormCompleter::queryItemsContains(const QueryItems &queryItems, const QString &attributeName, diff --git a/src/lib/autofill/pageformcompleter.h b/src/lib/autofill/pageformcompleter.h index 921f0ce6d..44393d5dd 100644 --- a/src/lib/autofill/pageformcompleter.h +++ b/src/lib/autofill/pageformcompleter.h @@ -41,7 +41,7 @@ public: explicit PageFormCompleter(QWebPage* page); PageFormData extractFormData(const QByteArray &postData) const; - void completePage(const QByteArray &data) const; + bool completePage(const QByteArray &data) const; private: typedef QPair QueryItem;