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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "wtf/ArrayBufferView.h" | 42 #include "wtf/ArrayBufferView.h" |
43 | 43 |
44 namespace WebCore { | 44 namespace WebCore { |
45 | 45 |
46 CryptoOperation::~CryptoOperation() | 46 CryptoOperation::~CryptoOperation() |
47 { | 47 { |
48 abortImpl(); | 48 abortImpl(); |
49 ASSERT(!m_impl); | 49 ASSERT(!m_impl); |
50 } | 50 } |
51 | 51 |
52 PassRefPtr<CryptoOperation> CryptoOperation::create(const WebKit::WebCryptoAlgor
ithm& algorithm, ExceptionState* es) | 52 PassRefPtr<CryptoOperation> CryptoOperation::create(const WebKit::WebCryptoAlgor
ithm& algorithm) |
53 { | 53 { |
54 return adoptRef(new CryptoOperation(algorithm, es)); | 54 return adoptRef(new CryptoOperation(algorithm)); |
55 } | 55 } |
56 | 56 |
57 CryptoOperation::CryptoOperation(const WebKit::WebCryptoAlgorithm& algorithm, Ex
ceptionState* es) | 57 CryptoOperation::CryptoOperation(const WebKit::WebCryptoAlgorithm& algorithm) |
58 : m_algorithm(algorithm) | 58 : m_algorithm(algorithm) |
59 , m_impl(0) | 59 , m_impl(0) |
60 , m_exceptionState(es) | 60 , m_exceptionCode(0) |
61 , m_state(Initializing) | 61 , m_state(Initializing) |
62 { | 62 { |
63 ASSERT(es); | |
64 ScriptWrappable::init(this); | 63 ScriptWrappable::init(this); |
65 } | 64 } |
66 | 65 |
67 CryptoOperation* CryptoOperation::process(ArrayBuffer* data) | 66 CryptoOperation* CryptoOperation::process(ArrayBuffer* data) |
68 { | 67 { |
69 process(static_cast<unsigned char*>(data->data()), data->byteLength()); | 68 process(static_cast<unsigned char*>(data->data()), data->byteLength()); |
70 return this; | 69 return this; |
71 } | 70 } |
72 | 71 |
73 CryptoOperation* CryptoOperation::process(ArrayBufferView* data) | 72 CryptoOperation* CryptoOperation::process(ArrayBufferView* data) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 { | 109 { |
111 if (!m_algorithmNode) | 110 if (!m_algorithmNode) |
112 m_algorithmNode = Algorithm::create(m_algorithm); | 111 m_algorithmNode = Algorithm::create(m_algorithm); |
113 return m_algorithmNode.get(); | 112 return m_algorithmNode.get(); |
114 } | 113 } |
115 | 114 |
116 void CryptoOperation::initializationFailed() | 115 void CryptoOperation::initializationFailed() |
117 { | 116 { |
118 ASSERT(m_state == Initializing); | 117 ASSERT(m_state == Initializing); |
119 | 118 |
120 m_exceptionState->throwDOMException(NotSupportedError); | 119 m_exceptionCode = NotSupportedError; |
121 | |
122 m_exceptionState = 0; | |
123 m_state = Done; | 120 m_state = Done; |
124 } | 121 } |
125 | 122 |
126 void CryptoOperation::initializationSucceded(WebKit::WebCryptoOperation* operati
onImpl) | 123 void CryptoOperation::initializationSucceeded(WebKit::WebCryptoOperation* operat
ionImpl) |
127 { | 124 { |
128 ASSERT(m_state == Initializing); | 125 ASSERT(m_state == Initializing); |
129 ASSERT(operationImpl); | 126 ASSERT(operationImpl); |
130 ASSERT(!m_impl); | 127 ASSERT(!m_impl); |
131 | 128 |
132 m_exceptionState = 0; | |
133 m_impl = operationImpl; | 129 m_impl = operationImpl; |
134 m_state = Processing; | 130 m_state = Processing; |
135 } | 131 } |
136 | 132 |
137 void CryptoOperation::completeWithError() | 133 void CryptoOperation::completeWithError() |
138 { | 134 { |
139 ASSERT(m_state == Processing || m_state == Finishing); | 135 ASSERT(m_state == Processing || m_state == Finishing); |
140 | 136 |
141 m_impl = 0; | 137 m_impl = 0; |
142 m_state = Done; | 138 m_state = Done; |
143 | 139 |
144 promiseResolver()->reject(ScriptValue::createNull()); | 140 promiseResolver()->reject(ScriptValue::createNull()); |
145 } | 141 } |
146 | 142 |
147 void CryptoOperation::completeWithArrayBuffer(const WebKit::WebArrayBuffer& buff
er) | 143 void CryptoOperation::completeWithArrayBuffer(const WebKit::WebArrayBuffer& buff
er) |
148 { | 144 { |
149 ASSERT(m_state == Processing || m_state == Finishing); | 145 ASSERT(m_state == Processing || m_state == Finishing); |
150 | 146 |
151 m_impl = 0; | 147 m_impl = 0; |
152 m_state = Done; | 148 m_state = Done; |
153 | 149 |
154 promiseResolver()->fulfill(PassRefPtr<ArrayBuffer>(buffer)); | 150 promiseResolver()->fulfill(PassRefPtr<ArrayBuffer>(buffer)); |
155 } | 151 } |
156 | 152 |
| 153 CryptoOperation* CryptoOperation::returnValue(ExceptionState& es) |
| 154 { |
| 155 ASSERT(m_state != Initializing); |
| 156 |
| 157 if (m_exceptionCode) { |
| 158 es.throwDOMException(m_exceptionCode); |
| 159 return 0; |
| 160 } |
| 161 return this; |
| 162 } |
| 163 |
157 void CryptoOperation::process(const unsigned char* bytes, size_t size) | 164 void CryptoOperation::process(const unsigned char* bytes, size_t size) |
158 { | 165 { |
159 switch (m_state) { | 166 switch (m_state) { |
160 case Initializing: | 167 case Initializing: |
161 ASSERT_NOT_REACHED(); | 168 ASSERT_NOT_REACHED(); |
162 case Processing: | 169 case Processing: |
163 m_impl->process(bytes, size); | 170 m_impl->process(bytes, size); |
164 break; | 171 break; |
165 case Finishing: | 172 case Finishing: |
166 case Done: | 173 case Done: |
(...skipping 23 matching lines...) Expand all Loading... |
190 } | 197 } |
191 | 198 |
192 ScriptPromiseResolver* CryptoOperation::promiseResolver() | 199 ScriptPromiseResolver* CryptoOperation::promiseResolver() |
193 { | 200 { |
194 if (!m_promiseResolver) | 201 if (!m_promiseResolver) |
195 m_promiseResolver = ScriptPromiseResolver::create(); | 202 m_promiseResolver = ScriptPromiseResolver::create(); |
196 return m_promiseResolver.get(); | 203 return m_promiseResolver.get(); |
197 } | 204 } |
198 | 205 |
199 } // namespace WebCore | 206 } // namespace WebCore |
OLD | NEW |