OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. |
3 * Copyright (C) 2011 Google Inc. All rights reserved. | 3 * Copyright (C) 2011 Google Inc. All rights reserved. |
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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 return; | 266 return; |
267 } | 267 } |
268 | 268 |
269 // We might run in to infinite recursion if we're stopping loading as the re
sult of | 269 // We might run in to infinite recursion if we're stopping loading as the re
sult of |
270 // detaching from the frame, so break out of that recursion here. | 270 // detaching from the frame, so break out of that recursion here. |
271 // See <rdar://problem/9673866> for more details. | 271 // See <rdar://problem/9673866> for more details. |
272 if (m_isStopping) | 272 if (m_isStopping) |
273 return; | 273 return; |
274 | 274 |
275 m_isStopping = true; | 275 m_isStopping = true; |
| 276 |
| 277 FrameLoader* frameLoader = DocumentLoader::frameLoader(); |
276 | 278 |
277 if (isLoadingMainResource()) | 279 if (isLoadingMainResource()) |
278 // Stop the main resource loader and let it send the cancelled message. | 280 // Stop the main resource loader and let it send the cancelled message. |
279 cancelMainResourceLoad(ResourceError::cancelledError(m_request.url())); | 281 cancelMainResourceLoad(frameLoader->cancelledError(m_request)); |
280 else if (!m_resourceLoaders.isEmpty()) | 282 else if (!m_resourceLoaders.isEmpty()) |
281 // The main resource loader already finished loading. Set the cancelled
error on the | 283 // The main resource loader already finished loading. Set the cancelled
error on the |
282 // document and let the resourceLoaders send individual cancelled messag
es below. | 284 // document and let the resourceLoaders send individual cancelled messag
es below. |
283 setMainDocumentError(ResourceError::cancelledError(m_request.url())); | 285 setMainDocumentError(frameLoader->cancelledError(m_request)); |
284 else | 286 else |
285 // If there are no resource loaders, we need to manufacture a cancelled
message. | 287 // If there are no resource loaders, we need to manufacture a cancelled
message. |
286 // (A back/forward navigation has no resource loaders because its resour
ces are cached.) | 288 // (A back/forward navigation has no resource loaders because its resour
ces are cached.) |
287 mainReceivedError(ResourceError::cancelledError(m_request.url())); | 289 mainReceivedError(frameLoader->cancelledError(m_request)); |
288 | 290 |
289 stopLoadingSubresources(); | 291 stopLoadingSubresources(); |
290 | 292 |
291 m_isStopping = false; | 293 m_isStopping = false; |
292 } | 294 } |
293 | 295 |
294 void DocumentLoader::commitIfReady() | 296 void DocumentLoader::commitIfReady() |
295 { | 297 { |
296 if (!m_committed) { | 298 if (!m_committed) { |
297 m_committed = true; | 299 m_committed = true; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 | 446 |
445 void DocumentLoader::willSendRequest(ResourceRequest& newRequest, const Resource
Response& redirectResponse) | 447 void DocumentLoader::willSendRequest(ResourceRequest& newRequest, const Resource
Response& redirectResponse) |
446 { | 448 { |
447 // Note that there are no asserts here as there are for the other callbacks.
This is due to the | 449 // Note that there are no asserts here as there are for the other callbacks.
This is due to the |
448 // fact that this "callback" is sent when starting every load, and the state
of callback | 450 // fact that this "callback" is sent when starting every load, and the state
of callback |
449 // deferrals plays less of a part in this function in preventing the bad beh
avior deferring | 451 // deferrals plays less of a part in this function in preventing the bad beh
avior deferring |
450 // callbacks is meant to prevent. | 452 // callbacks is meant to prevent. |
451 ASSERT(!newRequest.isNull()); | 453 ASSERT(!newRequest.isNull()); |
452 | 454 |
453 if (!frameLoader()->checkIfFormActionAllowedByCSP(newRequest.url())) { | 455 if (!frameLoader()->checkIfFormActionAllowedByCSP(newRequest.url())) { |
454 cancelMainResourceLoad(ResourceError::cancelledError(newRequest.url())); | 456 cancelMainResourceLoad(frameLoader()->cancelledError(newRequest)); |
455 return; | 457 return; |
456 } | 458 } |
457 | 459 |
458 ASSERT(timing()->fetchStart()); | 460 ASSERT(timing()->fetchStart()); |
459 if (!redirectResponse.isNull()) { | 461 if (!redirectResponse.isNull()) { |
460 // If the redirecting url is not allowed to display content from the tar
get origin, | 462 // If the redirecting url is not allowed to display content from the tar
get origin, |
461 // then block the redirect. | 463 // then block the redirect. |
462 RefPtr<SecurityOrigin> redirectingOrigin = SecurityOrigin::create(redire
ctResponse.url()); | 464 RefPtr<SecurityOrigin> redirectingOrigin = SecurityOrigin::create(redire
ctResponse.url()); |
463 if (!redirectingOrigin->canDisplay(newRequest.url())) { | 465 if (!redirectingOrigin->canDisplay(newRequest.url())) { |
464 FrameLoader::reportLocalLoadFailed(m_frame, newRequest.url().string(
)); | 466 FrameLoader::reportLocalLoadFailed(m_frame, newRequest.url().string(
)); |
465 cancelMainResourceLoad(ResourceError::cancelledError(newRequest.url(
))); | 467 cancelMainResourceLoad(frameLoader()->cancelledError(newRequest)); |
466 return; | 468 return; |
467 } | 469 } |
468 timing()->addRedirect(redirectResponse.url(), newRequest.url()); | 470 timing()->addRedirect(redirectResponse.url(), newRequest.url()); |
469 } | 471 } |
470 | 472 |
471 // Update cookie policy base URL as URL changes, except for subframes, which
use the | 473 // Update cookie policy base URL as URL changes, except for subframes, which
use the |
472 // URL of the main frame which doesn't change when we redirect. | 474 // URL of the main frame which doesn't change when we redirect. |
473 if (frameLoader()->isLoadingMainFrame()) | 475 if (frameLoader()->isLoadingMainFrame()) |
474 newRequest.setFirstPartyForCookies(newRequest.url()); | 476 newRequest.setFirstPartyForCookies(newRequest.url()); |
475 | 477 |
476 // If we're fielding a redirect in response to a POST, force a load from ori
gin, since | 478 // If we're fielding a redirect in response to a POST, force a load from ori
gin, since |
477 // this is a common site technique to return to a page viewing some data tha
t the POST | 479 // this is a common site technique to return to a page viewing some data tha
t the POST |
478 // just modified. | 480 // just modified. |
479 // Also, POST requests always load from origin, but this does not affect sub
resources. | 481 // Also, POST requests always load from origin, but this does not affect sub
resources. |
480 if (newRequest.cachePolicy() == UseProtocolCachePolicy && isPostOrRedirectAf
terPost(newRequest, redirectResponse)) | 482 if (newRequest.cachePolicy() == UseProtocolCachePolicy && isPostOrRedirectAf
terPost(newRequest, redirectResponse)) |
481 newRequest.setCachePolicy(ReloadIgnoringCacheData); | 483 newRequest.setCachePolicy(ReloadIgnoringCacheData); |
482 | 484 |
483 Frame* top = m_frame->tree()->top(); | 485 Frame* top = m_frame->tree()->top(); |
484 if (top != m_frame) { | 486 if (top != m_frame) { |
485 if (!frameLoader()->mixedContentChecker()->canDisplayInsecureContent(top
->document()->securityOrigin(), newRequest.url())) { | 487 if (!frameLoader()->mixedContentChecker()->canDisplayInsecureContent(top
->document()->securityOrigin(), newRequest.url())) { |
486 cancelMainResourceLoad(ResourceError::cancelledError(newRequest.url(
))); | 488 cancelMainResourceLoad(frameLoader()->cancelledError(newRequest)); |
487 return; | 489 return; |
488 } | 490 } |
489 } | 491 } |
490 | 492 |
491 setRequest(newRequest); | 493 setRequest(newRequest); |
492 | 494 |
493 if (redirectResponse.isNull()) | 495 if (redirectResponse.isNull()) |
494 return; | 496 return; |
495 | 497 |
496 // We checked application cache for initial URL, now we need to check it for
redirected one. | 498 // We checked application cache for initial URL, now we need to check it for
redirected one. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 ASSERT(m_mainResource); | 576 ASSERT(m_mainResource); |
575 unsigned long identifier = m_identifierForLoadWithoutResourceLoader ? m_
identifierForLoadWithoutResourceLoader : m_mainResource->identifier(); | 577 unsigned long identifier = m_identifierForLoadWithoutResourceLoader ? m_
identifierForLoadWithoutResourceLoader : m_mainResource->identifier(); |
576 ASSERT(identifier); | 578 ASSERT(identifier); |
577 if (frameLoader()->shouldInterruptLoadForXFrameOptions(content, response
.url(), identifier)) { | 579 if (frameLoader()->shouldInterruptLoadForXFrameOptions(content, response
.url(), identifier)) { |
578 InspectorInstrumentation::continueAfterXFrameOptionsDenied(m_frame,
this, identifier, response); | 580 InspectorInstrumentation::continueAfterXFrameOptionsDenied(m_frame,
this, identifier, response); |
579 String message = "Refused to display '" + response.url().elidedStrin
g() + "' in a frame because it set 'X-Frame-Options' to '" + content + "'."; | 581 String message = "Refused to display '" + response.url().elidedStrin
g() + "' in a frame because it set 'X-Frame-Options' to '" + content + "'."; |
580 frame()->document()->addConsoleMessage(SecurityMessageSource, ErrorM
essageLevel, message, identifier); | 582 frame()->document()->addConsoleMessage(SecurityMessageSource, ErrorM
essageLevel, message, identifier); |
581 frame()->document()->enforceSandboxFlags(SandboxOrigin); | 583 frame()->document()->enforceSandboxFlags(SandboxOrigin); |
582 if (HTMLFrameOwnerElement* ownerElement = frame()->ownerElement()) | 584 if (HTMLFrameOwnerElement* ownerElement = frame()->ownerElement()) |
583 ownerElement->dispatchEvent(Event::create(eventNames().loadEvent
, false, false)); | 585 ownerElement->dispatchEvent(Event::create(eventNames().loadEvent
, false, false)); |
584 cancelMainResourceLoad(ResourceError::cancelledError(m_request.url()
)); | 586 cancelMainResourceLoad(frameLoader()->cancelledError(m_request)); |
585 return; | 587 return; |
586 } | 588 } |
587 } | 589 } |
588 | 590 |
589 ASSERT(!mainResourceLoader() || !mainResourceLoader()->defersLoading()); | 591 ASSERT(!mainResourceLoader() || !mainResourceLoader()->defersLoading()); |
590 | 592 |
591 if (m_isLoadingMultipartContent) { | 593 if (m_isLoadingMultipartContent) { |
592 setupForReplace(); | 594 setupForReplace(); |
593 m_mainResource->clear(); | 595 m_mainResource->clear(); |
594 } else if (response.isMultipart()) { | 596 } else if (response.isMultipart()) { |
(...skipping 15 matching lines...) Expand all Loading... |
610 if (m_response.isHTTP()) { | 612 if (m_response.isHTTP()) { |
611 int status = m_response.httpStatusCode(); | 613 int status = m_response.httpStatusCode(); |
612 if (status < 200 || status >= 300) { | 614 if (status < 200 || status >= 300) { |
613 bool hostedByObject = frameLoader()->isHostedByObjectElement(); | 615 bool hostedByObject = frameLoader()->isHostedByObjectElement(); |
614 | 616 |
615 frameLoader()->handleFallbackContent(); | 617 frameLoader()->handleFallbackContent(); |
616 // object elements are no longer rendered after we fallback, so don'
t | 618 // object elements are no longer rendered after we fallback, so don'
t |
617 // keep trying to process data from their load | 619 // keep trying to process data from their load |
618 | 620 |
619 if (hostedByObject) | 621 if (hostedByObject) |
620 cancelMainResourceLoad(ResourceError::cancelledError(m_request.u
rl())); | 622 cancelMainResourceLoad(frameLoader()->cancelledError(m_request))
; |
621 } | 623 } |
622 } | 624 } |
623 | 625 |
624 if (!isStopping() && m_substituteData.isValid()) { | 626 if (!isStopping() && m_substituteData.isValid()) { |
625 if (m_substituteData.content()->size()) | 627 if (m_substituteData.content()->size()) |
626 dataReceived(0, m_substituteData.content()->data(), m_substituteData
.content()->size()); | 628 dataReceived(0, m_substituteData.content()->data(), m_substituteData
.content()->size()); |
627 if (isLoadingMainResource()) | 629 if (isLoadingMainResource()) |
628 finishedLoading(0); | 630 finishedLoading(0); |
629 } | 631 } |
630 } | 632 } |
(...skipping 12 matching lines...) Expand all Loading... |
643 | 645 |
644 commitIfReady(); | 646 commitIfReady(); |
645 FrameLoader* frameLoader = DocumentLoader::frameLoader(); | 647 FrameLoader* frameLoader = DocumentLoader::frameLoader(); |
646 if (!frameLoader) | 648 if (!frameLoader) |
647 return; | 649 return; |
648 if (isArchiveMIMEType(response().mimeType())) | 650 if (isArchiveMIMEType(response().mimeType())) |
649 return; | 651 return; |
650 frameLoader->client()->committedLoad(this, data, length); | 652 frameLoader->client()->committedLoad(this, data, length); |
651 } | 653 } |
652 | 654 |
| 655 ResourceError DocumentLoader::interruptedForPolicyChangeError() const |
| 656 { |
| 657 return frameLoader()->client()->interruptedForPolicyChangeError(request()); |
| 658 } |
| 659 |
653 void DocumentLoader::stopLoadingForPolicyChange() | 660 void DocumentLoader::stopLoadingForPolicyChange() |
654 { | 661 { |
655 ResourceError error = frameLoader()->client()->interruptedForPolicyChangeErr
or(m_request); | 662 ResourceError error = interruptedForPolicyChangeError(); |
656 error.setIsCancellation(true); | 663 error.setIsCancellation(true); |
657 cancelMainResourceLoad(error); | 664 cancelMainResourceLoad(error); |
658 } | 665 } |
659 | 666 |
660 void DocumentLoader::commitData(const char* bytes, size_t length) | 667 void DocumentLoader::commitData(const char* bytes, size_t length) |
661 { | 668 { |
662 if (!m_gotFirstByte) { | 669 if (!m_gotFirstByte) { |
663 m_gotFirstByte = true; | 670 m_gotFirstByte = true; |
664 m_writer.begin(documentURL(), false); | 671 m_writer.begin(documentURL(), false); |
665 m_writer.setDocumentWasLoadedAsPartOfNavigation(); | 672 m_writer.setDocumentWasLoadedAsPartOfNavigation(); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 if (m_frame->page()->defersLoading()) | 896 if (m_frame->page()->defersLoading()) |
890 return; | 897 return; |
891 | 898 |
892 SubstituteResourceMap copy; | 899 SubstituteResourceMap copy; |
893 copy.swap(m_pendingSubstituteResources); | 900 copy.swap(m_pendingSubstituteResources); |
894 | 901 |
895 SubstituteResourceMap::const_iterator end = copy.end(); | 902 SubstituteResourceMap::const_iterator end = copy.end(); |
896 for (SubstituteResourceMap::const_iterator it = copy.begin(); it != end; ++i
t) { | 903 for (SubstituteResourceMap::const_iterator it = copy.begin(); it != end; ++i
t) { |
897 RefPtr<ResourceLoader> loader = it->key; | 904 RefPtr<ResourceLoader> loader = it->key; |
898 SubstituteResource* resource = it->value.get(); | 905 SubstituteResource* resource = it->value.get(); |
899 ASSERT(resource); | |
900 | 906 |
901 if (resource) { | 907 if (resource) { |
902 SharedBuffer* data = resource->data(); | 908 SharedBuffer* data = resource->data(); |
903 | 909 |
904 loader->didReceiveResponse(0, resource->response()); | 910 loader->didReceiveResponse(0, resource->response()); |
905 | 911 |
906 // Calling ResourceLoader::didReceiveResponse can end up cancelling
the load, | 912 // Calling ResourceLoader::didReceiveResponse can end up cancelling
the load, |
907 // so we need to check if the loader has reached its terminal state. | 913 // so we need to check if the loader has reached its terminal state. |
908 if (loader->reachedTerminalState()) | 914 if (loader->reachedTerminalState()) |
909 return; | 915 return; |
910 | 916 |
911 loader->didReceiveData(0, data->data(), data->size(), data->size()); | 917 loader->didReceiveData(0, data->data(), data->size(), data->size()); |
912 | 918 |
913 // Calling ResourceLoader::didReceiveData can end up cancelling the
load, | 919 // Calling ResourceLoader::didReceiveData can end up cancelling the
load, |
914 // so we need to check if the loader has reached its terminal state. | 920 // so we need to check if the loader has reached its terminal state. |
915 if (loader->reachedTerminalState()) | 921 if (loader->reachedTerminalState()) |
916 return; | 922 return; |
917 | 923 |
918 loader->didFinishLoading(0, 0); | 924 loader->didFinishLoading(0, 0); |
| 925 } else { |
| 926 // A null resource means that we should fail the load. |
| 927 // FIXME: Maybe we should use another error here - something like "n
ot in cache". |
| 928 loader->didFail(0, loader->cannotShowURLError()); |
919 } | 929 } |
920 } | 930 } |
921 } | 931 } |
922 | 932 |
923 #ifndef NDEBUG | 933 #ifndef NDEBUG |
924 bool DocumentLoader::isSubstituteLoadPending(ResourceLoader* loader) const | 934 bool DocumentLoader::isSubstituteLoadPending(ResourceLoader* loader) const |
925 { | 935 { |
926 return m_pendingSubstituteResources.contains(loader); | 936 return m_pendingSubstituteResources.contains(loader); |
927 } | 937 } |
928 #endif | 938 #endif |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1127 // If there was a fragment identifier on m_request, the cache will have stri
pped it. m_request should include | 1137 // If there was a fragment identifier on m_request, the cache will have stri
pped it. m_request should include |
1128 // the fragment identifier, so add that back in. | 1138 // the fragment identifier, so add that back in. |
1129 if (equalIgnoringFragmentIdentifier(m_request.url(), request.url())) | 1139 if (equalIgnoringFragmentIdentifier(m_request.url(), request.url())) |
1130 request.setURL(m_request.url()); | 1140 request.setURL(m_request.url()); |
1131 setRequest(request); | 1141 setRequest(request); |
1132 } | 1142 } |
1133 | 1143 |
1134 void DocumentLoader::cancelMainResourceLoad(const ResourceError& resourceError) | 1144 void DocumentLoader::cancelMainResourceLoad(const ResourceError& resourceError) |
1135 { | 1145 { |
1136 RefPtr<DocumentLoader> protect(this); | 1146 RefPtr<DocumentLoader> protect(this); |
1137 ResourceError error = resourceError.isNull() ? ResourceError::cancelledError
(m_request.url()) : resourceError; | 1147 ResourceError error = resourceError.isNull() ? frameLoader()->cancelledError
(m_request) : resourceError; |
1138 | 1148 |
1139 m_dataLoadTimer.stop(); | 1149 m_dataLoadTimer.stop(); |
1140 if (mainResourceLoader()) | 1150 if (mainResourceLoader()) |
1141 mainResourceLoader()->cancel(error); | 1151 mainResourceLoader()->cancel(error); |
1142 | 1152 |
1143 mainReceivedError(error); | 1153 mainReceivedError(error); |
1144 } | 1154 } |
1145 | 1155 |
1146 void DocumentLoader::subresourceLoaderFinishedLoadingOnePart(ResourceLoader* loa
der) | 1156 void DocumentLoader::subresourceLoaderFinishedLoadingOnePart(ResourceLoader* loa
der) |
1147 { | 1157 { |
(...skipping 15 matching lines...) Expand all Loading... |
1163 commitLoad(resourceData->data(), resourceData->size()); | 1173 commitLoad(resourceData->data(), resourceData->size()); |
1164 } | 1174 } |
1165 | 1175 |
1166 void DocumentLoader::handledOnloadEvents() | 1176 void DocumentLoader::handledOnloadEvents() |
1167 { | 1177 { |
1168 m_wasOnloadHandled = true; | 1178 m_wasOnloadHandled = true; |
1169 applicationCacheHost()->stopDeferringEvents(); | 1179 applicationCacheHost()->stopDeferringEvents(); |
1170 } | 1180 } |
1171 | 1181 |
1172 } // namespace WebCore | 1182 } // namespace WebCore |
OLD | NEW |