1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-19 10:16:34 +01:00

Using clever approach to find username inputs in form.

Saving passwords and usernames should now work for much
more sites.
It now looks for input[type="email"] and inputs without
type attribute too.

Closes #674
This commit is contained in:
nowrep 2013-01-23 23:23:48 +01:00
parent 30719365ac
commit 1fef4efec7
3 changed files with 39 additions and 11 deletions

View File

@ -12,6 +12,7 @@ Version 1.4.0
* option to disable alt/ctrl + numbers shortcuts
* option to switch to tab from locationbar popup completer
* use .qupzilla/tmp instead of /tmp for temporary data
* saving passwords should now work for much more sites
* fixed loading NYTimes skimmer page
* fixed cookie domain handling according to RFC 6265
* fixed qvalue format in Accept-Language HTTP header

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
* Copyright (C) 2010-2013 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
@ -248,10 +248,10 @@ void AutoFillModel::completePage(WebPage* page)
for (int i = 0; i < inputs.count(); i++) {
QWebElement element = inputs.at(i);
const QString &typeAttr = element.attribute("type");
if (element.attribute("type") != QLatin1String("text")
&& element.attribute("type") != QLatin1String("password")
&& !element.attribute("type").isEmpty()) {
if (typeAttr != QLatin1String("text") && typeAttr != QLatin1String("password")
&& typeAttr != QLatin1String("email") && !typeAttr.isEmpty()) {
continue;
}
@ -261,7 +261,7 @@ void AutoFillModel::completePage(WebPage* page)
}
}
}
#include <QDebug>
void AutoFillModel::post(const QNetworkRequest &request, const QByteArray &outgoingData)
{
// Don't save in private browsing
@ -334,11 +334,26 @@ void AutoFillModel::post(const QNetworkRequest &request, const QByteArray &outgo
// We need to find username, we suppose that username is first not empty input[type=text] in form
// Tell me better solution. Maybe first try to find name="user", name="username" ?
foreach(const QWebElement & element, foundForm.findAll("input[type=\"text\"]")) {
usernameName = element.attribute("name");
usernameValue = getValueFromData(data, element);
bool found = false;
QStringList selectors;
selectors << "input[type=\"text\"][name*=\"user\"]"
<< "input[type=\"text\"][name*=\"name\"]"
<< "input[type=\"text\"]"
<< "input[type=\"email\"]"
<< "input:not([type=\"hidden\"])";
if (!usernameName.isEmpty() && !usernameValue.isEmpty()) {
foreach(const QString & selector, selectors) {
foreach(const QWebElement & element, foundForm.findAll(selector)) {
usernameName = element.attribute("name");
usernameValue = getValueFromData(data, element);
if (!usernameName.isEmpty() && !usernameValue.isEmpty()) {
found = true;
break;
}
}
if (found) {
break;
}
}

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
* Copyright (C) 2010-2013 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
@ -32,9 +32,21 @@ AutoFillNotification::AutoFillNotification(const QUrl &url, const QByteArray &da
{
setAttribute(Qt::WA_DeleteOnClose);
ui->setupUi(widget());
ui->label->setText(tr("Do you want QupZilla to remember the password for <b>%1</b> on %2?").arg(user, url.host()));
ui->closeButton->setIcon(qIconProvider->standardIcon(QStyle::SP_DialogCloseButton));
QString hostPart;
QString userPart;
if (!url.host().isEmpty()) {
hostPart = tr("on %1").arg(url.host());
}
if (!user.isEmpty()) {
userPart = tr("for <b>%1</b>").arg(user);
}
ui->label->setText(tr("Do you want QupZilla to remember the password %1 %2?").arg(userPart, hostPart));
connect(ui->remember, SIGNAL(clicked()), this, SLOT(remember()));
connect(ui->never, SIGNAL(clicked()), this, SLOT(never()));
connect(ui->notnow, SIGNAL(clicked()), this, SLOT(hide()));