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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 ASSERT(m_state != Terminated); | 142 ASSERT(m_state != Terminated); |
143 m_host->didInitializeResourceLoader(this); | 143 m_host->didInitializeResourceLoader(this); |
144 } | 144 } |
145 | 145 |
146 void ResourceLoader::start() | 146 void ResourceLoader::start() |
147 { | 147 { |
148 ASSERT(!m_loader); | 148 ASSERT(!m_loader); |
149 ASSERT(!m_request.isNull()); | 149 ASSERT(!m_request.isNull()); |
150 ASSERT(m_deferredRequest.isNull()); | 150 ASSERT(m_deferredRequest.isNull()); |
151 | 151 |
| 152 if (responseNeedsAccessControlCheck() && m_host->isControlledByServiceWorker
()) { |
| 153 m_fallbackRequestForServiceWorker = adoptPtr(new ResourceRequest(m_reque
st)); |
| 154 m_fallbackRequestForServiceWorker->setSkipServiceWorker(true); |
| 155 } |
| 156 |
152 m_host->willStartLoadingResource(m_resource, m_request); | 157 m_host->willStartLoadingResource(m_resource, m_request); |
153 | 158 |
154 if (m_options.synchronousPolicy == RequestSynchronously) { | 159 if (m_options.synchronousPolicy == RequestSynchronously) { |
155 requestSynchronously(); | 160 requestSynchronously(); |
156 return; | 161 return; |
157 } | 162 } |
158 | 163 |
159 if (m_defersLoading) { | 164 if (m_defersLoading) { |
160 m_deferredRequest = m_request; | 165 m_deferredRequest = m_request; |
161 return; | 166 return; |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 | 353 |
349 bool isMultipartPayload = response.isMultipartPayload(); | 354 bool isMultipartPayload = response.isMultipartPayload(); |
350 bool isValidStateTransition = (m_connectionState == ConnectionStateStarted |
| m_connectionState == ConnectionStateReceivedResponse); | 355 bool isValidStateTransition = (m_connectionState == ConnectionStateStarted |
| m_connectionState == ConnectionStateReceivedResponse); |
351 // In the case of multipart loads, calls to didReceiveData & didReceiveRespo
nse can be interleaved. | 356 // In the case of multipart loads, calls to didReceiveData & didReceiveRespo
nse can be interleaved. |
352 RELEASE_ASSERT(isMultipartPayload || isValidStateTransition); | 357 RELEASE_ASSERT(isMultipartPayload || isValidStateTransition); |
353 m_connectionState = ConnectionStateReceivedResponse; | 358 m_connectionState = ConnectionStateReceivedResponse; |
354 | 359 |
355 const ResourceResponse& resourceResponse = response.toResourceResponse(); | 360 const ResourceResponse& resourceResponse = response.toResourceResponse(); |
356 | 361 |
357 if (responseNeedsAccessControlCheck()) { | 362 if (responseNeedsAccessControlCheck()) { |
358 // If the response successfully validated a cached resource, perform | 363 if (response.wasFetchedViaServiceWorker()) { |
359 // the access control with respect to it. Need to do this right here | 364 if (response.wasFallbackRequiredByServiceWorker()) { |
360 // before the resource switches clients over to that validated resource. | 365 m_loader->cancel(); |
361 Resource* resource = m_resource; | 366 m_loader.clear(); |
362 if (resource->isCacheValidator() && resourceResponse.httpStatusCode() ==
304) | 367 m_connectionState = ConnectionStateStarted; |
363 resource = m_resource->resourceToRevalidate(); | 368 m_request = *m_fallbackRequestForServiceWorker; |
364 else | 369 m_loader = adoptPtr(blink::Platform::current()->createURLLoader(
)); |
365 m_resource->setResponse(resourceResponse); | 370 ASSERT(m_loader); |
366 if (!m_host->canAccessResource(resource, m_options.securityOrigin.get(),
response.url())) { | 371 blink::WrappedResourceRequest wrappedRequest(m_request); |
367 m_host->didReceiveResponse(m_resource, resourceResponse); | 372 m_loader->loadAsynchronously(wrappedRequest, this); |
368 cancel(); | 373 return; |
369 return; | 374 } |
| 375 } else { |
| 376 // If the response successfully validated a cached resource, perform |
| 377 // the access control with respect to it. Need to do this right here |
| 378 // before the resource switches clients over to that validated resou
rce. |
| 379 Resource* resource = m_resource; |
| 380 if (resource->isCacheValidator() && resourceResponse.httpStatusCode(
) == 304) |
| 381 resource = m_resource->resourceToRevalidate(); |
| 382 else |
| 383 m_resource->setResponse(resourceResponse); |
| 384 if (!m_host->canAccessResource(resource, m_options.securityOrigin.ge
t(), response.url())) { |
| 385 m_host->didReceiveResponse(m_resource, resourceResponse); |
| 386 cancel(); |
| 387 return; |
| 388 } |
370 } | 389 } |
371 } | 390 } |
372 | 391 |
373 // Reference the object in this method since the additional processing can d
o | 392 // Reference the object in this method since the additional processing can d
o |
374 // anything including removing the last reference to this object. | 393 // anything including removing the last reference to this object. |
375 RefPtrWillBeRawPtr<ResourceLoader> protect(this); | 394 RefPtrWillBeRawPtr<ResourceLoader> protect(this); |
376 m_resource->responseReceived(resourceResponse); | 395 m_resource->responseReceived(resourceResponse); |
377 if (m_state == Terminated) | 396 if (m_state == Terminated) |
378 return; | 397 return; |
379 | 398 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); | 548 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); |
530 } | 549 } |
531 | 550 |
532 ResourceRequest& ResourceLoader::applyOptions(ResourceRequest& request) const | 551 ResourceRequest& ResourceLoader::applyOptions(ResourceRequest& request) const |
533 { | 552 { |
534 request.setAllowStoredCredentials(m_options.allowCredentials == AllowStoredC
redentials); | 553 request.setAllowStoredCredentials(m_options.allowCredentials == AllowStoredC
redentials); |
535 return request; | 554 return request; |
536 } | 555 } |
537 | 556 |
538 } | 557 } |
OLD | NEW |