| 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 blink::WebCallbacks<typename S::WebT
ype, typename T::WebType> { |
| 80 public: | 80 public: |
| 81 explicit CallbackPromiseAdapter(PassRefPtr<ScriptPromiseResolver> resolver) | 81 explicit CallbackPromiseAdapter(PassRefPtr<ScriptPromiseResolver> resolver) |
| 82 : m_resolver(resolver) | 82 : m_resolver(resolver) |
| 83 { | 83 { |
| 84 ASSERT(m_resolver); | 84 ASSERT(m_resolver); |
| 85 } | 85 } |
| 86 virtual ~CallbackPromiseAdapter() { } | 86 virtual ~CallbackPromiseAdapter() { } |
| 87 | 87 |
| 88 virtual void onSuccess(typename S::WebType* result) OVERRIDE | 88 virtual void onSuccess(typename S::WebType* result) override |
| 89 { | 89 { |
| 90 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) { | 90 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) { |
| 91 S::dispose(result); | 91 S::dispose(result); |
| 92 return; | 92 return; |
| 93 } | 93 } |
| 94 m_resolver->resolve(S::take(m_resolver.get(), result)); | 94 m_resolver->resolve(S::take(m_resolver.get(), result)); |
| 95 } | 95 } |
| 96 | 96 |
| 97 virtual void onError(typename T::WebType* error) OVERRIDE | 97 virtual void onError(typename T::WebType* error) override |
| 98 { | 98 { |
| 99 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) { | 99 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) { |
| 100 T::dispose(error); | 100 T::dispose(error); |
| 101 return; | 101 return; |
| 102 } | 102 } |
| 103 m_resolver->reject(T::take(m_resolver.get(), error)); | 103 m_resolver->reject(T::take(m_resolver.get(), error)); |
| 104 } | 104 } |
| 105 | 105 |
| 106 private: | 106 private: |
| 107 RefPtr<ScriptPromiseResolver> m_resolver; | 107 RefPtr<ScriptPromiseResolver> m_resolver; |
| 108 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); | 108 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 template<typename T> | 111 template<typename T> |
| 112 class CallbackPromiseAdapter<void, T> FINAL : public blink::WebCallbacks<void, t
ypename T::WebType> { | 112 class CallbackPromiseAdapter<void, T> final : public blink::WebCallbacks<void, t
ypename T::WebType> { |
| 113 public: | 113 public: |
| 114 explicit CallbackPromiseAdapter(PassRefPtr<ScriptPromiseResolver> resolver) | 114 explicit CallbackPromiseAdapter(PassRefPtr<ScriptPromiseResolver> resolver) |
| 115 : m_resolver(resolver) | 115 : m_resolver(resolver) |
| 116 { | 116 { |
| 117 ASSERT(m_resolver); | 117 ASSERT(m_resolver); |
| 118 } | 118 } |
| 119 virtual ~CallbackPromiseAdapter() { } | 119 virtual ~CallbackPromiseAdapter() { } |
| 120 | 120 |
| 121 virtual void onSuccess() OVERRIDE | 121 virtual void onSuccess() override |
| 122 { | 122 { |
| 123 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) { | 123 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) { |
| 124 return; | 124 return; |
| 125 } | 125 } |
| 126 m_resolver->resolve(V8UndefinedType()); | 126 m_resolver->resolve(V8UndefinedType()); |
| 127 } | 127 } |
| 128 | 128 |
| 129 virtual void onError(typename T::WebType* error) OVERRIDE | 129 virtual void onError(typename T::WebType* error) override |
| 130 { | 130 { |
| 131 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) { | 131 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) { |
| 132 T::dispose(error); | 132 T::dispose(error); |
| 133 return; | 133 return; |
| 134 } | 134 } |
| 135 m_resolver->reject(T::take(m_resolver.get(), error)); | 135 m_resolver->reject(T::take(m_resolver.get(), error)); |
| 136 } | 136 } |
| 137 | 137 |
| 138 private: | 138 private: |
| 139 RefPtr<ScriptPromiseResolver> m_resolver; | 139 RefPtr<ScriptPromiseResolver> m_resolver; |
| 140 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); | 140 WTF_MAKE_NONCOPYABLE(CallbackPromiseAdapter); |
| 141 }; | 141 }; |
| 142 | 142 |
| 143 } // namespace blink | 143 } // namespace blink |
| 144 | 144 |
| 145 #endif | 145 #endif |
| OLD | NEW |