summaryrefslogtreecommitdiffstats
path: root/src/webenginewidgets/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/webenginewidgets/api')
-rw-r--r--src/webenginewidgets/api/qwebenginepage.cpp26
-rw-r--r--src/webenginewidgets/api/qwebenginepage_p.h3
-rw-r--r--src/webenginewidgets/api/qwebenginescriptcollection.cpp12
-rw-r--r--src/webenginewidgets/api/qwebenginescriptcollection_p.h2
4 files changed, 40 insertions, 3 deletions
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp
index 62c1adee6..2b448664f 100644
--- a/src/webenginewidgets/api/qwebenginepage.cpp
+++ b/src/webenginewidgets/api/qwebenginepage.cpp
@@ -112,6 +112,8 @@ QWebEnginePagePrivate::QWebEnginePagePrivate(QWebEngineProfile *_profile)
, m_isBeingAdopted(false)
, m_backgroundColor(Qt::white)
, fullscreenMode(false)
+ , webChannel(nullptr)
+ , webChannelWorldId(QWebEngineScript::MainWorld)
{
memset(actions, 0, sizeof(actions));
}
@@ -238,6 +240,8 @@ void QWebEnginePagePrivate::adoptNewWindow(WebContentsAdapter *newWebContents, W
Q_UNUSED(userGesture);
QWebEnginePage *newPage = q->createWindow(toWindowType(disposition));
+ if (!newPage)
+ return;
// Mark the new page as being in the process of being adopted, so that a second mouse move event
// sent by newWebContents->initialize() gets filtered in RenderWidgetHostViewQt::forwardEvent.
@@ -251,7 +255,7 @@ void QWebEnginePagePrivate::adoptNewWindow(WebContentsAdapter *newWebContents, W
newPage->d_func()->m_isBeingAdopted = true;
// Overwrite the new page's WebContents with ours.
- if (newPage && newPage->d_func() != this) {
+ if (newPage->d_func() != this) {
newPage->d_func()->adapter = newWebContents;
newWebContents->initialize(newPage->d_func());
if (!initialGeometry.isEmpty())
@@ -430,8 +434,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, webChannelWorldId);
+ scriptCollection.d->rebindToContents(adapter.data());
}
}
@@ -593,7 +603,7 @@ QWebEngineSettings *QWebEnginePage::settings() const
QWebChannel *QWebEnginePage::webChannel() const
{
Q_D(const QWebEnginePage);
- return d->adapter->webChannel();
+ return d->webChannel;
}
/*!
@@ -631,7 +641,11 @@ void QWebEnginePage::setWebChannel(QWebChannel *channel)
void QWebEnginePage::setWebChannel(QWebChannel *channel, uint worldId)
{
Q_D(QWebEnginePage);
- d->adapter->setWebChannel(channel, worldId);
+ if (d->webChannel != channel || d->webChannelWorldId != worldId) {
+ d->webChannel = channel;
+ d->webChannelWorldId = worldId;
+ d->adapter->setWebChannel(channel, worldId);
+ }
}
/*!
@@ -1197,6 +1211,12 @@ void QWebEnginePagePrivate::renderProcessTerminated(RenderProcessTerminationStat
terminationStatus), exitCode);
}
+void QWebEnginePagePrivate::requestGeometryChange(const QRect &geometry)
+{
+ Q_Q(QWebEnginePage);
+ Q_EMIT q->geometryChangeRequested(geometry);
+}
+
void QWebEnginePagePrivate::startDragging(const content::DropData &dropData,
Qt::DropActions allowedActions, const QPixmap &pixmap,
const QPoint &offset)
diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h
index 2e55bd7c2..ce769169e 100644
--- a/src/webenginewidgets/api/qwebenginepage_p.h
+++ b/src/webenginewidgets/api/qwebenginepage_p.h
@@ -128,6 +128,7 @@ public:
virtual void moveValidationMessage(const QRect &anchor) Q_DECL_OVERRIDE;
virtual void renderProcessTerminated(RenderProcessTerminationStatus terminationStatus,
int exitCode) Q_DECL_OVERRIDE;
+ virtual void requestGeometryChange(const QRect &geometry) Q_DECL_OVERRIDE;
virtual void updateScrollPosition(const QPointF &position) Q_DECL_OVERRIDE;
virtual void updateContentsSize(const QSizeF &size) Q_DECL_OVERRIDE;
void startDragging(const content::DropData &dropData, Qt::DropActions allowedActions,
@@ -160,6 +161,8 @@ public:
bool m_isBeingAdopted;
QColor m_backgroundColor;
bool fullscreenMode;
+ QWebChannel *webChannel;
+ unsigned int webChannelWorldId;
mutable QtWebEngineCore::CallbackDirectory m_callbacks;
mutable QAction *actions[QWebEnginePage::WebActionCount];
diff --git a/src/webenginewidgets/api/qwebenginescriptcollection.cpp b/src/webenginewidgets/api/qwebenginescriptcollection.cpp
index c17d05ce4..c53172261 100644
--- a/src/webenginewidgets/api/qwebenginescriptcollection.cpp
+++ b/src/webenginewidgets/api/qwebenginescriptcollection.cpp
@@ -223,3 +223,15 @@ void QWebEngineScriptCollectionPrivate::reserve(int capacity)
{
m_scriptController->reserve(m_contents, capacity);
}
+
+void QWebEngineScriptCollectionPrivate::rebindToContents(QtWebEngineCore::WebContentsAdapter *page)
+{
+ Q_ASSERT(m_contents);
+ Q_ASSERT(page);
+ Q_ASSERT(m_contents != page);
+
+ Q_FOREACH (const UserScript &script, m_scriptController->registeredScripts(m_contents)) {
+ m_scriptController->addUserScript(script, page);
+ }
+ m_contents = page;
+}
diff --git a/src/webenginewidgets/api/qwebenginescriptcollection_p.h b/src/webenginewidgets/api/qwebenginescriptcollection_p.h
index ebb0d1f00..185b590c4 100644
--- a/src/webenginewidgets/api/qwebenginescriptcollection_p.h
+++ b/src/webenginewidgets/api/qwebenginescriptcollection_p.h
@@ -72,6 +72,8 @@ public:
QList<QWebEngineScript> toList(const QString &scriptName = QString()) const;
QWebEngineScript find(const QString & name) const;
+ void rebindToContents(QtWebEngineCore::WebContentsAdapter *contents);
+
void insert(const QWebEngineScript &);
bool remove(const QWebEngineScript &);
void clear();