From 94912cf26ba70a2cadd23f1c931395be64c11eac Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Thu, 10 Jul 2014 00:05:28 +0200 Subject: Refactor and streamline API and IPC protocol. This patch removes the obsolete API support to send raw messages using a QWebChannel. Instead, it is encouraged to directly use WebSockets or navigator.qt. By doing so, we can cleanup the code considerably. While at it, the transport API is adapted to work on QJsonObject messages, instead of QStrings. This will allow us to use more efficient formats in e.g. QtWebKit or QtWebEngine. One could also implement a JSONRPC interface using a custom transport then. Change-Id: Ia8c125a5558507b3cbecf128a46b19fdb013f47b Reviewed-by: Allan Sandfeld Jensen --- src/webchannel/qwebchannel.cpp | 31 +------------------------------ 1 file changed, 1 insertion(+), 30 deletions(-) (limited to 'src/webchannel/qwebchannel.cpp') diff --git a/src/webchannel/qwebchannel.cpp b/src/webchannel/qwebchannel.cpp index d0b968e..3aebb14 100644 --- a/src/webchannel/qwebchannel.cpp +++ b/src/webchannel/qwebchannel.cpp @@ -50,20 +50,6 @@ QT_BEGIN_NAMESPACE -QByteArray generateJSONMessage(const QJsonValue &id, const QJsonValue &data, bool response) -{ - QJsonObject obj; - if (response) { - obj[QStringLiteral("response")] = true; - } - obj[QStringLiteral("id")] = id; - if (!data.isNull()) { - obj[QStringLiteral("data")] = data; - } - QJsonDocument doc(obj); - return doc.toJson(QJsonDocument::Compact); -} - void QWebChannelPrivate::_q_transportDestroyed(QObject *object) { const int idx = transports.indexOf(static_cast(object)); @@ -144,7 +130,7 @@ void QWebChannel::connectTo(QWebChannelAbstractTransport *transport) Q_ASSERT(transport); if (!d->transports.contains(transport)) { d->transports << transport; - connect(transport, &QWebChannelAbstractTransport::textMessageReceived, + connect(transport, &QWebChannelAbstractTransport::messageReceived, d->publisher, &QMetaObjectPublisher::handleMessage, Qt::UniqueConnection); connect(transport, SIGNAL(destroyed(QObject*)), @@ -162,21 +148,6 @@ void QWebChannel::disconnectFrom(QWebChannelAbstractTransport *transport) } } -void QWebChannel::sendMessage(const QJsonValue &id, const QJsonValue &data) const -{ - Q_D(const QWebChannel); - if (d->transports.isEmpty()) { - qWarning("QWebChannel is not connected to any transports, cannot send messages."); - return; - } - - const QByteArray &message = generateJSONMessage(id, data, false); - const QString &messageText = QString::fromUtf8(message); - foreach (QWebChannelAbstractTransport *transport, d->transports) { - transport->sendTextMessage(messageText); - } -} - QT_END_NAMESPACE #include "moc_qwebchannel.cpp" -- cgit v1.2.1