OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 // | 69 // |
70 // Now when calling into a WebKit API that requires a WebCallbacks<blink::WebMyC
lass, blink::WebMyClass>*: | 70 // Now when calling into a WebKit API that requires a WebCallbacks<blink::WebMyC
lass, blink::WebMyClass>*: |
71 // | 71 // |
72 // // call signature: callSomeMethod(WebCallbacks<MyClass, MyClass>* callback
s) | 72 // // call signature: callSomeMethod(WebCallbacks<MyClass, MyClass>* callback
s) |
73 // webObject->callSomeMethod(new CallbackPromiseAdapter<MyClass, MyClass>(res
olver, scriptExecutionContext)); | 73 // webObject->callSomeMethod(new CallbackPromiseAdapter<MyClass, MyClass>(res
olver, scriptExecutionContext)); |
74 // | 74 // |
75 // Note that this class does not manage its own lifetime. In this | 75 // Note that this class does not manage its own lifetime. In this |
76 // example that ownership of the WebCallbacks instance is being passed | 76 // example that ownership of the WebCallbacks instance is being passed |
77 // in and it is up to the callee to free the WebCallbacks instace. | 77 // in and it is up to the callee to free the WebCallbacks instace. |
78 template<typename S, typename T> | 78 template<typename S, typename T> |
79 class CallbackPromiseAdapter final : public blink::WebCallbacks<typename S::WebT
ype, typename T::WebType> { | 79 class CallbackPromiseAdapter final : public WebCallbacks<typename S::WebType, ty
pename T::WebType> { |
80 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); | 80 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); |
81 public: | 81 public: |
82 explicit CallbackPromiseAdapter(PassRefPtrWillBeRawPtr<ScriptPromiseResolver
> resolver) | 82 explicit CallbackPromiseAdapter(PassRefPtrWillBeRawPtr<ScriptPromiseResolver
> resolver) |
83 : m_resolver(resolver) | 83 : m_resolver(resolver) |
84 { | 84 { |
85 ASSERT(m_resolver); | 85 ASSERT(m_resolver); |
86 } | 86 } |
87 virtual ~CallbackPromiseAdapter() { } | 87 virtual ~CallbackPromiseAdapter() { } |
88 | 88 |
89 virtual void onSuccess(typename S::WebType* result) override | 89 virtual void onSuccess(typename S::WebType* result) override |
(...skipping 17 matching lines...) Expand all Loading... |
107 return; | 107 return; |
108 } | 108 } |
109 m_resolver->reject(T::take(m_resolver.get(), error)); | 109 m_resolver->reject(T::take(m_resolver.get(), error)); |
110 } | 110 } |
111 | 111 |
112 private: | 112 private: |
113 RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver; | 113 RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver; |
114 }; | 114 }; |
115 | 115 |
116 template<typename T> | 116 template<typename T> |
117 class CallbackPromiseAdapter<void, T> final : public blink::WebCallbacks<void, t
ypename T::WebType> { | 117 class CallbackPromiseAdapter<void, T> final : public WebCallbacks<void, typename
T::WebType> { |
118 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); | 118 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); |
119 public: | 119 public: |
120 explicit CallbackPromiseAdapter(PassRefPtrWillBeRawPtr<ScriptPromiseResolver
> resolver) | 120 explicit CallbackPromiseAdapter(PassRefPtrWillBeRawPtr<ScriptPromiseResolver
> resolver) |
121 : m_resolver(resolver) | 121 : m_resolver(resolver) |
122 { | 122 { |
123 ASSERT(m_resolver); | 123 ASSERT(m_resolver); |
124 } | 124 } |
125 virtual ~CallbackPromiseAdapter() { } | 125 virtual ~CallbackPromiseAdapter() { } |
126 | 126 |
127 virtual void onSuccess() override | 127 virtual void onSuccess() override |
(...skipping 10 matching lines...) Expand all Loading... |
138 return; | 138 return; |
139 } | 139 } |
140 m_resolver->reject(T::take(m_resolver.get(), error)); | 140 m_resolver->reject(T::take(m_resolver.get(), error)); |
141 } | 141 } |
142 | 142 |
143 private: | 143 private: |
144 RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver; | 144 RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver; |
145 }; | 145 }; |
146 | 146 |
147 template<typename S> | 147 template<typename S> |
148 class CallbackPromiseAdapter<S, void> final : public blink::WebCallbacks<typenam
e S::WebType, void> { | 148 class CallbackPromiseAdapter<S, void> final : public WebCallbacks<typename S::We
bType, void> { |
149 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); | 149 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); |
150 public: | 150 public: |
151 explicit CallbackPromiseAdapter(PassRefPtrWillBeRawPtr<ScriptPromiseResolver
> resolver) | 151 explicit CallbackPromiseAdapter(PassRefPtrWillBeRawPtr<ScriptPromiseResolver
> resolver) |
152 : m_resolver(resolver) | 152 : m_resolver(resolver) |
153 { | 153 { |
154 ASSERT(m_resolver); | 154 ASSERT(m_resolver); |
155 } | 155 } |
156 virtual ~CallbackPromiseAdapter() { } | 156 virtual ~CallbackPromiseAdapter() { } |
157 | 157 |
158 virtual void onSuccess(typename S::WebType* result) override | 158 virtual void onSuccess(typename S::WebType* result) override |
(...skipping 10 matching lines...) Expand all Loading... |
169 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | 169 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) |
170 return; | 170 return; |
171 m_resolver->reject(); | 171 m_resolver->reject(); |
172 } | 172 } |
173 | 173 |
174 private: | 174 private: |
175 RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver; | 175 RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver; |
176 }; | 176 }; |
177 | 177 |
178 template<typename T> | 178 template<typename T> |
179 class CallbackPromiseAdapter<bool, T> final : public blink::WebCallbacks<bool, t
ypename T::WebType> { | 179 class CallbackPromiseAdapter<bool, T> final : public WebCallbacks<bool, typename
T::WebType> { |
180 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); | 180 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); |
181 public: | 181 public: |
182 explicit CallbackPromiseAdapter(PassRefPtrWillBeRawPtr<ScriptPromiseResolver
> resolver) | 182 explicit CallbackPromiseAdapter(PassRefPtrWillBeRawPtr<ScriptPromiseResolver
> resolver) |
183 : m_resolver(resolver) | 183 : m_resolver(resolver) |
184 { | 184 { |
185 ASSERT(m_resolver); | 185 ASSERT(m_resolver); |
186 } | 186 } |
187 virtual ~CallbackPromiseAdapter() { } | 187 virtual ~CallbackPromiseAdapter() { } |
188 | 188 |
189 virtual void onSuccess(bool* result) override | 189 virtual void onSuccess(bool* result) override |
(...skipping 10 matching lines...) Expand all Loading... |
200 return; | 200 return; |
201 } | 201 } |
202 m_resolver->reject(T::take(m_resolver.get(), error)); | 202 m_resolver->reject(T::take(m_resolver.get(), error)); |
203 } | 203 } |
204 | 204 |
205 private: | 205 private: |
206 RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver; | 206 RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver; |
207 }; | 207 }; |
208 | 208 |
209 template<> | 209 template<> |
210 class CallbackPromiseAdapter<void, void> final : public blink::WebCallbacks<void
, void> { | 210 class CallbackPromiseAdapter<void, void> final : public WebCallbacks<void, void>
{ |
211 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); | 211 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); |
212 public: | 212 public: |
213 explicit CallbackPromiseAdapter(PassRefPtrWillBeRawPtr<ScriptPromiseResolver
> resolver) | 213 explicit CallbackPromiseAdapter(PassRefPtrWillBeRawPtr<ScriptPromiseResolver
> resolver) |
214 : m_resolver(resolver) | 214 : m_resolver(resolver) |
215 { | 215 { |
216 ASSERT(m_resolver); | 216 ASSERT(m_resolver); |
217 } | 217 } |
218 virtual ~CallbackPromiseAdapter() { } | 218 virtual ~CallbackPromiseAdapter() { } |
219 | 219 |
220 virtual void onSuccess() override | 220 virtual void onSuccess() override |
221 { | 221 { |
222 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | 222 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) |
223 return; | 223 return; |
224 m_resolver->resolve(); | 224 m_resolver->resolve(); |
225 } | 225 } |
226 | 226 |
227 virtual void onError() override | 227 virtual void onError() override |
228 { | 228 { |
229 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | 229 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) |
230 return; | 230 return; |
231 m_resolver->reject(); | 231 m_resolver->reject(); |
232 } | 232 } |
233 | 233 |
234 private: | 234 private: |
235 RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver; | 235 RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver; |
236 }; | 236 }; |
237 | 237 |
238 template<> | 238 template<> |
239 class CallbackPromiseAdapter<bool, void> final : public blink::WebCallbacks<bool
, void> { | 239 class CallbackPromiseAdapter<bool, void> final : public WebCallbacks<bool, void>
{ |
240 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); | 240 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); |
241 public: | 241 public: |
242 explicit CallbackPromiseAdapter(PassRefPtrWillBeRawPtr<ScriptPromiseResolver
> resolver) | 242 explicit CallbackPromiseAdapter(PassRefPtrWillBeRawPtr<ScriptPromiseResolver
> resolver) |
243 : m_resolver(resolver) | 243 : m_resolver(resolver) |
244 { | 244 { |
245 ASSERT(m_resolver); | 245 ASSERT(m_resolver); |
246 } | 246 } |
247 virtual ~CallbackPromiseAdapter() { } | 247 virtual ~CallbackPromiseAdapter() { } |
248 | 248 |
249 virtual void onSuccess(bool* result) override | 249 virtual void onSuccess(bool* result) override |
(...skipping 10 matching lines...) Expand all Loading... |
260 m_resolver->reject(); | 260 m_resolver->reject(); |
261 } | 261 } |
262 | 262 |
263 private: | 263 private: |
264 RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver; | 264 RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver; |
265 }; | 265 }; |
266 | 266 |
267 } // namespace blink | 267 } // namespace blink |
268 | 268 |
269 #endif | 269 #endif |
OLD | NEW |