From 54f66cc7a1e17155e90a1d3b5c33f627dbd0d50f Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Fri, 10 Jan 2014 14:21:05 +0100 Subject: Make the underlying transport mechanism of the webchannel pluggable. This enables us to optionally use navigator.qt instead of a WebSocket, which is nicer setup-wise and is also slightly faster: navigator.qt: 284.0 msecs per iteration (total: 2,840, iterations: 10) WebSocket: 295.8 msecs per iteration (total: 2,959, iterations: 10) The baseline is ca. 203 msecs, which would mean a performance boost of ca. 12.7%. Furthermore, this sets the fundation to eventually add a WebEngine transport mechanism. The WebViewTransport should also be removed and instead the WebView itself should directly implement the WebChannelTransportInterface. Change-Id: I368bb27e38ffa2f17ffeb7f5ae695690f6f5ad21 Reviewed-by: Simon Hausmann --- examples/qml/example.qml | 10 ++- examples/qml/index.html | 3 +- examples/standalone/main.cpp | 9 ++- src/imports/webchannel/plugin.cpp | 10 ++- src/imports/webchannel/qmlwebchannel.cpp | 66 +++++++++++++++- src/imports/webchannel/qmlwebchannel.h | 18 ++++- src/imports/webchannel/qmlwebviewtransport.cpp | 103 +++++++++++++++++++++++++ src/imports/webchannel/qmlwebviewtransport.h | 79 +++++++++++++++++++ src/imports/webchannel/webchannel.pro | 6 +- src/webchannel/qmetaobjectpublisher.cpp | 2 +- src/webchannel/qmetaobjectpublisher_p.h | 17 ++-- src/webchannel/qwebchannel.cpp | 75 +++++++----------- src/webchannel/qwebchannel.h | 21 +---- src/webchannel/qwebchannel.js | 63 +++++++++------ src/webchannel/qwebchannel_p.h | 7 +- src/webchannel/qwebchannelsocket.cpp | 10 +++ src/webchannel/qwebchannelsocket_p.h | 5 +- src/webchannel/qwebchanneltransportinterface.h | 93 ++++++++++++++++++++++ src/webchannel/qwebsocketserver.cpp | 3 + src/webchannel/qwebsockettransport.cpp | 101 ++++++++++++++++++++++++ src/webchannel/qwebsockettransport.h | 81 +++++++++++++++++++ src/webchannel/webchannel.pro | 7 +- tests/qml/WebChannelTest.qml | 38 +++++---- tests/qml/data/bench_init.html | 4 +- tests/qml/data/disconnect.html | 4 +- tests/qml/data/grouping.html | 4 +- tests/qml/data/method.html | 4 +- tests/qml/data/property.html | 4 +- tests/qml/data/receiveRaw.html | 6 +- tests/qml/data/respond.html | 6 +- tests/qml/data/send.html | 6 +- tests/qml/data/signal.html | 4 +- tests/qml/data/testsetup.js | 47 +++++++++++ tests/qml/data/wrapper.html | 4 +- tests/qml/tst_bench.qml | 13 +++- tests/qml/tst_webchannel.qml | 8 -- tests/webchannel/tst_webchannel.cpp | 28 ++++--- tests/webchannel/tst_webchannel.h | 23 +++++- 38 files changed, 813 insertions(+), 179 deletions(-) create mode 100644 src/imports/webchannel/qmlwebviewtransport.cpp create mode 100644 src/imports/webchannel/qmlwebviewtransport.h create mode 100644 src/webchannel/qwebchanneltransportinterface.h create mode 100644 src/webchannel/qwebsockettransport.cpp create mode 100644 src/webchannel/qwebsockettransport.h create mode 100644 tests/qml/data/testsetup.js diff --git a/examples/qml/example.qml b/examples/qml/example.qml index f77b4c6..2d51f27 100644 --- a/examples/qml/example.qml +++ b/examples/qml/example.qml @@ -58,8 +58,11 @@ ApplicationWindow { WebChannel { id: webChannel - onRawMessageReceived: { - textEdit.text += "Received message: " + rawMessage + "\n"; + connections: WebViewTransport { + webViewExperimental: webView.experimental + onMessageReceived: { + textEdit.text += "Received message: " + message + "\n"; + } } } @@ -106,8 +109,9 @@ ApplicationWindow { Layout.fillHeight: true Layout.minimumWidth: window.width / 2 id: webView - url: webChannel.baseUrl ? ("index.html?webChannelBaseUrl=" + webChannel.baseUrl) : "about:blank" + url: "index.html" experimental.preferences.developerExtrasEnabled: true + experimental.preferences.navigatorQtObjectEnabled: true } } } diff --git a/examples/qml/index.html b/examples/qml/index.html index cd20ac9..8b65dd2 100644 --- a/examples/qml/index.html +++ b/examples/qml/index.html @@ -5,8 +5,7 @@ + diff --git a/tests/qml/data/disconnect.html b/tests/qml/data/disconnect.html index dc771b9..a9a479c 100644 --- a/tests/qml/data/disconnect.html +++ b/tests/qml/data/disconnect.html @@ -1,10 +1,10 @@ + + + + + diff --git a/tests/qml/data/respond.html b/tests/qml/data/respond.html index 6c8db0d..5f0e7fc 100644 --- a/tests/qml/data/respond.html +++ b/tests/qml/data/respond.html @@ -1,14 +1,14 @@ + diff --git a/tests/qml/data/send.html b/tests/qml/data/send.html index 7d601a8..c60fbf4 100644 --- a/tests/qml/data/send.html +++ b/tests/qml/data/send.html @@ -1,14 +1,14 @@ + diff --git a/tests/qml/data/signal.html b/tests/qml/data/signal.html index 92b0ed5..bdce0c7 100644 --- a/tests/qml/data/signal.html +++ b/tests/qml/data/signal.html @@ -1,10 +1,10 @@ + +