Chromium Code Reviews| 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 18 matching lines...) Expand all Loading... | |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef CallbackPromiseAdapter_h | 31 #ifndef CallbackPromiseAdapter_h |
| 32 #define CallbackPromiseAdapter_h | 32 #define CallbackPromiseAdapter_h |
| 33 | 33 |
| 34 #include "bindings/core/v8/ScriptPromiseResolver.h" | 34 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 35 #include "public/platform/WebCallbacks.h" | 35 #include "public/platform/WebCallbacks.h" |
| 36 | 36 |
| 37 namespace blink { | 37 namespace blink { |
| 38 | 38 |
| 39 // TODO(nhiroki): Remove ifdef hack after Chromium-side patch is landed. | |
| 40 // http://crbug.com/493531 | |
| 41 #define CRBUG_493531 | |
| 42 | |
| 39 // This class provides an easy way to convert from a Script-exposed | 43 // This class provides an easy way to convert from a Script-exposed |
| 40 // class (i.e. a class that has a toV8() overload) that uses Promises | 44 // class (i.e. a class that has a toV8() overload) that uses Promises |
| 41 // to a WebKit API class that uses WebCallbacks. You can define | 45 // to a WebKit API class that uses WebCallbacks. You can define |
| 42 // separate Success and Error classes, but this example just uses one | 46 // separate Success and Error classes, but this example just uses one |
| 43 // object for both. | 47 // object for both. |
| 44 // | 48 // |
| 45 // To use: | 49 // To use: |
| 46 // | 50 // |
| 47 // class MyClass ... { | 51 // class MyClass ... { |
| 48 // typedef blink::WebMyClass WebType; | 52 // typedef blink::WebMyClass WebType; |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 class CallbackPromiseAdapter<bool, T> final : public WebCallbacks<bool, typename T::WebType> { | 179 class CallbackPromiseAdapter<bool, T> final : public WebCallbacks<bool, typename T::WebType> { |
| 176 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); | 180 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); |
| 177 public: | 181 public: |
| 178 explicit CallbackPromiseAdapter(PassRefPtrWillBeRawPtr<ScriptPromiseResolver > resolver) | 182 explicit CallbackPromiseAdapter(PassRefPtrWillBeRawPtr<ScriptPromiseResolver > resolver) |
| 179 : m_resolver(resolver) | 183 : m_resolver(resolver) |
| 180 { | 184 { |
| 181 ASSERT(m_resolver); | 185 ASSERT(m_resolver); |
| 182 } | 186 } |
| 183 virtual ~CallbackPromiseAdapter() { } | 187 virtual ~CallbackPromiseAdapter() { } |
| 184 | 188 |
| 185 // TODO(nhiroki): onSuccess should take ownership of a bool object for | 189 // Takes ownership of |result|. |
| 186 // consistency. (http://crbug.com/493531) | |
| 187 virtual void onSuccess(bool* result) override | 190 virtual void onSuccess(bool* result) override |
| 188 { | 191 { |
| 192 OwnPtr<bool> ownPtr = adoptPtr(result); | |
| 189 if (!m_resolver->executionContext() || m_resolver->executionContext()->a ctiveDOMObjectsAreStopped()) | 193 if (!m_resolver->executionContext() || m_resolver->executionContext()->a ctiveDOMObjectsAreStopped()) |
| 190 return; | 194 return; |
| 191 m_resolver->resolve(*result); | 195 m_resolver->resolve(*ownPtr); |
| 192 } | 196 } |
| 193 | 197 |
| 194 // Takes ownership of |error|. | 198 // Takes ownership of |error|. |
| 195 virtual void onError(typename T::WebType* error) override | 199 virtual void onError(typename T::WebType* error) override |
| 196 { | 200 { |
| 197 OwnPtr<typename T::WebType> ownPtr = adoptPtr(error); | 201 OwnPtr<typename T::WebType> ownPtr = adoptPtr(error); |
| 198 if (!m_resolver->executionContext() || m_resolver->executionContext()->a ctiveDOMObjectsAreStopped()) | 202 if (!m_resolver->executionContext() || m_resolver->executionContext()->a ctiveDOMObjectsAreStopped()) |
| 199 return; | 203 return; |
| 200 m_resolver->reject(T::take(m_resolver.get(), ownPtr.release())); | 204 m_resolver->reject(T::take(m_resolver.get(), ownPtr.release())); |
| 201 } | 205 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 class CallbackPromiseAdapter<bool, void> final : public WebCallbacks<bool, void> { | 241 class CallbackPromiseAdapter<bool, void> final : public WebCallbacks<bool, void> { |
| 238 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); | 242 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); |
| 239 public: | 243 public: |
| 240 explicit CallbackPromiseAdapter(PassRefPtrWillBeRawPtr<ScriptPromiseResolver > resolver) | 244 explicit CallbackPromiseAdapter(PassRefPtrWillBeRawPtr<ScriptPromiseResolver > resolver) |
| 241 : m_resolver(resolver) | 245 : m_resolver(resolver) |
| 242 { | 246 { |
| 243 ASSERT(m_resolver); | 247 ASSERT(m_resolver); |
| 244 } | 248 } |
| 245 virtual ~CallbackPromiseAdapter() { } | 249 virtual ~CallbackPromiseAdapter() { } |
| 246 | 250 |
| 247 // TODO(nhiroki): onSuccess should take ownership of a bool object for | 251 // Takes ownership of |result|. |
| 248 // consistency. (http://crbug.com/493531) | |
| 249 virtual void onSuccess(bool* result) override | 252 virtual void onSuccess(bool* result) override |
| 250 { | 253 { |
| 254 OwnPtr<bool> ownPtr = adoptPtr(result); | |
| 251 if (!m_resolver->executionContext() || m_resolver->executionContext()->a ctiveDOMObjectsAreStopped()) | 255 if (!m_resolver->executionContext() || m_resolver->executionContext()->a ctiveDOMObjectsAreStopped()) |
| 252 return; | 256 return; |
| 253 m_resolver->resolve(*result); | 257 m_resolver->resolve(*ownPtr); |
|
haraken
2015/07/03 05:57:49
This will end up with calling resolveOrReject(OwnP
yhirano
2015/07/03 06:04:12
This statement passes |*ownPtr| of type |bool|, so
haraken
2015/07/03 06:09:06
ah, OK. Then what's the merit of using an OwnPtr?
nhiroki
2015/07/03 06:59:39
Sorry, I'm not really sure why you feel this a bit
| |
| 254 } | 258 } |
| 255 | 259 |
| 256 virtual void onError() override | 260 virtual void onError() override |
| 257 { | 261 { |
| 258 if (!m_resolver->executionContext() || m_resolver->executionContext()->a ctiveDOMObjectsAreStopped()) | 262 if (!m_resolver->executionContext() || m_resolver->executionContext()->a ctiveDOMObjectsAreStopped()) |
| 259 return; | 263 return; |
| 260 m_resolver->reject(); | 264 m_resolver->reject(); |
| 261 } | 265 } |
| 262 | 266 |
| 263 private: | 267 private: |
| 264 RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver; | 268 RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver; |
| 265 }; | 269 }; |
| 266 | 270 |
| 267 } // namespace blink | 271 } // namespace blink |
| 268 | 272 |
| 269 #endif | 273 #endif |
| OLD | NEW |