OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/FetchManager.h" | 6 #include "modules/fetch/FetchManager.h" |
7 | 7 |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
10 #include "bindings/core/v8/ScriptState.h" | 10 #include "bindings/core/v8/ScriptState.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 visitor->trace(m_resolver); | 197 visitor->trace(m_resolver); |
198 visitor->trace(m_request); | 198 visitor->trace(m_request); |
199 visitor->trace(m_integrityVerifier); | 199 visitor->trace(m_integrityVerifier); |
200 ContextLifecycleObserver::trace(visitor); | 200 ContextLifecycleObserver::trace(visitor); |
201 } | 201 } |
202 | 202 |
203 void FetchManager::Loader::didReceiveResponse(unsigned long, const ResourceRespo
nse& response, PassOwnPtr<WebDataConsumerHandle> handle) | 203 void FetchManager::Loader::didReceiveResponse(unsigned long, const ResourceRespo
nse& response, PassOwnPtr<WebDataConsumerHandle> handle) |
204 { | 204 { |
205 ASSERT(handle); | 205 ASSERT(handle); |
206 | 206 |
| 207 if (response.url().protocolIs("blob") && response.httpStatusCode() == 404) { |
| 208 // "If |blob| is null, return a network error." |
| 209 // https://fetch.spec.whatwg.org/#concept-basic-fetch |
| 210 performNetworkError("Blob not found."); |
| 211 return; |
| 212 } |
| 213 |
| 214 if (response.url().protocolIs("blob") && response.httpStatusCode() == 405) { |
| 215 performNetworkError("Only 'GET' method is allowed for blob URLs."); |
| 216 return; |
| 217 } |
| 218 |
207 m_responseHttpStatusCode = response.httpStatusCode(); | 219 m_responseHttpStatusCode = response.httpStatusCode(); |
208 | 220 |
209 if (response.url().protocolIsData()) { | 221 if (response.url().protocolIsData()) { |
210 if (m_request->url() == response.url()) { | 222 if (m_request->url() == response.url()) { |
211 // A direct request to data. | 223 // A direct request to data. |
212 m_request->setResponseTainting(FetchRequestData::BasicTainting); | 224 m_request->setResponseTainting(FetchRequestData::BasicTainting); |
213 } else { | 225 } else { |
214 // A redirect to data: scheme occured. | 226 // A redirect to data: scheme occured. |
215 // Redirects to data URLs are rejected by the spec because | 227 // Redirects to data URLs are rejected by the spec because |
216 // same-origin data-URL flag is unset, except for no-cors mode. | 228 // same-origin data-URL flag is unset, except for no-cors mode. |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 | 486 |
475 void FetchManager::Loader::performBasicFetch() | 487 void FetchManager::Loader::performBasicFetch() |
476 { | 488 { |
477 // "To perform a basic fetch using |request|, switch on |request|'s url's | 489 // "To perform a basic fetch using |request|, switch on |request|'s url's |
478 // scheme, and run the associated steps:" | 490 // scheme, and run the associated steps:" |
479 if (SchemeRegistry::shouldTreatURLSchemeAsSupportingFetchAPI(m_request->url(
).protocol())) { | 491 if (SchemeRegistry::shouldTreatURLSchemeAsSupportingFetchAPI(m_request->url(
).protocol())) { |
480 // "Return the result of performing an HTTP fetch using |request|." | 492 // "Return the result of performing an HTTP fetch using |request|." |
481 performHTTPFetch(false, false); | 493 performHTTPFetch(false, false); |
482 } else if (m_request->url().protocolIsData()) { | 494 } else if (m_request->url().protocolIsData()) { |
483 performDataFetch(); | 495 performDataFetch(); |
| 496 } else if (m_request->url().protocolIs("blob")) { |
| 497 performHTTPFetch(false, false); |
484 } else { | 498 } else { |
485 // FIXME: implement other protocols. | 499 // FIXME: implement other protocols. |
486 performNetworkError("Fetch API cannot load " + m_request->url().string()
+ ". URL scheme \"" + m_request->url().protocol() + "\" is not supported."); | 500 performNetworkError("Fetch API cannot load " + m_request->url().string()
+ ". URL scheme \"" + m_request->url().protocol() + "\" is not supported."); |
487 } | 501 } |
488 } | 502 } |
489 | 503 |
490 void FetchManager::Loader::performNetworkError(const String& message) | 504 void FetchManager::Loader::performNetworkError(const String& message) |
491 { | 505 { |
492 failed(message); | 506 failed(message); |
493 } | 507 } |
494 | 508 |
495 void FetchManager::Loader::performHTTPFetch(bool corsFlag, bool corsPreflightFla
g) | 509 void FetchManager::Loader::performHTTPFetch(bool corsFlag, bool corsPreflightFla
g) |
496 { | 510 { |
497 ASSERT(SchemeRegistry::shouldTreatURLSchemeAsSupportingFetchAPI(m_request->u
rl().protocol())); | 511 ASSERT(SchemeRegistry::shouldTreatURLSchemeAsSupportingFetchAPI(m_request->u
rl().protocol()) || (m_request->url().protocolIs("blob") && !corsFlag && !corsPr
eflightFlag)); |
498 // CORS preflight fetch procedure is implemented inside DocumentThreadableLo
ader. | 512 // CORS preflight fetch procedure is implemented inside DocumentThreadableLo
ader. |
499 | 513 |
500 // "1. Let |HTTPRequest| be a copy of |request|, except that |HTTPRequest|'s | 514 // "1. Let |HTTPRequest| be a copy of |request|, except that |HTTPRequest|'s |
501 // body is a tee of |request|'s body." | 515 // body is a tee of |request|'s body." |
502 // We use ResourceRequest class for HTTPRequest. | 516 // We use ResourceRequest class for HTTPRequest. |
503 // FIXME: Support body. | 517 // FIXME: Support body. |
504 ResourceRequest request(m_request->url()); | 518 ResourceRequest request(m_request->url()); |
505 request.setRequestContext(m_request->context()); | 519 request.setRequestContext(m_request->context()); |
506 request.setHTTPMethod(m_request->method()); | 520 request.setHTTPMethod(m_request->method()); |
507 const Vector<OwnPtr<FetchHeaderList::Header>>& list = m_request->headerList(
)->list(); | 521 const Vector<OwnPtr<FetchHeaderList::Header>>& list = m_request->headerList(
)->list(); |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 loader->dispose(); | 700 loader->dispose(); |
687 } | 701 } |
688 | 702 |
689 DEFINE_TRACE(FetchManager) | 703 DEFINE_TRACE(FetchManager) |
690 { | 704 { |
691 visitor->trace(m_executionContext); | 705 visitor->trace(m_executionContext); |
692 visitor->trace(m_loaders); | 706 visitor->trace(m_loaders); |
693 } | 707 } |
694 | 708 |
695 } // namespace blink | 709 } // namespace blink |
OLD | NEW |