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

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: negation fix 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 // This may include other HTTP-like schemes if the embedder has added them
not at google - send to devlin 2015/08/28 16:44:32 I added this comment here.
401 // to SchemeRegistry::registerURLSchemeAsSupportingFetchAPI.
402 if (!SchemeRegistry::shouldTreatURLSchemeAsSupportingFetchAPI(m_request->url ().protocol())) {
400 // "A network error." 403 // "A network error."
401 performNetworkError("Fetch API cannot load " + m_request->url().string() + ". URL scheme must be \"http\" or \"https\" for CORS request."); 404 performNetworkError("Fetch API cannot load " + m_request->url().string() + ". URL scheme must be \"http\" or \"https\" for CORS request.");
402 return; 405 return;
403 } 406 }
404 407
405 // "- |request|'s mode is |CORS-with-forced-preflight|. 408 // "- |request|'s mode is |CORS-with-forced-preflight|.
406 // "- |request|'s unsafe request flag is set and either |request|'s method 409 // "- |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 410 // is not a simple method or a header in |request|'s header list is not a
408 // simple header" 411 // simple header"
409 if (m_request->mode() == WebURLRequest::FetchRequestModeCORSWithForcedPrefli ght 412 if (m_request->mode() == WebURLRequest::FetchRequestModeCORSWithForcedPrefli ght
(...skipping 23 matching lines...) Expand all
433 if (m_loader) { 436 if (m_loader) {
434 m_loader->cancel(); 437 m_loader->cancel();
435 m_loader.clear(); 438 m_loader.clear();
436 } 439 }
437 } 440 }
438 441
439 void FetchManager::Loader::performBasicFetch() 442 void FetchManager::Loader::performBasicFetch()
440 { 443 {
441 // "To perform a basic fetch using |request|, switch on |request|'s url's 444 // "To perform a basic fetch using |request|, switch on |request|'s url's
442 // scheme, and run the associated steps:" 445 // scheme, and run the associated steps:"
443 if (m_request->url().protocolIsInHTTPFamily()) { 446 if (SchemeRegistry::shouldTreatURLSchemeAsSupportingFetchAPI(m_request->url( ).protocol())) {
444 // "Return the result of performing an HTTP fetch using |request|." 447 // "Return the result of performing an HTTP fetch using |request|."
445 performHTTPFetch(false, false); 448 performHTTPFetch(false, false);
446 } else { 449 } else {
447 // FIXME: implement other protocols. 450 // FIXME: implement other protocols.
448 performNetworkError("Fetch API cannot load " + m_request->url().string() + ". URL scheme \"" + m_request->url().protocol() + "\" is not supported."); 451 performNetworkError("Fetch API cannot load " + m_request->url().string() + ". URL scheme \"" + m_request->url().protocol() + "\" is not supported.");
449 } 452 }
450 } 453 }
451 454
452 void FetchManager::Loader::performNetworkError(const String& message) 455 void FetchManager::Loader::performNetworkError(const String& message)
453 { 456 {
454 failed(message); 457 failed(message);
455 } 458 }
456 459
457 void FetchManager::Loader::performHTTPFetch(bool corsFlag, bool corsPreflightFla g) 460 void FetchManager::Loader::performHTTPFetch(bool corsFlag, bool corsPreflightFla g)
458 { 461 {
459 ASSERT(m_request->url().protocolIsInHTTPFamily()); 462 ASSERT(SchemeRegistry::shouldTreatURLSchemeAsSupportingFetchAPI(m_request->u rl().protocol()));
460 // CORS preflight fetch procedure is implemented inside DocumentThreadableLo ader. 463 // CORS preflight fetch procedure is implemented inside DocumentThreadableLo ader.
461 464
462 // "1. Let |HTTPRequest| be a copy of |request|, except that |HTTPRequest|'s 465 // "1. Let |HTTPRequest| be a copy of |request|, except that |HTTPRequest|'s
463 // body is a tee of |request|'s body." 466 // body is a tee of |request|'s body."
464 // We use ResourceRequest class for HTTPRequest. 467 // We use ResourceRequest class for HTTPRequest.
465 // FIXME: Support body. 468 // FIXME: Support body.
466 ResourceRequest request(m_request->url()); 469 ResourceRequest request(m_request->url());
467 request.setRequestContext(m_request->context()); 470 request.setRequestContext(m_request->context());
468 request.setHTTPMethod(m_request->method()); 471 request.setHTTPMethod(m_request->method());
469 const Vector<OwnPtr<FetchHeaderList::Header>>& list = m_request->headerList( )->list(); 472 const Vector<OwnPtr<FetchHeaderList::Header>>& list = m_request->headerList( )->list();
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 601
599 DEFINE_TRACE(FetchManager) 602 DEFINE_TRACE(FetchManager)
600 { 603 {
601 #if ENABLE(OILPAN) 604 #if ENABLE(OILPAN)
602 visitor->trace(m_executionContext); 605 visitor->trace(m_executionContext);
603 visitor->trace(m_loaders); 606 visitor->trace(m_loaders);
604 #endif 607 #endif
605 } 608 }
606 609
607 } // namespace blink 610 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | Source/platform/weborigin/SchemeRegistry.h » ('j') | public/web/WebSecurityPolicy.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698