| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 86 |
| 87 Blob::~Blob() {} | 87 Blob::~Blob() {} |
| 88 | 88 |
| 89 // static | 89 // static |
| 90 Blob* Blob::create( | 90 Blob* Blob::create( |
| 91 ExecutionContext* context, | 91 ExecutionContext* context, |
| 92 const HeapVector<ArrayBufferOrArrayBufferViewOrBlobOrUSVString>& blobParts, | 92 const HeapVector<ArrayBufferOrArrayBufferViewOrBlobOrUSVString>& blobParts, |
| 93 const BlobPropertyBag& options, | 93 const BlobPropertyBag& options, |
| 94 ExceptionState& exceptionState) { | 94 ExceptionState& exceptionState) { |
| 95 ASSERT(options.hasType()); | 95 ASSERT(options.hasType()); |
| 96 if (!options.type().containsOnlyASCII()) { | |
| 97 exceptionState.throwDOMException( | |
| 98 SyntaxError, "The 'type' property must consist of ASCII characters."); | |
| 99 return nullptr; | |
| 100 } | |
| 101 | 96 |
| 102 ASSERT(options.hasEndings()); | 97 ASSERT(options.hasEndings()); |
| 103 bool normalizeLineEndingsToNative = options.endings() == "native"; | 98 bool normalizeLineEndingsToNative = options.endings() == "native"; |
| 104 if (normalizeLineEndingsToNative) | 99 if (normalizeLineEndingsToNative) |
| 105 UseCounter::count(context, UseCounter::FileAPINativeLineEndings); | 100 UseCounter::count(context, UseCounter::FileAPINativeLineEndings); |
| 106 | 101 |
| 107 std::unique_ptr<BlobData> blobData = BlobData::create(); | 102 std::unique_ptr<BlobData> blobData = BlobData::create(); |
| 108 blobData->setContentType(options.type().lower()); | 103 blobData->setContentType(normalizeType(options.type())); |
| 109 | 104 |
| 110 populateBlobData(blobData.get(), blobParts, normalizeLineEndingsToNative); | 105 populateBlobData(blobData.get(), blobParts, normalizeLineEndingsToNative); |
| 111 | 106 |
| 112 long long blobSize = blobData->length(); | 107 long long blobSize = blobData->length(); |
| 113 return new Blob(BlobDataHandle::create(std::move(blobData), blobSize)); | 108 return new Blob(BlobDataHandle::create(std::move(blobData), blobSize)); |
| 114 } | 109 } |
| 115 | 110 |
| 116 Blob* Blob::create(const unsigned char* data, | 111 Blob* Blob::create(const unsigned char* data, |
| 117 size_t bytes, | 112 size_t bytes, |
| 118 const String& contentType) { | 113 const String& contentType) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 exceptionState.throwDOMException(InvalidStateError, | 177 exceptionState.throwDOMException(InvalidStateError, |
| 183 "Blob has been closed."); | 178 "Blob has been closed."); |
| 184 return nullptr; | 179 return nullptr; |
| 185 } | 180 } |
| 186 | 181 |
| 187 long long size = this->size(); | 182 long long size = this->size(); |
| 188 clampSliceOffsets(size, start, end); | 183 clampSliceOffsets(size, start, end); |
| 189 | 184 |
| 190 long long length = end - start; | 185 long long length = end - start; |
| 191 std::unique_ptr<BlobData> blobData = BlobData::create(); | 186 std::unique_ptr<BlobData> blobData = BlobData::create(); |
| 192 blobData->setContentType(contentType); | 187 blobData->setContentType(normalizeType(contentType)); |
| 193 blobData->appendBlob(m_blobDataHandle, start, length); | 188 blobData->appendBlob(m_blobDataHandle, start, length); |
| 194 return Blob::create(BlobDataHandle::create(std::move(blobData), length)); | 189 return Blob::create(BlobDataHandle::create(std::move(blobData), length)); |
| 195 } | 190 } |
| 196 | 191 |
| 197 void Blob::close(ScriptState* scriptState, ExceptionState& exceptionState) { | 192 void Blob::close(ScriptState* scriptState, 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; |
| 202 } | 197 } |
| (...skipping 14 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 |