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 15 matching lines...) Expand all Loading... |
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/NewScriptState.h" | 34 #include "bindings/v8/NewScriptState.h" |
35 #include "bindings/v8/ScriptPromiseResolverWithContext.h" | 35 #include "bindings/v8/ScriptPromiseResolverWithContext.h" |
| 36 #include "core/dom/DOMError.h" |
| 37 #include "core/dom/DOMException.h" |
36 #include "core/dom/ExecutionContext.h" | 38 #include "core/dom/ExecutionContext.h" |
37 #include "modules/crypto/Key.h" | 39 #include "modules/crypto/Key.h" |
38 #include "modules/crypto/KeyPair.h" | 40 #include "modules/crypto/KeyPair.h" |
39 #include "modules/crypto/NormalizeAlgorithm.h" | 41 #include "modules/crypto/NormalizeAlgorithm.h" |
40 #include "public/platform/Platform.h" | 42 #include "public/platform/Platform.h" |
41 #include "public/platform/WebArrayBuffer.h" | 43 #include "public/platform/WebArrayBuffer.h" |
42 #include "public/platform/WebCryptoAlgorithm.h" | 44 #include "public/platform/WebCryptoAlgorithm.h" |
43 #include "wtf/ArrayBufferView.h" | 45 #include "wtf/ArrayBufferView.h" |
44 | 46 |
45 namespace WebCore { | 47 namespace WebCore { |
46 | 48 |
| 49 namespace { |
| 50 |
| 51 ExceptionCode toExceptionCode(blink::WebCryptoErrorType exceptionType) |
| 52 { |
| 53 switch (exceptionType) { |
| 54 case blink::WebCryptoErrorTypeNotSupported: |
| 55 return NotSupportedError; |
| 56 case blink::WebCryptoErrorTypeSyntax: |
| 57 return SyntaxError; |
| 58 case blink::WebCryptoErrorTypeInvalidState: |
| 59 return InvalidStateError; |
| 60 case blink::WebCryptoErrorTypeInvalidAccess: |
| 61 return InvalidAccessError; |
| 62 case blink::WebCryptoErrorTypeUnknown: |
| 63 return UnknownError; |
| 64 case blink::WebCryptoErrorTypeData: |
| 65 return DataError; |
| 66 case blink::WebCryptoErrorTypeOperation: |
| 67 // FIXME: This exception type is new to WebCrypto and not yet defined. |
| 68 // Use a placeholder for now. |
| 69 return InvalidStateError; |
| 70 case blink::WebCryptoErrorTypeType: |
| 71 // FIXME: This should construct a TypeError instead. For now do |
| 72 // something to facilitate refactor, but this will need to be |
| 73 // revisited. |
| 74 return DataError; |
| 75 } |
| 76 } |
| 77 |
| 78 } // namespace |
| 79 |
47 CryptoResultImpl::~CryptoResultImpl() | 80 CryptoResultImpl::~CryptoResultImpl() |
48 { | 81 { |
49 } | 82 } |
50 | 83 |
51 PassRefPtr<CryptoResultImpl> CryptoResultImpl::create() | 84 PassRefPtr<CryptoResultImpl> CryptoResultImpl::create() |
52 { | 85 { |
53 return adoptRef(new CryptoResultImpl(callingExecutionContext(v8::Isolate::Ge
tCurrent()))); | 86 return adoptRef(new CryptoResultImpl(callingExecutionContext(v8::Isolate::Ge
tCurrent()))); |
54 } | 87 } |
55 | 88 |
56 void CryptoResultImpl::completeWithError(const blink::WebString& errorDetails) | 89 void CryptoResultImpl::completeWithError(blink::WebCryptoErrorType exceptionType
, const blink::WebString& errorDetails) |
57 { | 90 { |
58 ASSERT(!m_finished); | 91 ASSERT(!m_finished); |
59 | 92 |
60 if (canCompletePromise()) { | 93 if (canCompletePromise()) { |
61 if (!errorDetails.isEmpty()) { | 94 m_promiseResolver->reject(DOMException::create(toExceptionCode(exception
Type), errorDetails)); |
62 // FIXME: Include the line number which started the crypto operation
. | |
63 executionContext()->addConsoleMessage(JSMessageSource, ErrorMessageL
evel, errorDetails); | |
64 } | |
65 m_promiseResolver->reject(V8NullType()); | |
66 } | 95 } |
67 } | 96 } |
68 | 97 |
69 void CryptoResultImpl::completeWithError() | |
70 { | |
71 completeWithError(blink::WebString()); | |
72 } | |
73 | |
74 void CryptoResultImpl::completeWithBuffer(const blink::WebArrayBuffer& buffer) | 98 void CryptoResultImpl::completeWithBuffer(const blink::WebArrayBuffer& buffer) |
75 { | 99 { |
76 ASSERT(!m_finished); | 100 ASSERT(!m_finished); |
77 | 101 |
78 if (canCompletePromise()) { | 102 if (canCompletePromise()) { |
79 m_promiseResolver->resolve(PassRefPtr<ArrayBuffer>(buffer)); | 103 m_promiseResolver->resolve(PassRefPtr<ArrayBuffer>(buffer)); |
80 } | 104 } |
81 | 105 |
82 finish(); | 106 finish(); |
83 } | 107 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } | 177 } |
154 | 178 |
155 bool CryptoResultImpl::canCompletePromise() const | 179 bool CryptoResultImpl::canCompletePromise() const |
156 { | 180 { |
157 CheckValidThread(); | 181 CheckValidThread(); |
158 ExecutionContext* context = executionContext(); | 182 ExecutionContext* context = executionContext(); |
159 return context && !context->activeDOMObjectsAreSuspended() && !context->acti
veDOMObjectsAreStopped(); | 183 return context && !context->activeDOMObjectsAreSuspended() && !context->acti
veDOMObjectsAreStopped(); |
160 } | 184 } |
161 | 185 |
162 } // namespace WebCore | 186 } // namespace WebCore |
OLD | NEW |