| 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 20 matching lines...) Expand all Loading... |
| 31 #include "core/fileapi/Blob.h" | 31 #include "core/fileapi/Blob.h" |
| 32 | 32 |
| 33 #include "bindings/core/v8/ExceptionState.h" | 33 #include "bindings/core/v8/ExceptionState.h" |
| 34 #include "core/dom/DOMURL.h" | 34 #include "core/dom/DOMURL.h" |
| 35 #include "core/dom/ExceptionCode.h" | 35 #include "core/dom/ExceptionCode.h" |
| 36 #include "core/dom/ExecutionContext.h" | 36 #include "core/dom/ExecutionContext.h" |
| 37 #include "core/fileapi/BlobPropertyBag.h" | 37 #include "core/fileapi/BlobPropertyBag.h" |
| 38 #include "core/frame/UseCounter.h" | 38 #include "core/frame/UseCounter.h" |
| 39 #include "platform/blob/BlobRegistry.h" | 39 #include "platform/blob/BlobRegistry.h" |
| 40 #include "platform/blob/BlobURL.h" | 40 #include "platform/blob/BlobURL.h" |
| 41 #include <memory> | |
| 42 | 41 |
| 43 namespace blink { | 42 namespace blink { |
| 44 | 43 |
| 45 namespace { | 44 namespace { |
| 46 | 45 |
| 47 class BlobURLRegistry final : public URLRegistry { | 46 class BlobURLRegistry final : public URLRegistry { |
| 48 public: | 47 public: |
| 49 void registerURL(SecurityOrigin*, const KURL&, URLRegistrable*) override; | 48 void registerURL(SecurityOrigin*, const KURL&, URLRegistrable*) override; |
| 50 void unregisterURL(const KURL&) override; | 49 void unregisterURL(const KURL&) override; |
| 51 | 50 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 if (!options.type().containsOnlyASCII()) { | 92 if (!options.type().containsOnlyASCII()) { |
| 94 exceptionState.throwDOMException(SyntaxError, "The 'type' property must
consist of ASCII characters."); | 93 exceptionState.throwDOMException(SyntaxError, "The 'type' property must
consist of ASCII characters."); |
| 95 return nullptr; | 94 return nullptr; |
| 96 } | 95 } |
| 97 | 96 |
| 98 ASSERT(options.hasEndings()); | 97 ASSERT(options.hasEndings()); |
| 99 bool normalizeLineEndingsToNative = options.endings() == "native"; | 98 bool normalizeLineEndingsToNative = options.endings() == "native"; |
| 100 if (normalizeLineEndingsToNative) | 99 if (normalizeLineEndingsToNative) |
| 101 UseCounter::count(context, UseCounter::FileAPINativeLineEndings); | 100 UseCounter::count(context, UseCounter::FileAPINativeLineEndings); |
| 102 | 101 |
| 103 std::unique_ptr<BlobData> blobData = BlobData::create(); | 102 OwnPtr<BlobData> blobData = BlobData::create(); |
| 104 blobData->setContentType(options.type().lower()); | 103 blobData->setContentType(options.type().lower()); |
| 105 | 104 |
| 106 populateBlobData(blobData.get(), blobParts, normalizeLineEndingsToNative); | 105 populateBlobData(blobData.get(), blobParts, normalizeLineEndingsToNative); |
| 107 | 106 |
| 108 long long blobSize = blobData->length(); | 107 long long blobSize = blobData->length(); |
| 109 return new Blob(BlobDataHandle::create(std::move(blobData), blobSize)); | 108 return new Blob(BlobDataHandle::create(std::move(blobData), blobSize)); |
| 110 } | 109 } |
| 111 | 110 |
| 112 Blob* Blob::create(const unsigned char* data, size_t bytes, const String& conten
tType) | 111 Blob* Blob::create(const unsigned char* data, size_t bytes, const String& conten
tType) |
| 113 { | 112 { |
| 114 ASSERT(data); | 113 ASSERT(data); |
| 115 | 114 |
| 116 std::unique_ptr<BlobData> blobData = BlobData::create(); | 115 OwnPtr<BlobData> blobData = BlobData::create(); |
| 117 blobData->setContentType(contentType); | 116 blobData->setContentType(contentType); |
| 118 blobData->appendBytes(data, bytes); | 117 blobData->appendBytes(data, bytes); |
| 119 long long blobSize = blobData->length(); | 118 long long blobSize = blobData->length(); |
| 120 | 119 |
| 121 return new Blob(BlobDataHandle::create(std::move(blobData), blobSize)); | 120 return new Blob(BlobDataHandle::create(std::move(blobData), blobSize)); |
| 122 } | 121 } |
| 123 | 122 |
| 124 // static | 123 // static |
| 125 void Blob::populateBlobData(BlobData* blobData, const HeapVector<ArrayBufferOrAr
rayBufferViewOrBlobOrUSVString>& parts, bool normalizeLineEndingsToNative) | 124 void Blob::populateBlobData(BlobData* blobData, const HeapVector<ArrayBufferOrAr
rayBufferViewOrBlobOrUSVString>& parts, bool normalizeLineEndingsToNative) |
| 126 { | 125 { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 { | 170 { |
| 172 if (isClosed()) { | 171 if (isClosed()) { |
| 173 exceptionState.throwDOMException(InvalidStateError, "Blob has been close
d."); | 172 exceptionState.throwDOMException(InvalidStateError, "Blob has been close
d."); |
| 174 return nullptr; | 173 return nullptr; |
| 175 } | 174 } |
| 176 | 175 |
| 177 long long size = this->size(); | 176 long long size = this->size(); |
| 178 clampSliceOffsets(size, start, end); | 177 clampSliceOffsets(size, start, end); |
| 179 | 178 |
| 180 long long length = end - start; | 179 long long length = end - start; |
| 181 std::unique_ptr<BlobData> blobData = BlobData::create(); | 180 OwnPtr<BlobData> blobData = BlobData::create(); |
| 182 blobData->setContentType(contentType); | 181 blobData->setContentType(contentType); |
| 183 blobData->appendBlob(m_blobDataHandle, start, length); | 182 blobData->appendBlob(m_blobDataHandle, start, length); |
| 184 return Blob::create(BlobDataHandle::create(std::move(blobData), length)); | 183 return Blob::create(BlobDataHandle::create(std::move(blobData), length)); |
| 185 } | 184 } |
| 186 | 185 |
| 187 void Blob::close(ExecutionContext* executionContext, ExceptionState& exceptionSt
ate) | 186 void Blob::close(ExecutionContext* executionContext, ExceptionState& exceptionSt
ate) |
| 188 { | 187 { |
| 189 if (isClosed()) { | 188 if (isClosed()) { |
| 190 exceptionState.throwDOMException(InvalidStateError, "Blob has been close
d."); | 189 exceptionState.throwDOMException(InvalidStateError, "Blob has been close
d."); |
| 191 return; | 190 return; |
| 192 } | 191 } |
| 193 | 192 |
| 194 // Dereferencing a Blob that has been closed should result in | 193 // Dereferencing a Blob that has been closed should result in |
| 195 // a network error. Revoke URLs registered against it through | 194 // a network error. Revoke URLs registered against it through |
| 196 // its UUID. | 195 // its UUID. |
| 197 DOMURL::revokeObjectUUID(executionContext, uuid()); | 196 DOMURL::revokeObjectUUID(executionContext, uuid()); |
| 198 | 197 |
| 199 // A Blob enters a 'readability state' of closed, where it will report its | 198 // A Blob enters a 'readability state' of closed, where it will report its |
| 200 // size as zero. Blob and FileReader operations now throws on | 199 // size as zero. Blob and FileReader operations now throws on |
| 201 // being passed a Blob in that state. Downstream uses of closed Blobs | 200 // being passed a Blob in that state. Downstream uses of closed Blobs |
| 202 // (e.g., XHR.send()) consider them as empty. | 201 // (e.g., XHR.send()) consider them as empty. |
| 203 std::unique_ptr<BlobData> blobData = BlobData::create(); | 202 OwnPtr<BlobData> blobData = BlobData::create(); |
| 204 blobData->setContentType(type()); | 203 blobData->setContentType(type()); |
| 205 m_blobDataHandle = BlobDataHandle::create(std::move(blobData), 0); | 204 m_blobDataHandle = BlobDataHandle::create(std::move(blobData), 0); |
| 206 m_isClosed = true; | 205 m_isClosed = true; |
| 207 } | 206 } |
| 208 | 207 |
| 209 void Blob::appendTo(BlobData& blobData) const | 208 void Blob::appendTo(BlobData& blobData) const |
| 210 { | 209 { |
| 211 blobData.appendBlob(m_blobDataHandle, 0, m_blobDataHandle->size()); | 210 blobData.appendBlob(m_blobDataHandle, 0, m_blobDataHandle->size()); |
| 212 } | 211 } |
| 213 | 212 |
| 214 URLRegistry& Blob::registry() const | 213 URLRegistry& Blob::registry() const |
| 215 { | 214 { |
| 216 return BlobURLRegistry::registry(); | 215 return BlobURLRegistry::registry(); |
| 217 } | 216 } |
| 218 | 217 |
| 219 } // namespace blink | 218 } // namespace blink |
| OLD | NEW |