From dc29f6bde56e3f0cdf27813758764c5fb0fe7243 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Mon, 29 Sep 2014 16:03:22 +0200 Subject: [PATCH] QzTools: Add function to obtain url of QWebFrame QWebFrame::url() may be empty, and in that case QWebFrame::baseUrl() should be used The issue with empty frame url caused AutoFill to not complete such frames. Closes #1465 --- CHANGELOG | 5 +++++ src/lib/app/browserwindow.cpp | 2 +- src/lib/autofill/autofill.cpp | 18 +++++++++--------- src/lib/other/sourceviewer.cpp | 4 ++-- src/lib/plugins/speeddial.cpp | 2 +- src/lib/tools/qztools.cpp | 6 ++++++ src/lib/tools/qztools.h | 2 ++ src/plugins/GreaseMonkey/gm_manager.cpp | 2 +- 8 files changed, 27 insertions(+), 14 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index a3a321881..aab440f24 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ +Version 1.8.1 + * not yet released + * fixed: autofill not working for some frames + * fixed: building on Mac + Version 1.8.0 * released 25 September 2014 * added support for window.beforeunload event diff --git a/src/lib/app/browserwindow.cpp b/src/lib/app/browserwindow.cpp index d24eb6501..99a62b710 100644 --- a/src/lib/app/browserwindow.cpp +++ b/src/lib/app/browserwindow.cpp @@ -1187,7 +1187,7 @@ void BrowserWindow::printPage(QWebFrame* frame) connect(dialog, SIGNAL(paintRequested(QPrinter*)), weView(), SLOT(print(QPrinter*))); } else { - dialog->printer()->setDocName(QzTools::getFileNameFromUrl(frame->url())); + dialog->printer()->setDocName(QzTools::getFileNameFromUrl(QzTools::frameUrl(frame))); connect(dialog, SIGNAL(paintRequested(QPrinter*)), frame, SLOT(print(QPrinter*))); } diff --git a/src/lib/autofill/autofill.cpp b/src/lib/autofill/autofill.cpp index 7c05f39a6..d064e8e7e 100644 --- a/src/lib/autofill/autofill.cpp +++ b/src/lib/autofill/autofill.cpp @@ -26,6 +26,7 @@ #include "pageformcompleter.h" #include "settings.h" #include "passwordmanager.h" +#include "qztools.h" #include #include @@ -178,12 +179,12 @@ QVector AutoFill::completeFrame(QWebFrame* frame) return list; } - QUrl pageUrl = frame->url(); - if (!isStored(pageUrl)) { + const QUrl frameUrl = QzTools::frameUrl(frame); + if (!isStored(frameUrl)) { return list; } - list = getFormData(pageUrl); + list = getFormData(frameUrl); if (!list.isEmpty()) { const PasswordEntry entry = list.first(); @@ -221,9 +222,8 @@ void AutoFill::post(const QNetworkRequest &request, const QByteArray &outgoingDa return; } - const QUrl siteUrl = webPage->url(); - - if (!isStoringEnabled(siteUrl)) { + const QUrl frameUrl = QzTools::frameUrl(frame); + if (!isStoringEnabled(frameUrl)) { return; } @@ -236,8 +236,8 @@ void AutoFill::post(const QNetworkRequest &request, const QByteArray &outgoingDa PasswordEntry updateData; - if (isStored(siteUrl)) { - const QVector &list = getFormData(siteUrl); + if (isStored(frameUrl)) { + const QVector &list = getFormData(frameUrl); foreach (const PasswordEntry &data, list) { if (data.username == formData.username) { @@ -257,7 +257,7 @@ void AutoFill::post(const QNetworkRequest &request, const QByteArray &outgoingDa } } - AutoFillNotification* aWidget = new AutoFillNotification(siteUrl, formData, updateData); + AutoFillNotification* aWidget = new AutoFillNotification(frameUrl, formData, updateData); webView->addNotification(aWidget); } diff --git a/src/lib/other/sourceviewer.cpp b/src/lib/other/sourceviewer.cpp index 5c13186a4..2a305267a 100644 --- a/src/lib/other/sourceviewer.cpp +++ b/src/lib/other/sourceviewer.cpp @@ -38,7 +38,7 @@ SourceViewer::SourceViewer(QWebFrame* frame, const QString &selectedHtml) , m_selectedHtml(selectedHtml) { setAttribute(Qt::WA_DeleteOnClose); - setWindowTitle(tr("Source of ") + frame->url().toString()); + setWindowTitle(tr("Source of ") + QzTools::frameUrl(frame).toString()); m_layout = new QBoxLayout(QBoxLayout::TopToBottom, this); m_sourceEdit = new PlainEditWithLines(this); m_sourceEdit->setObjectName("sourceviewer-textedit"); @@ -46,7 +46,7 @@ SourceViewer::SourceViewer(QWebFrame* frame, const QString &selectedHtml) m_sourceEdit->setUndoRedoEnabled(false); m_statusBar = new QStatusBar(this); - m_statusBar->showMessage(frame->url().toString()); + m_statusBar->showMessage(QzTools::frameUrl(frame).toString()); QMenuBar* menuBar = new QMenuBar(this); m_layout->addWidget(m_sourceEdit); diff --git a/src/lib/plugins/speeddial.cpp b/src/lib/plugins/speeddial.cpp index 753cf66af..38373155b 100644 --- a/src/lib/plugins/speeddial.cpp +++ b/src/lib/plugins/speeddial.cpp @@ -382,7 +382,7 @@ QList SpeedDial::cleanFrames() for (int i = 0; i < m_webFrames.count(); i++) { QWebFrame* frame = m_webFrames.at(i).data(); - if (!frame || frame->url().toString() != QLatin1String("qupzilla:speeddial")) { + if (!frame || QzTools::frameUrl(frame).toString() != QLatin1String("qupzilla:speeddial")) { m_webFrames.removeAt(i); i--; continue; diff --git a/src/lib/tools/qztools.cpp b/src/lib/tools/qztools.cpp index 518d2eeb3..88842f6d5 100644 --- a/src/lib/tools/qztools.cpp +++ b/src/lib/tools/qztools.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #if QT_VERSION >= 0x050000 #include @@ -215,6 +216,11 @@ QString QzTools::escapeSqlString(QString urlString) return urlString; } +QUrl QzTools::frameUrl(QWebFrame* frame) +{ + return frame->url().isEmpty() ? frame->baseUrl() : frame->url(); +} + QString QzTools::ensureUniqueFilename(const QString &name, const QString &appendFormat) { if (!QFile::exists(name)) { diff --git a/src/lib/tools/qztools.h b/src/lib/tools/qztools.h index 4f359d37f..1d4bd282f 100644 --- a/src/lib/tools/qztools.h +++ b/src/lib/tools/qztools.h @@ -24,6 +24,7 @@ class QSslCertificate; class QFontMetrics; +class QWebFrame; class QPixmap; class QIcon; class QWidget; @@ -48,6 +49,7 @@ public: static QString urlEncodeQueryString(const QUrl &url); static QString fromPunycode(const QString &str); static QString escapeSqlString(QString urlString); + static QUrl frameUrl(QWebFrame* frame); static QString ensureUniqueFilename(const QString &name, const QString &appendFormat = QString("(%1)")); static QString getFileNameFromUrl(const QUrl &url); diff --git a/src/plugins/GreaseMonkey/gm_manager.cpp b/src/plugins/GreaseMonkey/gm_manager.cpp index 27e69d2ad..b23590744 100644 --- a/src/plugins/GreaseMonkey/gm_manager.cpp +++ b/src/plugins/GreaseMonkey/gm_manager.cpp @@ -201,7 +201,7 @@ void GM_Manager::frameLoadStart() return; } - const QUrl url = frame->url().isEmpty() ? frame->baseUrl() : frame->url(); + const QUrl url = QzTools::frameUrl(frame); const QString urlScheme = url.scheme(); const QString urlString = url.toEncoded();