| 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 17 matching lines...) Expand all Loading... |
| 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 #include "config.h" | 31 #include "config.h" |
| 32 #include "modules/crypto/CryptoResultImpl.h" | 32 #include "modules/crypto/CryptoResultImpl.h" |
| 33 | 33 |
| 34 #include "bindings/core/v8/Dictionary.h" | 34 #include "bindings/core/v8/Dictionary.h" |
| 35 #include "bindings/core/v8/ScriptPromiseResolver.h" | 35 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 36 #include "bindings/core/v8/ScriptState.h" | 36 #include "bindings/core/v8/ScriptState.h" |
| 37 #include "core/dom/ContextLifecycleObserver.h" | 37 #include "core/dom/ContextLifecycleObserver.h" |
| 38 #include "core/dom/DOMArrayBuffer.h" |
| 38 #include "core/dom/DOMError.h" | 39 #include "core/dom/DOMError.h" |
| 39 #include "core/dom/DOMException.h" | 40 #include "core/dom/DOMException.h" |
| 40 #include "core/dom/ExecutionContext.h" | 41 #include "core/dom/ExecutionContext.h" |
| 41 #include "modules/crypto/CryptoKey.h" | 42 #include "modules/crypto/CryptoKey.h" |
| 42 #include "modules/crypto/NormalizeAlgorithm.h" | 43 #include "modules/crypto/NormalizeAlgorithm.h" |
| 43 #include "public/platform/Platform.h" | 44 #include "public/platform/Platform.h" |
| 44 #include "public/platform/WebArrayBuffer.h" | 45 #include "public/platform/WebArrayBuffer.h" |
| 45 #include "public/platform/WebCryptoAlgorithm.h" | 46 #include "public/platform/WebCryptoAlgorithm.h" |
| 46 #include "wtf/ArrayBufferView.h" | |
| 47 | 47 |
| 48 namespace blink { | 48 namespace blink { |
| 49 | 49 |
| 50 class CryptoResultImpl::WeakResolver : public ScriptPromiseResolver { | 50 class CryptoResultImpl::WeakResolver : public ScriptPromiseResolver { |
| 51 public: | 51 public: |
| 52 static WeakPtr<ScriptPromiseResolver> create(ScriptState* scriptState, Crypt
oResultImpl* result) | 52 static WeakPtr<ScriptPromiseResolver> create(ScriptState* scriptState, Crypt
oResultImpl* result) |
| 53 { | 53 { |
| 54 RefPtr<WeakResolver> p = adoptRef(new WeakResolver(scriptState, result))
; | 54 RefPtr<WeakResolver> p = adoptRef(new WeakResolver(scriptState, result))
; |
| 55 p->suspendIfNeeded(); | 55 p->suspendIfNeeded(); |
| 56 p->keepAliveWhilePending(); | 56 p->keepAliveWhilePending(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 110 |
| 111 void CryptoResultImpl::completeWithError(WebCryptoErrorType errorType, const Web
String& errorDetails) | 111 void CryptoResultImpl::completeWithError(WebCryptoErrorType errorType, const Web
String& errorDetails) |
| 112 { | 112 { |
| 113 if (m_resolver) | 113 if (m_resolver) |
| 114 m_resolver->reject(DOMException::create(webCryptoErrorToExceptionCode(er
rorType), errorDetails)); | 114 m_resolver->reject(DOMException::create(webCryptoErrorToExceptionCode(er
rorType), errorDetails)); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void CryptoResultImpl::completeWithBuffer(const WebArrayBuffer& buffer) | 117 void CryptoResultImpl::completeWithBuffer(const WebArrayBuffer& buffer) |
| 118 { | 118 { |
| 119 if (m_resolver) | 119 if (m_resolver) |
| 120 m_resolver->resolve(PassRefPtr<ArrayBuffer>(buffer)); | 120 m_resolver->resolve(DOMArrayBuffer::create(PassRefPtr<ArrayBuffer>(buffe
r))); |
| 121 } | 121 } |
| 122 | 122 |
| 123 void CryptoResultImpl::completeWithJson(const char* utf8Data, unsigned length) | 123 void CryptoResultImpl::completeWithJson(const char* utf8Data, unsigned length) |
| 124 { | 124 { |
| 125 if (m_resolver) { | 125 if (m_resolver) { |
| 126 ScriptPromiseResolver* resolver = m_resolver.get(); | 126 ScriptPromiseResolver* resolver = m_resolver.get(); |
| 127 ScriptState* scriptState = resolver->scriptState(); | 127 ScriptState* scriptState = resolver->scriptState(); |
| 128 ScriptState::Scope scope(scriptState); | 128 ScriptState::Scope scope(scriptState); |
| 129 | 129 |
| 130 v8::Handle<v8::String> jsonString = v8::String::NewFromUtf8(scriptState-
>isolate(), utf8Data, v8::String::kInternalizedString, length); | 130 v8::Handle<v8::String> jsonString = v8::String::NewFromUtf8(scriptState-
>isolate(), utf8Data, v8::String::kInternalizedString, length); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 // been stopped. And in the process set m_cancelled to 1. | 187 // been stopped. And in the process set m_cancelled to 1. |
| 188 m_resolver = WeakResolver::create(scriptState, this); | 188 m_resolver = WeakResolver::create(scriptState, this); |
| 189 } | 189 } |
| 190 | 190 |
| 191 ScriptPromise CryptoResultImpl::promise() | 191 ScriptPromise CryptoResultImpl::promise() |
| 192 { | 192 { |
| 193 return m_resolver ? m_resolver->promise() : ScriptPromise(); | 193 return m_resolver ? m_resolver->promise() : ScriptPromise(); |
| 194 } | 194 } |
| 195 | 195 |
| 196 } // namespace blink | 196 } // namespace blink |
| OLD | NEW |