Commit 1738e62d authored by Stefano Crocco's avatar Stefano Crocco
Browse files

Move wallet from WebEnginePage to WebEnginePart

parent 816e5a75
......@@ -64,8 +64,7 @@ WebEnginePage::WebEnginePage(WebEnginePart *part, QWidget *parent)
m_kioErrorCode(0),
m_ignoreError(false),
m_part(part),
m_passwdServerClient(new KPasswdServerClient),
m_wallet(nullptr)
m_passwdServerClient(new KPasswdServerClient)
{
if (view())
WebEngineSettings::self()->computeFontSizes(view()->logicalDpiY());
......@@ -99,8 +98,6 @@ WebEnginePage::WebEnginePage(WebEnginePart *part, QWidget *parent)
}
m_part->downloadManager()->addPage(this);
m_wallet = new WebEngineWallet(this, parent ? parent->window()->winId() : 0);
}
WebEnginePage::~WebEnginePage()
......@@ -290,8 +287,8 @@ bool WebEnginePage::acceptNavigationRequest(const QUrl& url, NavigationType type
case QWebEnginePage::NavigationTypeFormSubmitted:
if (!checkFormData(url))
return false;
if (m_wallet) {
m_wallet->saveFormsInPage(this);
if (part() && part()->wallet()) {
part()->wallet()->saveFormsInPage(this);
}
break;
......
......@@ -55,8 +55,6 @@ public:
void setStatusBarText(const QString &text);
WebEngineWallet* wallet() const {return m_wallet;}
/**
* @brief Tells the page that the part has requested to load the given URL
*
......@@ -165,7 +163,6 @@ private:
QPointer<WebEnginePart> m_part;
QScopedPointer<KPasswdServerClient> m_passwdServerClient;
WebEngineWallet *m_wallet;
/**
* @brief The last URL that the application explicitly asked this part to open
......@@ -218,7 +215,6 @@ private:
KParts::WindowArgs m_windowArgs;
WebWindowType m_type;
bool m_createNewWindow;
WebEngineWallet* m_wallet;
};
#endif // WEBENGINEPAGE_H
......
......@@ -83,7 +83,7 @@
#include "utils.h"
#include <kio_version.h>
static QWebEngineScript detectRefreshScript() {
QWebEngineScript WebEnginePart::detectRefreshScript() {
static QWebEngineScript s_detectRefreshScript;
if (s_detectRefreshScript.isNull()) {
QFile jsfile(":/hasrefresh.js");
......@@ -199,7 +199,7 @@ WebEnginePart::WebEnginePart(QWidget *parentWidget, QObject *parent,
initActions();
// Load plugins once we are fully ready
setWallet(page()->wallet());
setWallet(new WebEngineWallet(this, parentWidget ? parentWidget->window()->winId() : 0));
setPage(page());
}
......@@ -208,20 +208,16 @@ WebEnginePart::~WebEnginePart()
{
}
void WebEnginePart::setPage(WebEnginePage* page)
void WebEnginePart::setPage(WebEnginePage* newPage)
{
if (m_webView) {
m_webView->setPage(page);
page->setParent(m_webView);
WebEnginePage *oldPage = page();
if (oldPage && oldPage != newPage) {
m_webView->setPage(newPage);
newPage->setParent(m_webView);
}
page->setPart(this);
page->scripts().insert(detectRefreshScript());
newPage->setPart(this);
// Connect the signals from the page...
connectWebEnginePageSignals(page);
if (m_wallet) {
page->scripts().insert(WebEngineWallet::formDetectorFunctionsScript());
} else {
}
connectWebEnginePageSignals(newPage);
}
WebEnginePage* WebEnginePart::page()
......@@ -400,6 +396,11 @@ void WebEnginePart::setWallet(WebEngineWallet* wallet)
}
}
WebEngineWallet* WebEnginePart::wallet() const
{
return m_wallet;
}
void WebEnginePart::attemptInstallKIOSchemeHandler(const QUrl& url)
{
if (KProtocolManager::defaultMimetype(url) == "text/html") { // man:, info:, etc.
......@@ -869,11 +870,11 @@ void WebEnginePart::togglePasswordStorableState(bool on)
void WebEnginePart::slotRemoveCachedPasswords()
{
if (!page() || !page()->wallet()) {
if (!m_wallet) {
return;
}
page()->wallet()->removeFormData(page());
m_wallet->removeFormData(page());
updateWalletData(WalletData::HasCachedData, false);
}
......
......@@ -17,6 +17,7 @@
#include <kparts_version.h>
#include <KParts/ReadOnlyPart>
#include <QUrl>
#include <QWebEngineScript>
namespace KParts {
class BrowserExtension;
......@@ -100,6 +101,10 @@ public:
void setWallet(WebEngineWallet* wallet);
WebEngineWallet* wallet() const;
static QWebEngineScript detectRefreshScript();
/**
* @brief Changes the page object associated with the part
*
......@@ -108,9 +113,9 @@ public:
* - making the part a child of the view
* - connecting signals between part and page
* - injecting scripts into the page
* @param page the new page
* @param newPage the new page
*/
void setPage(WebEnginePage *page);
void setPage(WebEnginePage *newPage);
public Q_SLOTS:
void exitFullScreen();
......
......@@ -47,7 +47,6 @@ WebEnginePartCertificateErrorDlg::WebEnginePartCertificateErrorDlg(const QWebEng
m_ui->details->hide();
QString translatedDesc = i18n(m_error.errorDescription().toUtf8());
qDebug() << "URL" << page->url();
QString text = i18n("<p>The server <tt>%1</tt> failed the authenticity check. The error is:</p><p><tt>%2</tt></p>Do you want to ignore this error?",
m_error.url().host(), translatedDesc);
m_ui->label->setText(text);
......
......@@ -16,12 +16,15 @@
#include "spellcheckermanager.h"
#include "webenginepartdownloadmanager.h"
#include "certificateerrordialogmanager.h"
#include "webenginewallet.h"
#include "webenginepart.h"
#include <KProtocolInfo>
#include <QWebEngineProfile>
#include <QWebEngineUrlScheme>
#include <QWebEngineSettings>
#include <QWebEngineScriptCollection>
WebEnginePartControls::WebEnginePartControls(): QObject(),
m_profile(nullptr), m_cookieJar(nullptr), m_spellCheckerManager(nullptr), m_downloadManager(nullptr),
......@@ -64,6 +67,8 @@ void WebEnginePartControls::setup(QWebEngineProfile* profile)
}
m_profile = profile;
m_profile->scripts()->insert({WebEngineWallet::formDetectorFunctionsScript(), WebEnginePart::detectRefreshScript()});
m_profile->installUrlSchemeHandler("error", new WebEnginePartErrorSchemeHandler(m_profile));
m_profile->installUrlSchemeHandler("konq", new KonqUrlSchemeHandler(m_profile));
m_profile->installUrlSchemeHandler("help", new WebEnginePartKIOHandler(m_profile));
......
......@@ -11,6 +11,7 @@
#include "webenginepage.h"
#include "utils.h"
#include "webenginecustomizecacheablefieldsdlg.h"
#include "webenginepart.h"
#include <webenginepart_debug.h>
......@@ -109,7 +110,7 @@ QString WebEngineWallet::WebForm::fieldNameFromType(WebEngineWallet::WebForm::We
return QString();
}
WebEngineWallet::WebEngineWallet(WebEnginePage *parent, WId wid)
WebEngineWallet::WebEngineWallet(WebEnginePart *parent, WId wid)
: QObject(parent), d(new WebEngineWalletPrivate(this))
{
d->wid = wid;
......@@ -135,7 +136,6 @@ void WebEngineWallet::detectAndFillPageForms(WebEnginePage *page)
}
auto callback = [this, url, page](const WebFormList &forms) {
emit formDetectionDone(url, !forms.isEmpty(), d->hasAutoFillableFields(forms));
if (!WebEngineSettings::self()->isNonPasswordStorableSite(url.host())) {
fillFormData(page, cacheableForms(url, forms, CacheOperation::Fill));
}
......
......@@ -23,6 +23,7 @@
#include "settings/webenginesettings.h"
class WebEnginePage;
class WebEnginePart;
class QWebEngineScript;
/**
......@@ -174,7 +175,7 @@ public:
* @param wid the window ID of the window the web page will be
* embedded in
*/
explicit WebEngineWallet(WebEnginePage *parent = nullptr, WId wid = 0);
explicit WebEngineWallet(WebEnginePart *parent = nullptr, WId wid = 0);
/**
* @brief Destructor
......
......@@ -24,6 +24,8 @@
#include <algorithm>
#include <QtWebEngineWidgets/QWebEngineScriptCollection>
class WebEngineWallet::WebEngineWalletPrivate
{
public:
......
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