| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/fetch/FetchDataLoader.h" | 5 #include "modules/fetch/FetchDataLoader.h" |
| 6 | 6 |
| 7 #include "core/html/parser/TextResourceDecoder.h" | 7 #include "core/html/parser/TextResourceDecoder.h" |
| 8 #include "public/platform/WebTaskRunner.h" |
| 8 #include "wtf/PtrUtil.h" | 9 #include "wtf/PtrUtil.h" |
| 9 #include "wtf/text/StringBuilder.h" | 10 #include "wtf/text/StringBuilder.h" |
| 10 #include "wtf/text/WTFString.h" | 11 #include "wtf/text/WTFString.h" |
| 11 #include "wtf/typed_arrays/ArrayBufferBuilder.h" | 12 #include "wtf/typed_arrays/ArrayBufferBuilder.h" |
| 12 #include <memory> | 13 #include <memory> |
| 14 #include <utility> |
| 13 | 15 |
| 14 namespace blink { | 16 namespace blink { |
| 15 | 17 |
| 16 namespace { | 18 namespace { |
| 17 | 19 |
| 18 class FetchDataLoaderAsBlobHandle | 20 class FetchDataLoaderAsBlobHandle |
| 19 : public FetchDataLoader | 21 : public FetchDataLoader |
| 20 , public WebDataConsumerHandle::Client { | 22 , public WebDataConsumerHandle::Client { |
| 21 public: | 23 public: |
| 22 explicit FetchDataLoaderAsBlobHandle(const String& mimeType) | 24 explicit FetchDataLoaderAsBlobHandle(const String& mimeType) |
| 23 : m_client(nullptr) | 25 : m_client(nullptr) |
| 24 , m_mimeType(mimeType) { } | 26 , m_mimeType(mimeType) { } |
| 25 | 27 |
| 26 DEFINE_INLINE_VIRTUAL_TRACE() | 28 DEFINE_INLINE_VIRTUAL_TRACE() |
| 27 { | 29 { |
| 28 FetchDataLoader::trace(visitor); | 30 FetchDataLoader::trace(visitor); |
| 29 visitor->trace(m_client); | 31 visitor->trace(m_client); |
| 30 } | 32 } |
| 31 | 33 |
| 32 private: | 34 private: |
| 33 void start(FetchDataConsumerHandle* handle, FetchDataLoader::Client* client)
override | 35 void start(FetchDataConsumerHandle* handle, FetchDataLoader::Client* client,
std::unique_ptr<WebTaskRunner> readerTaskRunner) override |
| 34 { | 36 { |
| 35 ASSERT(!m_client); | 37 ASSERT(!m_client); |
| 36 ASSERT(!m_reader); | 38 ASSERT(!m_reader); |
| 37 | 39 |
| 38 m_client = client; | 40 m_client = client; |
| 39 // Passing |this| here is safe because |this| owns |m_reader|. | 41 // Passing |this| here is safe because |this| owns |m_reader|. |
| 40 m_reader = handle->obtainFetchDataReader(this); | 42 m_reader = handle->obtainFetchDataReader(this, std::move(readerTaskRunne
r)); |
| 41 RefPtr<BlobDataHandle> blobHandle = m_reader->drainAsBlobDataHandle(); | 43 RefPtr<BlobDataHandle> blobHandle = m_reader->drainAsBlobDataHandle(); |
| 42 if (blobHandle) { | 44 if (blobHandle) { |
| 43 ASSERT(blobHandle->size() != UINT64_MAX); | 45 ASSERT(blobHandle->size() != UINT64_MAX); |
| 44 m_reader.reset(); | 46 m_reader.reset(); |
| 45 if (blobHandle->type() != m_mimeType) { | 47 if (blobHandle->type() != m_mimeType) { |
| 46 // A new BlobDataHandle is created to override the Blob's type. | 48 // A new BlobDataHandle is created to override the Blob's type. |
| 47 m_client->didFetchDataLoadedBlobHandle(BlobDataHandle::create(bl
obHandle->uuid(), m_mimeType, blobHandle->size())); | 49 m_client->didFetchDataLoadedBlobHandle(BlobDataHandle::create(bl
obHandle->uuid(), m_mimeType, blobHandle->size())); |
| 48 } else { | 50 } else { |
| 49 m_client->didFetchDataLoadedBlobHandle(blobHandle); | 51 m_client->didFetchDataLoadedBlobHandle(blobHandle); |
| 50 } | 52 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 FetchDataLoaderAsArrayBuffer() | 119 FetchDataLoaderAsArrayBuffer() |
| 118 : m_client(nullptr) { } | 120 : m_client(nullptr) { } |
| 119 | 121 |
| 120 DEFINE_INLINE_VIRTUAL_TRACE() | 122 DEFINE_INLINE_VIRTUAL_TRACE() |
| 121 { | 123 { |
| 122 FetchDataLoader::trace(visitor); | 124 FetchDataLoader::trace(visitor); |
| 123 visitor->trace(m_client); | 125 visitor->trace(m_client); |
| 124 } | 126 } |
| 125 | 127 |
| 126 protected: | 128 protected: |
| 127 void start(FetchDataConsumerHandle* handle, FetchDataLoader::Client* client)
override | 129 void start(FetchDataConsumerHandle* handle, FetchDataLoader::Client* client,
std::unique_ptr<WebTaskRunner> readerTaskRunner) override |
| 128 { | 130 { |
| 129 ASSERT(!m_client); | 131 ASSERT(!m_client); |
| 130 ASSERT(!m_rawData); | 132 ASSERT(!m_rawData); |
| 131 ASSERT(!m_reader); | 133 ASSERT(!m_reader); |
| 132 m_client = client; | 134 m_client = client; |
| 133 m_rawData = wrapUnique(new ArrayBufferBuilder()); | 135 m_rawData = wrapUnique(new ArrayBufferBuilder()); |
| 134 m_reader = handle->obtainFetchDataReader(this); | 136 m_reader = handle->obtainFetchDataReader(this, std::move(readerTaskRunne
r)); |
| 135 } | 137 } |
| 136 | 138 |
| 137 void didGetReadable() override | 139 void didGetReadable() override |
| 138 { | 140 { |
| 139 ASSERT(m_client); | 141 ASSERT(m_client); |
| 140 ASSERT(m_rawData); | 142 ASSERT(m_rawData); |
| 141 ASSERT(m_reader); | 143 ASSERT(m_reader); |
| 142 | 144 |
| 143 while (true) { | 145 while (true) { |
| 144 const void* buffer; | 146 const void* buffer; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 FetchDataLoaderAsString() | 208 FetchDataLoaderAsString() |
| 207 : m_client(nullptr) { } | 209 : m_client(nullptr) { } |
| 208 | 210 |
| 209 DEFINE_INLINE_VIRTUAL_TRACE() | 211 DEFINE_INLINE_VIRTUAL_TRACE() |
| 210 { | 212 { |
| 211 FetchDataLoader::trace(visitor); | 213 FetchDataLoader::trace(visitor); |
| 212 visitor->trace(m_client); | 214 visitor->trace(m_client); |
| 213 } | 215 } |
| 214 | 216 |
| 215 protected: | 217 protected: |
| 216 void start(FetchDataConsumerHandle* handle, FetchDataLoader::Client* client)
override | 218 void start(FetchDataConsumerHandle* handle, FetchDataLoader::Client* client,
std::unique_ptr<WebTaskRunner> readerTaskRunner) override |
| 217 { | 219 { |
| 218 ASSERT(!m_client); | 220 ASSERT(!m_client); |
| 219 ASSERT(!m_decoder); | 221 ASSERT(!m_decoder); |
| 220 ASSERT(!m_reader); | 222 ASSERT(!m_reader); |
| 221 m_client = client; | 223 m_client = client; |
| 222 m_decoder = TextResourceDecoder::createAlwaysUseUTF8ForText(); | 224 m_decoder = TextResourceDecoder::createAlwaysUseUTF8ForText(); |
| 223 m_reader = handle->obtainFetchDataReader(this); | 225 m_reader = handle->obtainFetchDataReader(this, std::move(readerTaskRunne
r)); |
| 224 } | 226 } |
| 225 | 227 |
| 226 void didGetReadable() override | 228 void didGetReadable() override |
| 227 { | 229 { |
| 228 ASSERT(m_client); | 230 ASSERT(m_client); |
| 229 ASSERT(m_decoder); | 231 ASSERT(m_decoder); |
| 230 ASSERT(m_reader); | 232 ASSERT(m_reader); |
| 231 | 233 |
| 232 while (true) { | 234 while (true) { |
| 233 const void* buffer; | 235 const void* buffer; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 , m_outStream(outStream) { } | 297 , m_outStream(outStream) { } |
| 296 | 298 |
| 297 DEFINE_INLINE_VIRTUAL_TRACE() | 299 DEFINE_INLINE_VIRTUAL_TRACE() |
| 298 { | 300 { |
| 299 FetchDataLoader::trace(visitor); | 301 FetchDataLoader::trace(visitor); |
| 300 visitor->trace(m_client); | 302 visitor->trace(m_client); |
| 301 visitor->trace(m_outStream); | 303 visitor->trace(m_outStream); |
| 302 } | 304 } |
| 303 | 305 |
| 304 protected: | 306 protected: |
| 305 void start(FetchDataConsumerHandle* handle, FetchDataLoader::Client* client)
override | 307 void start(FetchDataConsumerHandle* handle, FetchDataLoader::Client* client,
std::unique_ptr<WebTaskRunner> readerTaskRunner) override |
| 306 { | 308 { |
| 307 ASSERT(!m_client); | 309 ASSERT(!m_client); |
| 308 ASSERT(!m_reader); | 310 ASSERT(!m_reader); |
| 309 m_client = client; | 311 m_client = client; |
| 310 m_reader = handle->obtainFetchDataReader(this); | 312 m_reader = handle->obtainFetchDataReader(this, std::move(readerTaskRunne
r)); |
| 311 } | 313 } |
| 312 | 314 |
| 313 void didGetReadable() override | 315 void didGetReadable() override |
| 314 { | 316 { |
| 315 ASSERT(m_client); | 317 ASSERT(m_client); |
| 316 ASSERT(m_reader); | 318 ASSERT(m_reader); |
| 317 | 319 |
| 318 bool needToFlush = false; | 320 bool needToFlush = false; |
| 319 while (true) { | 321 while (true) { |
| 320 const void* buffer; | 322 const void* buffer; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 { | 396 { |
| 395 return new FetchDataLoaderAsString(); | 397 return new FetchDataLoaderAsString(); |
| 396 } | 398 } |
| 397 | 399 |
| 398 FetchDataLoader* FetchDataLoader::createLoaderAsStream(Stream* outStream) | 400 FetchDataLoader* FetchDataLoader::createLoaderAsStream(Stream* outStream) |
| 399 { | 401 { |
| 400 return new FetchDataLoaderAsStream(outStream); | 402 return new FetchDataLoaderAsStream(outStream); |
| 401 } | 403 } |
| 402 | 404 |
| 403 } // namespace blink | 405 } // namespace blink |
| OLD | NEW |