| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 const HeapVector<ArrayBufferOrArrayBufferViewOrBlobOrUSVString>& blobParts, | 91 const HeapVector<ArrayBufferOrArrayBufferViewOrBlobOrUSVString>& blobParts, |
| 92 const BlobPropertyBag& options, | 92 const BlobPropertyBag& options, |
| 93 ExceptionState& exceptionState) { | 93 ExceptionState& exceptionState) { |
| 94 ASSERT(options.hasType()); | 94 ASSERT(options.hasType()); |
| 95 if (!options.type().containsOnlyASCII()) { | 95 if (!options.type().containsOnlyASCII()) { |
| 96 exceptionState.throwDOMException( | 96 exceptionState.throwDOMException( |
| 97 SyntaxError, "The 'type' property must consist of ASCII characters."); | 97 SyntaxError, "The 'type' property must consist of ASCII characters."); |
| 98 return nullptr; | 98 return nullptr; |
| 99 } | 99 } |
| 100 | 100 |
| 101 ASSERT(options.hasEndings()); | |
| 102 bool normalizeLineEndingsToNative = options.endings() == "native"; | |
| 103 if (normalizeLineEndingsToNative) | |
| 104 UseCounter::count(context, UseCounter::FileAPINativeLineEndings); | |
| 105 | |
| 106 std::unique_ptr<BlobData> blobData = BlobData::create(); | 101 std::unique_ptr<BlobData> blobData = BlobData::create(); |
| 107 blobData->setContentType(options.type().lower()); | 102 blobData->setContentType(options.type().lower()); |
| 108 | 103 |
| 109 populateBlobData(blobData.get(), blobParts, normalizeLineEndingsToNative); | 104 populateBlobData(blobData.get(), blobParts); |
| 110 | 105 |
| 111 long long blobSize = blobData->length(); | 106 long long blobSize = blobData->length(); |
| 112 return new Blob(BlobDataHandle::create(std::move(blobData), blobSize)); | 107 return new Blob(BlobDataHandle::create(std::move(blobData), blobSize)); |
| 113 } | 108 } |
| 114 | 109 |
| 115 Blob* Blob::create(const unsigned char* data, | 110 Blob* Blob::create(const unsigned char* data, |
| 116 size_t bytes, | 111 size_t bytes, |
| 117 const String& contentType) { | 112 const String& contentType) { |
| 118 ASSERT(data); | 113 ASSERT(data); |
| 119 | 114 |
| 120 std::unique_ptr<BlobData> blobData = BlobData::create(); | 115 std::unique_ptr<BlobData> blobData = BlobData::create(); |
| 121 blobData->setContentType(contentType); | 116 blobData->setContentType(contentType); |
| 122 blobData->appendBytes(data, bytes); | 117 blobData->appendBytes(data, bytes); |
| 123 long long blobSize = blobData->length(); | 118 long long blobSize = blobData->length(); |
| 124 | 119 |
| 125 return new Blob(BlobDataHandle::create(std::move(blobData), blobSize)); | 120 return new Blob(BlobDataHandle::create(std::move(blobData), blobSize)); |
| 126 } | 121 } |
| 127 | 122 |
| 128 // static | 123 // static |
| 129 void Blob::populateBlobData( | 124 void Blob::populateBlobData( |
| 130 BlobData* blobData, | 125 BlobData* blobData, |
| 131 const HeapVector<ArrayBufferOrArrayBufferViewOrBlobOrUSVString>& parts, | 126 const HeapVector<ArrayBufferOrArrayBufferViewOrBlobOrUSVString>& parts) { |
| 132 bool normalizeLineEndingsToNative) { | |
| 133 for (const auto& item : parts) { | 127 for (const auto& item : parts) { |
| 134 if (item.isArrayBuffer()) { | 128 if (item.isArrayBuffer()) { |
| 135 DOMArrayBuffer* arrayBuffer = item.getAsArrayBuffer(); | 129 DOMArrayBuffer* arrayBuffer = item.getAsArrayBuffer(); |
| 136 blobData->appendBytes(arrayBuffer->data(), arrayBuffer->byteLength()); | 130 blobData->appendBytes(arrayBuffer->data(), arrayBuffer->byteLength()); |
| 137 } else if (item.isArrayBufferView()) { | 131 } else if (item.isArrayBufferView()) { |
| 138 DOMArrayBufferView* arrayBufferView = item.getAsArrayBufferView(); | 132 DOMArrayBufferView* arrayBufferView = item.getAsArrayBufferView(); |
| 139 blobData->appendBytes(arrayBufferView->baseAddress(), | 133 blobData->appendBytes(arrayBufferView->baseAddress(), |
| 140 arrayBufferView->byteLength()); | 134 arrayBufferView->byteLength()); |
| 141 } else if (item.isBlob()) { | 135 } else if (item.isBlob()) { |
| 142 item.getAsBlob()->appendTo(*blobData); | 136 item.getAsBlob()->appendTo(*blobData); |
| 143 } else if (item.isUSVString()) { | 137 } else if (item.isUSVString()) { |
| 144 blobData->appendText(item.getAsUSVString(), normalizeLineEndingsToNative); | 138 blobData->appendText(item.getAsUSVString()); |
| 145 } else { | 139 } else { |
| 146 NOTREACHED(); | 140 NOTREACHED(); |
| 147 } | 141 } |
| 148 } | 142 } |
| 149 } | 143 } |
| 150 | 144 |
| 151 // static | 145 // static |
| 152 void Blob::clampSliceOffsets(long long size, long long& start, long long& end) { | 146 void Blob::clampSliceOffsets(long long size, long long& start, long long& end) { |
| 153 ASSERT(size != -1); | 147 ASSERT(size != -1); |
| 154 | 148 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 | 212 |
| 219 void Blob::appendTo(BlobData& blobData) const { | 213 void Blob::appendTo(BlobData& blobData) const { |
| 220 blobData.appendBlob(m_blobDataHandle, 0, m_blobDataHandle->size()); | 214 blobData.appendBlob(m_blobDataHandle, 0, m_blobDataHandle->size()); |
| 221 } | 215 } |
| 222 | 216 |
| 223 URLRegistry& Blob::registry() const { | 217 URLRegistry& Blob::registry() const { |
| 224 return BlobURLRegistry::registry(); | 218 return BlobURLRegistry::registry(); |
| 225 } | 219 } |
| 226 | 220 |
| 227 } // namespace blink | 221 } // namespace blink |
| OLD | NEW |