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()) { | |
hiroshige
2015/07/30 12:07:21
Please call m_updater->update(createUnexpectedErro
tyoshino (SeeGerritForStatus)
2015/07/31 08:00:42
Good catch! Done
| |
249 return; | |
250 } | |
251 BlobRegistry::registerPublicBlobURL(executionContext->securityOrigin(), url, m_blobDataHandle); | |
252 | |
247 m_loader = createLoader(executionContext, this); | 253 m_loader = createLoader(executionContext, this); |
hiroshige
2015/07/30 12:07:21
Please add ASSERT(m_loader) here.
tyoshino (SeeGerritForStatus)
2015/07/31 08:00:42
Done.
| |
248 if (!m_loader) | 254 |
249 m_updater->update(createUnexpectedErrorDataConsumerHandle()); | 255 ResourceRequest request(url); |
256 request.setRequestContext(WebURLRequest::RequestContextInternal); | |
257 request.setUseStreamOnResponse(true); | |
258 m_loader->start(request); | |
250 } | 259 } |
251 | 260 |
252 private: | 261 private: |
253 PassRefPtr<ThreadableLoader> createLoader(ExecutionContext* executionContext , ThreadableLoaderClient* client) const | 262 PassRefPtr<ThreadableLoader> createLoader(ExecutionContext* executionContext , ThreadableLoaderClient* client) const |
254 { | 263 { |
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; | 264 ThreadableLoaderOptions options; |
266 options.preflightPolicy = ConsiderPreflight; | 265 options.preflightPolicy = ConsiderPreflight; |
267 options.crossOriginRequestPolicy = DenyCrossOriginRequests; | 266 options.crossOriginRequestPolicy = DenyCrossOriginRequests; |
268 options.contentSecurityPolicyEnforcement = DoNotEnforceContentSecurityPo licy; | 267 options.contentSecurityPolicyEnforcement = DoNotEnforceContentSecurityPo licy; |
269 options.initiator = FetchInitiatorTypeNames::internal; | 268 options.initiator = FetchInitiatorTypeNames::internal; |
270 | 269 |
271 ResourceLoaderOptions resourceLoaderOptions; | 270 ResourceLoaderOptions resourceLoaderOptions; |
272 resourceLoaderOptions.dataBufferingPolicy = DoNotBufferData; | 271 resourceLoaderOptions.dataBufferingPolicy = DoNotBufferData; |
273 | 272 |
274 return m_loaderFactory->create(*executionContext, client, request, optio ns, resourceLoaderOptions); | 273 return m_loaderFactory->create(*executionContext, client, options, resou rceLoaderOptions); |
275 } | 274 } |
276 | 275 |
277 // ThreadableLoaderClient | 276 // ThreadableLoaderClient |
278 void didReceiveResponse(unsigned long, const ResourceResponse&, PassOwnPtr<W ebDataConsumerHandle> handle) override | 277 void didReceiveResponse(unsigned long, const ResourceResponse&, PassOwnPtr<W ebDataConsumerHandle> handle) override |
279 { | 278 { |
280 ASSERT(!m_receivedResponse); | 279 ASSERT(!m_receivedResponse); |
281 m_receivedResponse = true; | 280 m_receivedResponse = true; |
282 if (!handle) { | 281 if (!handle) { |
283 // Here we assume WebURLLoader must return the response body as | 282 // Here we assume WebURLLoader must return the response body as |
284 // |WebDataConsumerHandle| since we call | 283 // |WebDataConsumerHandle| since we call |
(...skipping 29 matching lines...) Expand all Loading... | |
314 RefPtr<ThreadableLoader> m_loader; | 313 RefPtr<ThreadableLoader> m_loader; |
315 | 314 |
316 bool m_receivedResponse; | 315 bool m_receivedResponse; |
317 }; | 316 }; |
318 | 317 |
319 class DefaultLoaderFactory final : public FetchBlobDataConsumerHandle::LoaderFac tory { | 318 class DefaultLoaderFactory final : public FetchBlobDataConsumerHandle::LoaderFac tory { |
320 public: | 319 public: |
321 PassRefPtr<ThreadableLoader> create( | 320 PassRefPtr<ThreadableLoader> create( |
322 ExecutionContext& executionContext, | 321 ExecutionContext& executionContext, |
323 ThreadableLoaderClient* client, | 322 ThreadableLoaderClient* client, |
324 const ResourceRequest& request, | |
325 const ThreadableLoaderOptions& options, | 323 const ThreadableLoaderOptions& options, |
326 const ResourceLoaderOptions& resourceLoaderOptions) override | 324 const ResourceLoaderOptions& resourceLoaderOptions) override |
327 { | 325 { |
328 return ThreadableLoader::create(executionContext, client, request, optio ns, resourceLoaderOptions); | 326 return ThreadableLoader::create(executionContext, client, options, resou rceLoaderOptions); |
329 } | 327 } |
330 }; | 328 }; |
331 | 329 |
332 } // namespace | 330 } // namespace |
333 | 331 |
334 // ReaderContext is referenced from FetchBlobDataConsumerHandle and | 332 // ReaderContext is referenced from FetchBlobDataConsumerHandle and |
335 // ReaderContext::ReaderImpl. | 333 // ReaderContext::ReaderImpl. |
336 // All functions/members must be called/accessed only on the reader thread, | 334 // All functions/members must be called/accessed only on the reader thread, |
337 // except for constructor, destructor, and obtainReader(). | 335 // except for constructor, destructor, and obtainReader(). |
338 class FetchBlobDataConsumerHandle::ReaderContext final : public ThreadSafeRefCou nted<ReaderContext> { | 336 class FetchBlobDataConsumerHandle::ReaderContext final : public ThreadSafeRefCou nted<ReaderContext> { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
460 | 458 |
461 return adoptPtr(new FetchBlobDataConsumerHandle(executionContext, blobDataHa ndle, new DefaultLoaderFactory)); | 459 return adoptPtr(new FetchBlobDataConsumerHandle(executionContext, blobDataHa ndle, new DefaultLoaderFactory)); |
462 } | 460 } |
463 | 461 |
464 FetchDataConsumerHandle::Reader* FetchBlobDataConsumerHandle::obtainReaderIntern al(Client* client) | 462 FetchDataConsumerHandle::Reader* FetchBlobDataConsumerHandle::obtainReaderIntern al(Client* client) |
465 { | 463 { |
466 return m_readerContext->obtainReader(client).leakPtr(); | 464 return m_readerContext->obtainReader(client).leakPtr(); |
467 } | 465 } |
468 | 466 |
469 } // namespace blink | 467 } // namespace blink |
OLD | NEW |