Index: Source/modules/crypto/CrossThreadCryptoResult.h |
diff --git a/Source/modules/crypto/CrossThreadCryptoResult.h b/Source/modules/crypto/CrossThreadCryptoResult.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0590a505ad602d2615e8f57366f946c6b37d4ee0 |
--- /dev/null |
+++ b/Source/modules/crypto/CrossThreadCryptoResult.h |
@@ -0,0 +1,73 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CrossThreadCryptoResult_h |
+#define CrossThreadCryptoResult_h |
+ |
+#include "core/dom/ExceptionCode.h" |
+#include "platform/CryptoResult.h" |
+#include "public/platform/WebCrypto.h" |
+#include "wtf/WeakPtr.h" |
+ |
+namespace WebCore { |
+ |
+ExceptionCode webCryptoErrorToExceptionCode(blink::WebCryptoErrorType); |
+ |
+// Wrapper around a Promise to notify completion of the crypto operation. |
+// |
+// CrossThreadCryptoResult<T> inherits CryptoResult, where T must inherit |
+// CryptoResultBase. |
+// The thread on which CrossThreadCryptoResult was created on is referred to as the |
+// "origin thread". |
+// |
+// * At creation time there must be an active ExecutionContext. |
+// * The CryptoResult interface must only be called from the origin thread. |
+// * addref() and deref() can be called from any thread. |
+template<typename T> |
+class CrossThreadCryptoResult FINAL : public CryptoResult { |
+public: |
+ ~CrossThreadCryptoResult() { } |
+ |
+ static PassRefPtr<CrossThreadCryptoResult> create(WeakPtr<T> result) |
+ { |
+ return adoptRef(new CrossThreadCryptoResult(result)); |
+ } |
+ |
+ // CryptoResult implementation |
+ virtual void completeWithError(blink::WebCryptoErrorType type, const blink::WebString& message) OVERRIDE |
+ { |
+ if (m_result) |
+ m_result->completeWithError(type, message); |
+ } |
+ virtual void completeWithBuffer(const blink::WebArrayBuffer& buffer) OVERRIDE |
+ { |
+ if (m_result) |
+ m_result->completeWithBuffer(buffer); |
+ } |
+ virtual void completeWithBoolean(bool b) OVERRIDE |
+ { |
+ if (m_result) |
+ m_result->completeWithBoolean(b); |
+ } |
+ virtual void completeWithKey(const blink::WebCryptoKey& key) OVERRIDE |
+ { |
+ if (m_result) |
+ m_result->completeWithKey(key); |
+ } |
+ virtual void completeWithKeyPair(const blink::WebCryptoKey& publicKey, const blink::WebCryptoKey& privateKey) OVERRIDE |
+ { |
+ if (m_result) |
+ m_result->completeWithKeyPair(publicKey, privateKey); |
+ } |
+ |
+private: |
+ explicit CrossThreadCryptoResult(WeakPtr<T> result) |
+ : m_result(result) { } |
+ |
+ WeakPtr<T> m_result; |
+}; |
+ |
+} // namespace WebCore |
+ |
+#endif |