| 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 14 matching lines...) Expand all Loading... |
| 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 CryptoResultImpl_h | 31 #ifndef CryptoResultImpl_h |
| 32 #define CryptoResultImpl_h | 32 #define CryptoResultImpl_h |
| 33 | 33 |
| 34 #include "bindings/v8/ScriptPromise.h" | 34 #include "bindings/v8/ScriptPromise.h" |
| 35 #include "bindings/v8/ScriptPromiseResolverWithContext.h" | |
| 36 #include "core/dom/ContextLifecycleObserver.h" | |
| 37 #include "platform/CryptoResult.h" | 35 #include "platform/CryptoResult.h" |
| 38 #include "public/platform/WebCrypto.h" | 36 #include "public/platform/WebCrypto.h" |
| 39 #include "wtf/Assertions.h" | |
| 40 #include "wtf/Forward.h" | 37 #include "wtf/Forward.h" |
| 41 #include "wtf/Threading.h" | 38 #include "wtf/WeakPtr.h" |
| 42 | 39 |
| 43 namespace WebCore { | 40 namespace WebCore { |
| 44 | 41 |
| 45 // Wrapper around a Promise to notify completion of the crypto operation. | 42 // Wrapper around a Promise to notify completion of the crypto operation. |
| 46 // Platform cannot know about Promises which are declared in bindings. | 43 // |
| 47 class CryptoResultImpl FINAL : public CryptoResult, public ContextLifecycleObser
ver { | 44 // The thread on which CryptoResultImpl was created on is referred to as the |
| 45 // "origin thread". |
| 46 // |
| 47 // * At creation time there must be an active ExecutionContext. |
| 48 // * The CryptoResult interface must only be called from the origin thread. |
| 49 // * addref() and deref() can be called from any thread. |
| 50 // * One of the completeWith***() functions must be called, or the |
| 51 // PromiseState will be leaked until the ExecutionContext is destroyed. |
| 52 class CryptoResultImpl FINAL : public CryptoResult { |
| 48 public: | 53 public: |
| 49 ~CryptoResultImpl(); | 54 ~CryptoResultImpl(); |
| 50 | 55 |
| 51 static PassRefPtr<CryptoResultImpl> create(); | 56 static PassRefPtr<CryptoResultImpl> create(); |
| 52 | 57 |
| 53 virtual void completeWithError() OVERRIDE; | 58 virtual void completeWithError() OVERRIDE; |
| 54 virtual void completeWithError(const blink::WebString&) OVERRIDE; | 59 virtual void completeWithError(const blink::WebString&) OVERRIDE; |
| 55 virtual void completeWithBuffer(const blink::WebArrayBuffer&) OVERRIDE; | 60 virtual void completeWithBuffer(const blink::WebArrayBuffer&) OVERRIDE; |
| 56 virtual void completeWithBoolean(bool) OVERRIDE; | 61 virtual void completeWithBoolean(bool) OVERRIDE; |
| 57 virtual void completeWithKey(const blink::WebCryptoKey&) OVERRIDE; | 62 virtual void completeWithKey(const blink::WebCryptoKey&) OVERRIDE; |
| 58 virtual void completeWithKeyPair(const blink::WebCryptoKey& publicKey, const
blink::WebCryptoKey& privateKey) OVERRIDE; | 63 virtual void completeWithKeyPair(const blink::WebCryptoKey& publicKey, const
blink::WebCryptoKey& privateKey) OVERRIDE; |
| 59 | 64 |
| 60 ScriptPromise promise() { return m_promiseResolver->promise(); } | 65 // It is only valid to call this before completion. |
| 66 ScriptPromise promise(); |
| 61 | 67 |
| 62 private: | 68 private: |
| 63 CryptoResultImpl(ExecutionContext*); | 69 explicit CryptoResultImpl(ExecutionContext*); |
| 64 void finish(); | |
| 65 void CheckValidThread() const; | |
| 66 | 70 |
| 67 // Override from ContextLifecycleObserver | 71 class PromiseState; |
| 68 virtual void contextDestroyed() OVERRIDE; | 72 WeakPtr<PromiseState> m_promiseState; |
| 69 | |
| 70 // Returns true if the ExecutionContext is still alive and running. | |
| 71 bool canCompletePromise() const; | |
| 72 | |
| 73 void clearPromiseResolver(); | |
| 74 | |
| 75 RefPtr<ScriptPromiseResolverWithContext> m_promiseResolver; | |
| 76 | |
| 77 #if !ASSERT_DISABLED | |
| 78 ThreadIdentifier m_owningThread; | |
| 79 bool m_finished; | |
| 80 #endif | |
| 81 }; | 73 }; |
| 82 | 74 |
| 83 } // namespace WebCore | 75 } // namespace WebCore |
| 84 | 76 |
| 85 #endif | 77 #endif |
| OLD | NEW |