mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
AutoFill: Make it possible to request only usernames from backend
This commit is contained in:
parent
c2d7e1eb48
commit
2a22f61dec
@ -229,7 +229,8 @@ QVector<PasswordEntry> 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);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* ============================================================
|
||||
* Falkon - Qt web browser
|
||||
* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2013-2018 David Rosca <nowrep@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
|
||||
@ -37,9 +37,9 @@ void AutoFillIcon::setWebView(WebView* view)
|
||||
m_view = view;
|
||||
}
|
||||
|
||||
void AutoFillIcon::setFormData(const QVector<PasswordEntry> &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());
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* ============================================================
|
||||
* Falkon - Qt web browser
|
||||
* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2013-2018 David Rosca <nowrep@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
|
||||
@ -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<PasswordEntry> &data);
|
||||
void setUsernames(const QStringList &usernames);
|
||||
|
||||
private slots:
|
||||
void iconClicked();
|
||||
@ -43,7 +42,7 @@ private:
|
||||
|
||||
WebView* m_view;
|
||||
|
||||
QVector<PasswordEntry> m_data;
|
||||
QStringList m_usernames;
|
||||
|
||||
};
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* ============================================================
|
||||
* Falkon - Qt web browser
|
||||
* Copyright (C) 2013-2016 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2013-2018 David Rosca <nowrep@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
|
||||
@ -22,6 +22,8 @@
|
||||
#include "webview.h"
|
||||
#include "webpage.h"
|
||||
#include "scripts.h"
|
||||
#include "mainapplication.h"
|
||||
#include "passwordmanager.h"
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
@ -33,46 +35,36 @@ AutoFillWidget::AutoFillWidget(WebView* view, QWidget* parent)
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
void AutoFillWidget::setFormData(const QVector<PasswordEntry> &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<QPushButton*>(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;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* ============================================================
|
||||
* Falkon - Qt web browser
|
||||
* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2013-2018 David Rosca <nowrep@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
|
||||
@ -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<PasswordEntry> &data);
|
||||
|
||||
private slots:
|
||||
void loginToPage();
|
||||
void setUsernames(const QStringList &usernames);
|
||||
|
||||
private:
|
||||
Ui::AutoFillWidget* ui;
|
||||
|
||||
WebView* m_view;
|
||||
QVector<PasswordEntry> m_data;
|
||||
};
|
||||
|
||||
#endif // AUTOFILLWIDGET_H
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* ============================================================
|
||||
* Falkon - Qt web browser
|
||||
* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2013-2018 David Rosca <nowrep@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
|
||||
@ -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;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* ============================================================
|
||||
* Falkon - Qt web browser
|
||||
* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2013-2018 David Rosca <nowrep@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
|
||||
@ -31,6 +31,7 @@ public:
|
||||
|
||||
virtual QString name() const = 0;
|
||||
|
||||
virtual QStringList getUsernames(const QUrl &url);
|
||||
virtual QVector<PasswordEntry> getEntries(const QUrl &url) = 0;
|
||||
virtual QVector<PasswordEntry> getAllEntries() = 0;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* ============================================================
|
||||
* Falkon - Qt web browser
|
||||
* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2013-2018 David Rosca <nowrep@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
|
||||
@ -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);
|
||||
}
|
||||
|
@ -630,8 +630,8 @@ void LocationBar::loadFinished()
|
||||
|
||||
WebPage* page = qobject_cast<WebPage*>(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();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* ============================================================
|
||||
* Falkon - Qt web browser
|
||||
* Copyright (C) 2010-2016 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2010-2018 David Rosca <nowrep@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
|
||||
@ -90,8 +90,8 @@ void PopupLocationBar::stopLoading()
|
||||
|
||||
WebPage* page = qobject_cast<WebPage*>(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();
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include "ui_jsconfirm.h"
|
||||
#include "ui_jsalert.h"
|
||||
#include "ui_jsprompt.h"
|
||||
#include "passwordmanager.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@ -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<PasswordEntry> WebPage::autoFillData() const
|
||||
{
|
||||
return m_passwordEntries;
|
||||
return m_autoFillUsernames;
|
||||
}
|
||||
|
||||
bool WebPage::javaScriptPrompt(const QUrl &securityOrigin, const QString &msg, const QString &defaultValue, QString* result)
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include <QVector>
|
||||
|
||||
#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<PasswordEntry> autoFillData() const;
|
||||
QStringList autoFillUsernames() const;
|
||||
|
||||
bool isRunningLoop();
|
||||
|
||||
@ -103,7 +101,7 @@ private:
|
||||
DelayedFileWatcher* m_fileWatcher;
|
||||
QEventLoop* m_runningLoop;
|
||||
|
||||
QVector<PasswordEntry> m_passwordEntries;
|
||||
QStringList m_autoFillUsernames;
|
||||
|
||||
int m_loadProgress;
|
||||
bool m_blockAlerts;
|
||||
|
Loading…
Reference in New Issue
Block a user