diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2016-01-07 16:13:16 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2016-01-15 10:44:48 +0000 |
commit | bc315ce05298cf500f45f3a897b0f7c0408fd611 (patch) | |
tree | 7560fbe0e18f63dcc62a5e9d0f328b3cb2b67bec /src/webengine | |
parent | 4bf31a52de2f9c8d049d2fd7410b9cfb88d41168 (diff) |
Add API to set WebChannel on isolated world
Make it possible to set a web-channel so that it can only be accessed
by private scripts.
Pulls in needed API extension in 3rdparty.
Task-number: QTBUG-50318
Change-Id: I61bcce5c318dffe0a406ee8cddf31f58a021c22c
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
Diffstat (limited to 'src/webengine')
-rw-r--r-- | src/webengine/api/qquickwebengineview.cpp | 28 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineview_p.h | 4 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineview_p_p.h | 1 |
3 files changed, 28 insertions, 5 deletions
diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp index 61a19faa5..2eef6a767 100644 --- a/src/webengine/api/qquickwebengineview.cpp +++ b/src/webengine/api/qquickwebengineview.cpp @@ -109,9 +109,10 @@ QQuickWebEngineViewPrivate::QQuickWebEngineViewPrivate() , isLoading(false) , m_activeFocusOnPress(true) , devicePixelRatio(QGuiApplication::primaryScreen()->devicePixelRatio()) + , m_webChannel(0) + , m_webChannelWorld(0) , m_dpiScale(1.0) , m_backgroundColor(Qt::white) - , m_webChannel(0) { // The gold standard for mobile web content is 160 dpi, and the devicePixelRatio expected // is the (possibly quantized) ratio of device dpi to 160 dpi. @@ -733,7 +734,7 @@ void QQuickWebEngineViewPrivate::adoptWebContents(WebContentsAdapter *webContent // associate the webChannel with the new adapter if (m_webChannel) - adapter->setWebChannel(m_webChannel); + adapter->setWebChannel(m_webChannel, m_webChannelWorld); // set initial background color if non-default if (m_backgroundColor != Qt::white) @@ -782,7 +783,7 @@ void QQuickWebEngineViewPrivate::ensureContentsAdapter() if (m_backgroundColor != Qt::white) adapter->backgroundColorChanged(); if (m_webChannel) - adapter->setWebChannel(m_webChannel); + adapter->setWebChannel(m_webChannel, m_webChannelWorld); if (explicitUrl.isValid()) adapter->load(explicitUrl); // push down the page's user scripts @@ -1209,7 +1210,7 @@ QQmlWebChannel *QQuickWebEngineView::webChannel() if (!d->m_webChannel) { d->m_webChannel = new QQmlWebChannel(this); if (d->adapter) - d->adapter->setWebChannel(d->m_webChannel); + d->adapter->setWebChannel(d->m_webChannel, d->m_webChannelWorld); } return d->m_webChannel; @@ -1222,10 +1223,27 @@ void QQuickWebEngineView::setWebChannel(QQmlWebChannel *webChannel) return; d->m_webChannel = webChannel; if (d->adapter) - d->adapter->setWebChannel(webChannel); + d->adapter->setWebChannel(webChannel, d->m_webChannelWorld); Q_EMIT webChannelChanged(); } +uint QQuickWebEngineView::webChannelWorld() const +{ + Q_D(const QQuickWebEngineView); + return d->m_webChannelWorld; +} + +void QQuickWebEngineView::setWebChannelWorld(uint webChannelWorld) +{ + Q_D(QQuickWebEngineView); + if (d->m_webChannelWorld == webChannelWorld) + return; + d->m_webChannelWorld = webChannelWorld; + if (d->adapter) + d->adapter->setWebChannel(d->m_webChannel, d->m_webChannelWorld); + Q_EMIT webChannelWorldChanged(webChannelWorld); +} + void QQuickWebEngineView::grantFeaturePermission(const QUrl &securityOrigin, QQuickWebEngineView::Feature feature, bool granted) { if (!d_ptr->adapter) diff --git a/src/webengine/api/qquickwebengineview_p.h b/src/webengine/api/qquickwebengineview_p.h index 43cdcb73e..7fdbafb77 100644 --- a/src/webengine/api/qquickwebengineview_p.h +++ b/src/webengine/api/qquickwebengineview_p.h @@ -111,6 +111,7 @@ class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineView : public QQuickItem { Q_PROPERTY(QSizeF contentsSize READ contentsSize NOTIFY contentsSizeChanged FINAL REVISION 3) Q_PROPERTY(QPointF scrollPosition READ scrollPosition NOTIFY scrollPositionChanged FINAL REVISION 3) Q_PROPERTY(bool audioMuted READ isAudioMuted WRITE setAudioMuted NOTIFY audioMutedChanged REVISION 3) + Q_PROPERTY(uint webChannelWorld READ webChannelWorld WRITE setWebChannelWorld NOTIFY webChannelWorldChanged REVISION 3) #ifdef ENABLE_QML_TESTSUPPORT_API Q_PROPERTY(QQuickWebEngineTestSupport *testSupport READ testSupport WRITE setTestSupport FINAL) @@ -274,6 +275,8 @@ public: QQmlWebChannel *webChannel(); void setWebChannel(QQmlWebChannel *); QQuickWebEngineHistory *navigationHistory() const; + uint webChannelWorld() const; + void setWebChannelWorld(uint); #ifdef ENABLE_QML_TESTSUPPORT_API QQuickWebEngineTestSupport *testSupport() const; @@ -329,6 +332,7 @@ Q_SIGNALS: Q_REVISION(3) void scrollPositionChanged(const QPointF& position); Q_REVISION(3) void audioMutedChanged(bool muted); Q_REVISION(3) void wasRecentlyAudibleChanged(bool wasRecentlyAudible); + Q_REVISION(3) void webChannelWorldChanged(uint); protected: void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h index dd20c8972..6d72628a2 100644 --- a/src/webengine/api/qquickwebengineview_p_p.h +++ b/src/webengine/api/qquickwebengineview_p_p.h @@ -214,6 +214,7 @@ public: QMap<quint64, QJSValue> m_callbacks; QList<QSharedPointer<CertificateErrorController> > m_certificateErrorControllers; QQmlWebChannel *m_webChannel; + uint m_webChannelWorld; private: QScopedPointer<QtWebEngineCore::UIDelegatesManager> m_uIDelegatesManager; |