summaryrefslogtreecommitdiffstats
path: root/Source/WebKit2/UIProcess/GenericCallback.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebKit2/UIProcess/GenericCallback.h')
-rw-r--r--Source/WebKit2/UIProcess/GenericCallback.h114
1 files changed, 55 insertions, 59 deletions
diff --git a/Source/WebKit2/UIProcess/GenericCallback.h b/Source/WebKit2/UIProcess/GenericCallback.h
index c34414a..b0d7b9b 100644
--- a/Source/WebKit2/UIProcess/GenericCallback.h
+++ b/Source/WebKit2/UIProcess/GenericCallback.h
@@ -35,7 +35,35 @@
namespace WebKit {
-class VoidCallback : public RefCounted<VoidCallback> {
+class CallbackBase : public RefCounted<CallbackBase> {
+public:
+ virtual ~CallbackBase()
+ {
+ }
+
+ uint64_t callbackID() const { return m_callbackID; }
+
+protected:
+ CallbackBase(void* context)
+ : m_context(context)
+ , m_callbackID(generateCallbackID())
+ {
+ }
+
+ void* context() const { return m_context; }
+
+private:
+ static uint64_t generateCallbackID()
+ {
+ static uint64_t uniqueCallbackID = 1;
+ return uniqueCallbackID++;
+ }
+
+ void* m_context;
+ uint64_t m_callbackID;
+};
+
+class VoidCallback : public CallbackBase {
public:
typedef void (*CallbackFunction)(WKErrorRef, void*);
@@ -44,7 +72,7 @@ public:
return adoptRef(new VoidCallback(context, callback));
}
- VoidCallback()
+ virtual ~VoidCallback()
{
ASSERT(!m_callback);
}
@@ -53,7 +81,7 @@ public:
{
ASSERT(m_callback);
- m_callback(0, m_context);
+ m_callback(0, context());
m_callback = 0;
}
@@ -63,52 +91,41 @@ public:
ASSERT(m_callback);
RefPtr<WebError> error = WebError::create();
- m_callback(toAPI(error.get()), m_context);
+ m_callback(toAPI(error.get()), context());
m_callback = 0;
}
- uint64_t callbackID() const { return m_callbackID; }
-
private:
- static uint64_t generateCallbackID()
- {
- static uint64_t uniqueCallbackID = 1;
- return uniqueCallbackID++;
- }
-
VoidCallback(void* context, CallbackFunction callback)
- : m_context(context)
+ : CallbackBase(context)
, m_callback(callback)
- , m_callbackID(generateCallbackID())
{
}
- void* m_context;
CallbackFunction m_callback;
- uint64_t m_callbackID;
};
-// FIXME: Make a version of GenericCallback with two arguments, and define ComputedPagesCallback as a specialization.
-class ComputedPagesCallback : public RefCounted<ComputedPagesCallback> {
+template<typename APIReturnValueType, typename InternalReturnValueType = typename APITypeInfo<APIReturnValueType>::ImplType>
+class GenericCallback : public CallbackBase {
public:
- typedef void (*CallbackFunction)(const Vector<WebCore::IntRect>&, double, WKErrorRef, void*);
+ typedef void (*CallbackFunction)(APIReturnValueType, WKErrorRef, void*);
- static PassRefPtr<ComputedPagesCallback> create(void* context, CallbackFunction callback)
+ static PassRefPtr<GenericCallback> create(void* context, CallbackFunction callback)
{
- return adoptRef(new ComputedPagesCallback(context, callback));
+ return adoptRef(new GenericCallback(context, callback));
}
- ~ComputedPagesCallback()
+ virtual ~GenericCallback()
{
ASSERT(!m_callback);
}
- void performCallbackWithReturnValue(const Vector<WebCore::IntRect>& returnValue1, double returnValue2)
+ void performCallbackWithReturnValue(InternalReturnValueType returnValue)
{
ASSERT(m_callback);
- m_callback(returnValue1, returnValue2, 0, m_context);
+ m_callback(toAPI(returnValue), 0, context());
m_callback = 0;
}
@@ -118,52 +135,41 @@ public:
ASSERT(m_callback);
RefPtr<WebError> error = WebError::create();
- m_callback(Vector<WebCore::IntRect>(), 0, toAPI(error.get()), m_context);
+ m_callback(0, toAPI(error.get()), context());
m_callback = 0;
}
- uint64_t callbackID() const { return m_callbackID; }
-
private:
- static uint64_t generateCallbackID()
- {
- static uint64_t uniqueCallbackID = 1;
- return uniqueCallbackID++;
- }
-
- ComputedPagesCallback(void* context, CallbackFunction callback)
- : m_context(context)
+ GenericCallback(void* context, CallbackFunction callback)
+ : CallbackBase(context)
, m_callback(callback)
- , m_callbackID(generateCallbackID())
{
}
- void* m_context;
CallbackFunction m_callback;
- uint64_t m_callbackID;
};
-template<typename APIReturnValueType, typename InternalReturnValueType = typename APITypeInfo<APIReturnValueType>::ImplType>
-class GenericCallback : public RefCounted<GenericCallback<APIReturnValueType, InternalReturnValueType> > {
+// FIXME: Make a version of CallbackBase with two arguments, and define ComputedPagesCallback as a specialization.
+class ComputedPagesCallback : public CallbackBase {
public:
- typedef void (*CallbackFunction)(APIReturnValueType, WKErrorRef, void*);
+ typedef void (*CallbackFunction)(const Vector<WebCore::IntRect>&, double, WKErrorRef, void*);
- static PassRefPtr<GenericCallback> create(void* context, CallbackFunction callback)
+ static PassRefPtr<ComputedPagesCallback> create(void* context, CallbackFunction callback)
{
- return adoptRef(new GenericCallback(context, callback));
+ return adoptRef(new ComputedPagesCallback(context, callback));
}
- ~GenericCallback()
+ virtual ~ComputedPagesCallback()
{
ASSERT(!m_callback);
}
- void performCallbackWithReturnValue(InternalReturnValueType returnValue)
+ void performCallbackWithReturnValue(const Vector<WebCore::IntRect>& returnValue1, double returnValue2)
{
ASSERT(m_callback);
- m_callback(toAPI(returnValue), 0, m_context);
+ m_callback(returnValue1, returnValue2, 0, context());
m_callback = 0;
}
@@ -173,30 +179,20 @@ public:
ASSERT(m_callback);
RefPtr<WebError> error = WebError::create();
- m_callback(0, toAPI(error.get()), m_context);
+ m_callback(Vector<WebCore::IntRect>(), 0, toAPI(error.get()), context());
m_callback = 0;
}
- uint64_t callbackID() const { return m_callbackID; }
-
private:
- static uint64_t generateCallbackID()
- {
- static uint64_t uniqueCallbackID = 1;
- return uniqueCallbackID++;
- }
- GenericCallback(void* context, CallbackFunction callback)
- : m_context(context)
+ ComputedPagesCallback(void* context, CallbackFunction callback)
+ : CallbackBase(context)
, m_callback(callback)
- , m_callbackID(generateCallbackID())
{
}
- void* m_context;
CallbackFunction m_callback;
- uint64_t m_callbackID;
};
template<typename T>