OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. |
3 * Copyright (C) 2013, Intel Corporation | 3 * Copyright (C) 2013, Intel Corporation |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 // Max number of CORS redirects handled in DocumentThreadableLoader. | 60 // Max number of CORS redirects handled in DocumentThreadableLoader. |
61 // Same number as net/url_request/url_request.cc, and | 61 // Same number as net/url_request/url_request.cc, and |
62 // same number as https://fetch.spec.whatwg.org/#concept-http-fetch, Step 4. | 62 // same number as https://fetch.spec.whatwg.org/#concept-http-fetch, Step 4. |
63 // FIXME: currently the number of redirects is counted and limited here and in | 63 // FIXME: currently the number of redirects is counted and limited here and in |
64 // net/url_request/url_request.cc separately. | 64 // net/url_request/url_request.cc separately. |
65 static const int kMaxCORSRedirects = 20; | 65 static const int kMaxCORSRedirects = 20; |
66 | 66 |
67 void DocumentThreadableLoader::loadResourceSynchronously(Document& document, con st ResourceRequest& request, ThreadableLoaderClient& client, const ThreadableLoa derOptions& options, const ResourceLoaderOptions& resourceLoaderOptions) | 67 void DocumentThreadableLoader::loadResourceSynchronously(Document& document, con st ResourceRequest& request, ThreadableLoaderClient& client, const ThreadableLoa derOptions& options, const ResourceLoaderOptions& resourceLoaderOptions) |
68 { | 68 { |
69 // The loader will be deleted as soon as this function exits. | 69 // The loader will be deleted as soon as this function exits. |
70 RefPtr<DocumentThreadableLoader> loader = adoptRef(new DocumentThreadableLoa der(document, &client, LoadSynchronously, request, options, resourceLoaderOption s)); | 70 RefPtr<DocumentThreadableLoader> loader = adoptRef(new DocumentThreadableLoa der(document, &client, LoadSynchronously, options, resourceLoaderOptions)); |
71 loader->start(request); | |
71 ASSERT(loader->hasOneRef()); | 72 ASSERT(loader->hasOneRef()); |
72 } | 73 } |
73 | 74 |
74 PassRefPtr<DocumentThreadableLoader> DocumentThreadableLoader::create(Document& document, ThreadableLoaderClient* client, const ResourceRequest& request, const ThreadableLoaderOptions& options, const ResourceLoaderOptions& resourceLoaderOpt ions) | 75 PassRefPtr<DocumentThreadableLoader> DocumentThreadableLoader::create(Document& document, ThreadableLoaderClient* client, const ThreadableLoaderOptions& options , const ResourceLoaderOptions& resourceLoaderOptions) |
75 { | 76 { |
76 RefPtr<DocumentThreadableLoader> loader = adoptRef(new DocumentThreadableLoa der(document, client, LoadAsynchronously, request, options, resourceLoaderOption s)); | 77 RefPtr<DocumentThreadableLoader> loader = adoptRef(new DocumentThreadableLoa der(document, client, LoadAsynchronously, options, resourceLoaderOptions)); |
77 if (!loader->resource()) | |
78 loader = nullptr; | |
79 return loader.release(); | 78 return loader.release(); |
hiroshige
2015/07/30 12:07:21
Now can we merge the two lines above into one?
tyoshino (SeeGerritForStatus)
2015/07/31 08:00:42
Done.
| |
80 } | 79 } |
81 | 80 |
82 DocumentThreadableLoader::DocumentThreadableLoader(Document& document, Threadabl eLoaderClient* client, BlockingBehavior blockingBehavior, const ResourceRequest& request, const ThreadableLoaderOptions& options, const ResourceLoaderOptions& r esourceLoaderOptions) | 81 DocumentThreadableLoader::DocumentThreadableLoader(Document& document, Threadabl eLoaderClient* client, BlockingBehavior blockingBehavior, const ThreadableLoader Options& options, const ResourceLoaderOptions& resourceLoaderOptions) |
83 : m_client(client) | 82 : m_client(client) |
84 , m_document(document) | 83 , m_document(document) |
85 , m_options(options) | 84 , m_options(options) |
86 , m_resourceLoaderOptions(resourceLoaderOptions) | 85 , m_resourceLoaderOptions(resourceLoaderOptions) |
87 , m_forceDoNotAllowStoredCredentials(false) | 86 , m_forceDoNotAllowStoredCredentials(false) |
88 , m_securityOrigin(m_resourceLoaderOptions.securityOrigin) | 87 , m_securityOrigin(m_resourceLoaderOptions.securityOrigin) |
89 , m_sameOriginRequest(securityOrigin()->canRequestNoSuborigin(request.url()) ) | 88 , m_sameOriginRequest(false) |
hiroshige
2015/07/30 12:07:21
optional: Should we add a comment in the header th
tyoshino (SeeGerritForStatus)
2015/07/31 08:00:42
Said that start() must always follow create().
| |
90 , m_crossOriginNonSimpleRequest(false) | 89 , m_crossOriginNonSimpleRequest(false) |
91 , m_isUsingDataConsumerHandle(false) | 90 , m_isUsingDataConsumerHandle(false) |
92 , m_async(blockingBehavior == LoadAsynchronously) | 91 , m_async(blockingBehavior == LoadAsynchronously) |
93 , m_requestContext(request.requestContext()) | 92 , m_requestContext(WebURLRequest::RequestContextUnspecified) |
hiroshige
2015/07/30 12:07:21
ditto.
tyoshino (SeeGerritForStatus)
2015/07/31 08:00:42
Done.
| |
94 , m_timeoutTimer(this, &DocumentThreadableLoader::didTimeout) | 93 , m_timeoutTimer(this, &DocumentThreadableLoader::didTimeout) |
95 , m_requestStartedSeconds(0.0) | 94 , m_requestStartedSeconds(0.0) |
96 , m_corsRedirectLimit(kMaxCORSRedirects) | 95 , m_corsRedirectLimit(kMaxCORSRedirects) |
97 { | 96 { |
98 ASSERT(client); | 97 ASSERT(client); |
98 } | |
99 | |
100 void DocumentThreadableLoader::start(const ResourceRequest& request) | |
101 { | |
99 // Setting an outgoing referer is only supported in the async code path. | 102 // Setting an outgoing referer is only supported in the async code path. |
100 ASSERT(m_async || request.httpReferrer().isEmpty()); | 103 ASSERT(m_async || request.httpReferrer().isEmpty()); |
101 | 104 |
105 m_sameOriginRequest = securityOrigin()->canRequestNoSuborigin(request.url()) ; | |
106 m_requestContext = request.requestContext(); | |
107 | |
102 if (!m_sameOriginRequest && m_options.crossOriginRequestPolicy == DenyCrossO riginRequests) { | 108 if (!m_sameOriginRequest && m_options.crossOriginRequestPolicy == DenyCrossO riginRequests) { |
103 m_client->didFail(ResourceError(errorDomainBlinkInternal, 0, request.url ().string(), "Cross origin requests are not supported.")); | 109 m_client->didFail(ResourceError(errorDomainBlinkInternal, 0, request.url ().string(), "Cross origin requests are not supported.")); |
104 return; | 110 return; |
105 } | 111 } |
106 | 112 |
107 m_requestStartedSeconds = monotonicallyIncreasingTime(); | 113 m_requestStartedSeconds = monotonicallyIncreasingTime(); |
108 | 114 |
109 // Save any CORS simple headers on the request here. If this request redirec ts cross-origin, we cancel the old request | 115 // Save any CORS simple headers on the request here. If this request redirec ts cross-origin, we cancel the old request |
110 // create a new one, and copy these headers. | 116 // create a new one, and copy these headers. |
111 const HTTPHeaderMap& headerMap = request.httpHeaderFields(); | 117 const HTTPHeaderMap& headerMap = request.httpHeaderFields(); |
112 for (const auto& header : headerMap) { | 118 for (const auto& header : headerMap) { |
113 if (FetchUtils::isSimpleHeader(header.key, header.value)) | 119 if (FetchUtils::isSimpleHeader(header.key, header.value)) |
114 m_simpleRequestHeaders.add(header.key, header.value); | 120 m_simpleRequestHeaders.add(header.key, header.value); |
115 } | 121 } |
116 | 122 |
117 // If the fetch request will be handled by the ServiceWorker, the | 123 // If the fetch request will be handled by the ServiceWorker, the |
118 // FetchRequestMode of the request must be FetchRequestModeCORS or | 124 // FetchRequestMode of the request must be FetchRequestModeCORS or |
119 // FetchRequestModeCORSWithForcedPreflight. Otherwise the ServiceWorker can | 125 // FetchRequestModeCORSWithForcedPreflight. Otherwise the ServiceWorker can |
120 // return a opaque response which is from the other origin site and the | 126 // return a opaque response which is from the other origin site and the |
121 // script in the page can read the content. | 127 // script in the page can read the content. |
122 // | 128 // |
123 // We assume that ServiceWorker is skipped for sync requests and non-HTTP | 129 // We assume that ServiceWorker is skipped for sync requests and non-HTTP |
124 // familiy requests by content/ code. | 130 // familiy requests by content/ code. |
125 if (m_async && !request.skipServiceWorker() && request.url().protocolIsInHTT PFamily() && m_document.fetcher()->isControlledByServiceWorker()) { | 131 if (m_async && !request.skipServiceWorker() && request.url().protocolIsInHTT PFamily() && m_document.fetcher()->isControlledByServiceWorker()) { |
126 ResourceRequest newRequest(request); | 132 ResourceRequest newRequest(request); |
127 // FetchRequestMode should be set by the caller. But the expected value | 133 // FetchRequestMode should be set by the caller. But the expected value |
128 // of FetchRequestMode is not speced yet except for XHR. So we set here. | 134 // of FetchRequestMode is not speced yet except for XHR. So we set here. |
129 // FIXME: When we support fetch API in document, this value should not | 135 // FIXME: When we support fetch API in document, this value should not |
130 // be overridden here. | 136 // be overridden here. |
131 if (options.preflightPolicy == ForcePreflight) | 137 if (m_options.preflightPolicy == ForcePreflight) |
132 newRequest.setFetchRequestMode(WebURLRequest::FetchRequestModeCORSWi thForcedPreflight); | 138 newRequest.setFetchRequestMode(WebURLRequest::FetchRequestModeCORSWi thForcedPreflight); |
133 else | 139 else |
134 newRequest.setFetchRequestMode(WebURLRequest::FetchRequestModeCORS); | 140 newRequest.setFetchRequestMode(WebURLRequest::FetchRequestModeCORS); |
135 | 141 |
136 m_fallbackRequestForServiceWorker = adoptPtr(new ResourceRequest(request )); | 142 m_fallbackRequestForServiceWorker = adoptPtr(new ResourceRequest(request )); |
137 m_fallbackRequestForServiceWorker->setSkipServiceWorker(true); | 143 m_fallbackRequestForServiceWorker->setSkipServiceWorker(true); |
138 | 144 |
139 loadRequest(newRequest, m_resourceLoaderOptions); | 145 loadRequest(newRequest, m_resourceLoaderOptions); |
140 return; | 146 return; |
141 } | 147 } |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
586 if (m_actualRequest) | 592 if (m_actualRequest) |
587 resourceLoaderOptions.dataBufferingPolicy = BufferData; | 593 resourceLoaderOptions.dataBufferingPolicy = BufferData; |
588 | 594 |
589 if (m_options.timeoutMilliseconds > 0) | 595 if (m_options.timeoutMilliseconds > 0) |
590 m_timeoutTimer.startOneShot(m_options.timeoutMilliseconds / 1000.0, FROM_HERE); | 596 m_timeoutTimer.startOneShot(m_options.timeoutMilliseconds / 1000.0, FROM_HERE); |
591 | 597 |
592 FetchRequest newRequest(request, m_options.initiator, resourceLoaderOpti ons); | 598 FetchRequest newRequest(request, m_options.initiator, resourceLoaderOpti ons); |
593 if (m_options.crossOriginRequestPolicy == AllowCrossOriginRequests) | 599 if (m_options.crossOriginRequestPolicy == AllowCrossOriginRequests) |
594 newRequest.setOriginRestriction(FetchRequest::NoOriginRestriction); | 600 newRequest.setOriginRestriction(FetchRequest::NoOriginRestriction); |
595 ASSERT(!resource()); | 601 ASSERT(!resource()); |
602 | |
596 if (request.requestContext() == WebURLRequest::RequestContextVideo || re quest.requestContext() == WebURLRequest::RequestContextAudio) | 603 if (request.requestContext() == WebURLRequest::RequestContextVideo || re quest.requestContext() == WebURLRequest::RequestContextAudio) |
597 setResource(RawResource::fetchMedia(newRequest, m_document.fetcher() )); | 604 setResource(RawResource::fetchMedia(newRequest, m_document.fetcher() )); |
598 else | 605 else |
599 setResource(RawResource::fetch(newRequest, m_document.fetcher())); | 606 setResource(RawResource::fetch(newRequest, m_document.fetcher())); |
600 if (resource() && resource()->loader()) { | 607 |
608 if (!resource()) { | |
609 m_client->didFail(ResourceError(errorDomainBlinkInternal, 0, request URL.string(), "Failed to start loading.")); | |
610 return; | |
611 } | |
612 | |
613 if (resource()->loader()) { | |
601 unsigned long identifier = resource()->identifier(); | 614 unsigned long identifier = resource()->identifier(); |
602 InspectorInstrumentation::documentThreadableLoaderStartedLoadingForC lient(&m_document, identifier, m_client); | 615 InspectorInstrumentation::documentThreadableLoaderStartedLoadingForC lient(&m_document, identifier, m_client); |
603 } | 616 } |
604 return; | 617 return; |
605 } | 618 } |
606 | 619 |
607 FetchRequest fetchRequest(request, m_options.initiator, resourceLoaderOption s); | 620 FetchRequest fetchRequest(request, m_options.initiator, resourceLoaderOption s); |
608 if (m_options.crossOriginRequestPolicy == AllowCrossOriginRequests) | 621 if (m_options.crossOriginRequestPolicy == AllowCrossOriginRequests) |
609 fetchRequest.setOriginRestriction(FetchRequest::NoOriginRestriction); | 622 fetchRequest.setOriginRestriction(FetchRequest::NoOriginRestriction); |
610 ResourcePtr<Resource> resource = RawResource::fetchSynchronously(fetchReques t, m_document.fetcher()); | 623 ResourcePtr<Resource> resource = RawResource::fetchSynchronously(fetchReques t, m_document.fetcher()); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
664 return DoNotAllowStoredCredentials; | 677 return DoNotAllowStoredCredentials; |
665 return m_resourceLoaderOptions.allowCredentials; | 678 return m_resourceLoaderOptions.allowCredentials; |
666 } | 679 } |
667 | 680 |
668 SecurityOrigin* DocumentThreadableLoader::securityOrigin() const | 681 SecurityOrigin* DocumentThreadableLoader::securityOrigin() const |
669 { | 682 { |
670 return m_securityOrigin ? m_securityOrigin.get() : m_document.securityOrigin (); | 683 return m_securityOrigin ? m_securityOrigin.get() : m_document.securityOrigin (); |
671 } | 684 } |
672 | 685 |
673 } // namespace blink | 686 } // namespace blink |
OLD | NEW |