Changeset 80322 in webkit
- Timestamp:
- Mar 3, 2011 9:36:03 PM (13 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r80309 r80322 1 2011-03-03 Jeff Miller <jeffm@apple.com> 2 3 Reviewed by Darin Adler. 4 5 Refactor classes in GenericCallback.h 6 https://bugs.webkit.org/show_bug.cgi?id=55732 7 8 Since we're going to need to add additional callback classes, make a CallbackBase class that manages 9 the context and the callback ID. The existing callback classes (VoidCallback, GenericCallback, and 10 ComputedPagesCallback) now all derive from CallbackBase. 11 12 Fix bug in VoidCallback where we meant to implement the destructor, but we were implementing the default 13 constructor instead (we forgot the leading ~). 14 15 * UIProcess/GenericCallback.h: 16 (WebKit::CallbackBase::~CallbackBase): 17 (WebKit::CallbackBase::callbackID): 18 (WebKit::CallbackBase::CallbackBase): 19 (WebKit::CallbackBase::context): 20 (WebKit::CallbackBase::generateCallbackID): 21 (WebKit::VoidCallback::~VoidCallback): 22 (WebKit::VoidCallback::performCallback): 23 (WebKit::VoidCallback::invalidate): 24 (WebKit::VoidCallback::VoidCallback): 25 (WebKit::GenericCallback::create): 26 (WebKit::GenericCallback::~GenericCallback): 27 (WebKit::GenericCallback::performCallbackWithReturnValue): 28 (WebKit::GenericCallback::invalidate): 29 (WebKit::GenericCallback::GenericCallback): 30 (WebKit::ComputedPagesCallback::create): 31 (WebKit::ComputedPagesCallback::~ComputedPagesCallback): 32 (WebKit::ComputedPagesCallback::performCallbackWithReturnValue): 33 (WebKit::ComputedPagesCallback::invalidate): 34 (WebKit::ComputedPagesCallback::ComputedPagesCallback): 35 1 36 2011-03-03 Adam Roben <aroben@apple.com> 2 37 -
trunk/Source/WebKit2/UIProcess/GenericCallback.h
r76821 r80322 36 36 namespace WebKit { 37 37 38 class VoidCallback : public RefCounted<VoidCallback> { 38 class CallbackBase : public RefCounted<CallbackBase> { 39 public: 40 virtual ~CallbackBase() 41 { 42 } 43 44 uint64_t callbackID() const { return m_callbackID; } 45 46 protected: 47 CallbackBase(void* context) 48 : m_context(context) 49 , m_callbackID(generateCallbackID()) 50 { 51 } 52 53 void* context() const { return m_context; } 54 55 private: 56 static uint64_t generateCallbackID() 57 { 58 static uint64_t uniqueCallbackID = 1; 59 return uniqueCallbackID++; 60 } 61 62 void* m_context; 63 uint64_t m_callbackID; 64 }; 65 66 class VoidCallback : public CallbackBase { 39 67 public: 40 68 typedef void (*CallbackFunction)(WKErrorRef, void*); … … 45 73 } 46 74 47 VoidCallback()75 virtual ~VoidCallback() 48 76 { 49 77 ASSERT(!m_callback); … … 54 82 ASSERT(m_callback); 55 83 56 m_callback(0, m_context);84 m_callback(0, context()); 57 85 58 86 m_callback = 0; … … 64 92 65 93 RefPtr<WebError> error = WebError::create(); 66 m_callback(toAPI(error.get()), m_context);94 m_callback(toAPI(error.get()), context()); 67 95 68 96 m_callback = 0; 69 97 } 70 98 71 uint64_t callbackID() const { return m_callbackID; } 72 73 private: 74 static uint64_t generateCallbackID() 75 { 76 static uint64_t uniqueCallbackID = 1; 77 return uniqueCallbackID++; 78 } 79 99 private: 80 100 VoidCallback(void* context, CallbackFunction callback) 81 : m_context(context)101 : CallbackBase(context) 82 102 , m_callback(callback) 83 , m_callbackID(generateCallbackID()) 84 { 85 } 86 87 void* m_context; 103 { 104 } 105 88 106 CallbackFunction m_callback; 89 uint64_t m_callbackID; 90 }; 91 92 // FIXME: Make a version of GenericCallback with two arguments, and define ComputedPagesCallback as a specialization. 93 class ComputedPagesCallback : public RefCounted<ComputedPagesCallback> { 94 public: 95 typedef void (*CallbackFunction)(const Vector<WebCore::IntRect>&, double, WKErrorRef, void*); 96 97 static PassRefPtr<ComputedPagesCallback> create(void* context, CallbackFunction callback) 98 { 99 return adoptRef(new ComputedPagesCallback(context, callback)); 100 } 101 102 ~ComputedPagesCallback() 107 }; 108 109 template<typename APIReturnValueType, typename InternalReturnValueType = typename APITypeInfo<APIReturnValueType>::ImplType> 110 class GenericCallback : public CallbackBase { 111 public: 112 typedef void (*CallbackFunction)(APIReturnValueType, WKErrorRef, void*); 113 114 static PassRefPtr<GenericCallback> create(void* context, CallbackFunction callback) 115 { 116 return adoptRef(new GenericCallback(context, callback)); 117 } 118 119 virtual ~GenericCallback() 103 120 { 104 121 ASSERT(!m_callback); 105 122 } 106 123 107 void performCallbackWithReturnValue( const Vector<WebCore::IntRect>& returnValue1, double returnValue2)108 { 109 ASSERT(m_callback); 110 111 m_callback( returnValue1, returnValue2, 0, m_context);124 void performCallbackWithReturnValue(InternalReturnValueType returnValue) 125 { 126 ASSERT(m_callback); 127 128 m_callback(toAPI(returnValue), 0, context()); 112 129 113 130 m_callback = 0; … … 119 136 120 137 RefPtr<WebError> error = WebError::create(); 121 m_callback( Vector<WebCore::IntRect>(), 0, toAPI(error.get()), m_context);138 m_callback(0, toAPI(error.get()), context()); 122 139 123 140 m_callback = 0; 124 141 } 125 142 126 uint64_t callbackID() const { return m_callbackID; } 127 128 private: 129 static uint64_t generateCallbackID() 130 { 131 static uint64_t uniqueCallbackID = 1; 132 return uniqueCallbackID++; 133 } 134 135 ComputedPagesCallback(void* context, CallbackFunction callback) 136 : m_context(context) 143 private: 144 GenericCallback(void* context, CallbackFunction callback) 145 : CallbackBase(context) 137 146 , m_callback(callback) 138 , m_callbackID(generateCallbackID()) 139 { 140 } 141 142 void* m_context; 147 { 148 } 149 143 150 CallbackFunction m_callback; 144 uint64_t m_callbackID; 145 }; 146 147 template<typename APIReturnValueType, typename InternalReturnValueType = typename APITypeInfo<APIReturnValueType>::ImplType> 148 class GenericCallback : public RefCounted<GenericCallback<APIReturnValueType, InternalReturnValueType> > { 149 public: 150 typedef void (*CallbackFunction)(APIReturnValueType, WKErrorRef, void*); 151 152 static PassRefPtr<GenericCallback> create(void* context, CallbackFunction callback) 153 { 154 return adoptRef(new GenericCallback(context, callback)); 155 } 156 157 ~GenericCallback() 151 }; 152 153 // FIXME: Make a version of CallbackBase with two arguments, and define ComputedPagesCallback as a specialization. 154 class ComputedPagesCallback : public CallbackBase { 155 public: 156 typedef void (*CallbackFunction)(const Vector<WebCore::IntRect>&, double, WKErrorRef, void*); 157 158 static PassRefPtr<ComputedPagesCallback> create(void* context, CallbackFunction callback) 159 { 160 return adoptRef(new ComputedPagesCallback(context, callback)); 161 } 162 163 virtual ~ComputedPagesCallback() 158 164 { 159 165 ASSERT(!m_callback); 160 166 } 161 167 162 void performCallbackWithReturnValue( InternalReturnValueType returnValue)163 { 164 ASSERT(m_callback); 165 166 m_callback( toAPI(returnValue), 0, m_context);168 void performCallbackWithReturnValue(const Vector<WebCore::IntRect>& returnValue1, double returnValue2) 169 { 170 ASSERT(m_callback); 171 172 m_callback(returnValue1, returnValue2, 0, context()); 167 173 168 174 m_callback = 0; … … 174 180 175 181 RefPtr<WebError> error = WebError::create(); 176 m_callback( 0, toAPI(error.get()), m_context);182 m_callback(Vector<WebCore::IntRect>(), 0, toAPI(error.get()), context()); 177 183 178 184 m_callback = 0; 179 185 } 180 186 181 uint64_t callbackID() const { return m_callbackID; } 182 183 private: 184 static uint64_t generateCallbackID() 185 { 186 static uint64_t uniqueCallbackID = 1; 187 return uniqueCallbackID++; 188 } 189 190 GenericCallback(void* context, CallbackFunction callback) 191 : m_context(context) 187 private: 188 189 ComputedPagesCallback(void* context, CallbackFunction callback) 190 : CallbackBase(context) 192 191 , m_callback(callback) 193 , m_callbackID(generateCallbackID()) 194 { 195 } 196 197 void* m_context; 192 { 193 } 194 198 195 CallbackFunction m_callback; 199 uint64_t m_callbackID;200 196 }; 201 197
Note: See TracChangeset
for help on using the changeset viewer.