| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // | 64 // |
| 65 // Now when calling into a WebKit API that requires a WebCallbacks<blink::WebMyC
lass, blink::WebMyClass>*: | 65 // Now when calling into a WebKit API that requires a WebCallbacks<blink::WebMyC
lass, blink::WebMyClass>*: |
| 66 // | 66 // |
| 67 // // call signature: callSomeMethod(WebCallbacks<MyClass, MyClass>* callback
s) | 67 // // call signature: callSomeMethod(WebCallbacks<MyClass, MyClass>* callback
s) |
| 68 // webObject->callSomeMethod(new CallbackPromiseAdapter<MyClass, MyClass>(res
olver, scriptExecutionContext)); | 68 // webObject->callSomeMethod(new CallbackPromiseAdapter<MyClass, MyClass>(res
olver, scriptExecutionContext)); |
| 69 // | 69 // |
| 70 // Note: | 70 // Note: |
| 71 // - This class does not manage its own lifetime. In this example that ownership | 71 // - This class does not manage its own lifetime. In this example that ownership |
| 72 // of the WebCallbacks instance is being passed in and it is up to the callee | 72 // of the WebCallbacks instance is being passed in and it is up to the callee |
| 73 // to free the WebCallbacks instance. | 73 // to free the WebCallbacks instance. |
| 74 // - onSuccess and onError take ownership of the given WebType instance. | 74 // - onSuccess(typename S::WebType*) and onError(typename T::WebType*) take |
| 75 // ownership of the given WebType instance. |
| 75 template<typename S, typename T> | 76 template<typename S, typename T> |
| 76 class CallbackPromiseAdapter final : public WebCallbacks<typename S::WebType, ty
pename T::WebType> { | 77 class CallbackPromiseAdapter final : public WebCallbacks<typename S::WebType, ty
pename T::WebType> { |
| 77 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); | 78 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); |
| 78 public: | 79 public: |
| 79 explicit CallbackPromiseAdapter(PassRefPtrWillBeRawPtr<ScriptPromiseResolver
> resolver) | 80 explicit CallbackPromiseAdapter(PassRefPtrWillBeRawPtr<ScriptPromiseResolver
> resolver) |
| 80 : m_resolver(resolver) | 81 : m_resolver(resolver) |
| 81 { | 82 { |
| 82 ASSERT(m_resolver); | 83 ASSERT(m_resolver); |
| 83 } | 84 } |
| 84 virtual ~CallbackPromiseAdapter() { } | 85 virtual ~CallbackPromiseAdapter() { } |
| 85 | 86 |
| 87 virtual void onSuccess(typename S::WebType result) override |
| 88 { |
| 89 ASSERT_NOT_REACHED(); |
| 90 } |
| 91 |
| 86 // Takes ownership of |result|. | 92 // Takes ownership of |result|. |
| 87 virtual void onSuccess(typename S::WebType* result) override | 93 virtual void onSuccess(typename S::WebType* result) override |
| 88 { | 94 { |
| 89 OwnPtr<typename S::WebType> ownPtr = adoptPtr(result); | 95 OwnPtr<typename S::WebType> ownPtr = adoptPtr(result); |
| 90 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | 96 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) |
| 91 return; | 97 return; |
| 92 if (!result) { | 98 if (!result) { |
| 93 m_resolver->resolve(v8::Null(m_resolver->scriptState()->isolate())); | 99 m_resolver->resolve(v8::Null(m_resolver->scriptState()->isolate())); |
| 94 return; | 100 return; |
| 95 } | 101 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 class CallbackPromiseAdapter<S, void> final : public WebCallbacks<typename S::We
bType, void> { | 150 class CallbackPromiseAdapter<S, void> final : public WebCallbacks<typename S::We
bType, void> { |
| 145 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); | 151 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); |
| 146 public: | 152 public: |
| 147 explicit CallbackPromiseAdapter(PassRefPtrWillBeRawPtr<ScriptPromiseResolver
> resolver) | 153 explicit CallbackPromiseAdapter(PassRefPtrWillBeRawPtr<ScriptPromiseResolver
> resolver) |
| 148 : m_resolver(resolver) | 154 : m_resolver(resolver) |
| 149 { | 155 { |
| 150 ASSERT(m_resolver); | 156 ASSERT(m_resolver); |
| 151 } | 157 } |
| 152 virtual ~CallbackPromiseAdapter() { } | 158 virtual ~CallbackPromiseAdapter() { } |
| 153 | 159 |
| 160 virtual void onSuccess(typename S::WebType result) override |
| 161 { |
| 162 ASSERT_NOT_REACHED(); |
| 163 } |
| 164 |
| 154 // Takes ownership of |result|. | 165 // Takes ownership of |result|. |
| 155 virtual void onSuccess(typename S::WebType* result) override | 166 virtual void onSuccess(typename S::WebType* result) override |
| 156 { | 167 { |
| 157 OwnPtr<typename S::WebType> ownPtr = adoptPtr(result); | 168 OwnPtr<typename S::WebType> ownPtr = adoptPtr(result); |
| 158 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | 169 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) |
| 159 return; | 170 return; |
| 160 m_resolver->resolve(S::take(m_resolver.get(), ownPtr.release())); | 171 m_resolver->resolve(S::take(m_resolver.get(), ownPtr.release())); |
| 161 } | 172 } |
| 162 | 173 |
| 163 virtual void onError() override | 174 virtual void onError() override |
| (...skipping 11 matching lines...) Expand all Loading... |
| 175 class CallbackPromiseAdapter<bool, T> final : public WebCallbacks<bool, typename
T::WebType> { | 186 class CallbackPromiseAdapter<bool, T> final : public WebCallbacks<bool, typename
T::WebType> { |
| 176 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); | 187 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); |
| 177 public: | 188 public: |
| 178 explicit CallbackPromiseAdapter(PassRefPtrWillBeRawPtr<ScriptPromiseResolver
> resolver) | 189 explicit CallbackPromiseAdapter(PassRefPtrWillBeRawPtr<ScriptPromiseResolver
> resolver) |
| 179 : m_resolver(resolver) | 190 : m_resolver(resolver) |
| 180 { | 191 { |
| 181 ASSERT(m_resolver); | 192 ASSERT(m_resolver); |
| 182 } | 193 } |
| 183 virtual ~CallbackPromiseAdapter() { } | 194 virtual ~CallbackPromiseAdapter() { } |
| 184 | 195 |
| 185 // TODO(nhiroki): onSuccess should take ownership of a bool object for | 196 virtual void onSuccess(bool result) override |
| 186 // consistency. (http://crbug.com/493531) | |
| 187 virtual void onSuccess(bool* result) override | |
| 188 { | 197 { |
| 189 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | 198 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) |
| 190 return; | 199 return; |
| 200 m_resolver->resolve(result); |
| 201 } |
| 202 |
| 203 virtual void onSuccess(bool* result) override |
| 204 { |
| 205 // TODO(nhiroki): Replace with ASSERT_NOT_REACHED() after chromium-side |
| 206 // changes are landed (http://crbug.com/493531). |
| 207 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) |
| 208 return; |
| 191 m_resolver->resolve(*result); | 209 m_resolver->resolve(*result); |
| 192 } | 210 } |
| 193 | 211 |
| 194 // Takes ownership of |error|. | 212 // Takes ownership of |error|. |
| 195 virtual void onError(typename T::WebType* error) override | 213 virtual void onError(typename T::WebType* error) override |
| 196 { | 214 { |
| 197 OwnPtr<typename T::WebType> ownPtr = adoptPtr(error); | 215 OwnPtr<typename T::WebType> ownPtr = adoptPtr(error); |
| 198 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | 216 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) |
| 199 return; | 217 return; |
| 200 m_resolver->reject(T::take(m_resolver.get(), ownPtr.release())); | 218 m_resolver->reject(T::take(m_resolver.get(), ownPtr.release())); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 226 { | 244 { |
| 227 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | 245 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) |
| 228 return; | 246 return; |
| 229 m_resolver->reject(); | 247 m_resolver->reject(); |
| 230 } | 248 } |
| 231 | 249 |
| 232 private: | 250 private: |
| 233 RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver; | 251 RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver; |
| 234 }; | 252 }; |
| 235 | 253 |
| 236 template<> | |
| 237 class CallbackPromiseAdapter<bool, void> final : public WebCallbacks<bool, void>
{ | |
| 238 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); | |
| 239 public: | |
| 240 explicit CallbackPromiseAdapter(PassRefPtrWillBeRawPtr<ScriptPromiseResolver
> resolver) | |
| 241 : m_resolver(resolver) | |
| 242 { | |
| 243 ASSERT(m_resolver); | |
| 244 } | |
| 245 virtual ~CallbackPromiseAdapter() { } | |
| 246 | |
| 247 // TODO(nhiroki): onSuccess should take ownership of a bool object for | |
| 248 // consistency. (http://crbug.com/493531) | |
| 249 virtual void onSuccess(bool* result) override | |
| 250 { | |
| 251 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | |
| 252 return; | |
| 253 m_resolver->resolve(*result); | |
| 254 } | |
| 255 | |
| 256 virtual void onError() override | |
| 257 { | |
| 258 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | |
| 259 return; | |
| 260 m_resolver->reject(); | |
| 261 } | |
| 262 | |
| 263 private: | |
| 264 RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver; | |
| 265 }; | |
| 266 | |
| 267 } // namespace blink | 254 } // namespace blink |
| 268 | 255 |
| 269 #endif | 256 #endif |
| OLD | NEW |