| 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 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 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 #include "config.h" | 31 #include "config.h" |
| 32 #include "modules/crypto/CryptoResultImpl.h" | 32 #include "modules/crypto/CryptoResultImpl.h" |
| 33 | 33 |
| 34 #include "bindings/v8/Dictionary.h" |
| 34 #include "bindings/v8/ScriptPromiseResolver.h" | 35 #include "bindings/v8/ScriptPromiseResolver.h" |
| 35 #include "bindings/v8/ScriptState.h" | 36 #include "bindings/v8/ScriptState.h" |
| 36 #include "core/dom/ContextLifecycleObserver.h" | 37 #include "core/dom/ContextLifecycleObserver.h" |
| 37 #include "core/dom/DOMError.h" | 38 #include "core/dom/DOMError.h" |
| 38 #include "core/dom/DOMException.h" | 39 #include "core/dom/DOMException.h" |
| 39 #include "core/dom/ExecutionContext.h" | 40 #include "core/dom/ExecutionContext.h" |
| 40 #include "modules/crypto/CryptoKey.h" | 41 #include "modules/crypto/CryptoKey.h" |
| 41 #include "modules/crypto/NormalizeAlgorithm.h" | 42 #include "modules/crypto/NormalizeAlgorithm.h" |
| 42 #include "public/platform/Platform.h" | 43 #include "public/platform/Platform.h" |
| 43 #include "public/platform/WebArrayBuffer.h" | 44 #include "public/platform/WebArrayBuffer.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 if (m_resolver) | 151 if (m_resolver) |
| 151 m_resolver->resolve(CryptoKey::create(key)); | 152 m_resolver->resolve(CryptoKey::create(key)); |
| 152 } | 153 } |
| 153 | 154 |
| 154 void CryptoResultImpl::completeWithKeyPair(const blink::WebCryptoKey& publicKey,
const blink::WebCryptoKey& privateKey) | 155 void CryptoResultImpl::completeWithKeyPair(const blink::WebCryptoKey& publicKey,
const blink::WebCryptoKey& privateKey) |
| 155 { | 156 { |
| 156 if (m_resolver) { | 157 if (m_resolver) { |
| 157 ScriptState* scriptState = m_resolver->scriptState(); | 158 ScriptState* scriptState = m_resolver->scriptState(); |
| 158 ScriptState::Scope scope(scriptState); | 159 ScriptState::Scope scope(scriptState); |
| 159 | 160 |
| 160 // FIXME: Use Dictionary instead, to limit amount of direct v8 access us
ed from WebCore. | 161 Dictionary keyPair(scriptState->isolate()); |
| 161 v8::Handle<v8::Object> keyPair = v8::Object::New(scriptState->isolate())
; | |
| 162 | 162 |
| 163 v8::Handle<v8::Value> publicKeyValue = toV8NoInline(CryptoKey::create(pu
blicKey), scriptState->context()->Global(), scriptState->isolate()); | 163 v8::Handle<v8::Value> publicKeyValue = toV8NoInline(CryptoKey::create(pu
blicKey), scriptState->context()->Global(), scriptState->isolate()); |
| 164 v8::Handle<v8::Value> privateKeyValue = toV8NoInline(CryptoKey::create(p
rivateKey), scriptState->context()->Global(), scriptState->isolate()); | 164 v8::Handle<v8::Value> privateKeyValue = toV8NoInline(CryptoKey::create(p
rivateKey), scriptState->context()->Global(), scriptState->isolate()); |
| 165 | 165 |
| 166 keyPair->Set(v8::String::NewFromUtf8(scriptState->isolate(), "publicKey"
), publicKeyValue); | 166 keyPair.set("publicKey", publicKeyValue); |
| 167 keyPair->Set(v8::String::NewFromUtf8(scriptState->isolate(), "privateKey
"), privateKeyValue); | 167 keyPair.set("privateKey", privateKeyValue); |
| 168 | 168 |
| 169 m_resolver->resolve(v8::Handle<v8::Value>(keyPair)); | 169 m_resolver->resolve(keyPair.v8Value()); |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 | 172 |
| 173 bool CryptoResultImpl::cancelled() const | 173 bool CryptoResultImpl::cancelled() const |
| 174 { | 174 { |
| 175 return acquireLoad(&m_cancelled); | 175 return acquireLoad(&m_cancelled); |
| 176 } | 176 } |
| 177 | 177 |
| 178 void CryptoResultImpl::cancel() | 178 void CryptoResultImpl::cancel() |
| 179 { | 179 { |
| 180 releaseStore(&m_cancelled, 1); | 180 releaseStore(&m_cancelled, 1); |
| 181 } | 181 } |
| 182 | 182 |
| 183 CryptoResultImpl::CryptoResultImpl(ScriptState* scriptState) | 183 CryptoResultImpl::CryptoResultImpl(ScriptState* scriptState) |
| 184 : m_cancelled(0) | 184 : m_cancelled(0) |
| 185 { | 185 { |
| 186 // Creating the WeakResolver may return nullptr if active dom objects have | 186 // Creating the WeakResolver may return nullptr if active dom objects have |
| 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 WebCore | 196 } // namespace WebCore |
| OLD | NEW |