summaryrefslogtreecommitdiffstats
path: root/src/webenginewidgets/api/qwebenginepage.cpp
diff options
context:
space:
mode:
authorJocelyn Turcotte <jocelyn.turcotte@digia.com>2014-01-15 18:22:24 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-22 08:45:09 +0100
commit6d760436bc0d7081d5bdb50e4141171b6ba940ee (patch)
tree9f17b8122a09b89a818373d9a269072d984ca0a6 /src/webenginewidgets/api/qwebenginepage.cpp
parente6b846f3800eed35d31a45122f7f8c3215dc38ef (diff)
Refactor the callback mechanism used by runJavaScript
This prepares the way for other API made async like toHtml and toPlainText. Use a callback class with an implicit templated constructor to carry the functor across the API boundary and avoid the intermediate helper method as the ABI that we have to maintain. Also pass the callback result through WebContentsAdapterClient using a bookkeeping ID instead of transferring the callback to WebContentsAdapter. This will allow other calls, which might not already allow passing a callback functor, to use a consisten way of carrying back the result to the top API layer. Change-Id: Ia923767b9c1021a108c26da17d4c41878ef7cb95 Reviewed-by: Pierre Rossi <pierre.rossi@gmail.com>
Diffstat (limited to 'src/webenginewidgets/api/qwebenginepage.cpp')
-rw-r--r--src/webenginewidgets/api/qwebenginepage.cpp20
1 files changed, 8 insertions, 12 deletions
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp
index 54abb4384..8192f38ed 100644
--- a/src/webenginewidgets/api/qwebenginepage.cpp
+++ b/src/webenginewidgets/api/qwebenginepage.cpp
@@ -146,6 +146,11 @@ void QWebEnginePagePrivate::close()
Q_EMIT q->windowCloseRequested();
}
+void QWebEnginePagePrivate::didRunJavaScript(const QVariant& result, quint64 requestId)
+{
+ (*m_variantCallbacks.take(requestId))(result);
+}
+
void QWebEnginePagePrivate::updateAction(QWebEnginePage::WebAction action) const
{
#ifdef QT_NO_ACTION
@@ -490,20 +495,11 @@ void QWebEnginePage::runJavaScript(const QString &scriptSource, const QString &x
d->adapter->runJavaScript(scriptSource, xPath);
}
-namespace {
-struct JSCallbackFunctor : public JSCallbackBase {
- JSCallbackFunctor(QtWebEnginePrivate::FunctorBase *functor) : m_func(functor) { }
- ~JSCallbackFunctor() { delete m_func; }
- void call(const QVariant &value) { (*m_func)(value); }
-private:
- QtWebEnginePrivate::FunctorBase *m_func;
-};
-}
-
-void QWebEnginePage::runJavaScriptHelper(const QString &source, QtWebEnginePrivate::FunctorBase *functor, const QString &xPath)
+void QWebEnginePage::runJavaScript(const QString& scriptSource, const QWebEngineCallback<const QVariant &> &resultCallback, const QString &xPath)
{
Q_D(QWebEnginePage);
- d->adapter->runJavaScript(source, xPath, new JSCallbackFunctor(functor));
+ quint64 requestId = d->adapter->runJavaScriptCallbackResult(scriptSource, xPath);
+ d->m_variantCallbacks.insert(requestId, resultCallback.d);
}
QWebEnginePage *QWebEnginePage::createWindow(WebWindowType type)