Commit 56ea2a32 authored by Stefano Crocco's avatar Stefano Crocco

Add back KWallet support to Konqueror

Summary:
Added back the ability to store user names and passwords to KWallet and automatically fill them when loading a page.

I copied the files `kwebwallet.cpp` and `kwebwallet.h` from the `KDEWebKit` framework and modified it to adapt to `QWebEngine`. In particular, I needed to modify the way form data is passed from javascript to C++ serializing it using JSON and read it back using `QJsonDocument`. Also, since `QWebEnginePage` doesn't allow to access frames from the C++ side, I needed to remove all the code dealing with recurisve searches and implement it in javascript.

As the old code, this intentionally doesn't work with input elements with the `autocomplete` attribute set to `false`.

I've not modified the copyright information in the files I copied from `KDEWebKit` as I don't know which is the correct way to do so: I must make clear my files are based on the work on other people but at the same time that I've changed them: how do I do this?

Test Plan: I tried to access several sites requiring a login in, asking Konqueror to save the password, then logging out and visiting the page again. Except when the `autocomplete` attribute was `false` (checked by looking at the html code), Konqueror always saved and restored login information correctly.

Reviewers: dfaure

Reviewed By: dfaure

Differential Revision: https://phabricator.kde.org/D10178
parent 80024d0f
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Wallet)
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_BINARY_DIR})
set(kwebenginepartlib_LIB_SRCS
......@@ -8,6 +10,7 @@ set(kwebenginepartlib_LIB_SRCS
websslinfo.cpp
webhistoryinterface.cpp
webenginepartdownloadmanager.cpp
webenginewallet.cpp
settings/webenginesettings.cpp
settings/webengine_filter.cpp
ui/searchbar.cpp
......@@ -27,6 +30,7 @@ target_link_libraries(kwebenginepartlib Qt5::Core Qt5::DBus Qt5::Gui Qt5::Widget
KF5::Parts
KF5::SonnetCore
KF5::WindowSystem # for KUserTimestamp
KF5::Wallet
)
target_include_directories(kwebenginepartlib PUBLIC
......
......@@ -27,6 +27,7 @@
#include "webengineview.h"
#include "settings/webenginesettings.h"
#include "webenginepartdownloadmanager.h"
#include "webenginewallet.h"
#include <QWebEngineSettings>
#include <QWebEngineProfile>
......@@ -72,7 +73,8 @@ WebEnginePage::WebEnginePage(WebEnginePart *part, QWidget *parent)
m_kioErrorCode(0),
m_ignoreError(false),
m_part(part),
m_passwdServerClient(new KPasswdServerClient)
m_passwdServerClient(new KPasswdServerClient),
m_wallet(Q_NULLPTR)
{
if (view())
WebEngineSettings::self()->computeFontSizes(view()->logicalDpiY());
......@@ -94,6 +96,7 @@ WebEnginePage::WebEnginePage(WebEnginePart *part, QWidget *parent)
this->profile()->setHttpUserAgent(this->profile()->httpUserAgent() + " Konqueror (WebEnginePart)");
}
WebEnginePartDownloadManager::instance()->addPage(this);
m_wallet = new WebEngineWallet(this, parent ? parent->window()->winId() : 0);
}
WebEnginePage::~WebEnginePage()
......@@ -204,8 +207,9 @@ bool WebEnginePage::acceptNavigationRequest(const QUrl& url, NavigationType type
bool inPageRequest = true;
switch (type) {
case QWebEnginePage::NavigationTypeFormSubmitted:
//if (!checkFormData(request))
// return false;
if (!checkFormData(url))
return false;
m_wallet->saveFormData(this);
break;
#if 0
case QWebEnginePage::NavigationTypeFormResubmitted:
......@@ -548,9 +552,9 @@ bool WebEnginePage::checkLinkSecurity(const QNetworkRequest &req, NavigationType
return true;
}
bool WebEnginePage::checkFormData(const QNetworkRequest &req) const
bool WebEnginePage::checkFormData(const QUrl &url) const
{
const QString scheme (req.url().scheme());
const QString scheme (url.scheme());
if (m_sslInfo.isValid() &&
!scheme.compare(QL1S("https")) && !scheme.compare(QL1S("mailto")) &&
......
......@@ -40,6 +40,7 @@ class WebSslInfo;
class WebEnginePart;
class QWebEngineDownloadItem;
class KPasswdServerClient;
class WebEngineWallet;
class WebEnginePage : public QWebEnginePage
{
......@@ -64,6 +65,8 @@ public:
void download(const QUrl &url, bool newWindow = false);
WebEngineWallet* wallet() const {return m_wallet;}
Q_SIGNALS:
/**
* This signal is emitted whenever a user cancels/aborts a load resource
......@@ -107,7 +110,7 @@ protected Q_SLOTS:
private:
bool checkLinkSecurity(const QNetworkRequest& req, NavigationType type) const;
bool checkFormData(const QNetworkRequest& req) const;
bool checkFormData(const QUrl& url) const;
bool handleMailToUrl (const QUrl& , NavigationType type) const;
void setPageJScriptPolicy(const QUrl& url);
......@@ -121,6 +124,7 @@ private:
QPointer<WebEnginePart> m_part;
QScopedPointer<KPasswdServerClient> m_passwdServerClient;
WebEngineWallet *m_wallet;
};
......@@ -158,6 +162,7 @@ private:
KParts::WindowArgs m_windowArgs;
WebWindowType m_type;
bool m_createNewWindow;
WebEngineWallet* m_wallet;
};
#endif // WEBENGINEPAGE_H
......@@ -34,6 +34,7 @@
#include "webenginepage.h"
#include "websslinfo.h"
#include "webhistoryinterface.h"
#include "webenginewallet.h"
#include "ui/searchbar.h"
#include "ui/passwordbar.h"
......@@ -80,7 +81,8 @@ WebEnginePart::WebEnginePart(QWidget *parentWidget, QObject *parent,
m_statusBarWalletLabel(0),
m_searchBar(0),
m_passwordBar(0),
m_featurePermissionBar(0)
m_featurePermissionBar(0),
m_wallet(Q_NULLPTR)
{
KAboutData about = KAboutData(QStringLiteral("webenginepart"),
i18nc("Program Name", "WebEnginePart"),
......@@ -168,6 +170,7 @@ WebEnginePart::WebEnginePart(QWidget *parentWidget, QObject *parent,
// Load plugins once we are fully ready
loadPlugins();
setWallet(page()->wallet());
}
WebEnginePart::~WebEnginePart()
......@@ -311,17 +314,25 @@ void WebEnginePart::connectWebEnginePageSignals(WebEnginePage* page)
m_browserExtension->setIconUrl(url);
}
});
}
#if 0
KWebWallet *wallet = page->wallet();
if (wallet) {
connect(wallet, SIGNAL(saveFormDataRequested(QString,QUrl)),
this, SLOT(slotSaveFormDataRequested(QString,QUrl)));
connect(wallet, SIGNAL(fillFormRequestCompleted(bool)),
this, SLOT(slotFillFormRequestCompleted(bool)));
connect(wallet, SIGNAL(walletClosed()), this, SLOT(slotWalletClosed()));
void WebEnginePart::setWallet(WebEngineWallet* wallet)
{
if(m_wallet){
disconnect(m_wallet, &WebEngineWallet::saveFormDataRequested,
this, &WebEnginePart::slotSaveFormDataRequested);
disconnect(m_wallet, &WebEngineWallet::fillFormRequestCompleted,
this, &WebEnginePart::slotFillFormRequestCompleted);
disconnect(m_wallet, &WebEngineWallet::walletClosed, this, &WebEnginePart::slotWalletClosed);
}
m_wallet = wallet;
if (m_wallet) {
connect(m_wallet, &WebEngineWallet::saveFormDataRequested,
this, &WebEnginePart::slotSaveFormDataRequested);
connect(m_wallet, &WebEngineWallet::fillFormRequestCompleted,
this, &WebEnginePart::slotFillFormRequestCompleted);
connect(m_wallet, &WebEngineWallet::walletClosed, this, &WebEnginePart::slotWalletClosed);
}
#endif
}
bool WebEnginePart::openUrl(const QUrl &_u)
......@@ -451,15 +462,15 @@ void WebEnginePart::slotLoadFinished (bool ok)
}
if (!Utils::isBlankUrl(url())) {
m_hasCachedFormData = false;
if (WebEngineSettings::self()->isNonPasswordStorableSite(url().host())) {
addWalletStatusBarIcon();
} else {
}
else {
// Attempt to fill the web form...
// KWebWallet *webWallet = page() ? page()->wallet() : 0;
// if (webWallet) {
// webWallet->fillFormData(frame, false);
// }
WebEngineWallet *wallet = page() ? page()->wallet() : 0;
if (wallet){
wallet->fillFormData(page());
}
}
}
......@@ -766,10 +777,10 @@ void WebEnginePart::slotDeleteNonPasswordStorableSite()
void WebEnginePart::slotRemoveCachedPasswords()
{
if (!page()) // || !page()->wallet())
if (!page() || !page()->wallet())
return;
// page()->wallet()->removeFormData(page()->mainFrame(), true);
page()->wallet()->removeFormData(page());
m_hasCachedFormData = false;
}
......@@ -822,8 +833,8 @@ void WebEnginePart::slotShowFeaturePermissionBar(QWebEnginePage::Feature feature
this, SLOT(slotFeaturePermissionGranted(QWebEnginePage::Feature)));
connect(m_featurePermissionBar, SIGNAL(permissionDenied(QWebEnginePage::Feature)),
this, SLOT(slotFeaturePermissionDenied(QWebEnginePage::Feature)));
// connect(m_passwordBar, SIGNAL(done()),
// this, SLOT(slotSaveFormDataDone()));
connect(m_passwordBar, SIGNAL(done()),
this, SLOT(slotSaveFormDataDone()));
QBoxLayout* lay = qobject_cast<QBoxLayout*>(widget()->layout());
if (lay)
lay->insertWidget(0, m_featurePermissionBar);
......@@ -862,19 +873,16 @@ void WebEnginePart::slotSaveFormDataRequested (const QString& key, const QUrl& u
if (!m_passwordBar) {
m_passwordBar = new PasswordBar(widget());
#if 0
KWebWallet* wallet = page()->wallet();
if (!wallet) {
kWarning() << "No wallet instance found! This should never happen!";
if (!m_wallet) {
qDebug() << "No m_wallet instance found! This should never happen!";
return;
}
connect(m_passwordBar, SIGNAL(saveFormDataAccepted(QString)),
wallet, SLOT(acceptSaveFormDataRequest(QString)));
m_wallet, SLOT(acceptSaveFormDataRequest(QString)));
connect(m_passwordBar, SIGNAL(saveFormDataRejected(QString)),
wallet, SLOT(rejectSaveFormDataRequest(QString)));
m_wallet, SLOT(rejectSaveFormDataRequest(QString)));
connect(m_passwordBar, SIGNAL(done()),
this, SLOT(slotSaveFormDataDone()));
#endif
}
Q_ASSERT(m_passwordBar);
......
......@@ -42,6 +42,7 @@ class PasswordBar;
class FeaturePermissionBar;
class KUrlLabel;
class WebEngineBrowserExtension;
class WebEngineWallet;
/**
* A KPart wrapper for the QtWebEngine's browser rendering engine.
......@@ -98,6 +99,9 @@ public:
void connectWebEnginePageSignals(WebEnginePage* page);
void slotShowFeaturePermissionBar(QWebEnginePage::Feature);
void setWallet(WebEngineWallet* wallet);
protected:
/**
* Re-implemented for internal reasons. API remains unaffected.
......@@ -160,6 +164,7 @@ private:
WebEngineBrowserExtension* m_browserExtension;
KParts::StatusBarExtension* m_statusBarExtension;
WebEngineView* m_webView;
WebEngineWallet* m_wallet;
};
#endif // WEBENGINEPART_H
......@@ -24,6 +24,7 @@
#include <QWidget>
WebEngineFactory::~WebEngineFactory()
{
// kDebug() << this;
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment