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 13 matching lines...) Expand all Loading... | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 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/v8/NewScriptState.h" | 34 #include "bindings/v8/ScriptPromiseResolverWithContext.h" |
| 35 #include "bindings/v8/ScriptPromiseResolver.h" | |
| 36 #include "public/platform/WebCallbacks.h" | 35 #include "public/platform/WebCallbacks.h" |
| 37 | 36 |
| 38 namespace WebCore { | 37 namespace WebCore { |
| 39 | 38 |
| 40 // This class provides an easy way to convert from a Script-exposed | 39 // This class provides an easy way to convert from a Script-exposed |
| 41 // class (i.e. a class that has a toV8() overload) that uses Promises | 40 // class (i.e. a class that has a toV8() overload) that uses Promises |
| 42 // to a WebKit API class that uses WebCallbacks. You can define | 41 // to a WebKit API class that uses WebCallbacks. You can define |
| 43 // seperate Success and Error classes, but this example just uses one | 42 // seperate Success and Error classes, but this example just uses one |
| 44 // object for both. | 43 // object for both. |
| 45 // | 44 // |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 57 // | 56 // |
| 58 // // call signature: callSomeMethod(WebCallbacks<MyClass, MyClass>* callback s) | 57 // // call signature: callSomeMethod(WebCallbacks<MyClass, MyClass>* callback s) |
| 59 // webObject->callSomeMethod(new CallbackPromiseAdapter<MyClass, MyClass>(res olver, scriptExecutionContext)); | 58 // webObject->callSomeMethod(new CallbackPromiseAdapter<MyClass, MyClass>(res olver, scriptExecutionContext)); |
| 60 // | 59 // |
| 61 // Note that this class does not manage its own lifetime. In this | 60 // Note that this class does not manage its own lifetime. In this |
| 62 // example that ownership of the WebCallbacks instance is being passed | 61 // example that ownership of the WebCallbacks instance is being passed |
| 63 // in and it is up to the callee to free the WebCallbacks instace. | 62 // in and it is up to the callee to free the WebCallbacks instace. |
| 64 template<typename S, typename T> | 63 template<typename S, typename T> |
| 65 class CallbackPromiseAdapter FINAL : public blink::WebCallbacks<typename S::WebT ype, typename T::WebType> { | 64 class CallbackPromiseAdapter FINAL : public blink::WebCallbacks<typename S::WebT ype, typename T::WebType> { |
| 66 public: | 65 public: |
| 67 CallbackPromiseAdapter(PassRefPtr<ScriptPromiseResolver> resolver, Execution Context* context) | 66 CallbackPromiseAdapter(PassRefPtr<ScriptPromiseResolverWithContext> resolver ) |
| 68 : m_resolver(resolver) | 67 : m_resolver(resolver) |
| 69 , m_scriptState(NewScriptState::current(toIsolate(context))) | |
| 70 { | 68 { |
| 71 } | 69 } |
| 72 virtual ~CallbackPromiseAdapter() { } | 70 virtual ~CallbackPromiseAdapter() { } |
| 73 | 71 |
| 74 virtual void onSuccess(typename S::WebType* result) OVERRIDE | 72 virtual void onSuccess(typename S::WebType* result) OVERRIDE |
| 75 { | 73 { |
| 76 NewScriptState::Scope scope(m_scriptState.get()); | 74 if (!m_resolver->scriptState()) |
| 77 m_resolver->resolve(S::from(m_scriptState.get(), result)); | 75 return; |
|
haraken
2014/04/14 12:13:17
This will change existing behavior in a case where
yhirano
2014/04/14 12:37:23
Yes, this CL changes the behavior as written in th
yhirano
2014/04/15 01:02:17
I made ScriptPromiseResolver::m_scriptState const
| |
| 76 m_resolver->resolve(S::from(m_resolver->scriptState(), result)); | |
| 78 } | 77 } |
| 79 virtual void onError(typename T::WebType* error) OVERRIDE | 78 virtual void onError(typename T::WebType* error) OVERRIDE |
| 80 { | 79 { |
| 81 NewScriptState::Scope scope(m_scriptState.get()); | 80 if (!m_resolver->scriptState()) |
| 82 m_resolver->reject(T::from(m_scriptState.get(), error)); | 81 return; |
|
haraken
2014/04/14 12:13:17
Ditto.
| |
| 82 m_resolver->reject(T::from(m_resolver->scriptState(), error)); | |
| 83 } | 83 } |
| 84 private: | 84 private: |
| 85 RefPtr<ScriptPromiseResolver> m_resolver; | 85 RefPtr<ScriptPromiseResolverWithContext> m_resolver; |
| 86 RefPtr<NewScriptState> m_scriptState; | |
| 87 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); | 86 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); |
| 88 }; | 87 }; |
| 89 | 88 |
| 90 } // namespace WebCore | 89 } // namespace WebCore |
| 91 | 90 |
| 92 #endif | 91 #endif |
| OLD | NEW |