1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

Fixed saving passwords on some sites.

- WebKit sometimes sends data in its own format so it is
  neccessary to convert it to url query items

closes #301
This commit is contained in:
nowrep 2012-04-17 17:54:51 +02:00
parent 2c4b6e3d42
commit d02318382a
3 changed files with 53 additions and 8 deletions

View File

@ -238,7 +238,7 @@ void AutoFillModel::post(const QNetworkRequest &request, const QByteArray &outgo
return; return;
} }
m_lastOutgoingData = outgoingData; const QByteArray &data = convertWebKitFormBoundaryIfNeccessary(outgoingData);
QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100)); QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100));
WebPage* webPage = static_cast<WebPage*>(v.value<void*>()); WebPage* webPage = static_cast<WebPage*>(v.value<void*>());
@ -281,9 +281,9 @@ void AutoFillModel::post(const QNetworkRequest &request, const QByteArray &outgo
foreach(const QWebElement & formElement, allForms) { foreach(const QWebElement & formElement, allForms) {
foreach(const QWebElement &inputElement, formElement.findAll("input[type=\"password\"]")) { foreach(const QWebElement &inputElement, formElement.findAll("input[type=\"password\"]")) {
passwordName = inputElement.attribute("name"); passwordName = inputElement.attribute("name");
passwordValue = getValueFromData(outgoingData, inputElement); passwordValue = getValueFromData(data, inputElement);
if (!passwordValue.isEmpty() && dataContains(outgoingData, passwordName)) { if (!passwordValue.isEmpty() && dataContains(data, passwordName)) {
foundForm = formElement; foundForm = formElement;
break; break;
} }
@ -304,13 +304,13 @@ void AutoFillModel::post(const QNetworkRequest &request, const QByteArray &outgo
foreach(const QWebElement &element, foundForm.findAll("input[type=\"text\"]")) { foreach(const QWebElement &element, foundForm.findAll("input[type=\"text\"]")) {
usernameName = element.attribute("name"); usernameName = element.attribute("name");
usernameValue = getValueFromData(outgoingData, element); usernameValue = getValueFromData(data, element);
if (!usernameName.isEmpty() && !usernameValue.isEmpty()) { if (!usernameName.isEmpty() && !usernameValue.isEmpty()) {
break; break;
} }
} }
AutoFillNotification* aWidget = new AutoFillNotification(siteUrl, outgoingData, usernameValue, passwordValue); AutoFillNotification* aWidget = new AutoFillNotification(siteUrl, data, usernameValue, passwordValue);
webView->addNotification(aWidget); webView->addNotification(aWidget);
} }
@ -318,7 +318,7 @@ QString AutoFillModel::getValueFromData(const QByteArray &data, QWebElement elem
{ {
QString name = element.attribute("name"); QString name = element.attribute("name");
if (name.isEmpty()) { if (name.isEmpty()) {
return ""; return QString();
} }
QString value = element.evaluateJavaScript("this.value").toString(); QString value = element.evaluateJavaScript("this.value").toString();
@ -336,9 +336,54 @@ QString AutoFillModel::getValueFromData(const QByteArray &data, QWebElement elem
return value; return value;
} }
QByteArray AutoFillModel::convertWebKitFormBoundaryIfNeccessary(const QByteArray &data)
{
/* Sometimes, data are passed in this format:
------WebKitFormBoundary0bBp3bFMdGwqanMp
Content-Disposition: form-data; name="name-of-attribute"
value-of-attribute
------WebKitFormBoundary0bBp3bFMdGwqanMp--
So this function converts this format into url
*/
if (!data.contains(QByteArray("------WebKitFormBoundary"))) {
return data;
}
QByteArray formatedData;
QRegExp rx("name=\"(.*)------WebKitFormBoundary");
rx.setMinimal(true);
int pos = 0;
while ((pos = rx.indexIn(data, pos)) != -1) {
QString string = rx.cap(1);
pos += rx.matchedLength();
int endOfAttributeName = string.indexOf("\"");
if (endOfAttributeName == -1) {
continue;
}
QString attrName = string.left(endOfAttributeName);
QString attrValue = string.mid(endOfAttributeName + 1).trimmed().remove("\n");
if (attrName.isEmpty() || attrValue.isEmpty()) {
continue;
}
formatedData.append(attrName + "=" + attrValue + "&");
}
return formatedData;
}
bool AutoFillModel::dataContains(const QByteArray &data, const QString &attributeName) bool AutoFillModel::dataContains(const QByteArray &data, const QString &attributeName)
{ {
QueryItems queryItems = QUrl::fromEncoded("http://a.b/?" + data).queryItems(); QueryItems queryItems = QUrl::fromEncoded("http://a.b/?" + data).queryItems();
for (int i = 0; i < queryItems.count(); i++) { for (int i = 0; i < queryItems.count(); i++) {
QueryItem item = queryItems.at(i); QueryItem item = queryItems.at(i);

View File

@ -57,9 +57,9 @@ public:
private: private:
bool dataContains(const QByteArray &data, const QString &attributeName); bool dataContains(const QByteArray &data, const QString &attributeName);
QString getValueFromData(const QByteArray &data, QWebElement element); QString getValueFromData(const QByteArray &data, QWebElement element);
QByteArray convertWebKitFormBoundaryIfNeccessary(const QByteArray &data);
QupZilla* p_QupZilla; QupZilla* p_QupZilla;
QByteArray m_lastOutgoingData;
bool m_isStoring; bool m_isStoring;
}; };

View File

@ -32,7 +32,7 @@ WebPluginFactory::WebPluginFactory(WebPage* page)
QObject* WebPluginFactory::create(const QString &mimeType, const QUrl &url, const QStringList &argumentNames, const QStringList &argumentValues) const QObject* WebPluginFactory::create(const QString &mimeType, const QUrl &url, const QStringList &argumentNames, const QStringList &argumentValues) const
{ {
if (url.isEmpty()) { if (url.isEmpty()) {
return 0; return new QObject();
} }
QString mime = mimeType.trimmed(); //Fixing bad behaviour when mimeType contains spaces QString mime = mimeType.trimmed(); //Fixing bad behaviour when mimeType contains spaces