summaryrefslogtreecommitdiffstats
path: root/src/webenginewidgets/api/qwebenginepage_p.h
diff options
context:
space:
mode:
authorJocelyn Turcotte <jocelyn.turcotte@digia.com>2014-02-10 12:14:11 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-13 14:28:04 +0100
commit1f17c9b3307b2ec409b3db22e8bd45fc623ae0cd (patch)
tree1201d8da14aee4f9868788ddfe0b5115dbf29fb8 /src/webenginewidgets/api/qwebenginepage_p.h
parent71edccabd4c359eb1ac9d6f6c3220b0d308f3a7b (diff)
Refactor the way callbacks are stored
With the upcoming addition of a new type of callback result, this patch allows storing multiple callback types in the same QHash instead or requiring a different hash table just to please the type system. This does so by managing the ref-counted callback pointers directly instead of relying on a templated QExplicitlySharedDataPointer that requires a different type for each different callback pointer type. The ref-counting, construction and destruction is managed through a run-time type enum. Change-Id: I90ab2e1efc0c9703fc5b6ef57b38204ac8eea828 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/webenginewidgets/api/qwebenginepage_p.h')
-rw-r--r--src/webenginewidgets/api/qwebenginepage_p.h42
1 files changed, 38 insertions, 4 deletions
diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h
index 86605c78..9a4dc57f 100644
--- a/src/webenginewidgets/api/qwebenginepage_p.h
+++ b/src/webenginewidgets/api/qwebenginepage_p.h
@@ -58,6 +58,43 @@ class QWebEngineHistory;
class QWebEnginePage;
class QWebEngineView;
+class CallbackDirectory {
+public:
+ typedef QtWebEnginePrivate::QWebEngineCallbackPrivateBase<const QVariant&> VariantCallback;
+ typedef QtWebEnginePrivate::QWebEngineCallbackPrivateBase<const QString&> StringCallback;
+
+ ~CallbackDirectory();
+ void registerCallback(quint64 requestId, const QExplicitlySharedDataPointer<VariantCallback> &callback);
+ void registerCallback(quint64 requestId, const QExplicitlySharedDataPointer<StringCallback> &callback);
+ void invoke(quint64 requestId, const QVariant &result);
+ void invoke(quint64 requestId, const QString &result);
+
+private:
+ struct CallbackSharedDataPointer {
+ enum {
+ None,
+ Variant,
+ String
+ } type;
+ union {
+ VariantCallback *variantCallback;
+ StringCallback *stringCallback;
+ };
+ CallbackSharedDataPointer() : type(None) { }
+ CallbackSharedDataPointer(VariantCallback *callback) : type(Variant), variantCallback(callback) { callback->ref.ref(); }
+ CallbackSharedDataPointer(StringCallback *callback) : type(String), stringCallback(callback) { callback->ref.ref(); }
+ CallbackSharedDataPointer(const CallbackSharedDataPointer &other) : type(other.type), variantCallback(other.variantCallback) { doRef(); }
+ ~CallbackSharedDataPointer() { doDeref(); }
+ operator bool () const { return type != None; }
+
+ private:
+ void doRef();
+ void doDeref();
+ };
+
+ QHash<quint64, CallbackSharedDataPointer> m_callbackMap;
+};
+
class QWebEnginePagePrivate : public QObjectPrivate, public WebContentsAdapterClient
{
public:
@@ -104,10 +141,7 @@ public:
WebEngineContextMenuData m_menuData;
QPointer<RenderWidgetHostViewQtDelegateWebPage> m_rwhvDelegate;
- typedef QtWebEnginePrivate::QWebEngineCallbackPrivateBase<const QVariant&> VariantCallback;
- typedef QtWebEnginePrivate::QWebEngineCallbackPrivateBase<const QString&> StringCallback;
- mutable QHash<quint64, QExplicitlySharedDataPointer<VariantCallback> > m_variantCallbacks;
- mutable QHash<quint64, QExplicitlySharedDataPointer<StringCallback> > m_stringCallbacks;
+ mutable CallbackDirectory m_callbacks;
};
QT_END_NAMESPACE