summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core/type_conversion.h9
-rw-r--r--src/webengine/api/qquickwebengineview.cpp34
-rw-r--r--src/webengine/api/qquickwebengineview_p.h6
-rw-r--r--src/webengine/api/qquickwebengineview_p_p.h5
-rw-r--r--src/webenginewidgets/api/qwebenginepage.cpp31
-rw-r--r--src/webenginewidgets/api/qwebenginepage.h4
-rw-r--r--tests/auto/quick/qmltests/data/tst_webchannel.qml4
7 files changed, 77 insertions, 16 deletions
diff --git a/src/core/type_conversion.h b/src/core/type_conversion.h
index 6bb755abc..619a3b9ba 100644
--- a/src/core/type_conversion.h
+++ b/src/core/type_conversion.h
@@ -155,7 +155,14 @@ inline base::FilePath toFilePath(const QString &str)
}
template <typename T>
-inline T fileListingHelper(const QString &) {qFatal("Specialization missing for %s.", Q_FUNC_INFO); return T(); }
+inline T fileListingHelper(const QString &)
+// Clang is still picky about this though it should be supported eventually.
+// See http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#941
+#ifndef Q_CC_CLANG
+= delete;
+#else
+{ return T(); }
+#endif
template <>
inline content::FileChooserFileInfo fileListingHelper<content::FileChooserFileInfo>(const QString &file)
diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp
index a47defb7c..e70e7f790 100644
--- a/src/webengine/api/qquickwebengineview.cpp
+++ b/src/webengine/api/qquickwebengineview.cpp
@@ -812,21 +812,39 @@ QQuickWebEngineHistory *QQuickWebEngineViewExperimental::navigationHistory() con
return d_ptr->m_history.data();
}
-QQmlWebChannel *QQuickWebEngineViewExperimental::webChannel() const
+/*!
+ * \qmlproperty QQmlWebChannel WebEngineView::webChannel
+ * \since QtWebEngine 1.1
+ *
+ * The web channel instance used by this view.
+ * This channel is automatically using the internal QtWebEngine transport mechanism over Chromium IPC,
+ * and exposed in the javascript context of the page it is rendering as \c navigator.qtWebChannelTransport.
+ * This transport object is used when instantiating the JavaScript counterpart of QWebChannel using
+ * the \l{Qt WebChannel JavaScript API}.
+ *
+ * \note The view does not take ownership when explicitly setting a webChannel object.
+ */
+
+QQmlWebChannel *QQuickWebEngineView::webChannel()
{
- d_ptr->ensureContentsAdapter();
- QQmlWebChannel *qmlWebChannel = qobject_cast<QQmlWebChannel *>(d_ptr->adapter->webChannel());
- Q_ASSERT(!d_ptr->adapter->webChannel() || qmlWebChannel);
+ Q_D(QQuickWebEngineView);
+ d->ensureContentsAdapter();
+ QQmlWebChannel *qmlWebChannel = qobject_cast<QQmlWebChannel *>(d->adapter->webChannel());
+ Q_ASSERT(!d->adapter->webChannel() || qmlWebChannel);
if (!qmlWebChannel) {
- qmlWebChannel = new QQmlWebChannel;
- d_ptr->adapter->setWebChannel(qmlWebChannel);
+ qmlWebChannel = new QQmlWebChannel(this);
+ d->adapter->setWebChannel(qmlWebChannel);
}
return qmlWebChannel;
}
-void QQuickWebEngineViewExperimental::setWebChannel(QQmlWebChannel *webChannel)
+void QQuickWebEngineView::setWebChannel(QQmlWebChannel *webChannel)
{
- d_ptr->adapter->setWebChannel(webChannel);
+ Q_D(QQuickWebEngineView);
+ bool notify = (d->adapter->webChannel() == webChannel);
+ d->adapter->setWebChannel(webChannel);
+ if (notify)
+ Q_EMIT webChannelChanged();
}
void QQuickWebEngineViewExperimental::grantFeaturePermission(const QUrl &securityOrigin, QQuickWebEngineViewExperimental::Feature feature, bool granted)
diff --git a/src/webengine/api/qquickwebengineview_p.h b/src/webengine/api/qquickwebengineview_p.h
index 56a1b47ab..3057cc9a4 100644
--- a/src/webengine/api/qquickwebengineview_p.h
+++ b/src/webengine/api/qquickwebengineview_p.h
@@ -42,6 +42,7 @@
QT_BEGIN_NAMESPACE
+class QQmlWebChannel;
class QQuickWebEngineCertificateError;
class QQuickWebEngineLoadRequest;
class QQuickWebEngineNavigationRequest;
@@ -63,6 +64,7 @@ class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineView : public QQuickItem {
Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged REVISION 1)
Q_PROPERTY(QQuickWebEngineProfile *profile READ profile WRITE setProfile FINAL REVISION 1)
Q_PROPERTY(QQuickWebEngineSettings *settings READ settings REVISION 1)
+ Q_PROPERTY(QQmlWebChannel *webChannel READ webChannel WRITE setWebChannel NOTIFY webChannelChanged REVISION 1)
Q_ENUMS(NavigationRequestAction);
Q_ENUMS(NavigationType);
Q_ENUMS(LoadStatus);
@@ -143,6 +145,8 @@ public:
void setProfile(QQuickWebEngineProfile *);
QQuickWebEngineSettings *settings() const;
+ QQmlWebChannel *webChannel();
+ void setWebChannel(QQmlWebChannel *);
public Q_SLOTS:
void runJavaScript(const QString&, const QJSValue & = QJSValue());
@@ -164,6 +168,8 @@ Q_SIGNALS:
Q_REVISION(1) void certificateError(QQuickWebEngineCertificateError *error);
Q_REVISION(1) void newViewRequested(QQuickWebEngineNewViewRequest *request);
Q_REVISION(1) void zoomFactorChanged(qreal arg);
+ Q_REVISION(1) void webChannelChanged();
+
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 d7785092f..48eb25cb3 100644
--- a/src/webengine/api/qquickwebengineview_p_p.h
+++ b/src/webengine/api/qquickwebengineview_p_p.h
@@ -55,7 +55,6 @@ class QQuickWebEngineView;
class QQmlComponent;
class QQmlContext;
class QQuickWebEngineSettings;
-class QQmlWebChannel;
class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineViewport : public QObject {
Q_OBJECT
@@ -81,7 +80,6 @@ class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineViewExperimental : public QObjec
Q_PROPERTY(QQmlComponent *extraContextMenuEntriesComponent READ extraContextMenuEntriesComponent WRITE setExtraContextMenuEntriesComponent NOTIFY extraContextMenuEntriesComponentChanged)
Q_PROPERTY(bool isFullScreen READ isFullScreen WRITE setIsFullScreen NOTIFY isFullScreenChanged)
Q_PROPERTY(QQuickWebEngineHistory *navigationHistory READ navigationHistory CONSTANT FINAL)
- Q_PROPERTY(QQmlWebChannel *webChannel READ webChannel WRITE setWebChannel)
Q_ENUMS(Feature)
Q_FLAGS(FindFlags)
@@ -105,9 +103,6 @@ public:
void setExtraContextMenuEntriesComponent(QQmlComponent *);
QQmlComponent *extraContextMenuEntriesComponent() const;
QQuickWebEngineHistory *navigationHistory() const;
- QQuickWebEngineSettings *settings() const;
- QQmlWebChannel *webChannel() const;
- void setWebChannel(QQmlWebChannel *);
public Q_SLOTS:
void goBackTo(int index);
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp
index a59165e8b..91f10486f 100644
--- a/src/webenginewidgets/api/qwebenginepage.cpp
+++ b/src/webenginewidgets/api/qwebenginepage.cpp
@@ -482,6 +482,37 @@ QWebEngineSettings *QWebEnginePage::settings() const
return d->settings;
}
+/*!
+ * Returns a pointer to the web channel instance used by this page, or a null pointer if none was set.
+ * This channel is automatically using the internal QtWebEngine transport mechanism over Chromium IPC,
+ * and exposed in the javascript context of this page as \c navigator.qtWebChannelTransport
+ *
+ * \since 5.5
+ * \sa {QtWebChannel::QWebChannel}{QWebChannel}
+ */
+QWebChannel *QWebEnginePage::webChannel() const
+{
+ Q_D(const QWebEnginePage);
+ return d->adapter->webChannel();
+}
+
+/*!
+ * Sets the web channel instance to be used by this page and connects it to QtWebEngine's transport
+ * using Chromium IPC messages. That transport is exposed in the javascript context of this page as
+ * \c navigator.qtWebChannelTransport, which should be used when using the \l{Qt WebChannel JavaScript API}.
+ *
+ * \note The page does not take ownership of the \a channel object.
+ *
+ * \since 5.5
+ * \param channel
+ */
+
+void QWebEnginePage::setWebChannel(QWebChannel *channel)
+{
+ Q_D(QWebEnginePage);
+ d->adapter->setWebChannel(channel);
+}
+
void QWebEnginePage::setView(QWidget *view)
{
QWebEngineViewPrivate::bind(qobject_cast<QWebEngineView*>(view), this);
diff --git a/src/webenginewidgets/api/qwebenginepage.h b/src/webenginewidgets/api/qwebenginepage.h
index a194df831..8d8f3666a 100644
--- a/src/webenginewidgets/api/qwebenginepage.h
+++ b/src/webenginewidgets/api/qwebenginepage.h
@@ -48,6 +48,7 @@
QT_BEGIN_NAMESPACE
class QMenu;
+class QWebChannel;
class QWebEngineHistory;
class QWebEnginePage;
class QWebEnginePagePrivate;
@@ -232,6 +233,9 @@ public:
QWebEngineSettings *settings() const;
+ QWebChannel *webChannel() const;
+ void setWebChannel(QWebChannel *);
+
Q_SIGNALS:
void loadStarted();
void loadProgress(int progress);
diff --git a/tests/auto/quick/qmltests/data/tst_webchannel.qml b/tests/auto/quick/qmltests/data/tst_webchannel.qml
index 1abb191e1..c3618659a 100644
--- a/tests/auto/quick/qmltests/data/tst_webchannel.qml
+++ b/tests/auto/quick/qmltests/data/tst_webchannel.qml
@@ -2,7 +2,7 @@
** 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.
+** This file is part of the QtWebEngine module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
@@ -70,7 +70,7 @@ Item {
TestWebEngineView {
id: webView
- experimental.webChannel.registeredObjects: [testObject]
+ webChannel.registeredObjects: [testObject]
}
SignalSpy {