summaryrefslogtreecommitdiff
path: root/src/imports
diff options
context:
space:
mode:
Diffstat (limited to 'src/imports')
-rw-r--r--src/imports/webchannel/plugin.cpp9
-rw-r--r--src/imports/webchannel/plugins.qmltypes96
-rw-r--r--src/imports/webchannel/qmlwebchannel.cpp45
-rw-r--r--src/imports/webchannel/qmlwebchannel.h16
-rw-r--r--src/imports/webchannel/qmlwebviewtransport.cpp103
-rw-r--r--src/imports/webchannel/qmlwebviewtransport.h79
-rw-r--r--src/imports/webchannel/webchannel.pro6
7 files changed, 58 insertions, 296 deletions
diff --git a/src/imports/webchannel/plugin.cpp b/src/imports/webchannel/plugin.cpp
index 589e3cb..6507112 100644
--- a/src/imports/webchannel/plugin.cpp
+++ b/src/imports/webchannel/plugin.cpp
@@ -43,11 +43,6 @@
#include <QtQml/QQmlExtensionPlugin>
#include "qmlwebchannel.h"
-#include "qwebsockettransport.h"
-#include "qmlwebviewtransport.h"
-#include "qwebchanneltransportinterface.h"
-
-QML_DECLARE_INTERFACE_HASMETATYPE(QWebChannelTransportInterface);
QT_BEGIN_NAMESPACE
@@ -62,13 +57,9 @@ public:
void QWebChannelPlugin::registerTypes(const char *uri)
{
- qmlRegisterInterface<QWebChannelTransportInterface>("QWebChannelTransportInterface");
-
int major = 1;
int minor = 0;
qmlRegisterType<QmlWebChannel>(uri, major, minor, "WebChannel");
- qmlRegisterType<QWebSocketTransport>(uri, major, minor, "WebSocketTransport");
- qmlRegisterType<QmlWebViewTransport>(uri, major, minor, "WebViewTransport");
}
QT_END_NAMESPACE
diff --git a/src/imports/webchannel/plugins.qmltypes b/src/imports/webchannel/plugins.qmltypes
index 6d08f9c..789f2b4 100644
--- a/src/imports/webchannel/plugins.qmltypes
+++ b/src/imports/webchannel/plugins.qmltypes
@@ -4,95 +4,65 @@ import QtQuick.tooling 1.1
// It is used for QML tooling purposes only.
//
// This file was auto-generated by:
-// 'qmlplugindump -notrelocatable QtWebChannel 5.3'
+// 'qmlplugindump -notrelocatable QtWebChannel 1.0'
Module {
Component {
- name: "QMetaObjectPublisher"
+ name: "QWebChannel"
prototype: "QObject"
- exports: ["QtWebChannel/MetaObjectPublisher 5.3"]
- exportMetaObjectRevisions: [0]
- Property { name: "webChannel"; type: "QWebChannel"; isPointer: true }
Property { name: "blockUpdates"; type: "bool" }
Signal {
- name: "webChannelChanged"
- Parameter { name: "channel"; type: "QWebChannel"; isPointer: true }
- }
- Signal {
name: "blockUpdatesChanged"
Parameter { name: "block"; type: "bool" }
}
Method {
- name: "classInfoForObjects"
- type: "QVariantMap"
- Parameter { name: "objects"; type: "QVariantMap" }
- }
- Method {
- name: "classInfoForObject"
- type: "QVariantMap"
- Parameter { name: "object"; type: "QObject"; isPointer: true }
+ name: "sendMessage"
+ Parameter { name: "id"; type: "QJsonValue" }
+ Parameter { name: "data"; type: "QJsonValue" }
}
Method {
- name: "registerObjects"
- Parameter { name: "objects"; type: "QVariantMap" }
+ name: "sendMessage"
+ Parameter { name: "id"; type: "QJsonValue" }
}
Method {
- name: "handleRequest"
- type: "bool"
- Parameter { name: "message"; type: "QJsonObject" }
+ name: "registerObject"
+ Parameter { name: "id"; type: "string" }
+ Parameter { name: "object"; type: "QObject"; isPointer: true }
}
- Method { name: "bench_ensureUpdatesInitialized" }
- Method { name: "bench_sendPendingPropertyUpdates" }
Method {
- name: "bench_registerObjects"
- Parameter { name: "objects"; type: "QVariantMap" }
+ name: "deregisterObject"
+ Parameter { name: "object"; type: "QObject"; isPointer: true }
}
- Method { name: "bench_initializeClients" }
- Method { name: "test_clientIsIdle"; type: "bool" }
}
Component {
- name: "QWebChannel"
- prototype: "QObject"
- exports: ["QtWebChannel/WebChannel 5.3"]
+ name: "QmlWebChannel"
+ prototype: "QWebChannel"
+ exports: ["QtWebChannel/WebChannel 1.0"]
exportMetaObjectRevisions: [0]
- Property { name: "baseUrl"; type: "string"; isReadonly: true }
- Property { name: "useSecret"; type: "bool" }
- Signal {
- name: "baseUrlChanged"
- Parameter { name: "baseUrl"; type: "string" }
- }
- Signal {
- name: "rawMessageReceived"
- Parameter { name: "rawMessage"; type: "string" }
- }
- Signal { name: "pongReceived" }
- Signal { name: "initialized" }
- Signal {
- name: "failed"
- Parameter { name: "reason"; type: "string" }
- }
+ attachedType: "QmlWebChannelAttached"
+ Property { name: "transports"; type: "QObject"; isList: true; isReadonly: true }
+ Property { name: "registeredObjects"; type: "QObject"; isList: true; isReadonly: true }
Method {
- name: "sendMessage"
- Parameter { name: "id"; type: "QJsonValue" }
- Parameter { name: "data"; type: "QJsonValue" }
- }
- Method {
- name: "sendMessage"
- Parameter { name: "id"; type: "QJsonValue" }
+ name: "registerObjects"
+ Parameter { name: "objects"; type: "QVariantMap" }
}
+ Method { name: "test_clientIsIdle"; type: "bool" }
Method {
- name: "respond"
- Parameter { name: "messageId"; type: "QJsonValue" }
- Parameter { name: "data"; type: "QJsonValue" }
+ name: "connectTo"
+ Parameter { name: "transport"; type: "QObject"; isPointer: true }
}
Method {
- name: "respond"
- Parameter { name: "messageId"; type: "QJsonValue" }
+ name: "disconnectFrom"
+ Parameter { name: "transport"; type: "QObject"; isPointer: true }
}
- Method {
- name: "sendRawMessage"
- Parameter { name: "rawMessage"; type: "string" }
+ }
+ Component {
+ name: "QmlWebChannelAttached"
+ prototype: "QObject"
+ Property { name: "id"; type: "string" }
+ Signal {
+ name: "idChanged"
+ Parameter { name: "id"; type: "string" }
}
- Method { name: "ping" }
}
}
diff --git a/src/imports/webchannel/qmlwebchannel.cpp b/src/imports/webchannel/qmlwebchannel.cpp
index dc7398d..e61e9c8 100644
--- a/src/imports/webchannel/qmlwebchannel.cpp
+++ b/src/imports/webchannel/qmlwebchannel.cpp
@@ -43,6 +43,7 @@
#include "qwebchannel_p.h"
#include "qmetaobjectpublisher_p.h"
+#include "qwebchannelabstracttransport.h"
#include <QtQml/QQmlContext>
@@ -100,32 +101,19 @@ QmlWebChannelAttached *QmlWebChannel::qmlAttachedProperties(QObject *obj)
void QmlWebChannel::connectTo(QObject *transport)
{
- if (QWebChannelTransportInterface *iface = qobject_cast<QWebChannelTransportInterface*>(transport)) {
- m_connectedObjects.insert(transport, iface);
- QWebChannel::connectTo(iface);
- connect(transport, SIGNAL(destroyed(QObject*)), SLOT(transportDestroyed(QObject*)), Qt::UniqueConnection);
+ if (QWebChannelAbstractTransport *realTransport = qobject_cast<QWebChannelAbstractTransport*>(transport)) {
+ QWebChannel::connectTo(realTransport);
} else {
- qWarning() << "Cannot connect to transport" << transport << " - it does not implement the QWebChannelTransportInterface.";
+ qWarning() << "Cannot connect to transport" << transport << " - it is not a QWebChannelAbstractTransport.";
}
}
void QmlWebChannel::disconnectFrom(QObject *transport)
{
- if (QWebChannelTransportInterface *iface = qobject_cast<QWebChannelTransportInterface*>(transport)) {
- QWebChannel::disconnectFrom(iface);
- disconnect(transport, SIGNAL(destroyed(QObject*)), this, SLOT(transportDestroyed(QObject*)));
- m_connectedObjects.remove(transport);
+ if (QWebChannelAbstractTransport *realTransport = qobject_cast<QWebChannelAbstractTransport*>(transport)) {
+ QWebChannel::disconnectFrom(realTransport);
} else {
- qWarning() << "Cannot disconnect from transport" << transport << " - it does not implement the QWebChannelTransportInterface.";
- }
-}
-
-void QmlWebChannel::transportDestroyed(QObject *transport)
-{
- QWebChannelTransportInterface *iface = m_connectedObjects.take(transport);
- const int idx = d->transports.indexOf(iface);
- if (idx != -1) {
- d->transports.remove(idx);
+ qWarning() << "Cannot disconnect from transport" << transport << " - it is not a QWebChannelAbstractTransport.";
}
}
@@ -175,35 +163,36 @@ void QmlWebChannel::registeredObjects_clear(QQmlListProperty<QObject> *prop)
return channel->m_registeredObjects.clear();
}
-QQmlListProperty<QWebChannelTransportInterface> QmlWebChannel::transports()
+QQmlListProperty<QObject> QmlWebChannel::transports()
{
- return QQmlListProperty<QWebChannelTransportInterface>(this, 0,
+ return QQmlListProperty<QObject>(this, 0,
transports_append,
transports_count,
transports_at,
transports_clear);
}
-void QmlWebChannel::transports_append(QQmlListProperty<QWebChannelTransportInterface> *prop, QWebChannelTransportInterface *transport)
+void QmlWebChannel::transports_append(QQmlListProperty<QObject> *prop, QObject *transport)
{
- QWebChannel *channel = static_cast<QWebChannel*>(prop->object);
+ QmlWebChannel *channel = static_cast<QmlWebChannel*>(prop->object);
channel->connectTo(transport);
}
-int QmlWebChannel::transports_count(QQmlListProperty<QWebChannelTransportInterface> *prop)
+int QmlWebChannel::transports_count(QQmlListProperty<QObject> *prop)
{
return static_cast<QmlWebChannel*>(prop->object)->d->transports.size();
}
-QWebChannelTransportInterface *QmlWebChannel::transports_at(QQmlListProperty<QWebChannelTransportInterface> *prop, int index)
+QObject *QmlWebChannel::transports_at(QQmlListProperty<QObject> *prop, int index)
{
- return static_cast<QmlWebChannel*>(prop->object)->d->transports.at(index);
+ QmlWebChannel *channel = static_cast<QmlWebChannel*>(prop->object);
+ return dynamic_cast<QObject*>(channel->d->transports.at(index));
}
-void QmlWebChannel::transports_clear(QQmlListProperty<QWebChannelTransportInterface> *prop)
+void QmlWebChannel::transports_clear(QQmlListProperty<QObject> *prop)
{
QWebChannel *channel = static_cast<QWebChannel*>(prop->object);
- foreach (QWebChannelTransportInterface *transport, channel->d->transports) {
+ foreach (QWebChannelAbstractTransport *transport, channel->d->transports) {
channel->disconnectFrom(transport);
}
Q_ASSERT(channel->d->transports.isEmpty());
diff --git a/src/imports/webchannel/qmlwebchannel.h b/src/imports/webchannel/qmlwebchannel.h
index 3610307..6bc7127 100644
--- a/src/imports/webchannel/qmlwebchannel.h
+++ b/src/imports/webchannel/qmlwebchannel.h
@@ -45,7 +45,6 @@
#include <qwebchannel.h>
#include "qmlwebchannelattached.h"
-#include "qwebchanneltransportinterface.h"
#include <QVector>
@@ -58,7 +57,7 @@ class QmlWebChannel : public QWebChannel
{
Q_OBJECT
- Q_PROPERTY( QQmlListProperty<QWebChannelTransportInterface> connections READ transports );
+ Q_PROPERTY( QQmlListProperty<QObject> transports READ transports );
Q_PROPERTY( QQmlListProperty<QObject> registeredObjects READ registeredObjects )
public:
@@ -68,7 +67,7 @@ public:
Q_INVOKABLE void registerObjects(const QVariantMap &objects);
QQmlListProperty<QObject> registeredObjects();
- QQmlListProperty<QWebChannelTransportInterface> transports();
+ QQmlListProperty<QObject> transports();
// TODO: remove this by replacing QML with C++ tests
Q_INVOKABLE bool test_clientIsIdle() const;
@@ -80,7 +79,6 @@ public:
private Q_SLOTS:
void objectIdChanged(const QString &newId);
- void transportDestroyed(QObject *transport);
private:
static void registeredObjects_append(QQmlListProperty<QObject> *prop, QObject *item);
@@ -88,14 +86,12 @@ private:
static QObject *registeredObjects_at(QQmlListProperty<QObject> *prop, int index);
static void registeredObjects_clear(QQmlListProperty<QObject> *prop);
- static void transports_append(QQmlListProperty<QWebChannelTransportInterface> *prop, QWebChannelTransportInterface *item);
- static int transports_count(QQmlListProperty<QWebChannelTransportInterface> *prop);
- static QWebChannelTransportInterface *transports_at(QQmlListProperty<QWebChannelTransportInterface> *prop, int index);
- static void transports_clear(QQmlListProperty<QWebChannelTransportInterface> *prop);
+ static void transports_append(QQmlListProperty<QObject> *prop, QObject *item);
+ static int transports_count(QQmlListProperty<QObject> *prop);
+ static QObject *transports_at(QQmlListProperty<QObject> *prop, int index);
+ static void transports_clear(QQmlListProperty<QObject> *prop);
QVector<QObject*> m_registeredObjects;
- // required as when the object is destroyed, we must still find the address of the base class somehow
- QHash<QObject*, QWebChannelTransportInterface*> m_connectedObjects;
};
QML_DECLARE_TYPE( QmlWebChannel )
diff --git a/src/imports/webchannel/qmlwebviewtransport.cpp b/src/imports/webchannel/qmlwebviewtransport.cpp
deleted file mode 100644
index 3d4e2ed..0000000
--- a/src/imports/webchannel/qmlwebviewtransport.cpp
+++ /dev/null
@@ -1,103 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtWebChannel module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmlwebviewtransport.h"
-
-#include <QVariantMap>
-
-QT_USE_NAMESPACE
-
-QmlWebViewTransport::QmlWebViewTransport(QObject *parent)
- : QObject(parent)
- , m_webViewExperimental(Q_NULLPTR)
- , m_handler(Q_NULLPTR)
-{
-}
-
-QmlWebViewTransport::~QmlWebViewTransport()
-{
-
-}
-
-void QmlWebViewTransport::setWebViewExperimental(QObject *webViewExperimental)
-{
- if (webViewExperimental != m_webViewExperimental) {
- if (m_webViewExperimental) {
- disconnect(m_webViewExperimental, 0, this, 0);
- }
- m_webViewExperimental = webViewExperimental;
- connect(m_webViewExperimental, SIGNAL(messageReceived(QVariantMap)), this, SLOT(handleWebViewMessage(QVariantMap)));
- emit webViewChanged(webViewExperimental);
- }
-}
-
-QObject *QmlWebViewTransport::webViewExperimental() const
-{
- return m_webViewExperimental;
-}
-
-void QmlWebViewTransport::sendMessage(const QString &message, int /*clientId*/) const
-{
- if (!m_webViewExperimental) {
- qWarning("Cannot send message - did you forget to set the webViewExperimental property?");
- return;
- }
- QMetaObject::invokeMethod(m_webViewExperimental, "postMessage", Q_ARG(QString, message));
-}
-
-void QmlWebViewTransport::sendMessage(const QByteArray &message, int clientId) const
-{
- sendMessage(QString::fromUtf8(message), clientId);
-}
-
-void QmlWebViewTransport::handleWebViewMessage(const QVariantMap &message)
-{
- if (m_handler) {
- const QString &data = message[QStringLiteral("data")].toString();
- m_handler->handleMessage(data, this, -1);
- emit messageReceived(data);
- }
-}
-
-void QmlWebViewTransport::setMessageHandler(QWebChannelMessageHandlerInterface *handler)
-{
- m_handler = handler;
-}
diff --git a/src/imports/webchannel/qmlwebviewtransport.h b/src/imports/webchannel/qmlwebviewtransport.h
deleted file mode 100644
index 8fbfdd9..0000000
--- a/src/imports/webchannel/qmlwebviewtransport.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtWebChannel module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QMLWEBVIEWTRANSPORT_H
-#define QMLWEBVIEWTRANSPORT_H
-
-#include <qwebchanneltransportinterface.h>
-
-QT_BEGIN_NAMESPACE
-
-class QmlWebViewTransport : public QObject, public QWebChannelTransportInterface
-{
- Q_OBJECT
- Q_INTERFACES(QWebChannelTransportInterface)
- Q_PROPERTY(QObject *webViewExperimental READ webViewExperimental WRITE setWebViewExperimental NOTIFY webViewChanged)
-public:
- explicit QmlWebViewTransport(QObject *parent = 0);
- ~QmlWebViewTransport() Q_DECL_OVERRIDE;
-
- void sendMessage(const QString &message, int clientId) const Q_DECL_OVERRIDE;
- void sendMessage(const QByteArray &message, int clientId) const Q_DECL_OVERRIDE;
- void setMessageHandler(QWebChannelMessageHandlerInterface *handler) Q_DECL_OVERRIDE;
-
- void setWebViewExperimental(QObject *webViewExperimental);
- QObject *webViewExperimental() const;
-
-Q_SIGNALS:
- void webViewChanged(QObject *webViewExperimental);
- void messageReceived(const QString &message);
-
-private Q_SLOTS:
- void handleWebViewMessage(const QVariantMap &message);
-
-private:
- QObject *m_webViewExperimental;
- QWebChannelMessageHandlerInterface *m_handler;
-};
-
-QT_END_NAMESPACE
-
-#endif // QMLWEBVIEWTRANSPORT_H
diff --git a/src/imports/webchannel/webchannel.pro b/src/imports/webchannel/webchannel.pro
index 3042854..c1959f5 100644
--- a/src/imports/webchannel/webchannel.pro
+++ b/src/imports/webchannel/webchannel.pro
@@ -6,12 +6,10 @@ VPATH += ../../webchannel
SOURCES += \
plugin.cpp \
qmlwebchannel.cpp \
- qmlwebchannelattached.cpp \
- qmlwebviewtransport.cpp
+ qmlwebchannelattached.cpp
HEADERS += \
qmlwebchannel.h \
- qmlwebchannelattached.h \
- qmlwebviewtransport.h
+ qmlwebchannelattached.h
load(qml_plugin)