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 29 matching lines...) Expand all Loading... |
40 #include "modules/crypto/Key.h" | 40 #include "modules/crypto/Key.h" |
41 #include "modules/crypto/KeyPair.h" | 41 #include "modules/crypto/KeyPair.h" |
42 #include "modules/crypto/NormalizeAlgorithm.h" | 42 #include "modules/crypto/NormalizeAlgorithm.h" |
43 #include "public/platform/Platform.h" | 43 #include "public/platform/Platform.h" |
44 #include "public/platform/WebArrayBuffer.h" | 44 #include "public/platform/WebArrayBuffer.h" |
45 #include "public/platform/WebCryptoAlgorithm.h" | 45 #include "public/platform/WebCryptoAlgorithm.h" |
46 #include "wtf/ArrayBufferView.h" | 46 #include "wtf/ArrayBufferView.h" |
47 | 47 |
48 namespace WebCore { | 48 namespace WebCore { |
49 | 49 |
50 namespace { | 50 class CryptoResultImpl::WeakResolver : public ScriptPromiseResolverWithContext { |
51 | |
52 class WeakResolver : public ScriptPromiseResolverWithContext { | |
53 public: | 51 public: |
54 static WeakPtr<ScriptPromiseResolverWithContext> create(ScriptState* scriptS
tate) | 52 static WeakPtr<ScriptPromiseResolverWithContext> create(ScriptState* scriptS
tate, CryptoResultImpl* result) |
55 { | 53 { |
56 RefPtr<WeakResolver> p = adoptRef(new WeakResolver(scriptState)); | 54 RefPtr<WeakResolver> p = adoptRef(new WeakResolver(scriptState, result))
; |
57 p->suspendIfNeeded(); | 55 p->suspendIfNeeded(); |
58 p->keepAliveWhilePending(); | 56 p->keepAliveWhilePending(); |
59 return p->m_weakPtrFactory.createWeakPtr(); | 57 return p->m_weakPtrFactory.createWeakPtr(); |
60 } | 58 } |
61 | 59 |
| 60 virtual ~WeakResolver() |
| 61 { |
| 62 m_result->cancel(); |
| 63 } |
| 64 |
62 private: | 65 private: |
63 explicit WeakResolver(ScriptState* scriptState) | 66 WeakResolver(ScriptState* scriptState, CryptoResultImpl* result) |
64 : ScriptPromiseResolverWithContext(scriptState) | 67 : ScriptPromiseResolverWithContext(scriptState) |
65 , m_weakPtrFactory(this) { } | 68 , m_weakPtrFactory(this) |
| 69 , m_result(result) { } |
66 WeakPtrFactory<ScriptPromiseResolverWithContext> m_weakPtrFactory; | 70 WeakPtrFactory<ScriptPromiseResolverWithContext> m_weakPtrFactory; |
| 71 RefPtr<CryptoResultImpl> m_result; |
67 }; | 72 }; |
68 | 73 |
69 } // namespace | |
70 | |
71 ExceptionCode webCryptoErrorToExceptionCode(blink::WebCryptoErrorType errorType) | 74 ExceptionCode webCryptoErrorToExceptionCode(blink::WebCryptoErrorType errorType) |
72 { | 75 { |
73 switch (errorType) { | 76 switch (errorType) { |
74 case blink::WebCryptoErrorTypeNotSupported: | 77 case blink::WebCryptoErrorTypeNotSupported: |
75 return NotSupportedError; | 78 return NotSupportedError; |
76 case blink::WebCryptoErrorTypeSyntax: | 79 case blink::WebCryptoErrorTypeSyntax: |
77 return SyntaxError; | 80 return SyntaxError; |
78 case blink::WebCryptoErrorTypeInvalidState: | 81 case blink::WebCryptoErrorTypeInvalidState: |
79 return InvalidStateError; | 82 return InvalidStateError; |
80 case blink::WebCryptoErrorTypeInvalidAccess: | 83 case blink::WebCryptoErrorTypeInvalidAccess: |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 if (m_resolver) | 151 if (m_resolver) |
149 m_resolver->resolve(Key::create(key)); | 152 m_resolver->resolve(Key::create(key)); |
150 } | 153 } |
151 | 154 |
152 void CryptoResultImpl::completeWithKeyPair(const blink::WebCryptoKey& publicKey,
const blink::WebCryptoKey& privateKey) | 155 void CryptoResultImpl::completeWithKeyPair(const blink::WebCryptoKey& publicKey,
const blink::WebCryptoKey& privateKey) |
153 { | 156 { |
154 if (m_resolver) | 157 if (m_resolver) |
155 m_resolver->resolve(KeyPair::create(publicKey, privateKey)); | 158 m_resolver->resolve(KeyPair::create(publicKey, privateKey)); |
156 } | 159 } |
157 | 160 |
| 161 bool CryptoResultImpl::cancelled() const |
| 162 { |
| 163 return acquireLoad(&m_cancelled); |
| 164 } |
| 165 |
| 166 void CryptoResultImpl::cancel() |
| 167 { |
| 168 releaseStore(&m_cancelled, 1); |
| 169 } |
| 170 |
158 CryptoResultImpl::CryptoResultImpl(ScriptState* scriptState) | 171 CryptoResultImpl::CryptoResultImpl(ScriptState* scriptState) |
159 : m_resolver(WeakResolver::create(scriptState)) | 172 : m_resolver(WeakResolver::create(scriptState, this)) |
| 173 , m_cancelled(0) |
160 { | 174 { |
161 } | 175 } |
162 | 176 |
163 ScriptPromise CryptoResultImpl::promise() | 177 ScriptPromise CryptoResultImpl::promise() |
164 { | 178 { |
165 return m_resolver->promise(); | 179 return m_resolver->promise(); |
166 } | 180 } |
167 | 181 |
168 } // namespace WebCore | 182 } // namespace WebCore |
OLD | NEW |