summaryrefslogtreecommitdiffstats
path: root/src/webenginewidgets/api/qwebenginepage.cpp
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-01-29 15:57:18 +0100
committerAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-01-31 21:31:45 +0000
commitef1f608f76f02f11b4bdcc8d52fa41cdf4cdf5c3 (patch)
tree047a52a007af9f835f077d5061861557296ae7a8 /src/webenginewidgets/api/qwebenginepage.cpp
parent23c652c3c1680f42adfd5c6500280b103ce1d095 (diff)
Preserve webchannel and userscripts when restoring history
Most page-state is set in webcontentsadapter::initialize except user scripts and webchannel. This patch ensures those are initialized too when changing to a new adapter during history restore. Change-Id: I4dca23ddab50480b1a72252a038834ce1802ad77 Task-number: QTBUG-50751 Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com> Reviewed-by: David Rosca <nowrep@gmail.com>
Diffstat (limited to 'src/webenginewidgets/api/qwebenginepage.cpp')
-rw-r--r--src/webenginewidgets/api/qwebenginepage.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp
index 511ddfb0f..b1bf33067 100644
--- a/src/webenginewidgets/api/qwebenginepage.cpp
+++ b/src/webenginewidgets/api/qwebenginepage.cpp
@@ -107,6 +107,7 @@ QWebEnginePagePrivate::QWebEnginePagePrivate(QWebEngineProfile *_profile)
, m_isBeingAdopted(false)
, m_backgroundColor(Qt::white)
, fullscreenMode(false)
+ , webChannel(nullptr)
{
memset(actions, 0, sizeof(actions));
}
@@ -407,8 +408,14 @@ void QWebEnginePagePrivate::recreateFromSerializedHistory(QDataStream &input)
{
QExplicitlySharedDataPointer<WebContentsAdapter> newWebContents = WebContentsAdapter::createFromSerializedNavigationHistory(input, this);
if (newWebContents) {
+ // Keep the old adapter referenced so the user-scripts are not
+ // unregistered immediately.
+ QExplicitlySharedDataPointer<WebContentsAdapter> oldWebContents = adapter;
adapter = newWebContents.data();
adapter->initialize(this);
+ if (webChannel)
+ adapter->setWebChannel(webChannel);
+ scriptCollection.d->rebindToContents(adapter.data());
}
}
@@ -519,7 +526,7 @@ QWebEngineSettings *QWebEnginePage::settings() const
QWebChannel *QWebEnginePage::webChannel() const
{
Q_D(const QWebEnginePage);
- return d->adapter->webChannel();
+ return d->webChannel;
}
/*!
@@ -536,7 +543,10 @@ QWebChannel *QWebEnginePage::webChannel() const
void QWebEnginePage::setWebChannel(QWebChannel *channel)
{
Q_D(QWebEnginePage);
- d->adapter->setWebChannel(channel);
+ if (d->webChannel != channel) {
+ d->webChannel = channel;
+ d->adapter->setWebChannel(channel);
+ }
}
/*!