| Index: Source/modules/crypto/SubtleCrypto.cpp
|
| diff --git a/Source/modules/crypto/SubtleCrypto.cpp b/Source/modules/crypto/SubtleCrypto.cpp
|
| index 832f916541561c73da9c175f00c8229f9d9976be..6be374a1803ed494691b1c19181172592a10040f 100644
|
| --- a/Source/modules/crypto/SubtleCrypto.cpp
|
| +++ b/Source/modules/crypto/SubtleCrypto.cpp
|
| @@ -32,17 +32,86 @@
|
| #include "modules/crypto/SubtleCrypto.h"
|
|
|
| #include "bindings/v8/Dictionary.h"
|
| +#include "bindings/v8/ScriptPromiseResolverWithContext.h"
|
| +#include "core/dom/DOMException.h"
|
| #include "core/dom/ExecutionContext.h"
|
| +#include "modules/crypto/CrossThreadCryptoResult.h"
|
| #include "modules/crypto/CryptoResultImpl.h"
|
| #include "modules/crypto/Key.h"
|
| +#include "modules/crypto/KeyPair.h"
|
| #include "modules/crypto/NormalizeAlgorithm.h"
|
| #include "public/platform/Platform.h"
|
| +#include "public/platform/WebArrayBuffer.h"
|
| #include "public/platform/WebCrypto.h"
|
| #include "public/platform/WebCryptoAlgorithm.h"
|
| #include "wtf/ArrayBufferView.h"
|
|
|
| namespace WebCore {
|
|
|
| +class SubtleCrypto::PendingResult : public CryptoResult {
|
| +public:
|
| + virtual ~PendingResult() { }
|
| +
|
| + static PassRefPtr<PendingResult> create(ScriptState* scriptState, RawPtr<SubtleCrypto> owner)
|
| + {
|
| + return adoptRef(new PendingResult(scriptState, owner));
|
| + }
|
| +
|
| + virtual void completeWithError(blink::WebCryptoErrorType errorType, const blink::WebString& errorDetails) OVERRIDE
|
| + {
|
| + m_resolver->reject(DOMException::create(webCryptoErrorToExceptionCode(errorType), errorDetails));
|
| + unregisterThis();
|
| + }
|
| +
|
| + virtual void completeWithBuffer(const blink::WebArrayBuffer& buffer) OVERRIDE
|
| + {
|
| + m_resolver->resolve(PassRefPtr<ArrayBuffer>(buffer));
|
| + unregisterThis();
|
| + }
|
| +
|
| + virtual void completeWithBoolean(bool b) OVERRIDE
|
| + {
|
| + m_resolver->resolve(b);
|
| + unregisterThis();
|
| + }
|
| +
|
| + virtual void completeWithKey(const blink::WebCryptoKey& key) OVERRIDE
|
| + {
|
| + m_resolver->resolve(Key::create(key));
|
| + unregisterThis();
|
| + }
|
| +
|
| + virtual void completeWithKeyPair(const blink::WebCryptoKey& publicKey, const blink::WebCryptoKey& privateKey) OVERRIDE
|
| + {
|
| + m_resolver->resolve(KeyPair::create(publicKey, privateKey));
|
| + unregisterThis();
|
| + }
|
| +
|
| + ScriptPromise promise() { return m_resolver->promise(); }
|
| +
|
| + WeakPtr<PendingResult> createWeakPtr() { return m_factory.createWeakPtr(); }
|
| +
|
| +private:
|
| + PendingResult(ScriptState* scriptState, RawPtr<SubtleCrypto> owner)
|
| + : m_resolver(ScriptPromiseResolverWithContext::create(scriptState))
|
| + , m_owner(owner)
|
| + , m_factory(this)
|
| + {
|
| + m_resolver->keepObjectWhilePending(owner);
|
| + m_owner->m_pendingResults.add(this);
|
| + }
|
| +
|
| + void unregisterThis()
|
| + {
|
| + if (m_owner->m_pendingResults.contains(this))
|
| + m_owner->m_pendingResults.remove(this);
|
| + }
|
| +
|
| + RefPtr<ScriptPromiseResolverWithContext> m_resolver;
|
| + Persistent<SubtleCrypto> m_owner;
|
| + WeakPtrFactory<PendingResult> m_factory;
|
| +};
|
| +
|
| // Seems like the generated bindings should take care of these however it
|
| // currently doesn't. See also http://crbug.com/264520
|
| static bool ensureNotNull(const ArrayPiece& x, const char* paramName, CryptoResult* result)
|
| @@ -85,10 +154,11 @@ static bool canAccessWebCrypto(ScriptState* scriptState, CryptoResult* result)
|
| return true;
|
| }
|
|
|
| -static ScriptPromise startCryptoOperation(ScriptState* scriptState, const Dictionary& rawAlgorithm, Key* key, blink::WebCryptoOperation operationType, const ArrayPiece& signature, const ArrayPiece& dataBuffer)
|
| +ScriptPromise SubtleCrypto::startCryptoOperation(ScriptState* scriptState, const Dictionary& rawAlgorithm, Key* key, blink::WebCryptoOperation operationType, const ArrayPiece& signature, const ArrayPiece& dataBuffer)
|
| {
|
| - RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(scriptState);
|
| - ScriptPromise promise = result->promise();
|
| + RefPtr<PendingResult> pending = PendingResult::create(scriptState, this);
|
| + RefPtr<CrossThreadCryptoResult<PendingResult> > result = CrossThreadCryptoResult<PendingResult>::create(pending->createWeakPtr());
|
| + ScriptPromise promise = pending->promise();
|
|
|
| if (!canAccessWebCrypto(scriptState, result.get()))
|
| return promise;
|
| @@ -168,8 +238,9 @@ ScriptPromise SubtleCrypto::digest(ScriptState* scriptState, const Dictionary& r
|
|
|
| ScriptPromise SubtleCrypto::generateKey(ScriptState* scriptState, const Dictionary& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages)
|
| {
|
| - RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(scriptState);
|
| - ScriptPromise promise = result->promise();
|
| + RefPtr<PendingResult> pending = PendingResult::create(scriptState, this);
|
| + RefPtr<CrossThreadCryptoResult<PendingResult> > result = CrossThreadCryptoResult<PendingResult>::create(pending->createWeakPtr());
|
| + ScriptPromise promise = pending->promise();
|
|
|
| if (!canAccessWebCrypto(scriptState, result.get()))
|
| return promise;
|
| @@ -188,8 +259,9 @@ ScriptPromise SubtleCrypto::generateKey(ScriptState* scriptState, const Dictiona
|
|
|
| ScriptPromise SubtleCrypto::importKey(ScriptState* scriptState, const String& rawFormat, const ArrayPiece& keyData, const Dictionary& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages)
|
| {
|
| - RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(scriptState);
|
| - ScriptPromise promise = result->promise();
|
| + RefPtr<PendingResult> pending = PendingResult::create(scriptState, this);
|
| + RefPtr<CrossThreadCryptoResult<PendingResult> > result = CrossThreadCryptoResult<PendingResult>::create(pending->createWeakPtr());
|
| + ScriptPromise promise = pending->promise();
|
|
|
| if (!canAccessWebCrypto(scriptState, result.get()))
|
| return promise;
|
| @@ -215,8 +287,9 @@ ScriptPromise SubtleCrypto::importKey(ScriptState* scriptState, const String& ra
|
|
|
| ScriptPromise SubtleCrypto::exportKey(ScriptState* scriptState, const String& rawFormat, Key* key)
|
| {
|
| - RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(scriptState);
|
| - ScriptPromise promise = result->promise();
|
| + RefPtr<PendingResult> pending = PendingResult::create(scriptState, this);
|
| + RefPtr<CrossThreadCryptoResult<PendingResult> > result = CrossThreadCryptoResult<PendingResult>::create(pending->createWeakPtr());
|
| + ScriptPromise promise = pending->promise();
|
|
|
| if (!canAccessWebCrypto(scriptState, result.get()))
|
| return promise;
|
| @@ -239,8 +312,9 @@ ScriptPromise SubtleCrypto::exportKey(ScriptState* scriptState, const String& ra
|
|
|
| ScriptPromise SubtleCrypto::wrapKey(ScriptState* scriptState, const String& rawFormat, Key* key, Key* wrappingKey, const Dictionary& rawWrapAlgorithm)
|
| {
|
| - RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(scriptState);
|
| - ScriptPromise promise = result->promise();
|
| + RefPtr<PendingResult> pending = PendingResult::create(scriptState, this);
|
| + RefPtr<CrossThreadCryptoResult<PendingResult> > result = CrossThreadCryptoResult<PendingResult>::create(pending->createWeakPtr());
|
| + ScriptPromise promise = pending->promise();
|
|
|
| if (!canAccessWebCrypto(scriptState, result.get()))
|
| return promise;
|
| @@ -273,8 +347,9 @@ ScriptPromise SubtleCrypto::wrapKey(ScriptState* scriptState, const String& rawF
|
|
|
| ScriptPromise SubtleCrypto::unwrapKey(ScriptState* scriptState, const String& rawFormat, const ArrayPiece& wrappedKey, Key* unwrappingKey, const Dictionary& rawUnwrapAlgorithm, const Dictionary& rawUnwrappedKeyAlgorithm, bool extractable, const Vector<String>& rawKeyUsages)
|
| {
|
| - RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(scriptState);
|
| - ScriptPromise promise = result->promise();
|
| + RefPtr<PendingResult> pending = PendingResult::create(scriptState, this);
|
| + RefPtr<CrossThreadCryptoResult<PendingResult> > result = CrossThreadCryptoResult<PendingResult>::create(pending->createWeakPtr());
|
| + ScriptPromise promise = pending->promise();
|
|
|
| if (!canAccessWebCrypto(scriptState, result.get()))
|
| return promise;
|
|
|