diff --git a/src/lib/autofill/autofill.cpp b/src/lib/autofill/autofill.cpp index 32e8eb5df..b2f72d2f4 100644 --- a/src/lib/autofill/autofill.cpp +++ b/src/lib/autofill/autofill.cpp @@ -229,7 +229,8 @@ QVector AutoFill::completePage(WebPage *page, const QUrl &frameUr list = getFormData(frameUrl); if (!list.isEmpty()) { - const PasswordEntry entry = list.at(0); + PasswordEntry entry = list.at(0); + updateLastUsed(entry); page->runJavaScript(Scripts::completeFormData(entry.data), WebPage::SafeJsWorld); } diff --git a/src/lib/autofill/autofillicon.cpp b/src/lib/autofill/autofillicon.cpp index e45faa3b3..91c9b11da 100644 --- a/src/lib/autofill/autofillicon.cpp +++ b/src/lib/autofill/autofillicon.cpp @@ -1,6 +1,6 @@ /* ============================================================ * Falkon - Qt web browser -* Copyright (C) 2013-2014 David Rosca +* Copyright (C) 2013-2018 David Rosca * * 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 @@ -37,9 +37,9 @@ void AutoFillIcon::setWebView(WebView* view) m_view = view; } -void AutoFillIcon::setFormData(const QVector &data) +void AutoFillIcon::setUsernames(const QStringList &usernames) { - m_data = data; + m_usernames = usernames; } void AutoFillIcon::iconClicked() @@ -49,7 +49,7 @@ void AutoFillIcon::iconClicked() } AutoFillWidget* widget = new AutoFillWidget(m_view, this); - widget->setFormData(m_data); + widget->setUsernames(m_usernames); widget->showAt(parentWidget()); } diff --git a/src/lib/autofill/autofillicon.h b/src/lib/autofill/autofillicon.h index 1f62698ed..96bf2e77a 100644 --- a/src/lib/autofill/autofillicon.h +++ b/src/lib/autofill/autofillicon.h @@ -1,6 +1,6 @@ /* ============================================================ * Falkon - Qt web browser -* Copyright (C) 2013-2014 David Rosca +* Copyright (C) 2013-2018 David Rosca * * 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 @@ -20,7 +20,6 @@ #include "qzcommon.h" #include "clickablelabel.h" -#include "passwordmanager.h" class WebView; @@ -32,7 +31,7 @@ public: explicit AutoFillIcon(QWidget* parent = 0); void setWebView(WebView* view); - void setFormData(const QVector &data); + void setUsernames(const QStringList &usernames); private slots: void iconClicked(); @@ -43,7 +42,7 @@ private: WebView* m_view; - QVector m_data; + QStringList m_usernames; }; diff --git a/src/lib/autofill/autofillwidget.cpp b/src/lib/autofill/autofillwidget.cpp index c85a46a6c..112018592 100644 --- a/src/lib/autofill/autofillwidget.cpp +++ b/src/lib/autofill/autofillwidget.cpp @@ -1,6 +1,6 @@ /* ============================================================ * Falkon - Qt web browser -* Copyright (C) 2013-2016 David Rosca +* Copyright (C) 2013-2018 David Rosca * * 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 @@ -22,6 +22,8 @@ #include "webview.h" #include "webpage.h" #include "scripts.h" +#include "mainapplication.h" +#include "passwordmanager.h" #include @@ -33,46 +35,36 @@ AutoFillWidget::AutoFillWidget(WebView* view, QWidget* parent) ui->setupUi(this); } -void AutoFillWidget::setFormData(const QVector &data) +void AutoFillWidget::setUsernames(const QStringList &usernames) { - m_data = data; - - for (int i = 0; i < data.count(); ++i) { - const PasswordEntry d = data.at(i); - if (d.username.isEmpty()) { + int i = 0; + for (const QString &username : usernames) { + if (username.isEmpty()) { continue; } QPushButton* button = new QPushButton(this); button->setIcon(QIcon(":icons/other/login.png")); button->setStyleSheet("text-align:left;font-weight:bold;"); - button->setText(d.username); - button->setProperty("data-index", i); + button->setText(username); button->setFlat(true); - ui->gridLayout->addWidget(button, i, 0); - connect(button, SIGNAL(clicked()), this, SLOT(loginToPage())); + ui->gridLayout->addWidget(button, i++, 0); + connect(button, &QPushButton::clicked, this, [=]() { + const auto entries = mApp->autoFill()->getFormData(m_view->url()); + for (PasswordEntry entry : entries) { + if (entry.username != username) { + continue; + } + mApp->autoFill()->updateLastUsed(entry); + m_view->page()->runJavaScript(Scripts::completeFormData(entry.data), WebPage::SafeJsWorld); + break; + } + close(); + }); } } -void AutoFillWidget::loginToPage() -{ - QPushButton* button = qobject_cast(sender()); - if (!button || !m_view) { - return; - } - - bool ok; - int index = button->property("data-index").toInt(&ok); - - if (ok && QzTools::containsIndex(m_data, index)) { - const PasswordEntry entry = m_data.at(index); - m_view->page()->runJavaScript(Scripts::completeFormData(entry.data), WebPage::SafeJsWorld); - } - - close(); -} - AutoFillWidget::~AutoFillWidget() { delete ui; diff --git a/src/lib/autofill/autofillwidget.h b/src/lib/autofill/autofillwidget.h index 2e246b5a9..93bcce0c7 100644 --- a/src/lib/autofill/autofillwidget.h +++ b/src/lib/autofill/autofillwidget.h @@ -1,6 +1,6 @@ /* ============================================================ * Falkon - Qt web browser -* Copyright (C) 2013-2014 David Rosca +* Copyright (C) 2013-2018 David Rosca * * 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 @@ -30,7 +30,6 @@ class AutoFillWidget; } class WebView; -struct PasswordEntry; class FALKON_EXPORT AutoFillWidget : public LocationBarPopup { @@ -40,16 +39,12 @@ public: explicit AutoFillWidget(WebView* view, QWidget* parent = 0); ~AutoFillWidget(); - void setFormData(const QVector &data); - -private slots: - void loginToPage(); + void setUsernames(const QStringList &usernames); private: Ui::AutoFillWidget* ui; WebView* m_view; - QVector m_data; }; #endif // AUTOFILLWIDGET_H diff --git a/src/lib/autofill/passwordbackends/passwordbackend.cpp b/src/lib/autofill/passwordbackends/passwordbackend.cpp index b5fc5a95b..1e22ecc58 100644 --- a/src/lib/autofill/passwordbackends/passwordbackend.cpp +++ b/src/lib/autofill/passwordbackends/passwordbackend.cpp @@ -1,6 +1,6 @@ /* ============================================================ * Falkon - Qt web browser -* Copyright (C) 2013-2014 David Rosca +* Copyright (C) 2013-2018 David Rosca * * 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 @@ -22,6 +22,16 @@ PasswordBackend::PasswordBackend() { } +QStringList PasswordBackend::getUsernames(const QUrl &url) +{ + QStringList out; + const auto entries = getEntries(url); + for (const PasswordEntry &entry : entries) { + out.append(entry.username); + } + return out; +} + void PasswordBackend::setActive(bool active) { m_active = active; diff --git a/src/lib/autofill/passwordbackends/passwordbackend.h b/src/lib/autofill/passwordbackends/passwordbackend.h index bd15df1bf..6fceb1e79 100644 --- a/src/lib/autofill/passwordbackends/passwordbackend.h +++ b/src/lib/autofill/passwordbackends/passwordbackend.h @@ -1,6 +1,6 @@ /* ============================================================ * Falkon - Qt web browser -* Copyright (C) 2013-2014 David Rosca +* Copyright (C) 2013-2018 David Rosca * * 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 @@ -31,6 +31,7 @@ public: virtual QString name() const = 0; + virtual QStringList getUsernames(const QUrl &url); virtual QVector getEntries(const QUrl &url) = 0; virtual QVector getAllEntries() = 0; diff --git a/src/lib/autofill/passwordmanager.cpp b/src/lib/autofill/passwordmanager.cpp index ca0f1c841..b6a074e33 100644 --- a/src/lib/autofill/passwordmanager.cpp +++ b/src/lib/autofill/passwordmanager.cpp @@ -1,6 +1,6 @@ /* ============================================================ * Falkon - Qt web browser -* Copyright (C) 2013-2014 David Rosca +* Copyright (C) 2013-2018 David Rosca * * 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 @@ -76,6 +76,9 @@ void PasswordManager::loadSettings() QString backendId = settings.value("Backend", "database").toString(); settings.endGroup(); + if (m_backend) { + m_backend->setActive(false); + } m_backend = m_backends[m_backends.contains(backendId) ? backendId : "database"]; m_backend->setActive(true); } diff --git a/src/lib/navigation/locationbar.cpp b/src/lib/navigation/locationbar.cpp index 616f2e93c..aabd7c24b 100644 --- a/src/lib/navigation/locationbar.cpp +++ b/src/lib/navigation/locationbar.cpp @@ -630,8 +630,8 @@ void LocationBar::loadFinished() WebPage* page = qobject_cast(m_webView->page()); - if (page && page->hasMultipleUsernames()) { - m_autofillIcon->setFormData(page->autoFillData()); + if (page && !page->autoFillUsernames().isEmpty()) { + m_autofillIcon->setUsernames(page->autoFillUsernames()); m_autofillIcon->show(); } } diff --git a/src/lib/popupwindow/popuplocationbar.cpp b/src/lib/popupwindow/popuplocationbar.cpp index 3c83b3206..9fed1f2fe 100644 --- a/src/lib/popupwindow/popuplocationbar.cpp +++ b/src/lib/popupwindow/popuplocationbar.cpp @@ -1,6 +1,6 @@ /* ============================================================ * Falkon - Qt web browser -* Copyright (C) 2010-2016 David Rosca +* Copyright (C) 2010-2018 David Rosca * * 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 @@ -90,8 +90,8 @@ void PopupLocationBar::stopLoading() WebPage* page = qobject_cast(m_view->page()); - if (page && page->hasMultipleUsernames()) { - m_autofillIcon->setFormData(page->autoFillData()); + if (page && !page->autoFillUsernames().isEmpty()) { + m_autofillIcon->setUsernames(page->autoFillUsernames()); m_autofillIcon->show(); } diff --git a/src/lib/webengine/webpage.cpp b/src/lib/webengine/webpage.cpp index 069098bc1..567b32571 100644 --- a/src/lib/webengine/webpage.cpp +++ b/src/lib/webengine/webpage.cpp @@ -41,6 +41,7 @@ #include "ui_jsconfirm.h" #include "ui_jsalert.h" #include "ui_jsprompt.h" +#include "passwordmanager.h" #include @@ -240,7 +241,11 @@ void WebPage::finished() } // AutoFill - m_passwordEntries = mApp->autoFill()->completePage(this, url()); + m_autoFillUsernames.clear(); + const auto entries = mApp->autoFill()->completePage(this, url()); + for (const PasswordEntry &entry : entries) { + m_autoFillUsernames.append(entry.username); + } } void WebPage::watchedFileChanged(const QString &file) @@ -449,14 +454,9 @@ QStringList WebPage::chooseFiles(QWebEnginePage::FileSelectionMode mode, const Q return files; } -bool WebPage::hasMultipleUsernames() const +QStringList WebPage::autoFillUsernames() const { - return m_passwordEntries.count() > 1; -} - -QVector WebPage::autoFillData() const -{ - return m_passwordEntries; + return m_autoFillUsernames; } bool WebPage::javaScriptPrompt(const QUrl &securityOrigin, const QString &msg, const QString &defaultValue, QString* result) diff --git a/src/lib/webengine/webpage.h b/src/lib/webengine/webpage.h index 029a5bd68..54d699197 100644 --- a/src/lib/webengine/webpage.h +++ b/src/lib/webengine/webpage.h @@ -24,7 +24,6 @@ #include #include "qzcommon.h" -#include "passwordmanager.h" class QEventLoop; class QWebEngineDownloadItem; @@ -62,8 +61,7 @@ public: void javaScriptAlert(const QUrl &securityOrigin, const QString &msg) Q_DECL_OVERRIDE; void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString &message, int lineNumber, const QString &sourceID) override; - bool hasMultipleUsernames() const; - QVector autoFillData() const; + QStringList autoFillUsernames() const; bool isRunningLoop(); @@ -103,7 +101,7 @@ private: DelayedFileWatcher* m_fileWatcher; QEventLoop* m_runningLoop; - QVector m_passwordEntries; + QStringList m_autoFillUsernames; int m_loadProgress; bool m_blockAlerts;