Chromium Code Reviews| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 , m_fetcher(FrameFetchContext::createContextAndFetcher(this)) | 88 , m_fetcher(FrameFetchContext::createContextAndFetcher(this)) |
| 89 , m_originalRequest(req) | 89 , m_originalRequest(req) |
| 90 , m_substituteData(substituteData) | 90 , m_substituteData(substituteData) |
| 91 , m_request(req) | 91 , m_request(req) |
| 92 , m_isClientRedirect(false) | 92 , m_isClientRedirect(false) |
| 93 , m_replacesCurrentHistoryItem(false) | 93 , m_replacesCurrentHistoryItem(false) |
| 94 , m_navigationType(NavigationTypeOther) | 94 , m_navigationType(NavigationTypeOther) |
| 95 , m_documentLoadTiming(*this) | 95 , m_documentLoadTiming(*this) |
| 96 , m_timeOfLastDataReceived(0.0) | 96 , m_timeOfLastDataReceived(0.0) |
| 97 , m_applicationCacheHost(ApplicationCacheHost::create(this)) | 97 , m_applicationCacheHost(ApplicationCacheHost::create(this)) |
| 98 , m_state(NotStarted) | 98 , m_state(Provisional) |
| 99 , m_inDataReceived(false) | 99 , m_inDataReceived(false) |
| 100 , m_dataBuffer(SharedBuffer::create()) | 100 , m_dataBuffer(SharedBuffer::create()) |
| 101 { | 101 { |
| 102 timing().markNavigationStart(); | |
|
Nate Chapin
2015/11/04 22:13:09
As of https://chromium.googlesource.com/chromium/s
| |
| 102 } | 103 } |
| 103 | 104 |
| 104 FrameLoader* DocumentLoader::frameLoader() const | 105 FrameLoader* DocumentLoader::frameLoader() const |
| 105 { | 106 { |
| 106 if (!m_frame) | 107 if (!m_frame) |
| 107 return nullptr; | 108 return nullptr; |
| 108 return &m_frame->loader(); | 109 return &m_frame->loader(); |
| 109 } | 110 } |
| 110 | 111 |
| 111 ResourceLoader* DocumentLoader::mainResourceLoader() const | 112 ResourceLoader* DocumentLoader::mainResourceLoader() const |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 m_state = Committed; | 244 m_state = Committed; |
| 244 frameLoader()->commitProvisionalLoad(); | 245 frameLoader()->commitProvisionalLoad(); |
| 245 } | 246 } |
| 246 } | 247 } |
| 247 | 248 |
| 248 bool DocumentLoader::isLoading() const | 249 bool DocumentLoader::isLoading() const |
| 249 { | 250 { |
| 250 if (document() && document()->hasActiveParser()) | 251 if (document() && document()->hasActiveParser()) |
| 251 return true; | 252 return true; |
| 252 | 253 |
| 253 return (m_state > NotStarted && m_state < MainResourceDone) || m_fetcher->is Fetching(); | 254 return m_state < MainResourceDone || m_fetcher->isFetching(); |
| 254 } | 255 } |
| 255 | 256 |
| 256 void DocumentLoader::notifyFinished(Resource* resource) | 257 void DocumentLoader::notifyFinished(Resource* resource) |
| 257 { | 258 { |
| 258 ASSERT_UNUSED(resource, m_mainResource == resource); | 259 ASSERT_UNUSED(resource, m_mainResource == resource); |
| 259 ASSERT(m_mainResource); | 260 ASSERT(m_mainResource); |
| 260 | 261 |
| 261 RefPtrWillBeRawPtr<DocumentLoader> protect(this); | 262 RefPtrWillBeRawPtr<DocumentLoader> protect(this); |
| 262 | 263 |
| 263 if (!m_mainResource->errorOccurred() && !m_mainResource->wasCanceled()) { | 264 if (!m_mainResource->errorOccurred() && !m_mainResource->wasCanceled()) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 if (((status >= 301 && status <= 303) || status == 307) | 306 if (((status >= 301 && status <= 303) || status == 307) |
| 306 && m_originalRequest.httpMethod() == "POST") | 307 && m_originalRequest.httpMethod() == "POST") |
| 307 return true; | 308 return true; |
| 308 | 309 |
| 309 return false; | 310 return false; |
| 310 } | 311 } |
| 311 | 312 |
| 312 void DocumentLoader::redirectReceived(Resource* resource, ResourceRequest& reque st, const ResourceResponse& redirectResponse) | 313 void DocumentLoader::redirectReceived(Resource* resource, ResourceRequest& reque st, const ResourceResponse& redirectResponse) |
| 313 { | 314 { |
| 314 ASSERT_UNUSED(resource, resource == m_mainResource); | 315 ASSERT_UNUSED(resource, resource == m_mainResource); |
| 315 willSendRequest(request, redirectResponse); | |
| 316 } | |
| 317 | |
| 318 void DocumentLoader::updateRequest(Resource* resource, const ResourceRequest& re quest) | |
| 319 { | |
| 320 ASSERT_UNUSED(resource, resource == m_mainResource); | |
| 321 m_request = request; | |
| 322 } | |
| 323 | |
| 324 static bool isFormSubmission(NavigationType type) | |
| 325 { | |
| 326 return type == NavigationTypeFormSubmitted || type == NavigationTypeFormResu bmitted; | |
| 327 } | |
| 328 | |
| 329 void DocumentLoader::willSendRequest(ResourceRequest& newRequest, const Resource Response& redirectResponse) | |
| 330 { | |
| 331 // Note that there are no asserts here as there are for the other callbacks. This is due to the | |
| 332 // fact that this "callback" is sent when starting every load, and the state of callback | |
| 333 // deferrals plays less of a part in this function in preventing the bad beh avior deferring | |
| 334 // callbacks is meant to prevent. | |
| 335 ASSERT(!newRequest.isNull()); | |
| 336 if (isFormSubmission(m_navigationType) && !m_frame->document()->contentSecur ityPolicy()->allowFormAction(newRequest.url())) { | |
|
Nate Chapin
2015/11/04 22:13:09
This is the only clause in willSendRequest() that
| |
| 337 cancelMainResourceLoad(ResourceError::cancelledError(newRequest.url())); | |
| 338 return; | |
| 339 } | |
| 340 | |
| 341 ASSERT(timing().fetchStart()); | |
| 342 if (!redirectResponse.isNull()) { | |
| 343 // If the redirecting url is not allowed to display content from the tar get origin, | |
| 344 // then block the redirect. | |
| 345 RefPtr<SecurityOrigin> redirectingOrigin = SecurityOrigin::create(redire ctResponse.url()); | |
| 346 if (!redirectingOrigin->canDisplay(newRequest.url())) { | |
| 347 FrameLoader::reportLocalLoadFailed(m_frame, newRequest.url().string( )); | |
| 348 cancelMainResourceLoad(ResourceError::cancelledError(newRequest.url( ))); | |
| 349 return; | |
| 350 } | |
| 351 timing().addRedirect(redirectResponse.url(), newRequest.url()); | |
| 352 } | |
| 353 | 316 |
| 354 // If we're fielding a redirect in response to a POST, force a load from ori gin, since | 317 // If we're fielding a redirect in response to a POST, force a load from ori gin, since |
| 355 // this is a common site technique to return to a page viewing some data tha t the POST | 318 // this is a common site technique to return to a page viewing some data tha t the POST |
| 356 // just modified. | 319 // just modified. |
| 357 if (newRequest.cachePolicy() == UseProtocolCachePolicy && isRedirectAfterPos t(newRequest, redirectResponse)) | 320 if (request.cachePolicy() == UseProtocolCachePolicy && isRedirectAfterPost(r equest, redirectResponse)) |
| 358 newRequest.setCachePolicy(ReloadBypassingCache); | 321 request.setCachePolicy(ReloadBypassingCache); |
| 359 | 322 |
| 360 m_request = newRequest; | 323 m_request = request; |
| 361 | 324 |
| 362 if (redirectResponse.isNull()) | 325 // Add the fragment to the new request url. Note that this is only done on m _request, |
|
Nate Chapin
2015/11/04 22:13:09
Did you know reference fragments are propagated th
| |
| 326 // not on the request that will be passed back out of blink. The network sta ck doesn't care | |
| 327 // about the fragment, and doesn't expect the URL to change unless it is inv alidated. | |
| 328 KURL url = request.url(); | |
| 329 if (m_originalRequest.url().hasFragmentIdentifier()) { | |
| 330 url.setFragmentIdentifier(m_originalRequest.url().fragmentIdentifier()); | |
| 331 m_request.setURL(url); | |
| 332 } | |
| 333 | |
| 334 // If the redirecting url is not allowed to display content from the target origin, | |
| 335 // then block the redirect. | |
| 336 RefPtr<SecurityOrigin> redirectingOrigin = SecurityOrigin::create(redirectRe sponse.url()); | |
| 337 if (!redirectingOrigin->canDisplay(url)) { | |
| 338 FrameLoader::reportLocalLoadFailed(m_frame, url.string()); | |
| 339 cancelMainResourceLoad(ResourceError::cancelledError(url)); | |
| 363 return; | 340 return; |
| 341 } | |
| 364 | 342 |
| 365 appendRedirect(newRequest.url()); | 343 timing().addRedirect(redirectResponse.url(), url); |
| 344 appendRedirect(url); | |
| 366 frameLoader()->receivedMainResourceRedirect(m_request.url()); | 345 frameLoader()->receivedMainResourceRedirect(m_request.url()); |
| 367 if (!frameLoader()->shouldContinueForNavigationPolicy(newRequest, Substitute Data(), this, CheckContentSecurityPolicy, m_navigationType, NavigationPolicyCurr entTab, replacesCurrentHistoryItem())) | 346 if (!frameLoader()->shouldContinueForNavigationPolicy(request, SubstituteDat a(), this, CheckContentSecurityPolicy, m_navigationType, NavigationPolicyCurrent Tab, replacesCurrentHistoryItem())) |
| 368 cancelMainResourceLoad(ResourceError::cancelledError(m_request.url())); | 347 cancelMainResourceLoad(ResourceError::cancelledError(url)); |
| 369 } | 348 } |
| 370 | 349 |
| 371 static bool canShowMIMEType(const String& mimeType, Page* page) | 350 static bool canShowMIMEType(const String& mimeType, Page* page) |
| 372 { | 351 { |
| 373 if (Platform::current()->mimeRegistry()->supportsMIMEType(mimeType) == WebMi meRegistry::IsSupported) | 352 if (Platform::current()->mimeRegistry()->supportsMIMEType(mimeType) == WebMi meRegistry::IsSupported) |
| 374 return true; | 353 return true; |
| 375 PluginData* pluginData = page->pluginData(); | 354 PluginData* pluginData = page->pluginData(); |
| 376 return !mimeType.isEmpty() && pluginData && pluginData->supportsMimeType(mim eType); | 355 return !mimeType.isEmpty() && pluginData && pluginData->supportsMimeType(mim eType); |
| 377 } | 356 } |
| 378 | 357 |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 715 if (m_request.url().isEmpty() && !frameLoader()->stateMachine()->creatingIni tialEmptyDocument()) | 694 if (m_request.url().isEmpty() && !frameLoader()->stateMachine()->creatingIni tialEmptyDocument()) |
| 716 m_request.setURL(blankURL()); | 695 m_request.setURL(blankURL()); |
| 717 m_response = ResourceResponse(m_request.url(), "text/html", 0, nullAtom, Str ing()); | 696 m_response = ResourceResponse(m_request.url(), "text/html", 0, nullAtom, Str ing()); |
| 718 finishedLoading(monotonicallyIncreasingTime()); | 697 finishedLoading(monotonicallyIncreasingTime()); |
| 719 return true; | 698 return true; |
| 720 } | 699 } |
| 721 | 700 |
| 722 void DocumentLoader::startLoadingMainResource() | 701 void DocumentLoader::startLoadingMainResource() |
| 723 { | 702 { |
| 724 RefPtrWillBeRawPtr<DocumentLoader> protect(this); | 703 RefPtrWillBeRawPtr<DocumentLoader> protect(this); |
| 725 m_mainDocumentError = ResourceError(); | 704 ASSERT(m_state == Provisional); |
|
Nate Chapin
2015/11/04 22:13:09
I have no idea when this line was relevant. Maybe
| |
| 726 timing().markNavigationStart(); | |
| 727 ASSERT(!m_mainResource); | |
| 728 ASSERT(m_state == NotStarted); | |
| 729 m_state = Provisional; | |
| 730 | 705 |
| 731 if (maybeLoadEmpty()) | 706 if (maybeLoadEmpty()) |
| 732 return; | 707 return; |
| 733 | 708 |
| 734 ASSERT(timing().navigationStart()); | |
| 735 ASSERT(!timing().fetchStart()); | 709 ASSERT(!timing().fetchStart()); |
| 736 timing().markFetchStart(); | 710 timing().markFetchStart(); |
| 737 willSendRequest(m_request, ResourceResponse()); | |
| 738 | |
| 739 // willSendRequest() may lead to our LocalFrame being detached or cancelling the load via nulling the ResourceRequest. | |
| 740 if (!m_frame || m_request.isNull()) | |
| 741 return; | |
| 742 | |
| 743 m_applicationCacheHost->willStartLoadingMainResource(m_request); | |
| 744 prepareSubframeArchiveLoadIfNeeded(); | 711 prepareSubframeArchiveLoadIfNeeded(); |
| 745 | 712 |
| 746 ResourceRequest request(m_request); | |
| 747 DEFINE_STATIC_LOCAL(ResourceLoaderOptions, mainResourceLoadOptions, | 713 DEFINE_STATIC_LOCAL(ResourceLoaderOptions, mainResourceLoadOptions, |
| 748 (DoNotBufferData, AllowStoredCredentials, ClientRequestedCredentials, Ch eckContentSecurityPolicy, DocumentContext)); | 714 (DoNotBufferData, AllowStoredCredentials, ClientRequestedCredentials, Ch eckContentSecurityPolicy, DocumentContext)); |
| 749 FetchRequest cachedResourceRequest(request, FetchInitiatorTypeNames::documen t, mainResourceLoadOptions); | 715 FetchRequest fetchRequest(m_request, FetchInitiatorTypeNames::document, main ResourceLoadOptions); |
| 750 m_mainResource = RawResource::fetchMainResource(cachedResourceRequest, fetch er(), m_substituteData); | 716 |
| 717 m_mainResource = RawResource::fetchMainResource(fetchRequest, fetcher(), m_s ubstituteData); | |
| 751 if (!m_mainResource) { | 718 if (!m_mainResource) { |
| 752 m_request = ResourceRequest(); | 719 m_request = ResourceRequest(); |
| 753 // If the load was aborted by clearing m_request, it's possible the Appl icationCacheHost | |
| 754 // is now in a state where starting an empty load will be inconsistent. Replace it with | |
| 755 // a new ApplicationCacheHost. | |
| 756 if (m_applicationCacheHost) | |
| 757 m_applicationCacheHost->detachFromDocumentLoader(); | |
| 758 m_applicationCacheHost = ApplicationCacheHost::create(this); | |
|
Nate Chapin
2015/11/04 22:13:09
Moved the m_applicationCacheHost->willStartLoading
| |
| 759 maybeLoadEmpty(); | 720 maybeLoadEmpty(); |
| 760 return; | 721 return; |
| 761 } | 722 } |
| 723 | |
| 762 m_mainResource->addClient(this); | 724 m_mainResource->addClient(this); |
| 725 if (!m_mainResource) | |
|
Nate Chapin
2015/11/04 22:13:09
Pre-cached main resources (i.e., data: urls or Sub
| |
| 726 return; | |
| 763 | 727 |
| 764 // A bunch of headers are set when the underlying ResourceLoader is created, and m_request needs to include those. | 728 // A bunch of headers are set when the underlying ResourceLoader is created, and m_request needs to include those. |
| 765 if (mainResourceLoader()) | 729 // However, if there was a fragment identifier on m_request, the cache will have stripped it. m_request should include |
| 766 request = mainResourceLoader()->originalRequest(); | 730 // the fragment identifier, so reset the url. |
| 767 // If there was a fragment identifier on m_request, the cache will have stri pped it. m_request should include | 731 m_request = m_mainResource->resourceRequest(); |
| 768 // the fragment identifier, so add that back in. | 732 m_request.setURL(m_originalRequest.url()); |
| 769 if (equalIgnoringFragmentIdentifier(m_request.url(), request.url())) | |
| 770 request.setURL(m_request.url()); | |
| 771 m_request = request; | |
| 772 } | 733 } |
| 773 | 734 |
| 774 void DocumentLoader::cancelMainResourceLoad(const ResourceError& resourceError) | 735 void DocumentLoader::cancelMainResourceLoad(const ResourceError& resourceError) |
| 775 { | 736 { |
| 776 RefPtrWillBeRawPtr<DocumentLoader> protect(this); | 737 RefPtrWillBeRawPtr<DocumentLoader> protect(this); |
| 777 ResourceError error = resourceError.isNull() ? ResourceError::cancelledError (m_request.url()) : resourceError; | 738 ResourceError error = resourceError.isNull() ? ResourceError::cancelledError (m_request.url()) : resourceError; |
| 778 | 739 |
| 779 if (mainResourceLoader()) | 740 if (mainResourceLoader()) |
| 780 mainResourceLoader()->cancel(error); | 741 mainResourceLoader()->cancel(error); |
| 781 | 742 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 833 { | 794 { |
| 834 m_writer = createWriterFor(ownerDocument, init, mimeType(), m_writer ? m_wri ter->encoding() : emptyAtom, true, ForceSynchronousParsing); | 795 m_writer = createWriterFor(ownerDocument, init, mimeType(), m_writer ? m_wri ter->encoding() : emptyAtom, true, ForceSynchronousParsing); |
| 835 if (!source.isNull()) | 796 if (!source.isNull()) |
| 836 m_writer->appendReplacingData(source); | 797 m_writer->appendReplacingData(source); |
| 837 endWriting(m_writer.get()); | 798 endWriting(m_writer.get()); |
| 838 } | 799 } |
| 839 | 800 |
| 840 DEFINE_WEAK_IDENTIFIER_MAP(DocumentLoader); | 801 DEFINE_WEAK_IDENTIFIER_MAP(DocumentLoader); |
| 841 | 802 |
| 842 } // namespace blink | 803 } // namespace blink |
| OLD | NEW |