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

Side by Side Diff: third_party/WebKit/Source/core/loader/DocumentThreadableLoader.cpp

Issue 1264453002: Split the constructor of ThreadableLoader into two methods (ctor and start()) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Removed pipes around non-variables in a comment Created 4 years, 10 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 /* 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 // Max number of CORS redirects handled in DocumentThreadableLoader. 100 // Max number of CORS redirects handled in DocumentThreadableLoader.
101 // Same number as net/url_request/url_request.cc, and 101 // Same number as net/url_request/url_request.cc, and
102 // same number as https://fetch.spec.whatwg.org/#concept-http-fetch, Step 4. 102 // same number as https://fetch.spec.whatwg.org/#concept-http-fetch, Step 4.
103 // FIXME: currently the number of redirects is counted and limited here and in 103 // FIXME: currently the number of redirects is counted and limited here and in
104 // net/url_request/url_request.cc separately. 104 // net/url_request/url_request.cc separately.
105 static const int kMaxCORSRedirects = 20; 105 static const int kMaxCORSRedirects = 20;
106 106
107 void DocumentThreadableLoader::loadResourceSynchronously(Document& document, con st ResourceRequest& request, ThreadableLoaderClient& client, const ThreadableLoa derOptions& options, const ResourceLoaderOptions& resourceLoaderOptions) 107 void DocumentThreadableLoader::loadResourceSynchronously(Document& document, con st ResourceRequest& request, ThreadableLoaderClient& client, const ThreadableLoa derOptions& options, const ResourceLoaderOptions& resourceLoaderOptions)
108 { 108 {
109 // The loader will be deleted as soon as this function exits. 109 // The loader will be deleted as soon as this function exits.
110 RefPtr<DocumentThreadableLoader> loader = adoptRef(new DocumentThreadableLoa der(document, &client, LoadSynchronously, request, options, resourceLoaderOption s)); 110 RefPtr<DocumentThreadableLoader> loader = adoptRef(new DocumentThreadableLoa der(document, &client, LoadSynchronously, options, resourceLoaderOptions));
111 loader->start(request);
111 ASSERT(loader->hasOneRef()); 112 ASSERT(loader->hasOneRef());
112 } 113 }
113 114
114 PassRefPtr<DocumentThreadableLoader> DocumentThreadableLoader::create(Document& document, ThreadableLoaderClient* client, const ResourceRequest& request, const ThreadableLoaderOptions& options, const ResourceLoaderOptions& resourceLoaderOpt ions) 115 PassRefPtr<DocumentThreadableLoader> DocumentThreadableLoader::create(Document& document, ThreadableLoaderClient* client, const ThreadableLoaderOptions& options , const ResourceLoaderOptions& resourceLoaderOptions)
115 { 116 {
116 RefPtr<DocumentThreadableLoader> loader = adoptRef(new DocumentThreadableLoa der(document, client, LoadAsynchronously, request, options, resourceLoaderOption s)); 117 return adoptRef(new DocumentThreadableLoader(document, client, LoadAsynchron ously, options, resourceLoaderOptions));
117 if (!loader->resource())
118 loader = nullptr;
119 return loader.release();
120 } 118 }
121 119
122 DocumentThreadableLoader::DocumentThreadableLoader(Document& document, Threadabl eLoaderClient* client, BlockingBehavior blockingBehavior, const ResourceRequest& request, const ThreadableLoaderOptions& options, const ResourceLoaderOptions& r esourceLoaderOptions) 120 DocumentThreadableLoader::DocumentThreadableLoader(Document& document, Threadabl eLoaderClient* client, BlockingBehavior blockingBehavior, const ThreadableLoader Options& options, const ResourceLoaderOptions& resourceLoaderOptions)
123 : m_client(client) 121 : m_client(client)
124 , m_document(&document) 122 , m_document(&document)
125 , m_options(options) 123 , m_options(options)
126 , m_resourceLoaderOptions(resourceLoaderOptions) 124 , m_resourceLoaderOptions(resourceLoaderOptions)
127 , m_forceDoNotAllowStoredCredentials(false) 125 , m_forceDoNotAllowStoredCredentials(false)
128 , m_securityOrigin(m_resourceLoaderOptions.securityOrigin) 126 , m_securityOrigin(m_resourceLoaderOptions.securityOrigin)
129 , m_sameOriginRequest(securityOrigin()->canRequestNoSuborigin(request.url()) ) 127 , m_sameOriginRequest(false)
130 , m_crossOriginNonSimpleRequest(false) 128 , m_crossOriginNonSimpleRequest(false)
131 , m_isUsingDataConsumerHandle(false) 129 , m_isUsingDataConsumerHandle(false)
132 , m_async(blockingBehavior == LoadAsynchronously) 130 , m_async(blockingBehavior == LoadAsynchronously)
133 , m_requestContext(request.requestContext()) 131 , m_requestContext(WebURLRequest::RequestContextUnspecified)
134 , m_timeoutTimer(this, &DocumentThreadableLoader::didTimeout) 132 , m_timeoutTimer(this, &DocumentThreadableLoader::didTimeout)
135 , m_requestStartedSeconds(0.0) 133 , m_requestStartedSeconds(0.0)
136 , m_corsRedirectLimit(kMaxCORSRedirects) 134 , m_corsRedirectLimit(kMaxCORSRedirects)
137 , m_redirectMode(request.fetchRedirectMode()) 135 , m_redirectMode(WebURLRequest::FetchRedirectModeFollow)
138 { 136 {
139 ASSERT(client); 137 ASSERT(client);
138 }
139
140 void DocumentThreadableLoader::start(const ResourceRequest& request)
141 {
140 // Setting an outgoing referer is only supported in the async code path. 142 // Setting an outgoing referer is only supported in the async code path.
141 ASSERT(m_async || request.httpReferrer().isEmpty()); 143 ASSERT(m_async || request.httpReferrer().isEmpty());
142 144
145 m_sameOriginRequest = securityOrigin()->canRequestNoSuborigin(request.url()) ;
146 m_requestContext = request.requestContext();
147 m_redirectMode = request.fetchRedirectMode();
148
143 if (!m_sameOriginRequest && m_options.crossOriginRequestPolicy == DenyCrossO riginRequests) { 149 if (!m_sameOriginRequest && m_options.crossOriginRequestPolicy == DenyCrossO riginRequests) {
144 ThreadableLoaderClient* client = m_client; 150 ThreadableLoaderClient* client = m_client;
145 clear(); 151 clear();
146 client->didFail(ResourceError(errorDomainBlinkInternal, 0, request.url() .string(), "Cross origin requests are not supported.")); 152 client->didFail(ResourceError(errorDomainBlinkInternal, 0, request.url() .string(), "Cross origin requests are not supported."));
147 // |this| may be dead here. 153 // |this| may be dead here.
148 return; 154 return;
149 } 155 }
150 156
151 m_requestStartedSeconds = monotonicallyIncreasingTime(); 157 m_requestStartedSeconds = monotonicallyIncreasingTime();
152 158
(...skipping 17 matching lines...) Expand all
170 // - ThreadableLoader is used as backend for all javascript initiated networ k 176 // - ThreadableLoader is used as backend for all javascript initiated networ k
171 // fetches. 177 // fetches.
172 // - Note that ThreadableLoader is also used for non-network fetch such as 178 // - Note that ThreadableLoader is also used for non-network fetch such as
173 // FileReaderLoader. However it emulates GET method so signal is not 179 // FileReaderLoader. However it emulates GET method so signal is not
174 // recorded here. 180 // recorded here.
175 // - ThreadableLoader w/ non-GET request is only created from javascript 181 // - ThreadableLoader w/ non-GET request is only created from javascript
176 // initiated fetch. 182 // initiated fetch.
177 // - Some non-script initiated fetches such as WorkerScriptLoader also use 183 // - Some non-script initiated fetches such as WorkerScriptLoader also use
178 // ThreadableLoader, but they are guaranteed to use GET method. 184 // ThreadableLoader, but they are guaranteed to use GET method.
179 if (request.httpMethod() != HTTPNames::GET) { 185 if (request.httpMethod() != HTTPNames::GET) {
180 if (Page* page = document.page()) 186 if (Page* page = m_document->page())
181 page->chromeClient().didObserveNonGetFetchFromScript(); 187 page->chromeClient().didObserveNonGetFetchFromScript();
182 } 188 }
183 189
184 // We assume that ServiceWorker is skipped for sync requests and unsupported 190 // We assume that ServiceWorker is skipped for sync requests and unsupported
185 // protocol requests by content/ code. 191 // protocol requests by content/ code.
186 if (m_async && !request.skipServiceWorker() && SchemeRegistry::shouldTreatUR LSchemeAsAllowingServiceWorkers(request.url().protocol()) && document.fetcher()- >isControlledByServiceWorker()) { 192 if (m_async && !request.skipServiceWorker() && SchemeRegistry::shouldTreatUR LSchemeAsAllowingServiceWorkers(request.url().protocol()) && m_document->fetcher ()->isControlledByServiceWorker()) {
187 ResourceRequest newRequest(request); 193 ResourceRequest newRequest(request);
188 const WebURLRequest::RequestContext requestContext(request.requestContex t()); 194 const WebURLRequest::RequestContext requestContext(request.requestContex t());
189 if (requestContext != WebURLRequest::RequestContextFetch) { 195 if (requestContext != WebURLRequest::RequestContextFetch) {
190 // When the request context is not "fetch", 196 // When the request context is not "fetch",
191 // |crossOriginRequestPolicy| represents the fetch request mode, 197 // |crossOriginRequestPolicy| represents the fetch request mode,
192 // and |credentialsRequested| represents the fetch credentials mode. 198 // and |credentialsRequested| represents the fetch credentials mode.
193 // So we set those flags here so that we can see the correct request 199 // So we set those flags here so that we can see the correct request
194 // mode and credentials mode in the service worker's fetch event 200 // mode and credentials mode in the service worker's fetch event
195 // handler. 201 // handler.
196 switch (m_options.crossOriginRequestPolicy) { 202 switch (m_options.crossOriginRequestPolicy) {
197 case DenyCrossOriginRequests: 203 case DenyCrossOriginRequests:
198 newRequest.setFetchRequestMode(WebURLRequest::FetchRequestModeSa meOrigin); 204 newRequest.setFetchRequestMode(WebURLRequest::FetchRequestModeSa meOrigin);
199 break; 205 break;
200 case UseAccessControl: 206 case UseAccessControl:
201 if (options.preflightPolicy == ForcePreflight) 207 if (m_options.preflightPolicy == ForcePreflight)
202 newRequest.setFetchRequestMode(WebURLRequest::FetchRequestMo deCORSWithForcedPreflight); 208 newRequest.setFetchRequestMode(WebURLRequest::FetchRequestMo deCORSWithForcedPreflight);
203 else 209 else
204 newRequest.setFetchRequestMode(WebURLRequest::FetchRequestMo deCORS); 210 newRequest.setFetchRequestMode(WebURLRequest::FetchRequestMo deCORS);
205 break; 211 break;
206 case AllowCrossOriginRequests: 212 case AllowCrossOriginRequests:
207 // No-CORS requests are allowed only for those contexts. 213 // No-CORS requests are allowed only for those contexts.
208 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(requestContext == WebUR LRequest::RequestContextAudio || requestContext == WebURLRequest::RequestContext Video || requestContext == WebURLRequest::RequestContextObject || requestContext == WebURLRequest::RequestContextFavicon || requestContext == WebURLRequest::Req uestContextImage || requestContext == WebURLRequest::RequestContextScript); 214 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(requestContext == WebUR LRequest::RequestContextAudio || requestContext == WebURLRequest::RequestContext Video || requestContext == WebURLRequest::RequestContextObject || requestContext == WebURLRequest::RequestContextFavicon || requestContext == WebURLRequest::Req uestContextImage || requestContext == WebURLRequest::RequestContextScript);
209 newRequest.setFetchRequestMode(WebURLRequest::FetchRequestModeNo CORS); 215 newRequest.setFetchRequestMode(WebURLRequest::FetchRequestModeNo CORS);
210 break; 216 break;
211 } 217 }
212 if (m_resourceLoaderOptions.allowCredentials == AllowStoredCredentia ls) 218 if (m_resourceLoaderOptions.allowCredentials == AllowStoredCredentia ls)
213 newRequest.setFetchCredentialsMode(WebURLRequest::FetchCredentia lsModeInclude); 219 newRequest.setFetchCredentialsMode(WebURLRequest::FetchCredentia lsModeInclude);
214 else 220 else
215 newRequest.setFetchCredentialsMode(WebURLRequest::FetchCredentia lsModeSameOrigin); 221 newRequest.setFetchCredentialsMode(WebURLRequest::FetchCredentia lsModeSameOrigin);
216 } 222 }
217 if (newRequest.fetchRequestMode() == WebURLRequest::FetchRequestModeCORS || newRequest.fetchRequestMode() == WebURLRequest::FetchRequestModeCORSWithForc edPreflight) { 223 if (newRequest.fetchRequestMode() == WebURLRequest::FetchRequestModeCORS || newRequest.fetchRequestMode() == WebURLRequest::FetchRequestModeCORSWithForc edPreflight) {
218 m_fallbackRequestForServiceWorker = ResourceRequest(request); 224 m_fallbackRequestForServiceWorker = ResourceRequest(request);
219 m_fallbackRequestForServiceWorker.setSkipServiceWorker(true); 225 m_fallbackRequestForServiceWorker.setSkipServiceWorker(true);
220 } 226 }
221 227
222 loadRequest(newRequest, m_resourceLoaderOptions); 228 loadRequest(newRequest, m_resourceLoaderOptions);
229 // |this| may be dead here.
223 return; 230 return;
224 } 231 }
225 232
226 dispatchInitialRequest(request); 233 dispatchInitialRequest(request);
227 // |this| may be dead here in async mode. 234 // |this| may be dead here in async mode.
228 } 235 }
229 236
230 void DocumentThreadableLoader::dispatchInitialRequest(const ResourceRequest& req uest) 237 void DocumentThreadableLoader::dispatchInitialRequest(const ResourceRequest& req uest)
231 { 238 {
232 if (m_sameOriginRequest || m_options.crossOriginRequestPolicy == AllowCrossO riginRequests) { 239 if (m_sameOriginRequest || m_options.crossOriginRequestPolicy == AllowCrossO riginRequests) {
233 loadRequest(request, m_resourceLoaderOptions); 240 loadRequest(request, m_resourceLoaderOptions);
241 // |this| may be dead here in async mode.
234 return; 242 return;
235 } 243 }
236 244
237 ASSERT(m_options.crossOriginRequestPolicy == UseAccessControl); 245 ASSERT(m_options.crossOriginRequestPolicy == UseAccessControl);
238 246
239 makeCrossOriginAccessRequest(request); 247 makeCrossOriginAccessRequest(request);
240 // |this| may be dead here in async mode. 248 // |this| may be dead here in async mode.
241 } 249 }
242 250
243 void DocumentThreadableLoader::makeCrossOriginAccessRequest(const ResourceReques t& request) 251 void DocumentThreadableLoader::makeCrossOriginAccessRequest(const ResourceReques t& request)
(...skipping 19 matching lines...) Expand all
263 // example, referrer. We need to accept them. For security, we must reject 271 // example, referrer. We need to accept them. For security, we must reject
264 // forbidden headers/methods at the point we accept user's input. Not here. 272 // forbidden headers/methods at the point we accept user's input. Not here.
265 if ((m_options.preflightPolicy == ConsiderPreflight && FetchUtils::isSimpleO rForbiddenRequest(request.httpMethod(), request.httpHeaderFields())) || m_option s.preflightPolicy == PreventPreflight) { 273 if ((m_options.preflightPolicy == ConsiderPreflight && FetchUtils::isSimpleO rForbiddenRequest(request.httpMethod(), request.httpHeaderFields())) || m_option s.preflightPolicy == PreventPreflight) {
266 ResourceRequest crossOriginRequest(request); 274 ResourceRequest crossOriginRequest(request);
267 ResourceLoaderOptions crossOriginOptions(m_resourceLoaderOptions); 275 ResourceLoaderOptions crossOriginOptions(m_resourceLoaderOptions);
268 updateRequestForAccessControl(crossOriginRequest, securityOrigin(), effe ctiveAllowCredentials()); 276 updateRequestForAccessControl(crossOriginRequest, securityOrigin(), effe ctiveAllowCredentials());
269 // We update the credentials mode according to effectiveAllowCredentials () here for backward compatibility. But this is not correct. 277 // We update the credentials mode according to effectiveAllowCredentials () here for backward compatibility. But this is not correct.
270 // FIXME: We should set it in the caller of DocumentThreadableLoader. 278 // FIXME: We should set it in the caller of DocumentThreadableLoader.
271 crossOriginRequest.setFetchCredentialsMode(effectiveAllowCredentials() = = AllowStoredCredentials ? WebURLRequest::FetchCredentialsModeInclude : WebURLRe quest::FetchCredentialsModeOmit); 279 crossOriginRequest.setFetchCredentialsMode(effectiveAllowCredentials() = = AllowStoredCredentials ? WebURLRequest::FetchCredentialsModeInclude : WebURLRe quest::FetchCredentialsModeOmit);
272 loadRequest(crossOriginRequest, crossOriginOptions); 280 loadRequest(crossOriginRequest, crossOriginOptions);
281 // |this| may be dead here in async mode.
273 } else { 282 } else {
274 m_crossOriginNonSimpleRequest = true; 283 m_crossOriginNonSimpleRequest = true;
275 284
276 ResourceRequest crossOriginRequest(request); 285 ResourceRequest crossOriginRequest(request);
277 ResourceLoaderOptions crossOriginOptions(m_resourceLoaderOptions); 286 ResourceLoaderOptions crossOriginOptions(m_resourceLoaderOptions);
278 // Do not set the Origin header for preflight requests. 287 // Do not set the Origin header for preflight requests.
279 updateRequestForAccessControl(crossOriginRequest, 0, effectiveAllowCrede ntials()); 288 updateRequestForAccessControl(crossOriginRequest, 0, effectiveAllowCrede ntials());
280 // We update the credentials mode according to effectiveAllowCredentials () here for backward compatibility. But this is not correct. 289 // We update the credentials mode according to effectiveAllowCredentials () here for backward compatibility. But this is not correct.
281 // FIXME: We should set it in the caller of DocumentThreadableLoader. 290 // FIXME: We should set it in the caller of DocumentThreadableLoader.
282 crossOriginRequest.setFetchCredentialsMode(effectiveAllowCredentials() = = AllowStoredCredentials ? WebURLRequest::FetchCredentialsModeInclude : WebURLRe quest::FetchCredentialsModeOmit); 291 crossOriginRequest.setFetchCredentialsMode(effectiveAllowCredentials() = = AllowStoredCredentials ? WebURLRequest::FetchCredentialsModeInclude : WebURLRe quest::FetchCredentialsModeOmit);
283 m_actualRequest = crossOriginRequest; 292 m_actualRequest = crossOriginRequest;
284 m_actualOptions = crossOriginOptions; 293 m_actualOptions = crossOriginOptions;
285 294
286 bool shouldForcePreflight = InspectorInstrumentation::shouldForceCORSPre flight(m_document); 295 bool shouldForcePreflight = InspectorInstrumentation::shouldForceCORSPre flight(m_document);
287 bool canSkipPreflight = CrossOriginPreflightResultCache::shared().canSki pPreflight(securityOrigin()->toString(), m_actualRequest.url(), effectiveAllowCr edentials(), m_actualRequest.httpMethod(), m_actualRequest.httpHeaderFields()); 296 bool canSkipPreflight = CrossOriginPreflightResultCache::shared().canSki pPreflight(securityOrigin()->toString(), m_actualRequest.url(), effectiveAllowCr edentials(), m_actualRequest.httpMethod(), m_actualRequest.httpHeaderFields());
288 if (canSkipPreflight && !shouldForcePreflight) { 297 if (canSkipPreflight && !shouldForcePreflight) {
289 loadActualRequest(); 298 loadActualRequest();
299 // |this| may be dead here in async mode.
290 } else { 300 } else {
291 ResourceRequest preflightRequest = createAccessControlPreflightReque st(m_actualRequest, securityOrigin()); 301 ResourceRequest preflightRequest = createAccessControlPreflightReque st(m_actualRequest, securityOrigin());
292 // Create a ResourceLoaderOptions for preflight. 302 // Create a ResourceLoaderOptions for preflight.
293 ResourceLoaderOptions preflightOptions = m_actualOptions; 303 ResourceLoaderOptions preflightOptions = m_actualOptions;
294 preflightOptions.allowCredentials = DoNotAllowStoredCredentials; 304 preflightOptions.allowCredentials = DoNotAllowStoredCredentials;
295 loadRequest(preflightRequest, preflightOptions); 305 loadRequest(preflightRequest, preflightOptions);
306 // |this| may be dead here in async mode.
296 } 307 }
297 } 308 }
298 } 309 }
299 310
300 DocumentThreadableLoader::~DocumentThreadableLoader() 311 DocumentThreadableLoader::~DocumentThreadableLoader()
301 { 312 {
302 // TODO(oilpan): Remove this once DocumentThreadableLoader is once again a R esourceOwner. 313 // TODO(oilpan): Remove this once DocumentThreadableLoader is once again a R esourceOwner.
303 clearResource(); 314 clearResource();
304 } 315 }
305 316
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 { 719 {
709 ASSERT(m_fallbackRequestForServiceWorker.isNull()); 720 ASSERT(m_fallbackRequestForServiceWorker.isNull());
710 721
711 if (!m_actualRequest.isNull()) { 722 if (!m_actualRequest.isNull()) {
712 // FIXME: Timeout should be applied to whole fetch, not for each of 723 // FIXME: Timeout should be applied to whole fetch, not for each of
713 // preflight and actual request. 724 // preflight and actual request.
714 m_timeoutTimer.stop(); 725 m_timeoutTimer.stop();
715 ASSERT(!m_sameOriginRequest); 726 ASSERT(!m_sameOriginRequest);
716 ASSERT(m_options.crossOriginRequestPolicy == UseAccessControl); 727 ASSERT(m_options.crossOriginRequestPolicy == UseAccessControl);
717 loadActualRequest(); 728 loadActualRequest();
729 // |this| may be dead here in async mode.
718 return; 730 return;
719 } 731 }
720 732
721 ThreadableLoaderClient* client = m_client; 733 ThreadableLoaderClient* client = m_client;
722 m_client = 0; 734 m_client = 0;
723 // Don't clear the resource as the client may need to access the downloaded 735 // Don't clear the resource as the client may need to access the downloaded
724 // file which will be released when the resource is destoryed. 736 // file which will be released when the resource is destoryed.
725 if (m_async) { 737 if (m_async) {
726 m_timeoutTimer.stop(); 738 m_timeoutTimer.stop();
727 m_requestStartedSeconds = 0.0; 739 m_requestStartedSeconds = 0.0;
(...skipping 29 matching lines...) Expand all
757 ResourceRequest actualRequest = m_actualRequest; 769 ResourceRequest actualRequest = m_actualRequest;
758 ResourceLoaderOptions actualOptions = m_actualOptions; 770 ResourceLoaderOptions actualOptions = m_actualOptions;
759 m_actualRequest = ResourceRequest(); 771 m_actualRequest = ResourceRequest();
760 m_actualOptions = ResourceLoaderOptions(); 772 m_actualOptions = ResourceLoaderOptions();
761 773
762 actualRequest.setHTTPOrigin(securityOrigin()); 774 actualRequest.setHTTPOrigin(securityOrigin());
763 775
764 clearResource(); 776 clearResource();
765 777
766 loadRequest(actualRequest, actualOptions); 778 loadRequest(actualRequest, actualOptions);
779 // |this| may be dead here in async mode.
767 } 780 }
768 781
769 void DocumentThreadableLoader::handlePreflightFailure(const String& url, const S tring& errorDescription) 782 void DocumentThreadableLoader::handlePreflightFailure(const String& url, const S tring& errorDescription)
770 { 783 {
771 ResourceError error(errorDomainBlinkInternal, 0, url, errorDescription); 784 ResourceError error(errorDomainBlinkInternal, 0, url, errorDescription);
772 785
773 // Prevent handleSuccessfulFinish() from bypassing access check. 786 // Prevent handleSuccessfulFinish() from bypassing access check.
774 m_actualRequest = ResourceRequest(); 787 m_actualRequest = ResourceRequest();
775 788
776 ThreadableLoaderClient* client = m_client; 789 ThreadableLoaderClient* client = m_client;
(...skipping 30 matching lines...) Expand all
807 if (!m_actualRequest.isNull()) 820 if (!m_actualRequest.isNull())
808 resourceLoaderOptions.dataBufferingPolicy = BufferData; 821 resourceLoaderOptions.dataBufferingPolicy = BufferData;
809 822
810 if (m_options.timeoutMilliseconds > 0) 823 if (m_options.timeoutMilliseconds > 0)
811 m_timeoutTimer.startOneShot(m_options.timeoutMilliseconds / 1000.0, BLINK_FROM_HERE); 824 m_timeoutTimer.startOneShot(m_options.timeoutMilliseconds / 1000.0, BLINK_FROM_HERE);
812 825
813 FetchRequest newRequest(request, m_options.initiator, resourceLoaderOpti ons); 826 FetchRequest newRequest(request, m_options.initiator, resourceLoaderOpti ons);
814 if (m_options.crossOriginRequestPolicy == AllowCrossOriginRequests) 827 if (m_options.crossOriginRequestPolicy == AllowCrossOriginRequests)
815 newRequest.setOriginRestriction(FetchRequest::NoOriginRestriction); 828 newRequest.setOriginRestriction(FetchRequest::NoOriginRestriction);
816 ASSERT(!resource()); 829 ASSERT(!resource());
830
817 if (request.requestContext() == WebURLRequest::RequestContextVideo || re quest.requestContext() == WebURLRequest::RequestContextAudio) 831 if (request.requestContext() == WebURLRequest::RequestContextVideo || re quest.requestContext() == WebURLRequest::RequestContextAudio)
818 setResource(RawResource::fetchMedia(newRequest, document().fetcher() )); 832 setResource(RawResource::fetchMedia(newRequest, document().fetcher() ));
819 else if (request.requestContext() == WebURLRequest::RequestContextManife st) 833 else if (request.requestContext() == WebURLRequest::RequestContextManife st)
820 setResource(RawResource::fetchManifest(newRequest, document().fetche r())); 834 setResource(RawResource::fetchManifest(newRequest, document().fetche r()));
821 else 835 else
822 setResource(RawResource::fetch(newRequest, document().fetcher())); 836 setResource(RawResource::fetch(newRequest, document().fetcher()));
823 if (resource() && resource()->loader()) { 837
838 if (!resource()) {
839 ThreadableLoaderClient* client = m_client;
840 clear();
841 client->didFail(ResourceError(errorDomainBlinkInternal, 0, requestUR L.string(), "Failed to start loading."));
842 // |this| may be dead here.
843 return;
844 }
845
846 if (resource()->loader()) {
824 unsigned long identifier = resource()->identifier(); 847 unsigned long identifier = resource()->identifier();
825 InspectorInstrumentation::documentThreadableLoaderStartedLoadingForC lient(m_document, identifier, m_client); 848 InspectorInstrumentation::documentThreadableLoaderStartedLoadingForC lient(m_document, identifier, m_client);
826 } 849 }
827 return; 850 return;
828 } 851 }
829 852
830 FetchRequest fetchRequest(request, m_options.initiator, resourceLoaderOption s); 853 FetchRequest fetchRequest(request, m_options.initiator, resourceLoaderOption s);
831 if (m_options.crossOriginRequestPolicy == AllowCrossOriginRequests) 854 if (m_options.crossOriginRequestPolicy == AllowCrossOriginRequests)
832 fetchRequest.setOriginRestriction(FetchRequest::NoOriginRestriction); 855 fetchRequest.setOriginRestriction(FetchRequest::NoOriginRestriction);
833 RefPtrWillBeRawPtr<Resource> resource = RawResource::fetchSynchronously(fetc hRequest, document().fetcher()); 856 RefPtrWillBeRawPtr<Resource> resource = RawResource::fetchSynchronously(fetc hRequest, document().fetcher());
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 return m_securityOrigin ? m_securityOrigin.get() : document().securityOrigin (); 929 return m_securityOrigin ? m_securityOrigin.get() : document().securityOrigin ();
907 } 930 }
908 931
909 Document& DocumentThreadableLoader::document() const 932 Document& DocumentThreadableLoader::document() const
910 { 933 {
911 ASSERT(m_document); 934 ASSERT(m_document);
912 return *m_document; 935 return *m_document;
913 } 936 }
914 937
915 } // namespace blink 938 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698