OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CrossThreadCryptoResult_h |
| 6 #define CrossThreadCryptoResult_h |
| 7 |
| 8 #include "core/dom/ExceptionCode.h" |
| 9 #include "platform/CryptoResult.h" |
| 10 #include "public/platform/WebCrypto.h" |
| 11 #include "wtf/WeakPtr.h" |
| 12 |
| 13 namespace WebCore { |
| 14 |
| 15 ExceptionCode webCryptoErrorToExceptionCode(blink::WebCryptoErrorType); |
| 16 |
| 17 // Wrapper around a Promise to notify completion of the crypto operation. |
| 18 // |
| 19 // CrossThreadCryptoResult<T> inherits CryptoResult, where T must inherit |
| 20 // CryptoResultBase. |
| 21 // The thread on which CrossThreadCryptoResult was created on is referred to as
the |
| 22 // "origin thread". |
| 23 // |
| 24 // * At creation time there must be an active ExecutionContext. |
| 25 // * The CryptoResult interface must only be called from the origin thread. |
| 26 // * addref() and deref() can be called from any thread. |
| 27 template<typename T> |
| 28 class CrossThreadCryptoResult FINAL : public CryptoResult { |
| 29 public: |
| 30 ~CrossThreadCryptoResult() { } |
| 31 |
| 32 static PassRefPtr<CrossThreadCryptoResult> create(WeakPtr<T> result) |
| 33 { |
| 34 return adoptRef(new CrossThreadCryptoResult(result)); |
| 35 } |
| 36 |
| 37 // CryptoResult implementation |
| 38 virtual void completeWithError(blink::WebCryptoErrorType type, const blink::
WebString& message) OVERRIDE |
| 39 { |
| 40 if (m_result) |
| 41 m_result->completeWithError(type, message); |
| 42 } |
| 43 virtual void completeWithBuffer(const blink::WebArrayBuffer& buffer) OVERRID
E |
| 44 { |
| 45 if (m_result) |
| 46 m_result->completeWithBuffer(buffer); |
| 47 } |
| 48 virtual void completeWithBoolean(bool b) OVERRIDE |
| 49 { |
| 50 if (m_result) |
| 51 m_result->completeWithBoolean(b); |
| 52 } |
| 53 virtual void completeWithKey(const blink::WebCryptoKey& key) OVERRIDE |
| 54 { |
| 55 if (m_result) |
| 56 m_result->completeWithKey(key); |
| 57 } |
| 58 virtual void completeWithKeyPair(const blink::WebCryptoKey& publicKey, const
blink::WebCryptoKey& privateKey) OVERRIDE |
| 59 { |
| 60 if (m_result) |
| 61 m_result->completeWithKeyPair(publicKey, privateKey); |
| 62 } |
| 63 |
| 64 private: |
| 65 explicit CrossThreadCryptoResult(WeakPtr<T> result) |
| 66 : m_result(result) { } |
| 67 |
| 68 WeakPtr<T> m_result; |
| 69 }; |
| 70 |
| 71 } // namespace WebCore |
| 72 |
| 73 #endif |
OLD | NEW |