From 53876e63be3a5aa1de038e3ecd593fdac721b78d Mon Sep 17 00:00:00 2001 From: Pierre Rossi Date: Thu, 12 Feb 2015 15:13:46 +0100 Subject: Add QWebChannel setter and getter to QWebEnginePage This allows using the WebChannel integration from the widgets API. Contains documentation, the underlying API for transport is tested by the qml tests already. Change-Id: If5520eddf5d1a9c917df890960e042f53baa42ce Reviewed-by: Andras Becsi --- src/webenginewidgets/api/qwebenginepage.cpp | 31 +++++++++++++++++++++++++++++ src/webenginewidgets/api/qwebenginepage.h | 4 ++++ 2 files changed, 35 insertions(+) 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(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); -- cgit v1.2.3