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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 85 |
86 Blob::~Blob() {} | 86 Blob::~Blob() {} |
87 | 87 |
88 // static | 88 // static |
89 Blob* Blob::create( | 89 Blob* Blob::create( |
90 ExecutionContext* context, | 90 ExecutionContext* context, |
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()) { | |
96 exceptionState.throwDOMException( | |
97 SyntaxError, "The 'type' property must consist of ASCII characters."); | |
98 return nullptr; | |
99 } | |
100 | 95 |
101 ASSERT(options.hasEndings()); | 96 ASSERT(options.hasEndings()); |
102 bool normalizeLineEndingsToNative = options.endings() == "native"; | 97 bool normalizeLineEndingsToNative = options.endings() == "native"; |
103 if (normalizeLineEndingsToNative) | 98 if (normalizeLineEndingsToNative) |
104 UseCounter::count(context, UseCounter::FileAPINativeLineEndings); | 99 UseCounter::count(context, UseCounter::FileAPINativeLineEndings); |
105 | 100 |
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(normalizeType(options.type())); |
108 | 103 |
109 populateBlobData(blobData.get(), blobParts, normalizeLineEndingsToNative); | 104 populateBlobData(blobData.get(), blobParts, normalizeLineEndingsToNative); |
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) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 exceptionState.throwDOMException(InvalidStateError, | 176 exceptionState.throwDOMException(InvalidStateError, |
182 "Blob has been closed."); | 177 "Blob has been closed."); |
183 return nullptr; | 178 return nullptr; |
184 } | 179 } |
185 | 180 |
186 long long size = this->size(); | 181 long long size = this->size(); |
187 clampSliceOffsets(size, start, end); | 182 clampSliceOffsets(size, start, end); |
188 | 183 |
189 long long length = end - start; | 184 long long length = end - start; |
190 std::unique_ptr<BlobData> blobData = BlobData::create(); | 185 std::unique_ptr<BlobData> blobData = BlobData::create(); |
191 blobData->setContentType(contentType); | 186 blobData->setContentType(normalizeType(contentType)); |
192 blobData->appendBlob(m_blobDataHandle, start, length); | 187 blobData->appendBlob(m_blobDataHandle, start, length); |
193 return Blob::create(BlobDataHandle::create(std::move(blobData), length)); | 188 return Blob::create(BlobDataHandle::create(std::move(blobData), length)); |
194 } | 189 } |
195 | 190 |
196 void Blob::close(ExecutionContext* executionContext, | 191 void Blob::close(ExecutionContext* executionContext, |
197 ExceptionState& exceptionState) { | 192 ExceptionState& exceptionState) { |
198 if (isClosed()) { | 193 if (isClosed()) { |
199 exceptionState.throwDOMException(InvalidStateError, | 194 exceptionState.throwDOMException(InvalidStateError, |
200 "Blob has been closed."); | 195 "Blob has been closed."); |
201 return; | 196 return; |
(...skipping 15 matching lines...) Expand all Loading... |
217 } | 212 } |
218 | 213 |
219 void Blob::appendTo(BlobData& blobData) const { | 214 void Blob::appendTo(BlobData& blobData) const { |
220 blobData.appendBlob(m_blobDataHandle, 0, m_blobDataHandle->size()); | 215 blobData.appendBlob(m_blobDataHandle, 0, m_blobDataHandle->size()); |
221 } | 216 } |
222 | 217 |
223 URLRegistry& Blob::registry() const { | 218 URLRegistry& Blob::registry() const { |
224 return BlobURLRegistry::registry(); | 219 return BlobURLRegistry::registry(); |
225 } | 220 } |
226 | 221 |
| 222 // static |
| 223 String Blob::normalizeType(const String& type) { |
| 224 if (type.isNull()) |
| 225 return emptyString; |
| 226 const size_t length = type.length(); |
| 227 if (type.is8Bit()) { |
| 228 const LChar* chars = type.characters8(); |
| 229 for (size_t i = 0; i < length; ++i) { |
| 230 if (chars[i] < 0x20 || chars[i] > 0x7e) |
| 231 return emptyString; |
| 232 } |
| 233 } else { |
| 234 const UChar* chars = type.characters16(); |
| 235 for (size_t i = 0; i < length; ++i) { |
| 236 if (chars[i] < 0x0020 || chars[i] > 0x007e) |
| 237 return emptyString; |
| 238 } |
| 239 } |
| 240 return type.lower(); |
| 241 } |
| 242 |
227 } // namespace blink | 243 } // namespace blink |
OLD | NEW |