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