1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-21 17:52:10 +02:00

AutoFill: Add option to disable auto complete on sites

This is particularly useful with Encrypted backend as it will
only prompt for password when you actually want to fill passwords.
This commit is contained in:
David Rosca 2018-01-28 13:57:10 +01:00
parent e719a959d4
commit 89f3b18df3
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
9 changed files with 62 additions and 14 deletions

View File

@ -38,7 +38,6 @@
AutoFill::AutoFill(QObject* parent) AutoFill::AutoFill(QObject* parent)
: QObject(parent) : QObject(parent)
, m_manager(new PasswordManager(this)) , m_manager(new PasswordManager(this))
, m_isStoring(false)
{ {
loadSettings(); loadSettings();
@ -62,6 +61,7 @@ void AutoFill::loadSettings()
Settings settings; Settings settings;
settings.beginGroup("Web-Browser-Settings"); settings.beginGroup("Web-Browser-Settings");
m_isStoring = settings.value("SavePasswordsOnSites", true).toBool(); m_isStoring = settings.value("SavePasswordsOnSites", true).toBool();
m_isAutoComplete = settings.value("AutoCompletePasswords", true).toBool();
settings.endGroup(); settings.endGroup();
} }
@ -71,7 +71,7 @@ bool AutoFill::isStored(const QUrl &url)
return false; return false;
} }
return !m_manager->getEntries(url).isEmpty(); return !m_manager->getUsernames(url).isEmpty();
} }
bool AutoFill::isStoringEnabled(const QUrl &url) bool AutoFill::isStoringEnabled(const QUrl &url)
@ -226,6 +226,10 @@ QStringList AutoFill::completePage(WebPage *page, const QUrl &frameUrl)
if (!page || !isStored(frameUrl)) if (!page || !isStored(frameUrl))
return usernames; return usernames;
if (!m_isAutoComplete) {
return m_manager->getUsernames(frameUrl);
}
const auto entries = getFormData(frameUrl); const auto entries = getFormData(frameUrl);
if (!entries.isEmpty()) { if (!entries.isEmpty()) {

View File

@ -79,7 +79,8 @@ public:
private: private:
PasswordManager* m_manager; PasswordManager* m_manager;
bool m_isStoring; bool m_isStoring = false;
bool m_isAutoComplete = false;
QPointer<AutoFillNotification> m_lastNotification; QPointer<AutoFillNotification> m_lastNotification;
WebPage *m_lastNotificationPage = nullptr; WebPage *m_lastNotificationPage = nullptr;

View File

@ -18,7 +18,6 @@
#include "autofillwidget.h" #include "autofillwidget.h"
#include "ui_autofillwidget.h" #include "ui_autofillwidget.h"
#include "autofill.h" #include "autofill.h"
#include "qztools.h"
#include "webview.h" #include "webview.h"
#include "webpage.h" #include "webpage.h"
#include "scripts.h" #include "scripts.h"
@ -52,13 +51,22 @@ void AutoFillWidget::setUsernames(const QStringList &usernames)
ui->gridLayout->addWidget(button, i++, 0); ui->gridLayout->addWidget(button, i++, 0);
connect(button, &QPushButton::clicked, this, [=]() { connect(button, &QPushButton::clicked, this, [=]() {
const auto entries = mApp->autoFill()->getFormData(m_view->url()); const auto entries = mApp->autoFill()->getFormData(m_view->url());
for (PasswordEntry entry : entries) { PasswordEntry entry;
if (entry.username != username) { // Find exact username match
continue; for (const PasswordEntry &e : entries) {
if (e.username == username) {
entry = e;
break;
} }
}
// Find by index
// This is needed for DatabaseEncryptedPasswordBackend because it also encrypts usernames.
if (!entry.isValid()) {
entry = entries.value(i - 1);
}
if (entry.isValid()) {
mApp->autoFill()->updateLastUsed(entry); mApp->autoFill()->updateLastUsed(entry);
m_view->page()->runJavaScript(Scripts::completeFormData(entry.data), WebPage::SafeJsWorld); m_view->page()->runJavaScript(Scripts::completeFormData(entry.data), WebPage::SafeJsWorld);
break;
} }
close(); close();
}); });

View File

@ -1,7 +1,7 @@
/* ============================================================ /* ============================================================
* Falkon - Qt web browser * Falkon - Qt web browser
* Copyright (C) 2013-2014 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com> * Copyright (C) 2013-2014 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
* Copyright (C) 2013-2017 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
@ -47,6 +47,24 @@ DatabaseEncryptedPasswordBackend::~DatabaseEncryptedPasswordBackend()
{ {
} }
QStringList DatabaseEncryptedPasswordBackend::getUsernames(const QUrl &url)
{
if (!m_askMasterPassword) {
return PasswordBackend::getUsernames(url);
}
QSqlQuery query(SqlDatabase::instance()->database());
query.prepare("SELECT username_encrypted FROM autofill_encrypted WHERE server=? ORDER BY last_used DESC");
query.addBindValue(PasswordManager::createHost(url));
query.exec();
QStringList list;
while (query.next()) {
list.append(QSL("Encrypted %1").arg(list.size() + 1));
}
return list;
}
QVector<PasswordEntry> DatabaseEncryptedPasswordBackend::getEntries(const QUrl &url) QVector<PasswordEntry> DatabaseEncryptedPasswordBackend::getEntries(const QUrl &url)
{ {
QVector<PasswordEntry> list; QVector<PasswordEntry> list;

View File

@ -1,7 +1,7 @@
/* ============================================================ /* ============================================================
* Falkon - Qt web browser * Falkon - Qt web browser
* Copyright (C) 2013-2014 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com> * Copyright (C) 2013-2014 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
* 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
@ -40,6 +40,7 @@ public:
~DatabaseEncryptedPasswordBackend(); ~DatabaseEncryptedPasswordBackend();
QStringList getUsernames(const QUrl &url);
QVector<PasswordEntry> getEntries(const QUrl &url); QVector<PasswordEntry> getEntries(const QUrl &url);
QVector<PasswordEntry> getAllEntries(); QVector<PasswordEntry> getAllEntries();

View File

@ -83,6 +83,12 @@ void PasswordManager::loadSettings()
m_backend->setActive(true); m_backend->setActive(true);
} }
QStringList PasswordManager::getUsernames(const QUrl &url)
{
ensureLoaded();
return m_backend->getUsernames(url);
}
QVector<PasswordEntry> PasswordManager::getEntries(const QUrl &url) QVector<PasswordEntry> PasswordManager::getEntries(const QUrl &url)
{ {
ensureLoaded(); ensureLoaded();

View File

@ -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
@ -63,6 +63,7 @@ public:
void loadSettings(); void loadSettings();
QStringList getUsernames(const QUrl &url);
QVector<PasswordEntry> getEntries(const QUrl &url); QVector<PasswordEntry> getEntries(const QUrl &url);
QVector<PasswordEntry> getAllEntries(); QVector<PasswordEntry> getAllEntries();

View File

@ -294,6 +294,7 @@ Preferences::Preferences(BrowserWindow* window)
//PASSWORD MANAGER //PASSWORD MANAGER
ui->allowPassManager->setChecked(settings.value("SavePasswordsOnSites", true).toBool()); ui->allowPassManager->setChecked(settings.value("SavePasswordsOnSites", true).toBool());
ui->autoCompletePasswords->setChecked(settings.value("AutoCompletePasswords", true).toBool());
connect(ui->allowPassManager, SIGNAL(toggled(bool)), this, SLOT(showPassManager(bool))); connect(ui->allowPassManager, SIGNAL(toggled(bool)), this, SLOT(showPassManager(bool)));
showPassManager(ui->allowPassManager->isChecked()); showPassManager(ui->allowPassManager->isChecked());
@ -984,6 +985,7 @@ void Preferences::saveSettings()
//PASSWORD MANAGER //PASSWORD MANAGER
settings.setValue("SavePasswordsOnSites", ui->allowPassManager->isChecked()); settings.setValue("SavePasswordsOnSites", ui->allowPassManager->isChecked());
settings.setValue("AutoCompletePasswords", ui->autoCompletePasswords->isChecked());
//PRIVACY //PRIVACY
//Web storage //Web storage

View File

@ -1966,7 +1966,7 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="2" column="0" colspan="3"> <item row="3" column="0" colspan="3">
<widget class="QFrame" name="AutoFillFrame"> <widget class="QFrame" name="AutoFillFrame">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@ -1981,6 +1981,13 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="2" column="1">
<widget class="QCheckBox" name="autoCompletePasswords">
<property name="text">
<string>Automatically complete passwords on sites</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="privacyPage"> <widget class="QWidget" name="privacyPage">
@ -2412,8 +2419,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>96</width> <width>560</width>
<height>31</height> <height>80</height>
</rect> </rect>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_14"> <layout class="QHBoxLayout" name="horizontalLayout_14">