mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +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);
|
list = getFormData(frameUrl);
|
||||||
|
|
||||||
if (!list.isEmpty()) {
|
if (!list.isEmpty()) {
|
||||||
const PasswordEntry entry = list.at(0);
|
PasswordEntry entry = list.at(0);
|
||||||
|
updateLastUsed(entry);
|
||||||
page->runJavaScript(Scripts::completeFormData(entry.data), WebPage::SafeJsWorld);
|
page->runJavaScript(Scripts::completeFormData(entry.data), WebPage::SafeJsWorld);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* ============================================================
|
/* ============================================================
|
||||||
* Falkon - Qt web browser
|
* 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
|
* 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
|
* 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;
|
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()
|
void AutoFillIcon::iconClicked()
|
||||||
@ -49,7 +49,7 @@ void AutoFillIcon::iconClicked()
|
|||||||
}
|
}
|
||||||
|
|
||||||
AutoFillWidget* widget = new AutoFillWidget(m_view, this);
|
AutoFillWidget* widget = new AutoFillWidget(m_view, this);
|
||||||
widget->setFormData(m_data);
|
widget->setUsernames(m_usernames);
|
||||||
widget->showAt(parentWidget());
|
widget->showAt(parentWidget());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* ============================================================
|
/* ============================================================
|
||||||
* Falkon - Qt web browser
|
* 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
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
#include "qzcommon.h"
|
#include "qzcommon.h"
|
||||||
#include "clickablelabel.h"
|
#include "clickablelabel.h"
|
||||||
#include "passwordmanager.h"
|
|
||||||
|
|
||||||
class WebView;
|
class WebView;
|
||||||
|
|
||||||
@ -32,7 +31,7 @@ public:
|
|||||||
explicit AutoFillIcon(QWidget* parent = 0);
|
explicit AutoFillIcon(QWidget* parent = 0);
|
||||||
|
|
||||||
void setWebView(WebView* view);
|
void setWebView(WebView* view);
|
||||||
void setFormData(const QVector<PasswordEntry> &data);
|
void setUsernames(const QStringList &usernames);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void iconClicked();
|
void iconClicked();
|
||||||
@ -43,7 +42,7 @@ private:
|
|||||||
|
|
||||||
WebView* m_view;
|
WebView* m_view;
|
||||||
|
|
||||||
QVector<PasswordEntry> m_data;
|
QStringList m_usernames;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* ============================================================
|
/* ============================================================
|
||||||
* Falkon - Qt web browser
|
* 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
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -22,6 +22,8 @@
|
|||||||
#include "webview.h"
|
#include "webview.h"
|
||||||
#include "webpage.h"
|
#include "webpage.h"
|
||||||
#include "scripts.h"
|
#include "scripts.h"
|
||||||
|
#include "mainapplication.h"
|
||||||
|
#include "passwordmanager.h"
|
||||||
|
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
|
||||||
@ -33,44 +35,34 @@ AutoFillWidget::AutoFillWidget(WebView* view, QWidget* parent)
|
|||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoFillWidget::setFormData(const QVector<PasswordEntry> &data)
|
void AutoFillWidget::setUsernames(const QStringList &usernames)
|
||||||
{
|
{
|
||||||
m_data = data;
|
int i = 0;
|
||||||
|
for (const QString &username : usernames) {
|
||||||
for (int i = 0; i < data.count(); ++i) {
|
if (username.isEmpty()) {
|
||||||
const PasswordEntry d = data.at(i);
|
|
||||||
if (d.username.isEmpty()) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPushButton* button = new QPushButton(this);
|
QPushButton* button = new QPushButton(this);
|
||||||
button->setIcon(QIcon(":icons/other/login.png"));
|
button->setIcon(QIcon(":icons/other/login.png"));
|
||||||
button->setStyleSheet("text-align:left;font-weight:bold;");
|
button->setStyleSheet("text-align:left;font-weight:bold;");
|
||||||
button->setText(d.username);
|
button->setText(username);
|
||||||
button->setProperty("data-index", i);
|
|
||||||
button->setFlat(true);
|
button->setFlat(true);
|
||||||
|
|
||||||
ui->gridLayout->addWidget(button, i, 0);
|
ui->gridLayout->addWidget(button, i++, 0);
|
||||||
connect(button, SIGNAL(clicked()), this, SLOT(loginToPage()));
|
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);
|
||||||
|
|
||||||
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);
|
m_view->page()->runJavaScript(Scripts::completeFormData(entry.data), WebPage::SafeJsWorld);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
close();
|
close();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoFillWidget::~AutoFillWidget()
|
AutoFillWidget::~AutoFillWidget()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* ============================================================
|
/* ============================================================
|
||||||
* Falkon - Qt web browser
|
* 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
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -30,7 +30,6 @@ class AutoFillWidget;
|
|||||||
}
|
}
|
||||||
|
|
||||||
class WebView;
|
class WebView;
|
||||||
struct PasswordEntry;
|
|
||||||
|
|
||||||
class FALKON_EXPORT AutoFillWidget : public LocationBarPopup
|
class FALKON_EXPORT AutoFillWidget : public LocationBarPopup
|
||||||
{
|
{
|
||||||
@ -40,16 +39,12 @@ public:
|
|||||||
explicit AutoFillWidget(WebView* view, QWidget* parent = 0);
|
explicit AutoFillWidget(WebView* view, QWidget* parent = 0);
|
||||||
~AutoFillWidget();
|
~AutoFillWidget();
|
||||||
|
|
||||||
void setFormData(const QVector<PasswordEntry> &data);
|
void setUsernames(const QStringList &usernames);
|
||||||
|
|
||||||
private slots:
|
|
||||||
void loginToPage();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::AutoFillWidget* ui;
|
Ui::AutoFillWidget* ui;
|
||||||
|
|
||||||
WebView* m_view;
|
WebView* m_view;
|
||||||
QVector<PasswordEntry> m_data;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // AUTOFILLWIDGET_H
|
#endif // AUTOFILLWIDGET_H
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* ============================================================
|
/* ============================================================
|
||||||
* Falkon - Qt web browser
|
* 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
|
* 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
|
* 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)
|
void PasswordBackend::setActive(bool active)
|
||||||
{
|
{
|
||||||
m_active = active;
|
m_active = active;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* ============================================================
|
/* ============================================================
|
||||||
* Falkon - Qt web browser
|
* 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
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -31,6 +31,7 @@ public:
|
|||||||
|
|
||||||
virtual QString name() const = 0;
|
virtual QString name() const = 0;
|
||||||
|
|
||||||
|
virtual QStringList getUsernames(const QUrl &url);
|
||||||
virtual QVector<PasswordEntry> getEntries(const QUrl &url) = 0;
|
virtual QVector<PasswordEntry> getEntries(const QUrl &url) = 0;
|
||||||
virtual QVector<PasswordEntry> getAllEntries() = 0;
|
virtual QVector<PasswordEntry> getAllEntries() = 0;
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* ============================================================
|
/* ============================================================
|
||||||
* Falkon - Qt web browser
|
* 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
|
* 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
|
* 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();
|
QString backendId = settings.value("Backend", "database").toString();
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
|
if (m_backend) {
|
||||||
|
m_backend->setActive(false);
|
||||||
|
}
|
||||||
m_backend = m_backends[m_backends.contains(backendId) ? backendId : "database"];
|
m_backend = m_backends[m_backends.contains(backendId) ? backendId : "database"];
|
||||||
m_backend->setActive(true);
|
m_backend->setActive(true);
|
||||||
}
|
}
|
||||||
|
@ -630,8 +630,8 @@ void LocationBar::loadFinished()
|
|||||||
|
|
||||||
WebPage* page = qobject_cast<WebPage*>(m_webView->page());
|
WebPage* page = qobject_cast<WebPage*>(m_webView->page());
|
||||||
|
|
||||||
if (page && page->hasMultipleUsernames()) {
|
if (page && !page->autoFillUsernames().isEmpty()) {
|
||||||
m_autofillIcon->setFormData(page->autoFillData());
|
m_autofillIcon->setUsernames(page->autoFillUsernames());
|
||||||
m_autofillIcon->show();
|
m_autofillIcon->show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* ============================================================
|
/* ============================================================
|
||||||
* Falkon - Qt web browser
|
* 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
|
* 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
|
* 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());
|
WebPage* page = qobject_cast<WebPage*>(m_view->page());
|
||||||
|
|
||||||
if (page && page->hasMultipleUsernames()) {
|
if (page && !page->autoFillUsernames().isEmpty()) {
|
||||||
m_autofillIcon->setFormData(page->autoFillData());
|
m_autofillIcon->setUsernames(page->autoFillUsernames());
|
||||||
m_autofillIcon->show();
|
m_autofillIcon->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
#include "ui_jsconfirm.h"
|
#include "ui_jsconfirm.h"
|
||||||
#include "ui_jsalert.h"
|
#include "ui_jsalert.h"
|
||||||
#include "ui_jsprompt.h"
|
#include "ui_jsprompt.h"
|
||||||
|
#include "passwordmanager.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@ -240,7 +241,11 @@ void WebPage::finished()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AutoFill
|
// 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)
|
void WebPage::watchedFileChanged(const QString &file)
|
||||||
@ -449,14 +454,9 @@ QStringList WebPage::chooseFiles(QWebEnginePage::FileSelectionMode mode, const Q
|
|||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebPage::hasMultipleUsernames() const
|
QStringList WebPage::autoFillUsernames() const
|
||||||
{
|
{
|
||||||
return m_passwordEntries.count() > 1;
|
return m_autoFillUsernames;
|
||||||
}
|
|
||||||
|
|
||||||
QVector<PasswordEntry> WebPage::autoFillData() const
|
|
||||||
{
|
|
||||||
return m_passwordEntries;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebPage::javaScriptPrompt(const QUrl &securityOrigin, const QString &msg, const QString &defaultValue, QString* result)
|
bool WebPage::javaScriptPrompt(const QUrl &securityOrigin, const QString &msg, const QString &defaultValue, QString* result)
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
#include "qzcommon.h"
|
#include "qzcommon.h"
|
||||||
#include "passwordmanager.h"
|
|
||||||
|
|
||||||
class QEventLoop;
|
class QEventLoop;
|
||||||
class QWebEngineDownloadItem;
|
class QWebEngineDownloadItem;
|
||||||
@ -62,8 +61,7 @@ public:
|
|||||||
void javaScriptAlert(const QUrl &securityOrigin, const QString &msg) Q_DECL_OVERRIDE;
|
void javaScriptAlert(const QUrl &securityOrigin, const QString &msg) Q_DECL_OVERRIDE;
|
||||||
void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString &message, int lineNumber, const QString &sourceID) override;
|
void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString &message, int lineNumber, const QString &sourceID) override;
|
||||||
|
|
||||||
bool hasMultipleUsernames() const;
|
QStringList autoFillUsernames() const;
|
||||||
QVector<PasswordEntry> autoFillData() const;
|
|
||||||
|
|
||||||
bool isRunningLoop();
|
bool isRunningLoop();
|
||||||
|
|
||||||
@ -103,7 +101,7 @@ private:
|
|||||||
DelayedFileWatcher* m_fileWatcher;
|
DelayedFileWatcher* m_fileWatcher;
|
||||||
QEventLoop* m_runningLoop;
|
QEventLoop* m_runningLoop;
|
||||||
|
|
||||||
QVector<PasswordEntry> m_passwordEntries;
|
QStringList m_autoFillUsernames;
|
||||||
|
|
||||||
int m_loadProgress;
|
int m_loadProgress;
|
||||||
bool m_blockAlerts;
|
bool m_blockAlerts;
|
||||||
|
Loading…
Reference in New Issue
Block a user