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