Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2010, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2010, 2011 Apple Inc. All rights reserved. |
| 3 * (C) 2007 Graham Dennis (graham.dennis@gmail.com) | 3 * (C) 2007 Graham Dennis (graham.dennis@gmail.com) |
| 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 | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 | 49 |
| 50 namespace { | 50 namespace { |
| 51 | 51 |
| 52 bool isManualRedirectFetchRequest(const ResourceRequest& request) | 52 bool isManualRedirectFetchRequest(const ResourceRequest& request) |
| 53 { | 53 { |
| 54 return request.fetchRedirectMode() == WebURLRequest::FetchRedirectModeManual && request.requestContext() == WebURLRequest::RequestContextFetch; | 54 return request.fetchRedirectMode() == WebURLRequest::FetchRedirectModeManual && request.requestContext() == WebURLRequest::RequestContextFetch; |
| 55 } | 55 } |
| 56 | 56 |
| 57 } // namespace | 57 } // namespace |
| 58 | 58 |
| 59 ResourceLoader* ResourceLoader::create(ResourceFetcher* fetcher, Resource* resou rce, const ResourceRequest& request, const ResourceLoaderOptions& options) | 59 ResourceLoader* ResourceLoader::create(ResourceFetcher* fetcher, Resource* resou rce) |
| 60 { | 60 { |
| 61 ResourceLoader* loader = new ResourceLoader(fetcher, resource, options); | 61 return new ResourceLoader(fetcher, resource); |
| 62 loader->init(request); | |
| 63 return loader; | |
| 64 } | 62 } |
| 65 | 63 |
| 66 ResourceLoader::ResourceLoader(ResourceFetcher* fetcher, Resource* resource, con st ResourceLoaderOptions& options) | 64 ResourceLoader::ResourceLoader(ResourceFetcher* fetcher, Resource* resource) |
| 67 : m_fetcher(fetcher) | 65 : m_fetcher(fetcher) |
| 68 , m_notifiedLoadComplete(false) | 66 , m_notifiedLoadComplete(false) |
| 69 , m_loadingMultipartContent(false) | 67 , m_loadingMultipartContent(false) |
| 70 , m_options(options) | |
| 71 , m_resource(resource) | 68 , m_resource(resource) |
| 72 , m_state(ConnectionStateNew) | 69 , m_state(ConnectionStateNew) |
| 73 { | 70 { |
| 74 ASSERT(m_resource); | 71 ASSERT(m_resource); |
| 75 ASSERT(m_fetcher); | 72 ASSERT(m_fetcher); |
| 73 m_fetcher->didInitializeResourceLoader(this); | |
| 76 } | 74 } |
| 77 | 75 |
| 78 ResourceLoader::~ResourceLoader() | 76 ResourceLoader::~ResourceLoader() |
| 79 { | 77 { |
| 80 ASSERT(m_state == ConnectionStateReleased); | 78 ASSERT(m_state == ConnectionStateReleased); |
| 81 } | 79 } |
| 82 | 80 |
| 83 DEFINE_TRACE(ResourceLoader) | 81 DEFINE_TRACE(ResourceLoader) |
| 84 { | 82 { |
| 85 visitor->trace(m_fetcher); | 83 visitor->trace(m_fetcher); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 98 | 96 |
| 99 ASSERT(m_state != ConnectionStateReleased); | 97 ASSERT(m_state != ConnectionStateReleased); |
| 100 m_state = ConnectionStateReleased; | 98 m_state = ConnectionStateReleased; |
| 101 if (m_loader) { | 99 if (m_loader) { |
| 102 m_loader->cancel(); | 100 m_loader->cancel(); |
| 103 m_loader.clear(); | 101 m_loader.clear(); |
| 104 } | 102 } |
| 105 m_fetcher.clear(); | 103 m_fetcher.clear(); |
| 106 } | 104 } |
| 107 | 105 |
| 108 void ResourceLoader::init(const ResourceRequest& passedRequest) | 106 void ResourceLoader::start(ResourceRequest& request) |
| 109 { | |
| 110 ResourceRequest request(passedRequest); | |
| 111 m_fetcher->willSendRequest(m_resource->identifier(), request, ResourceRespon se(), m_options.initiatorInfo); | |
| 112 m_originalRequest = m_request = applyOptions(request); | |
| 113 m_resource->updateRequest(request); | |
|
Nate Chapin
2016/03/09 00:38:20
This call of updateRequest() is a no-op. When a Re
hiroshige
2016/03/09 02:01:56
I suspect this might not be a case when delayed lo
Nate Chapin
2016/03/09 22:35:54
Agreed. I had reached the same conclusion, but in
| |
| 114 m_fetcher->didInitializeResourceLoader(this); | |
| 115 } | |
| 116 | |
| 117 void ResourceLoader::start() | |
| 118 { | 107 { |
| 119 ASSERT(!m_loader); | 108 ASSERT(!m_loader); |
| 120 ASSERT(!m_request.isNull()); | |
| 121 | 109 |
| 122 m_fetcher->willStartLoadingResource(m_resource.get(), m_request); | 110 m_fetcher->willStartLoadingResource(m_resource.get(), request); |
| 111 m_fetcher->willSendRequest(m_resource->identifier(), request, ResourceRespon se(), m_resource->options().initiatorInfo); | |
|
hiroshige
2016/03/09 02:01:56
This CL changes the order from:
- willSendRequest(
Nate Chapin
2016/03/09 22:35:54
I've done a bit more refactoring than that. Resour
| |
| 112 applyOptions(request); | |
| 123 RELEASE_ASSERT(m_state == ConnectionStateNew); | 113 RELEASE_ASSERT(m_state == ConnectionStateNew); |
| 124 m_state = ConnectionStateStarted; | 114 m_state = ConnectionStateStarted; |
| 125 | 115 |
| 126 m_loader = adoptPtr(Platform::current()->createURLLoader()); | 116 m_loader = adoptPtr(Platform::current()->createURLLoader()); |
| 127 m_loader->setDefersLoading(m_fetcher->defersLoading()); | 117 m_loader->setDefersLoading(m_fetcher->defersLoading()); |
| 128 ASSERT(m_loader); | 118 ASSERT(m_loader); |
| 129 m_loader->setLoadingTaskRunner(m_fetcher->loadingTaskRunner()); | 119 m_loader->setLoadingTaskRunner(m_fetcher->loadingTaskRunner()); |
| 130 | 120 |
| 131 if (m_options.synchronousPolicy == RequestSynchronously) | 121 if (m_resource->options().synchronousPolicy == RequestSynchronously) |
| 132 requestSynchronously(); | 122 requestSynchronously(request); |
| 133 else | 123 else |
| 134 m_loader->loadAsynchronously(WrappedResourceRequest(m_request), this); | 124 m_loader->loadAsynchronously(WrappedResourceRequest(request), this); |
| 135 } | |
| 136 | |
| 137 void ResourceLoader::changeToSynchronous() | |
| 138 { | |
| 139 ASSERT(m_options.synchronousPolicy == RequestAsynchronously); | |
| 140 ASSERT(m_loader); | |
| 141 m_loader->cancel(); | |
| 142 m_loader.clear(); | |
| 143 m_loader = adoptPtr(Platform::current()->createURLLoader()); | |
| 144 ASSERT(m_loader); | |
| 145 m_request.setPriority(ResourceLoadPriorityHighest); | |
| 146 m_state = ConnectionStateStarted; | |
| 147 requestSynchronously(); | |
| 148 } | 125 } |
| 149 | 126 |
| 150 void ResourceLoader::setDefersLoading(bool defers) | 127 void ResourceLoader::setDefersLoading(bool defers) |
| 151 { | 128 { |
| 152 ASSERT(m_loader); | 129 ASSERT(m_loader); |
| 153 m_loader->setDefersLoading(defers); | 130 m_loader->setDefersLoading(defers); |
| 154 } | 131 } |
| 155 | 132 |
| 156 void ResourceLoader::didDownloadData(WebURLLoader*, int length, int encodedDataL ength) | 133 void ResourceLoader::didDownloadData(WebURLLoader*, int length, int encodedDataL ength) |
| 157 { | 134 { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 void ResourceLoader::cancel(const ResourceError& error) | 174 void ResourceLoader::cancel(const ResourceError& error) |
| 198 { | 175 { |
| 199 // If the load has already completed - succeeded, failed, or previously canc elled - do nothing. | 176 // If the load has already completed - succeeded, failed, or previously canc elled - do nothing. |
| 200 if (m_state == ConnectionStateReleased) | 177 if (m_state == ConnectionStateReleased) |
| 201 return; | 178 return; |
| 202 if (isFinishing()) { | 179 if (isFinishing()) { |
| 203 releaseResources(); | 180 releaseResources(); |
| 204 return; | 181 return; |
| 205 } | 182 } |
| 206 | 183 |
| 207 ResourceError nonNullError = error.isNull() ? ResourceError::cancelledError( m_request.url()) : error; | 184 ResourceError nonNullError = error.isNull() ? ResourceError::cancelledError( m_resource->lastResourceRequest().url()) : error; |
| 208 | 185 |
| 209 WTF_LOG(ResourceLoading, "Cancelled load of '%s'.\n", m_resource->url().getS tring().latin1().data()); | 186 WTF_LOG(ResourceLoading, "Cancelled load of '%s'.\n", m_resource->url().getS tring().latin1().data()); |
| 210 m_state = ConnectionStateCanceled; | 187 m_state = ConnectionStateCanceled; |
| 211 m_resource->setResourceError(nonNullError); | 188 m_resource->setResourceError(nonNullError); |
| 212 | 189 |
| 213 if (!m_notifiedLoadComplete) { | 190 if (!m_notifiedLoadComplete) { |
| 214 m_notifiedLoadComplete = true; | 191 m_notifiedLoadComplete = true; |
| 215 m_fetcher->didFailLoading(m_resource.get(), nonNullError); | 192 m_fetcher->didFailLoading(m_resource.get(), nonNullError); |
| 216 } | 193 } |
| 217 | 194 |
| 218 if (m_state != ConnectionStateReleased) | 195 if (m_state != ConnectionStateReleased) |
| 219 m_resource->error(Resource::LoadError); | 196 m_resource->error(Resource::LoadError); |
| 220 if (m_state != ConnectionStateReleased) | 197 if (m_state != ConnectionStateReleased) |
| 221 releaseResources(); | 198 releaseResources(); |
| 222 } | 199 } |
| 223 | 200 |
| 224 void ResourceLoader::willFollowRedirect(WebURLLoader*, WebURLRequest& passedNewR equest, const WebURLResponse& passedRedirectResponse) | 201 void ResourceLoader::willFollowRedirect(WebURLLoader*, WebURLRequest& passedNewR equest, const WebURLResponse& passedRedirectResponse) |
| 225 { | 202 { |
| 226 ASSERT(m_state != ConnectionStateReleased); | 203 ASSERT(m_state != ConnectionStateReleased); |
| 227 | 204 |
| 228 ResourceRequest& newRequest(applyOptions(passedNewRequest.toMutableResourceR equest())); | 205 ResourceRequest& newRequest(applyOptions(passedNewRequest.toMutableResourceR equest())); |
| 206 ResourceLoaderOptions options = m_resource->options(); | |
|
Nate Chapin
2016/03/09 00:38:20
m_resource->options() is const, hence the copy. Is
| |
| 229 | 207 |
| 230 ASSERT(!newRequest.isNull()); | 208 ASSERT(!newRequest.isNull()); |
| 231 const ResourceResponse& redirectResponse(passedRedirectResponse.toResourceRe sponse()); | 209 const ResourceResponse& redirectResponse(passedRedirectResponse.toResourceRe sponse()); |
| 232 ASSERT(!redirectResponse.isNull()); | 210 ASSERT(!redirectResponse.isNull()); |
| 233 newRequest.setFollowedRedirect(true); | 211 newRequest.setFollowedRedirect(true); |
| 234 if (!isManualRedirectFetchRequest(m_resource->resourceRequest()) && !m_fetch er->canAccessRedirect(m_resource.get(), newRequest, redirectResponse, m_options) ) { | 212 if (!isManualRedirectFetchRequest(m_resource->resourceRequest()) && !m_fetch er->canAccessRedirect(m_resource.get(), newRequest, redirectResponse, options)) { |
| 235 cancel(ResourceError::cancelledDueToAccessCheckError(newRequest.url())); | 213 cancel(ResourceError::cancelledDueToAccessCheckError(newRequest.url())); |
| 236 return; | 214 return; |
| 237 } | 215 } |
| 238 ASSERT(m_state != ConnectionStateReleased); | 216 ASSERT(m_state != ConnectionStateReleased); |
| 239 | 217 |
| 240 applyOptions(newRequest); // canAccessRedirect() can modify m_options so we should re-apply it. | 218 m_resource->setOptions(options); |
| 219 applyOptions(newRequest); // canAccessRedirect() can modify options so we sh ould re-apply it. | |
| 241 m_fetcher->redirectReceived(m_resource.get(), redirectResponse); | 220 m_fetcher->redirectReceived(m_resource.get(), redirectResponse); |
| 242 ASSERT(m_state != ConnectionStateReleased); | 221 m_fetcher->willSendRequest(m_resource->identifier(), newRequest, redirectRes ponse, options.initiatorInfo); |
| 243 m_resource->willFollowRedirect(newRequest, redirectResponse); | 222 m_resource->willFollowRedirect(newRequest, redirectResponse); |
|
Nate Chapin
2016/03/09 00:38:20
By doing m_resource->willFollowRedirect() last, cl
| |
| 244 if (newRequest.isNull() || m_state == ConnectionStateReleased) | |
| 245 return; | |
| 246 | |
| 247 m_fetcher->willSendRequest(m_resource->identifier(), newRequest, redirectRes ponse, m_options.initiatorInfo); | |
| 248 ASSERT(m_state != ConnectionStateReleased); | |
| 249 ASSERT(!newRequest.isNull()); | |
| 250 m_resource->updateRequest(newRequest); | |
| 251 m_request = newRequest; | |
| 252 } | 223 } |
| 253 | 224 |
| 254 void ResourceLoader::didReceiveCachedMetadata(WebURLLoader*, const char* data, i nt length) | 225 void ResourceLoader::didReceiveCachedMetadata(WebURLLoader*, const char* data, i nt length) |
| 255 { | 226 { |
| 256 RELEASE_ASSERT(m_state == ConnectionStateReceivedResponse || m_state == Conn ectionStateReceivingData); | 227 RELEASE_ASSERT(m_state == ConnectionStateReceivedResponse || m_state == Conn ectionStateReceivingData); |
| 257 m_resource->setSerializedCachedMetadata(data, length); | 228 m_resource->setSerializedCachedMetadata(data, length); |
| 258 } | 229 } |
| 259 | 230 |
| 260 void ResourceLoader::didSendData(WebURLLoader*, unsigned long long bytesSent, un signed long long totalBytesToBeSent) | 231 void ResourceLoader::didSendData(WebURLLoader*, unsigned long long bytesSent, un signed long long totalBytesToBeSent) |
| 261 { | 232 { |
| 262 m_resource->didSendData(bytesSent, totalBytesToBeSent); | 233 m_resource->didSendData(bytesSent, totalBytesToBeSent); |
| 263 } | 234 } |
| 264 | 235 |
| 265 bool ResourceLoader::responseNeedsAccessControlCheck() const | 236 bool ResourceLoader::responseNeedsAccessControlCheck() const |
| 266 { | 237 { |
| 267 // If the fetch was (potentially) CORS enabled, an access control check of t he response is required. | 238 // If the fetch was (potentially) CORS enabled, an access control check of t he response is required. |
| 268 return m_options.corsEnabled == IsCORSEnabled; | 239 return m_resource->options().corsEnabled == IsCORSEnabled; |
| 269 } | 240 } |
| 270 | 241 |
| 271 void ResourceLoader::didReceiveResponse(WebURLLoader*, const WebURLResponse& res ponse, WebDataConsumerHandle* rawHandle) | 242 void ResourceLoader::didReceiveResponse(WebURLLoader*, const WebURLResponse& res ponse, WebDataConsumerHandle* rawHandle) |
| 272 { | 243 { |
| 273 ASSERT(!response.isNull()); | 244 ASSERT(!response.isNull()); |
| 274 // |rawHandle|'s ownership is transferred to the callee. | 245 // |rawHandle|'s ownership is transferred to the callee. |
| 275 OwnPtr<WebDataConsumerHandle> handle = adoptPtr(rawHandle); | 246 OwnPtr<WebDataConsumerHandle> handle = adoptPtr(rawHandle); |
| 276 | 247 |
| 277 bool isMultipartPayload = response.isMultipartPayload(); | 248 bool isMultipartPayload = response.isMultipartPayload(); |
| 278 bool isValidStateTransition = (m_state == ConnectionStateStarted || m_state == ConnectionStateReceivedResponse); | 249 bool isValidStateTransition = (m_state == ConnectionStateStarted || m_state == ConnectionStateReceivedResponse); |
| 279 // In the case of multipart loads, calls to didReceiveData & didReceiveRespo nse can be interleaved. | 250 // In the case of multipart loads, calls to didReceiveData & didReceiveRespo nse can be interleaved. |
| 280 RELEASE_ASSERT(isMultipartPayload || isValidStateTransition); | 251 RELEASE_ASSERT(isMultipartPayload || isValidStateTransition); |
| 281 m_state = ConnectionStateReceivedResponse; | 252 m_state = ConnectionStateReceivedResponse; |
| 282 | 253 |
| 283 const ResourceResponse& resourceResponse = response.toResourceResponse(); | 254 const ResourceResponse& resourceResponse = response.toResourceResponse(); |
| 284 | 255 |
| 285 if (responseNeedsAccessControlCheck()) { | 256 if (responseNeedsAccessControlCheck()) { |
| 286 if (response.wasFetchedViaServiceWorker()) { | 257 if (response.wasFetchedViaServiceWorker()) { |
| 287 if (response.wasFallbackRequiredByServiceWorker()) { | 258 if (response.wasFallbackRequiredByServiceWorker()) { |
| 288 m_loader->cancel(); | 259 m_loader->cancel(); |
| 289 m_loader.clear(); | 260 m_loader.clear(); |
| 290 m_state = ConnectionStateStarted; | 261 m_state = ConnectionStateStarted; |
| 291 m_loader = adoptPtr(Platform::current()->createURLLoader()); | 262 m_loader = adoptPtr(Platform::current()->createURLLoader()); |
| 292 ASSERT(m_loader); | 263 ASSERT(m_loader); |
| 293 ASSERT(!m_request.skipServiceWorker()); | 264 ResourceRequest request = m_resource->lastResourceRequest(); |
| 294 m_request.setSkipServiceWorker(true); | 265 ASSERT(!request.skipServiceWorker()); |
| 295 WrappedResourceRequest wrappedRequest(m_request); | 266 request.setSkipServiceWorker(true); |
| 296 m_loader->loadAsynchronously(wrappedRequest, this); | 267 m_loader->loadAsynchronously(WrappedResourceRequest(request), th is); |
| 297 return; | 268 return; |
| 298 } | 269 } |
| 299 } else { | 270 } else { |
| 300 if (!m_resource->isCacheValidator() || resourceResponse.httpStatusCo de() != 304) | 271 if (!m_resource->isCacheValidator() || resourceResponse.httpStatusCo de() != 304) |
| 301 m_resource->setResponse(resourceResponse); | 272 m_resource->setResponse(resourceResponse); |
| 302 if (!m_fetcher->canAccessResource(m_resource.get(), m_options.securi tyOrigin.get(), response.url(), ResourceFetcher::ShouldLogAccessControlErrors)) { | 273 if (!m_fetcher->canAccessResource(m_resource.get(), m_resource->opti ons().securityOrigin.get(), response.url(), ResourceFetcher::ShouldLogAccessCont rolErrors)) { |
| 303 m_fetcher->didReceiveResponse(m_resource.get(), resourceResponse ); | 274 m_fetcher->didReceiveResponse(m_resource.get(), resourceResponse ); |
| 304 cancel(ResourceError::cancelledDueToAccessCheckError(KURL(respon se.url()))); | 275 cancel(ResourceError::cancelledDueToAccessCheckError(KURL(respon se.url()))); |
| 305 return; | 276 return; |
| 306 } | 277 } |
| 307 } | 278 } |
| 308 } | 279 } |
| 309 | 280 |
| 310 m_resource->responseReceived(resourceResponse, handle.release()); | 281 m_resource->responseReceived(resourceResponse, handle.release()); |
| 311 if (m_state == ConnectionStateReleased) | 282 if (m_state == ConnectionStateReleased) |
| 312 return; | 283 return; |
| 313 | 284 |
| 314 m_fetcher->didReceiveResponse(m_resource.get(), resourceResponse); | 285 m_fetcher->didReceiveResponse(m_resource.get(), resourceResponse); |
| 315 if (m_state == ConnectionStateReleased) | 286 if (m_state == ConnectionStateReleased) |
| 316 return; | 287 return; |
| 317 | 288 |
| 318 if (response.toResourceResponse().isMultipart()) { | 289 if (response.toResourceResponse().isMultipart()) { |
| 319 // We only support multipart for images, though the image may be loaded | 290 // We only support multipart for images, though the image may be loaded |
| 320 // as a main resource that we end up displaying through an ImageDocument . | 291 // as a main resource that we end up displaying through an ImageDocument . |
| 321 if (!m_resource->isImage() && m_resource->getType() != Resource::MainRes ource) { | 292 if (!m_resource->isImage() && m_resource->getType() != Resource::MainRes ource) { |
| 322 cancel(); | 293 cancel(ResourceError::cancelledError(resourceResponse.url())); |
| 323 return; | 294 return; |
| 324 } | 295 } |
| 325 m_loadingMultipartContent = true; | 296 m_loadingMultipartContent = true; |
| 326 } else if (isMultipartPayload) { | 297 } else if (isMultipartPayload) { |
| 327 // Since a subresource loader does not load multipart sections progressi vely, data was delivered to the loader all at once. | 298 // Since a subresource loader does not load multipart sections progressi vely, data was delivered to the loader all at once. |
| 328 // After the first multipart section is complete, signal to delegates th at this load is "finished" | 299 // After the first multipart section is complete, signal to delegates th at this load is "finished" |
| 329 m_fetcher->subresourceLoaderFinishedLoadingOnePart(this); | 300 m_fetcher->subresourceLoaderFinishedLoadingOnePart(this); |
| 330 didFinishLoadingOnePart(0, WebURLLoaderClient::kUnknownEncodedDataLength ); | 301 didFinishLoadingOnePart(0, WebURLLoaderClient::kUnknownEncodedDataLength ); |
| 331 } | 302 } |
| 332 if (m_state == ConnectionStateReleased) | 303 if (m_state == ConnectionStateReleased) |
| 333 return; | 304 return; |
| 334 | 305 |
| 335 if (m_resource->response().httpStatusCode() < 400 || m_resource->shouldIgnor eHTTPStatusCodeErrors()) | 306 if (m_resource->response().httpStatusCode() < 400 || m_resource->shouldIgnor eHTTPStatusCodeErrors()) |
| 336 return; | 307 return; |
| 337 | 308 |
| 338 if (!m_notifiedLoadComplete) { | 309 if (!m_notifiedLoadComplete) { |
| 339 m_notifiedLoadComplete = true; | 310 m_notifiedLoadComplete = true; |
| 340 m_fetcher->didFailLoading(m_resource.get(), ResourceError::cancelledErro r(m_request.url())); | 311 m_fetcher->didFailLoading(m_resource.get(), ResourceError::cancelledErro r(resourceResponse.url())); |
| 341 } | 312 } |
| 342 | 313 |
| 343 ASSERT(m_state != ConnectionStateReleased); | 314 ASSERT(m_state != ConnectionStateReleased); |
| 344 m_resource->error(Resource::LoadError); | 315 m_resource->error(Resource::LoadError); |
| 345 cancel(); | 316 cancel(ResourceError::cancelledError(resourceResponse.url())); |
| 346 } | 317 } |
| 347 | 318 |
| 348 void ResourceLoader::didReceiveResponse(WebURLLoader* loader, const WebURLRespon se& response) | 319 void ResourceLoader::didReceiveResponse(WebURLLoader* loader, const WebURLRespon se& response) |
| 349 { | 320 { |
| 350 didReceiveResponse(loader, response, nullptr); | 321 didReceiveResponse(loader, response, nullptr); |
| 351 } | 322 } |
| 352 | 323 |
| 353 void ResourceLoader::didReceiveData(WebURLLoader*, const char* data, int length, int encodedDataLength) | 324 void ResourceLoader::didReceiveData(WebURLLoader*, const char* data, int length, int encodedDataLength) |
| 354 { | 325 { |
| 355 RELEASE_ASSERT(m_state == ConnectionStateReceivedResponse || m_state == Conn ectionStateReceivingData); | 326 RELEASE_ASSERT(m_state == ConnectionStateReceivedResponse || m_state == Conn ectionStateReceivingData); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 409 return; | 380 return; |
| 410 | 381 |
| 411 m_resource->error(Resource::LoadError); | 382 m_resource->error(Resource::LoadError); |
| 412 | 383 |
| 413 if (m_state == ConnectionStateReleased) | 384 if (m_state == ConnectionStateReleased) |
| 414 return; | 385 return; |
| 415 | 386 |
| 416 releaseResources(); | 387 releaseResources(); |
| 417 } | 388 } |
| 418 | 389 |
| 419 void ResourceLoader::requestSynchronously() | 390 void ResourceLoader::requestSynchronously(ResourceRequest& request) |
| 420 { | 391 { |
| 421 // downloadToFile is not supported for synchronous requests. | 392 // downloadToFile is not supported for synchronous requests. |
| 422 ASSERT(!m_request.downloadToFile()); | 393 ASSERT(!request.downloadToFile()); |
| 423 ASSERT(m_loader); | 394 ASSERT(m_loader); |
| 424 | 395 |
| 396 // Synchronous requests should always be max priority, lest they hang the re nderer. | |
| 397 request.setPriority(ResourceLoadPriorityHighest); | |
| 398 | |
| 425 if (m_fetcher->defersLoading()) { | 399 if (m_fetcher->defersLoading()) { |
| 426 cancel(); | 400 cancel(); |
| 427 return; | 401 return; |
| 428 } | 402 } |
| 429 | 403 |
| 430 RefPtrWillBeRawPtr<Resource> protectResource(m_resource.get()); | 404 RefPtrWillBeRawPtr<Resource> protectResource(m_resource.get()); |
| 431 WrappedResourceRequest requestIn(m_request); | 405 WrappedResourceRequest requestIn(request); |
| 432 WebURLResponse responseOut; | 406 WebURLResponse responseOut; |
| 433 responseOut.initialize(); | 407 responseOut.initialize(); |
| 434 WebURLError errorOut; | 408 WebURLError errorOut; |
| 435 WebData dataOut; | 409 WebData dataOut; |
| 436 m_loader->loadSynchronously(requestIn, responseOut, errorOut, dataOut); | 410 m_loader->loadSynchronously(requestIn, responseOut, errorOut, dataOut); |
| 437 if (errorOut.reason) { | 411 if (errorOut.reason) { |
| 438 if (m_state == ConnectionStateReleased) { | 412 if (m_state == ConnectionStateReleased) { |
| 439 // A message dispatched while synchronously fetching the resource | 413 // A message dispatched while synchronously fetching the resource |
| 440 // can bring about the cancellation of this load. | 414 // can bring about the cancellation of this load. |
| 441 ASSERT(!m_resource); | 415 ASSERT(!m_resource); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 456 // a 304, where it will overwrite the cached data we should be reusing. | 430 // a 304, where it will overwrite the cached data we should be reusing. |
| 457 if (dataOut.size()) { | 431 if (dataOut.size()) { |
| 458 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size (), encodedDataLength); | 432 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size (), encodedDataLength); |
| 459 m_resource->setResourceBuffer(dataOut); | 433 m_resource->setResourceBuffer(dataOut); |
| 460 } | 434 } |
| 461 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); | 435 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); |
| 462 } | 436 } |
| 463 | 437 |
| 464 ResourceRequest& ResourceLoader::applyOptions(ResourceRequest& request) const | 438 ResourceRequest& ResourceLoader::applyOptions(ResourceRequest& request) const |
| 465 { | 439 { |
| 466 request.setAllowStoredCredentials(m_options.allowCredentials == AllowStoredC redentials); | 440 request.setAllowStoredCredentials(m_resource->options().allowCredentials == AllowStoredCredentials); |
| 467 return request; | 441 return request; |
| 468 } | 442 } |
| 469 | 443 |
| 470 } // namespace blink | 444 } // namespace blink |
| OLD | NEW |