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 "config.h" | 5 #include "config.h" |
6 #include "modules/fetch/FetchBlobDataConsumerHandle.h" | 6 #include "modules/fetch/FetchBlobDataConsumerHandle.h" |
7 | 7 |
8 #include "core/dom/ActiveDOMObject.h" | 8 #include "core/dom/ActiveDOMObject.h" |
9 #include "core/dom/CrossThreadTask.h" | 9 #include "core/dom/CrossThreadTask.h" |
10 #include "core/dom/ExecutionContext.h" | 10 #include "core/dom/ExecutionContext.h" |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 m_loader->cancel(); | 237 m_loader->cancel(); |
238 m_loader.clear(); | 238 m_loader.clear(); |
239 } | 239 } |
240 } | 240 } |
241 | 241 |
242 void start(ExecutionContext* executionContext) override | 242 void start(ExecutionContext* executionContext) override |
243 { | 243 { |
244 ASSERT(executionContext->isContextThread()); | 244 ASSERT(executionContext->isContextThread()); |
245 ASSERT(!m_loader); | 245 ASSERT(!m_loader); |
246 | 246 |
| 247 KURL url = BlobURL::createPublicURL(executionContext->securityOrigin()); |
| 248 if (url.isEmpty()) { |
| 249 m_updater->update(createUnexpectedErrorDataConsumerHandle()); |
| 250 return; |
| 251 } |
| 252 BlobRegistry::registerPublicBlobURL(executionContext->securityOrigin(),
url, m_blobDataHandle); |
| 253 |
247 m_loader = createLoader(executionContext, this); | 254 m_loader = createLoader(executionContext, this); |
248 if (!m_loader) | 255 ASSERT(m_loader); |
249 m_updater->update(createUnexpectedErrorDataConsumerHandle()); | 256 |
| 257 ResourceRequest request(url); |
| 258 request.setRequestContext(WebURLRequest::RequestContextInternal); |
| 259 request.setUseStreamOnResponse(true); |
| 260 m_loader->start(request); |
250 } | 261 } |
251 | 262 |
252 private: | 263 private: |
253 PassRefPtr<ThreadableLoader> createLoader(ExecutionContext* executionContext
, ThreadableLoaderClient* client) const | 264 PassRefPtr<ThreadableLoader> createLoader(ExecutionContext* executionContext
, ThreadableLoaderClient* client) const |
254 { | 265 { |
255 KURL url = BlobURL::createPublicURL(executionContext->securityOrigin()); | |
256 if (url.isEmpty()) { | |
257 return nullptr; | |
258 } | |
259 BlobRegistry::registerPublicBlobURL(executionContext->securityOrigin(),
url, m_blobDataHandle); | |
260 | |
261 ResourceRequest request(url); | |
262 request.setRequestContext(WebURLRequest::RequestContextInternal); | |
263 request.setUseStreamOnResponse(true); | |
264 | |
265 ThreadableLoaderOptions options; | 266 ThreadableLoaderOptions options; |
266 options.preflightPolicy = ConsiderPreflight; | 267 options.preflightPolicy = ConsiderPreflight; |
267 options.crossOriginRequestPolicy = DenyCrossOriginRequests; | 268 options.crossOriginRequestPolicy = DenyCrossOriginRequests; |
268 options.contentSecurityPolicyEnforcement = DoNotEnforceContentSecurityPo
licy; | 269 options.contentSecurityPolicyEnforcement = DoNotEnforceContentSecurityPo
licy; |
269 options.initiator = FetchInitiatorTypeNames::internal; | 270 options.initiator = FetchInitiatorTypeNames::internal; |
270 | 271 |
271 ResourceLoaderOptions resourceLoaderOptions; | 272 ResourceLoaderOptions resourceLoaderOptions; |
272 resourceLoaderOptions.dataBufferingPolicy = DoNotBufferData; | 273 resourceLoaderOptions.dataBufferingPolicy = DoNotBufferData; |
273 | 274 |
274 return m_loaderFactory->create(*executionContext, client, request, optio
ns, resourceLoaderOptions); | 275 return m_loaderFactory->create(*executionContext, client, options, resou
rceLoaderOptions); |
275 } | 276 } |
276 | 277 |
277 // ThreadableLoaderClient | 278 // ThreadableLoaderClient |
278 void didReceiveResponse(unsigned long, const ResourceResponse&, PassOwnPtr<W
ebDataConsumerHandle> handle) override | 279 void didReceiveResponse(unsigned long, const ResourceResponse&, PassOwnPtr<W
ebDataConsumerHandle> handle) override |
279 { | 280 { |
280 ASSERT(!m_receivedResponse); | 281 ASSERT(!m_receivedResponse); |
281 m_receivedResponse = true; | 282 m_receivedResponse = true; |
282 if (!handle) { | 283 if (!handle) { |
283 // Here we assume WebURLLoader must return the response body as | 284 // Here we assume WebURLLoader must return the response body as |
284 // |WebDataConsumerHandle| since we call | 285 // |WebDataConsumerHandle| since we call |
(...skipping 29 matching lines...) Expand all Loading... |
314 RefPtr<ThreadableLoader> m_loader; | 315 RefPtr<ThreadableLoader> m_loader; |
315 | 316 |
316 bool m_receivedResponse; | 317 bool m_receivedResponse; |
317 }; | 318 }; |
318 | 319 |
319 class DefaultLoaderFactory final : public FetchBlobDataConsumerHandle::LoaderFac
tory { | 320 class DefaultLoaderFactory final : public FetchBlobDataConsumerHandle::LoaderFac
tory { |
320 public: | 321 public: |
321 PassRefPtr<ThreadableLoader> create( | 322 PassRefPtr<ThreadableLoader> create( |
322 ExecutionContext& executionContext, | 323 ExecutionContext& executionContext, |
323 ThreadableLoaderClient* client, | 324 ThreadableLoaderClient* client, |
324 const ResourceRequest& request, | |
325 const ThreadableLoaderOptions& options, | 325 const ThreadableLoaderOptions& options, |
326 const ResourceLoaderOptions& resourceLoaderOptions) override | 326 const ResourceLoaderOptions& resourceLoaderOptions) override |
327 { | 327 { |
328 return ThreadableLoader::create(executionContext, client, request, optio
ns, resourceLoaderOptions); | 328 return ThreadableLoader::create(executionContext, client, options, resou
rceLoaderOptions); |
329 } | 329 } |
330 }; | 330 }; |
331 | 331 |
332 } // namespace | 332 } // namespace |
333 | 333 |
334 // ReaderContext is referenced from FetchBlobDataConsumerHandle and | 334 // ReaderContext is referenced from FetchBlobDataConsumerHandle and |
335 // ReaderContext::ReaderImpl. | 335 // ReaderContext::ReaderImpl. |
336 // All functions/members must be called/accessed only on the reader thread, | 336 // All functions/members must be called/accessed only on the reader thread, |
337 // except for constructor, destructor, and obtainReader(). | 337 // except for constructor, destructor, and obtainReader(). |
338 class FetchBlobDataConsumerHandle::ReaderContext final : public ThreadSafeRefCou
nted<ReaderContext> { | 338 class FetchBlobDataConsumerHandle::ReaderContext final : public ThreadSafeRefCou
nted<ReaderContext> { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 | 460 |
461 return adoptPtr(new FetchBlobDataConsumerHandle(executionContext, blobDataHa
ndle, new DefaultLoaderFactory)); | 461 return adoptPtr(new FetchBlobDataConsumerHandle(executionContext, blobDataHa
ndle, new DefaultLoaderFactory)); |
462 } | 462 } |
463 | 463 |
464 FetchDataConsumerHandle::Reader* FetchBlobDataConsumerHandle::obtainReaderIntern
al(Client* client) | 464 FetchDataConsumerHandle::Reader* FetchBlobDataConsumerHandle::obtainReaderIntern
al(Client* client) |
465 { | 465 { |
466 return m_readerContext->obtainReader(client).leakPtr(); | 466 return m_readerContext->obtainReader(client).leakPtr(); |
467 } | 467 } |
468 | 468 |
469 } // namespace blink | 469 } // namespace blink |
OLD | NEW |