| 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 11 matching lines...) Expand all Loading... |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 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 "core/fileapi/Stream.h" | 32 #include "modules/crypto/CryptoOperation.h" |
| 33 | 33 |
| 34 #include "core/fileapi/BlobRegistry.h" | 34 #include "modules/crypto/AesCbcParams.h" |
| 35 #include "core/fileapi/BlobURL.h" | 35 #include "modules/crypto/AesKeyGenParams.h" |
| 36 #include "core/platform/network/BlobData.h" | 36 #include "modules/crypto/Algorithm.h" |
| 37 | 37 |
| 38 namespace WebCore { | 38 namespace WebCore { |
| 39 | 39 |
| 40 Stream::Stream(const String& mediaType) | 40 namespace { |
| 41 : m_mediaType(mediaType) | 41 |
| 42 , m_isNeutered(false) | 42 PassRefPtr<Algorithm> createAlgorithm(const WebKit::WebCryptoAlgorithm& algorith
m) |
| 43 { |
| 44 switch (algorithm.paramsType()) { |
| 45 case WebKit::WebCryptoAlgorithmParamsTypeNone: |
| 46 return Algorithm::create(algorithm); |
| 47 case WebKit::WebCryptoAlgorithmParamsTypeAesCbcParams: |
| 48 return AesCbcParams::create(algorithm); |
| 49 case WebKit::WebCryptoAlgorithmParamsTypeAesKeyGenParams: |
| 50 return AesKeyGenParams::create(algorithm); |
| 51 } |
| 52 ASSERT_NOT_REACHED(); |
| 53 return 0; |
| 54 } |
| 55 |
| 56 } // namespace |
| 57 |
| 58 CryptoOperation::CryptoOperation(const WebKit::WebCryptoAlgorithm& algorithm) |
| 59 : m_algorithm(algorithm) |
| 43 { | 60 { |
| 44 ScriptWrappable::init(this); | 61 ScriptWrappable::init(this); |
| 45 | |
| 46 // Create a new internal URL for a stream and register it with the provided | |
| 47 // media type. | |
| 48 m_internalURL = BlobURL::createInternalURL(); | |
| 49 BlobRegistry::registerStreamURL(m_internalURL, m_mediaType); | |
| 50 } | 62 } |
| 51 | 63 |
| 52 void Stream::addData(const char* data, size_t len) | 64 Algorithm* CryptoOperation::algorithm() |
| 53 { | 65 { |
| 54 RefPtr<RawData> buffer(RawData::create()); | 66 if (!m_algorithmNode) |
| 55 buffer->mutableData()->resize(len); | 67 m_algorithmNode = createAlgorithm(m_algorithm); |
| 56 memcpy(buffer->mutableData()->data(), data, len); | 68 return m_algorithmNode.get(); |
| 57 BlobRegistry::addDataToStream(m_internalURL, buffer); | |
| 58 } | |
| 59 | |
| 60 void Stream::finalize() | |
| 61 { | |
| 62 BlobRegistry::finalizeStream(m_internalURL); | |
| 63 } | |
| 64 | |
| 65 Stream::~Stream() | |
| 66 { | |
| 67 BlobRegistry::unregisterBlobURL(m_internalURL); | |
| 68 } | 69 } |
| 69 | 70 |
| 70 } // namespace WebCore | 71 } // namespace WebCore |
| OLD | NEW |