diff options
author | Milian Wolff <milian.wolff@kdab.com> | 2014-07-03 19:12:37 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@digia.com> | 2014-08-16 09:49:41 +0200 |
commit | 05ea746d3042d1409305bc1ebcaf15095870b6d9 (patch) | |
tree | 5155938d7e853d96a6a4de44c314d715b88d547c /Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp | |
parent | 6d998167b9f14d441172022636091251fa34a15a (diff) | |
download | qtwebkit-05ea746d3042d1409305bc1ebcaf15095870b6d9.tar.gz |
Integrate QWebChannel with QtWebKit.
WebView.experimental gets a new webChannel property. By default, this
is initialized to a QQmlWebChannel internal to the WebView. By setting
it from the outside, it is possible to share the same WebChannel
between different WebViews. The webChannel property can be set to null
to disable this new feature.
For IPC, a navigator.qtWebChannelTransport property is added, which is
essentially a copy of navigator.qt. This is required to be able to use
both independently. The transport is implicitly connected to the
WebView's webChannel.
On the JavaScript client side, some manual boiler plate code is still
required. Potentially, this can be adapted in the future to preload
the qwebchannel.js. Furthermore, we might be able to instantiate and
initialize the QWebChannel before we emit window.onload.
A basic test is added which verifies that this basic integration works.
Change-Id: I5eb0389e6edd6d0c978917e441365e11a02b5c3f
Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com>
Diffstat (limited to 'Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp')
-rw-r--r-- | Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp b/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp index a46b6972e..86b8cb4d4 100644 --- a/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp +++ b/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp @@ -84,6 +84,11 @@ #include <wtf/Vector.h> #include <wtf/text/WTFString.h> +#ifdef HAVE_WEBCHANNEL +#include <QtWebChannel/QQmlWebChannel> +#include "qwebchannelwebkittransport_p.h" +#endif + using namespace WebCore; using namespace WebKit; @@ -959,6 +964,14 @@ void QQuickWebViewPrivate::didReceiveMessageFromNavigatorQtObject(WKStringRef me emit q_ptr->experimental()->messageReceived(variantMap); } +#ifdef HAVE_WEBCHANNEL +void QQuickWebViewPrivate::didReceiveMessageFromNavigatorQtWebChannelTransportObject(WKStringRef message) +{ + // TODO: can I convert a WKStringRef to a UTF8 QByteArray directly? + q_ptr->experimental()->m_webChannelTransport->receiveMessage(WKStringCopyQString(message).toUtf8()); +} +#endif + CoordinatedGraphicsScene* QQuickWebViewPrivate::coordinatedGraphicsScene() { if (webPageProxy && webPageProxy->drawingArea() && webPageProxy->drawingArea()->coordinatedLayerTreeHostProxy()) @@ -1074,7 +1087,14 @@ QQuickWebViewExperimental::QQuickWebViewExperimental(QQuickWebView *webView, QQu , d_ptr(webViewPrivate) , schemeParent(new QObject(this)) , m_test(new QWebKitTest(webViewPrivate, this)) +#ifdef HAVE_WEBCHANNEL + , m_webChannel(new QQmlWebChannel(this)) + , m_webChannelTransport(new QWebChannelWebKitTransport(this)) +#endif { +#ifdef HAVE_WEBCHANNEL + m_webChannel->connectTo(m_webChannelTransport); +#endif } QQuickWebViewExperimental::~QQuickWebViewExperimental() @@ -1163,6 +1183,29 @@ bool QQuickWebViewExperimental::flickableViewportEnabled() return s_flickableViewportEnabled; } +#ifdef HAVE_WEBCHANNEL +QQmlWebChannel* QQuickWebViewExperimental::webChannel() const +{ + return m_webChannel; +} + +void QQuickWebViewExperimental::setWebChannel(QQmlWebChannel* channel) +{ + if (channel == m_webChannel) + return; + + if (m_webChannel) + m_webChannel->disconnectFrom(m_webChannelTransport); + + m_webChannel = channel; + + if (m_webChannel) + m_webChannel->connectTo(m_webChannelTransport); + + emit webChannelChanged(channel); +} +#endif + /*! \internal @@ -1182,6 +1225,16 @@ void QQuickWebViewExperimental::postMessage(const QString& message) WKPagePostMessageToInjectedBundle(d->webPage.get(), messageName, contents.get()); } +#ifdef HAVE_WEBCHANNEL +void QQuickWebViewExperimental::postQtWebChannelTransportMessage(const QByteArray& message) +{ + Q_D(QQuickWebView); + static WKStringRef messageName = WKStringCreateWithUTF8CString("MessageToNavigatorQtWebChannelTransportObject"); + WKRetainPtr<WKStringRef> contents = adoptWK(WKStringCreateWithUTF8CString(message.constData())); + WKPagePostMessageToInjectedBundle(d->webPage.get(), messageName, contents.get()); +} +#endif + QQmlComponent* QQuickWebViewExperimental::alertDialog() const { Q_D(const QQuickWebView); |