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