Commit 816e5a75 authored by Stefano Crocco's avatar Stefano Crocco
Browse files

Inject scripts in parts created by WebEnginePage::createWindow

Previously, when a new WebEnginePart was created from
WebEnginePage::createWindow, the associated page wouldn't work with
KWallet because the required javascript scripts wouldn't have been
injected in it. This happened because the scripts were injected from the
part constructor, but the page was later changed (from
NewWindowPage::acceptNavigationRequest) and the original page was
discarded. This meant that only the discarded page would end up with the
scripts, while the real page wouldn't have them.

To avoid this, the code to inject scripts has been moved to a separate
function which is called both by the part's constructor and from
NewWindowPage::acceptNavigationRequest.
parent 56bc69f5
......@@ -926,14 +926,7 @@ bool NewWindowPage::acceptNavigationRequest(const QUrl &url, NavigationType type
this->deleteLater();
return false;
}
// Reparent this page to the new webview to prevent memory leaks.
setParent(webView);
// Replace the webpage of the new webview with this one. Nice trick...
webView->setPage(this);
// Set the new part as the one this page will use going forward.
setPart(webenginePart);
// Connect all the signals from this page to the slots in the new part.
webenginePart->connectWebEnginePageSignals(this);
webenginePart->setPage(this);
//Set the create new window flag to false...
m_createNewWindow = false;
......
......@@ -66,6 +66,12 @@ public:
*/
void markUrlAsRequestedByApp(const QUrl &url){m_urlRequestedByApp = url;}
/**
* @brief Sets the webengine part to be used by this object.
* @param part the part
*/
void setPart(WebEnginePart *part);
Q_SIGNALS:
/**
* This signal is emitted whenever a user cancels/aborts a load resource
......@@ -82,12 +88,6 @@ protected:
*/
WebEnginePart* part() const;
/**
* Sets the webengine part to be used by this object.
* @internal
*/
void setPart(WebEnginePart*);
/**
* Reimplemented for internal reasons, the API is not affected.
* @internal
......
......@@ -195,24 +195,35 @@ WebEnginePart::WebEnginePart(QWidget *parentWidget, QObject *parent,
connect(m_webView, &QWebEngineView::loadFinished,
this, &WebEnginePart::slotLoadFinished);
page()->scripts().insert(detectRefreshScript());
// Connect the signals from the page...
connectWebEnginePageSignals(page());
// Init the QAction we are going to use...
initActions();
// Load plugins once we are fully ready
setWallet(page()->wallet());
if (m_wallet) {
page()->scripts().insert(WebEngineWallet::formDetectorFunctionsScript());
}
setPage(page());
}
WebEnginePart::~WebEnginePart()
{
}
void WebEnginePart::setPage(WebEnginePage* page)
{
if (m_webView) {
m_webView->setPage(page);
page->setParent(m_webView);
}
page->setPart(this);
page->scripts().insert(detectRefreshScript());
// Connect the signals from the page...
connectWebEnginePageSignals(page);
if (m_wallet) {
page->scripts().insert(WebEngineWallet::formDetectorFunctionsScript());
} else {
}
}
WebEnginePage* WebEnginePart::page()
{
if (m_webView)
......
......@@ -100,6 +100,18 @@ public:
void setWallet(WebEngineWallet* wallet);
/**
* @brief Changes the page object associated with the part
*
* This currently includes:
* - calling WebEngineView::setPage
* - making the part a child of the view
* - connecting signals between part and page
* - injecting scripts into the page
* @param page the new page
*/
void setPage(WebEnginePage *page);
public Q_SLOTS:
void exitFullScreen();
void setInspectedPart(KParts::ReadOnlyPart *part);
......
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