Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: Source/modules/fetch/FetchManager.cpp

Issue 1336933003: [Migrated][Fetch] Support blob: scheme (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Network Error for non-GET blob URLs. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « LayoutTests/http/tests/fetch/workers/thorough/scheme-blob-other-https.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 visitor->trace(m_resolver); 195 visitor->trace(m_resolver);
196 visitor->trace(m_request); 196 visitor->trace(m_request);
197 visitor->trace(m_integrityVerifier); 197 visitor->trace(m_integrityVerifier);
198 ContextLifecycleObserver::trace(visitor); 198 ContextLifecycleObserver::trace(visitor);
199 } 199 }
200 200
201 void FetchManager::Loader::didReceiveResponse(unsigned long, const ResourceRespo nse& response, PassOwnPtr<WebDataConsumerHandle> handle) 201 void FetchManager::Loader::didReceiveResponse(unsigned long, const ResourceRespo nse& response, PassOwnPtr<WebDataConsumerHandle> handle)
202 { 202 {
203 ASSERT(handle); 203 ASSERT(handle);
204 204
205 if (response.url().protocolIs("blob") && response.httpStatusCode() == 404) {
206 // "If |blob| is null, return a network error."
207 // https://fetch.spec.whatwg.org/#concept-basic-fetch
208 performNetworkError("Blob not found.");
209 return;
210 }
211
212 if (response.url().protocolIs("blob") && response.httpStatusCode() == 405) {
213 // TODO(hiroshige): Spec will be updated https://github.com/whatwg/fetch /issues/125. Update this comment with citing the new spec before commit.
yhirano 2015/10/06 05:02:01 The issue was closed.
214 performNetworkError("Only 'GET' method is allowed for blob URLs.");
215 return;
216 }
217
205 m_responseHttpStatusCode = response.httpStatusCode(); 218 m_responseHttpStatusCode = response.httpStatusCode();
206 219
207 // Recompute the tainting if the request was redirected to a different 220 // Recompute the tainting if the request was redirected to a different
208 // origin. 221 // origin.
209 if (!SecurityOrigin::create(response.url())->isSameSchemeHostPort(m_request- >origin().get())) { 222 if (!SecurityOrigin::create(response.url())->isSameSchemeHostPort(m_request- >origin().get())) {
210 switch (m_request->mode()) { 223 switch (m_request->mode()) {
211 case WebURLRequest::FetchRequestModeSameOrigin: 224 case WebURLRequest::FetchRequestModeSameOrigin:
212 ASSERT_NOT_REACHED(); 225 ASSERT_NOT_REACHED();
213 break; 226 break;
214 case WebURLRequest::FetchRequestModeNoCORS: 227 case WebURLRequest::FetchRequestModeNoCORS:
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 } 452 }
440 } 453 }
441 454
442 void FetchManager::Loader::performBasicFetch() 455 void FetchManager::Loader::performBasicFetch()
443 { 456 {
444 // "To perform a basic fetch using |request|, switch on |request|'s url's 457 // "To perform a basic fetch using |request|, switch on |request|'s url's
445 // scheme, and run the associated steps:" 458 // scheme, and run the associated steps:"
446 if (SchemeRegistry::shouldTreatURLSchemeAsSupportingFetchAPI(m_request->url( ).protocol())) { 459 if (SchemeRegistry::shouldTreatURLSchemeAsSupportingFetchAPI(m_request->url( ).protocol())) {
447 // "Return the result of performing an HTTP fetch using |request|." 460 // "Return the result of performing an HTTP fetch using |request|."
448 performHTTPFetch(false, false); 461 performHTTPFetch(false, false);
462 } else if (m_request->url().protocolIs("blob")) {
463 performHTTPFetch(false, false);
449 } else { 464 } else {
450 // FIXME: implement other protocols. 465 // FIXME: implement other protocols.
451 performNetworkError("Fetch API cannot load " + m_request->url().string() + ". URL scheme \"" + m_request->url().protocol() + "\" is not supported."); 466 performNetworkError("Fetch API cannot load " + m_request->url().string() + ". URL scheme \"" + m_request->url().protocol() + "\" is not supported.");
452 } 467 }
453 } 468 }
454 469
455 void FetchManager::Loader::performNetworkError(const String& message) 470 void FetchManager::Loader::performNetworkError(const String& message)
456 { 471 {
457 failed(message); 472 failed(message);
458 } 473 }
459 474
460 void FetchManager::Loader::performHTTPFetch(bool corsFlag, bool corsPreflightFla g) 475 void FetchManager::Loader::performHTTPFetch(bool corsFlag, bool corsPreflightFla g)
461 { 476 {
462 ASSERT(SchemeRegistry::shouldTreatURLSchemeAsSupportingFetchAPI(m_request->u rl().protocol())); 477 ASSERT(SchemeRegistry::shouldTreatURLSchemeAsSupportingFetchAPI(m_request->u rl().protocol()) || (m_request->url().protocolIs("blob") && !corsFlag && !corsPr eflightFlag));
463 // CORS preflight fetch procedure is implemented inside DocumentThreadableLo ader. 478 // CORS preflight fetch procedure is implemented inside DocumentThreadableLo ader.
464 479
465 // "1. Let |HTTPRequest| be a copy of |request|, except that |HTTPRequest|'s 480 // "1. Let |HTTPRequest| be a copy of |request|, except that |HTTPRequest|'s
466 // body is a tee of |request|'s body." 481 // body is a tee of |request|'s body."
467 // We use ResourceRequest class for HTTPRequest. 482 // We use ResourceRequest class for HTTPRequest.
468 // FIXME: Support body. 483 // FIXME: Support body.
469 ResourceRequest request(m_request->url()); 484 ResourceRequest request(m_request->url());
470 request.setRequestContext(m_request->context()); 485 request.setRequestContext(m_request->context());
471 request.setHTTPMethod(m_request->method()); 486 request.setHTTPMethod(m_request->method());
472 const Vector<OwnPtr<FetchHeaderList::Header>>& list = m_request->headerList( )->list(); 487 const Vector<OwnPtr<FetchHeaderList::Header>>& list = m_request->headerList( )->list();
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 616
602 DEFINE_TRACE(FetchManager) 617 DEFINE_TRACE(FetchManager)
603 { 618 {
604 #if ENABLE(OILPAN) 619 #if ENABLE(OILPAN)
605 visitor->trace(m_executionContext); 620 visitor->trace(m_executionContext);
606 visitor->trace(m_loaders); 621 visitor->trace(m_loaders);
607 #endif 622 #endif
608 } 623 }
609 624
610 } // namespace blink 625 } // namespace blink
OLDNEW
« no previous file with comments | « LayoutTests/http/tests/fetch/workers/thorough/scheme-blob-other-https.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698