diff options
Diffstat (limited to 'Source/WebKit2/UIProcess/GenericCallback.h')
-rw-r--r-- | Source/WebKit2/UIProcess/GenericCallback.h | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/Source/WebKit2/UIProcess/GenericCallback.h b/Source/WebKit2/UIProcess/GenericCallback.h index b72314a..c34414a 100644 --- a/Source/WebKit2/UIProcess/GenericCallback.h +++ b/Source/WebKit2/UIProcess/GenericCallback.h @@ -35,6 +35,115 @@ namespace WebKit { +class VoidCallback : public RefCounted<VoidCallback> { +public: + typedef void (*CallbackFunction)(WKErrorRef, void*); + + static PassRefPtr<VoidCallback> create(void* context, CallbackFunction callback) + { + return adoptRef(new VoidCallback(context, callback)); + } + + VoidCallback() + { + ASSERT(!m_callback); + } + + void performCallback() + { + ASSERT(m_callback); + + m_callback(0, m_context); + + m_callback = 0; + } + + void invalidate() + { + ASSERT(m_callback); + + RefPtr<WebError> error = WebError::create(); + m_callback(toAPI(error.get()), m_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) + , 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> { +public: + typedef void (*CallbackFunction)(const Vector<WebCore::IntRect>&, double, WKErrorRef, void*); + + static PassRefPtr<ComputedPagesCallback> create(void* context, CallbackFunction callback) + { + return adoptRef(new ComputedPagesCallback(context, callback)); + } + + ~ComputedPagesCallback() + { + ASSERT(!m_callback); + } + + void performCallbackWithReturnValue(const Vector<WebCore::IntRect>& returnValue1, double returnValue2) + { + ASSERT(m_callback); + + m_callback(returnValue1, returnValue2, 0, m_context); + + m_callback = 0; + } + + void invalidate() + { + ASSERT(m_callback); + + RefPtr<WebError> error = WebError::create(); + m_callback(Vector<WebCore::IntRect>(), 0, toAPI(error.get()), m_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) + , 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> > { public: |