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

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

Issue 1313733006: Allowing registering arbitrary schemes as supporting the fetch API. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: SupportingFetchAPI 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
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 16 matching lines...) Expand all
27 #include "modules/fetch/BodyStreamBuffer.h" 27 #include "modules/fetch/BodyStreamBuffer.h"
28 #include "modules/fetch/CompositeDataConsumerHandle.h" 28 #include "modules/fetch/CompositeDataConsumerHandle.h"
29 #include "modules/fetch/DataConsumerHandleUtil.h" 29 #include "modules/fetch/DataConsumerHandleUtil.h"
30 #include "modules/fetch/FetchFormDataConsumerHandle.h" 30 #include "modules/fetch/FetchFormDataConsumerHandle.h"
31 #include "modules/fetch/FetchRequestData.h" 31 #include "modules/fetch/FetchRequestData.h"
32 #include "modules/fetch/Response.h" 32 #include "modules/fetch/Response.h"
33 #include "modules/fetch/ResponseInit.h" 33 #include "modules/fetch/ResponseInit.h"
34 #include "platform/network/ResourceError.h" 34 #include "platform/network/ResourceError.h"
35 #include "platform/network/ResourceRequest.h" 35 #include "platform/network/ResourceRequest.h"
36 #include "platform/network/ResourceResponse.h" 36 #include "platform/network/ResourceResponse.h"
37 #include "platform/weborigin/SchemeRegistry.h"
37 #include "platform/weborigin/SecurityOrigin.h" 38 #include "platform/weborigin/SecurityOrigin.h"
38 #include "public/platform/WebURLRequest.h" 39 #include "public/platform/WebURLRequest.h"
39 #include "wtf/HashSet.h" 40 #include "wtf/HashSet.h"
40 #include "wtf/Vector.h" 41 #include "wtf/Vector.h"
41 #include "wtf/text/WTFString.h" 42 #include "wtf/text/WTFString.h"
42 43
43 namespace blink { 44 namespace blink {
44 45
45 namespace { 46 namespace {
46 47
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 // "- |request|'s mode is |no CORS|" 390 // "- |request|'s mode is |no CORS|"
390 if (m_request->mode() == WebURLRequest::FetchRequestModeNoCORS) { 391 if (m_request->mode() == WebURLRequest::FetchRequestModeNoCORS) {
391 // "Set |request|'s response tainting to |opaque|." 392 // "Set |request|'s response tainting to |opaque|."
392 m_request->setResponseTainting(FetchRequestData::OpaqueTainting); 393 m_request->setResponseTainting(FetchRequestData::OpaqueTainting);
393 // "The result of performing a basic fetch using |request|." 394 // "The result of performing a basic fetch using |request|."
394 performBasicFetch(); 395 performBasicFetch();
395 return; 396 return;
396 } 397 }
397 398
398 // "- |request|'s url's scheme is not one of 'http' and 'https'" 399 // "- |request|'s url's scheme is not one of 'http' and 'https'"
399 if (!m_request->url().protocolIsInHTTPFamily()) { 400 if (!m_request->url().protocolIsInHTTPFamily()) {
hiroshige 2015/08/27 09:39:51 shouldTreatURLSchemeAsSupportingFetchAPI() should
400 // "A network error." 401 // "A network error."
401 performNetworkError("Fetch API cannot load " + m_request->url().string() + ". URL scheme must be \"http\" or \"https\" for CORS request."); 402 performNetworkError("Fetch API cannot load " + m_request->url().string() + ". URL scheme must be \"http\" or \"https\" for CORS request.");
402 return; 403 return;
403 } 404 }
404 405
405 // "- |request|'s mode is |CORS-with-forced-preflight|. 406 // "- |request|'s mode is |CORS-with-forced-preflight|.
406 // "- |request|'s unsafe request flag is set and either |request|'s method 407 // "- |request|'s unsafe request flag is set and either |request|'s method
407 // is not a simple method or a header in |request|'s header list is not a 408 // is not a simple method or a header in |request|'s header list is not a
408 // simple header" 409 // simple header"
409 if (m_request->mode() == WebURLRequest::FetchRequestModeCORSWithForcedPrefli ght 410 if (m_request->mode() == WebURLRequest::FetchRequestModeCORSWithForcedPrefli ght
(...skipping 23 matching lines...) Expand all
433 if (m_loader) { 434 if (m_loader) {
434 m_loader->cancel(); 435 m_loader->cancel();
435 m_loader.clear(); 436 m_loader.clear();
436 } 437 }
437 } 438 }
438 439
439 void FetchManager::Loader::performBasicFetch() 440 void FetchManager::Loader::performBasicFetch()
440 { 441 {
441 // "To perform a basic fetch using |request|, switch on |request|'s url's 442 // "To perform a basic fetch using |request|, switch on |request|'s url's
442 // scheme, and run the associated steps:" 443 // scheme, and run the associated steps:"
443 if (m_request->url().protocolIsInHTTPFamily()) { 444 if (SchemeRegistry::shouldTreatURLSchemeAsSupportingFetchAPI(m_request->url( ).protocol())) {
pdr. 2015/08/25 21:25:09 This code is in the critical path but has to wait
not at google - send to devlin 2015/08/25 22:04:45 (I will defer to fetch owner to answer this)
tyoshino (SeeGerritForStatus) 2015/08/26 07:24:48 We already have one in DocumentThreadableLoader. A
444 // "Return the result of performing an HTTP fetch using |request|." 445 // "Return the result of performing an HTTP fetch using |request|."
445 performHTTPFetch(false, false); 446 performHTTPFetch(false, false);
446 } else { 447 } else {
447 // FIXME: implement other protocols. 448 // FIXME: implement other protocols.
448 performNetworkError("Fetch API cannot load " + m_request->url().string() + ". URL scheme \"" + m_request->url().protocol() + "\" is not supported."); 449 performNetworkError("Fetch API cannot load " + m_request->url().string() + ". URL scheme \"" + m_request->url().protocol() + "\" is not supported.");
449 } 450 }
450 } 451 }
451 452
452 void FetchManager::Loader::performNetworkError(const String& message) 453 void FetchManager::Loader::performNetworkError(const String& message)
453 { 454 {
454 failed(message); 455 failed(message);
455 } 456 }
456 457
457 void FetchManager::Loader::performHTTPFetch(bool corsFlag, bool corsPreflightFla g) 458 void FetchManager::Loader::performHTTPFetch(bool corsFlag, bool corsPreflightFla g)
458 { 459 {
459 ASSERT(m_request->url().protocolIsInHTTPFamily()); 460 ASSERT(SchemeRegistry::shouldTreatURLSchemeAsSupportingFetchAPI(m_request->u rl().protocol()));
460 // CORS preflight fetch procedure is implemented inside DocumentThreadableLo ader. 461 // CORS preflight fetch procedure is implemented inside DocumentThreadableLo ader.
461 462
462 // "1. Let |HTTPRequest| be a copy of |request|, except that |HTTPRequest|'s 463 // "1. Let |HTTPRequest| be a copy of |request|, except that |HTTPRequest|'s
463 // body is a tee of |request|'s body." 464 // body is a tee of |request|'s body."
464 // We use ResourceRequest class for HTTPRequest. 465 // We use ResourceRequest class for HTTPRequest.
465 // FIXME: Support body. 466 // FIXME: Support body.
466 ResourceRequest request(m_request->url()); 467 ResourceRequest request(m_request->url());
467 request.setRequestContext(m_request->context()); 468 request.setRequestContext(m_request->context());
468 request.setHTTPMethod(m_request->method()); 469 request.setHTTPMethod(m_request->method());
469 const Vector<OwnPtr<FetchHeaderList::Header>>& list = m_request->headerList( )->list(); 470 const Vector<OwnPtr<FetchHeaderList::Header>>& list = m_request->headerList( )->list();
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 599
599 DEFINE_TRACE(FetchManager) 600 DEFINE_TRACE(FetchManager)
600 { 601 {
601 #if ENABLE(OILPAN) 602 #if ENABLE(OILPAN)
602 visitor->trace(m_executionContext); 603 visitor->trace(m_executionContext);
603 visitor->trace(m_loaders); 604 visitor->trace(m_loaders);
604 #endif 605 #endif
605 } 606 }
606 607
607 } // namespace blink 608 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | Source/platform/weborigin/SchemeRegistry.h » ('j') | Source/platform/weborigin/SchemeRegistry.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698