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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 if (m_isClientRedirect) | 150 if (m_isClientRedirect) |
| 151 appendRedirect(oldURL); | 151 appendRedirect(oldURL); |
| 152 appendRedirect(newURL); | 152 appendRedirect(newURL); |
| 153 } | 153 } |
| 154 | 154 |
| 155 bool DocumentLoader::isURLValidForNewHistoryEntry() const | 155 bool DocumentLoader::isURLValidForNewHistoryEntry() const |
| 156 { | 156 { |
| 157 return !originalRequest().url().isEmpty() || !unreachableURL().isEmpty(); | 157 return !originalRequest().url().isEmpty() || !unreachableURL().isEmpty(); |
| 158 } | 158 } |
| 159 | 159 |
| 160 void DocumentLoader::setRequest(const ResourceRequest& req) | |
| 161 { | |
| 162 // Replacing an unreachable URL with alternate content looks like a server-s ide | |
| 163 // redirect at this point, but we can replace a committed dataSource. | |
| 164 bool handlingUnreachableURL = false; | |
| 165 | |
| 166 handlingUnreachableURL = m_substituteData.isValid() && !m_substituteData.fai lingURL().isEmpty(); | |
| 167 | |
| 168 if (handlingUnreachableURL) | |
| 169 m_committed = false; | |
| 170 | |
| 171 // We should never be getting a redirect callback after the data | |
| 172 // source is committed, except in the unreachable URL case. It | |
| 173 // would be a WebFoundation bug if it sent a redirect callback after commit. | |
| 174 ASSERT(!m_committed); | |
|
Nate Chapin
2014/01/06 21:13:22
This ASSERT and resetting of m_committed are not v
| |
| 175 | |
| 176 m_request = req; | |
| 177 } | |
| 178 | |
| 179 void DocumentLoader::setMainDocumentError(const ResourceError& error) | 160 void DocumentLoader::setMainDocumentError(const ResourceError& error) |
| 180 { | 161 { |
| 181 m_mainDocumentError = error; | 162 m_mainDocumentError = error; |
| 182 } | 163 } |
| 183 | 164 |
| 184 void DocumentLoader::mainReceivedError(const ResourceError& error) | 165 void DocumentLoader::mainReceivedError(const ResourceError& error) |
| 185 { | 166 { |
| 186 ASSERT(!error.isNull()); | 167 ASSERT(!error.isNull()); |
| 187 ASSERT(!mainResourceLoader() || !mainResourceLoader()->defersLoading() || In spectorInstrumentation::isDebuggerPaused(m_frame)); | 168 ASSERT(!mainResourceLoader() || !mainResourceLoader()->defersLoading() || In spectorInstrumentation::isDebuggerPaused(m_frame)); |
| 188 m_applicationCacheHost->failedLoadingMainResource(); | 169 m_applicationCacheHost->failedLoadingMainResource(); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 if (((status >= 301 && status <= 303) || status == 307) | 300 if (((status >= 301 && status <= 303) || status == 307) |
| 320 && m_originalRequest.httpMethod() == "POST") | 301 && m_originalRequest.httpMethod() == "POST") |
| 321 return true; | 302 return true; |
| 322 | 303 |
| 323 return false; | 304 return false; |
| 324 } | 305 } |
| 325 | 306 |
| 326 bool DocumentLoader::shouldContinueForNavigationPolicy(const ResourceRequest& re quest, PolicyCheckLoadType policyCheckLoadType) | 307 bool DocumentLoader::shouldContinueForNavigationPolicy(const ResourceRequest& re quest, PolicyCheckLoadType policyCheckLoadType) |
| 327 { | 308 { |
| 328 // Don't ask if we are loading an empty URL. | 309 // Don't ask if we are loading an empty URL. |
| 329 if (request.url().isEmpty()) | 310 if (request.url().isEmpty() || m_substituteData.isValid()) |
| 330 return true; | |
| 331 | |
| 332 // We are always willing to show alternate content for unreachable URLs. | |
| 333 if (m_substituteData.isValid() && !m_substituteData.failingURL().isEmpty()) | |
| 334 return true; | 311 return true; |
| 335 | 312 |
| 336 // If we're loading content into a subframe, check against the parent's Cont ent Security Policy | 313 // If we're loading content into a subframe, check against the parent's Cont ent Security Policy |
| 337 // and kill the load if that check fails. | 314 // and kill the load if that check fails. |
| 338 if (m_frame->ownerElement() && !m_frame->ownerElement()->document().contentS ecurityPolicy()->allowChildFrameFromSource(request.url())) | 315 if (m_frame->ownerElement() && !m_frame->ownerElement()->document().contentS ecurityPolicy()->allowChildFrameFromSource(request.url())) |
| 339 return false; | 316 return false; |
| 340 | 317 |
| 341 NavigationPolicy policy = m_triggeringAction.policy(); | 318 NavigationPolicy policy = m_triggeringAction.policy(); |
| 342 if (policyCheckLoadType != PolicyCheckFragment) | 319 if (policyCheckLoadType != PolicyCheckFragment) |
| 343 policy = frameLoader()->client()->decidePolicyForNavigation(request, thi s, policy); | 320 policy = frameLoader()->client()->decidePolicyForNavigation(request, thi s, policy); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 399 newRequest.setCachePolicy(ReloadIgnoringCacheData); | 376 newRequest.setCachePolicy(ReloadIgnoringCacheData); |
| 400 | 377 |
| 401 Frame* parent = m_frame->tree().parent(); | 378 Frame* parent = m_frame->tree().parent(); |
| 402 if (parent) { | 379 if (parent) { |
| 403 if (!parent->loader().mixedContentChecker()->canRunInsecureContent(paren t->document()->securityOrigin(), newRequest.url())) { | 380 if (!parent->loader().mixedContentChecker()->canRunInsecureContent(paren t->document()->securityOrigin(), newRequest.url())) { |
| 404 cancelMainResourceLoad(ResourceError::cancelledError(newRequest.url( ))); | 381 cancelMainResourceLoad(ResourceError::cancelledError(newRequest.url( ))); |
| 405 return; | 382 return; |
| 406 } | 383 } |
| 407 } | 384 } |
| 408 | 385 |
| 409 setRequest(newRequest); | 386 m_request = newRequest; |
| 410 | 387 |
| 411 if (redirectResponse.isNull()) | 388 if (redirectResponse.isNull()) |
| 412 return; | 389 return; |
| 413 | 390 |
| 414 appendRedirect(newRequest.url()); | 391 appendRedirect(newRequest.url()); |
| 415 frameLoader()->client()->dispatchDidReceiveServerRedirectForProvisionalLoad( ); | 392 frameLoader()->client()->dispatchDidReceiveServerRedirectForProvisionalLoad( ); |
| 416 if (!shouldContinueForNavigationPolicy(newRequest, PolicyCheckStandard)) | 393 if (!shouldContinueForNavigationPolicy(newRequest, PolicyCheckStandard)) |
| 417 cancelMainResourceLoad(ResourceError::cancelledError(m_request.url())); | 394 cancelMainResourceLoad(ResourceError::cancelledError(m_request.url())); |
| 418 } | 395 } |
| 419 | 396 |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 781 | 758 |
| 782 m_applicationCacheHost->willStartLoadingMainResource(m_request); | 759 m_applicationCacheHost->willStartLoadingMainResource(m_request); |
| 783 prepareSubframeArchiveLoadIfNeeded(); | 760 prepareSubframeArchiveLoadIfNeeded(); |
| 784 | 761 |
| 785 ResourceRequest request(m_request); | 762 ResourceRequest request(m_request); |
| 786 DEFINE_STATIC_LOCAL(ResourceLoaderOptions, mainResourceLoadOptions, | 763 DEFINE_STATIC_LOCAL(ResourceLoaderOptions, mainResourceLoadOptions, |
| 787 (SniffContent, DoNotBufferData, AllowStoredCredentials, ClientRequestedC redentials, AskClientForCrossOriginCredentials, SkipSecurityCheck, CheckContentS ecurityPolicy, DocumentContext)); | 764 (SniffContent, DoNotBufferData, AllowStoredCredentials, ClientRequestedC redentials, AskClientForCrossOriginCredentials, SkipSecurityCheck, CheckContentS ecurityPolicy, DocumentContext)); |
| 788 FetchRequest cachedResourceRequest(request, FetchInitiatorTypeNames::documen t, mainResourceLoadOptions); | 765 FetchRequest cachedResourceRequest(request, FetchInitiatorTypeNames::documen t, mainResourceLoadOptions); |
| 789 m_mainResource = m_fetcher->fetchMainResource(cachedResourceRequest, m_subst ituteData); | 766 m_mainResource = m_fetcher->fetchMainResource(cachedResourceRequest, m_subst ituteData); |
| 790 if (!m_mainResource) { | 767 if (!m_mainResource) { |
| 791 setRequest(ResourceRequest()); | 768 m_request = ResourceRequest(); |
| 792 // If the load was aborted by clearing m_request, it's possible the Appl icationCacheHost | 769 // If the load was aborted by clearing m_request, it's possible the Appl icationCacheHost |
| 793 // is now in a state where starting an empty load will be inconsistent. Replace it with | 770 // is now in a state where starting an empty load will be inconsistent. Replace it with |
| 794 // a new ApplicationCacheHost. | 771 // a new ApplicationCacheHost. |
| 795 m_applicationCacheHost = adoptPtr(new ApplicationCacheHost(this)); | 772 m_applicationCacheHost = adoptPtr(new ApplicationCacheHost(this)); |
| 796 maybeLoadEmpty(); | 773 maybeLoadEmpty(); |
| 797 return; | 774 return; |
| 798 } | 775 } |
| 799 m_mainResource->addClient(this); | 776 m_mainResource->addClient(this); |
| 800 | 777 |
| 801 // A bunch of headers are set when the underlying ResourceLoader is created, and m_request needs to include those. | 778 // A bunch of headers are set when the underlying ResourceLoader is created, and m_request needs to include those. |
| 802 if (mainResourceLoader()) | 779 if (mainResourceLoader()) |
| 803 request = mainResourceLoader()->originalRequest(); | 780 request = mainResourceLoader()->originalRequest(); |
| 804 // If there was a fragment identifier on m_request, the cache will have stri pped it. m_request should include | 781 // If there was a fragment identifier on m_request, the cache will have stri pped it. m_request should include |
| 805 // the fragment identifier, so add that back in. | 782 // the fragment identifier, so add that back in. |
| 806 if (equalIgnoringFragmentIdentifier(m_request.url(), request.url())) | 783 if (equalIgnoringFragmentIdentifier(m_request.url(), request.url())) |
| 807 request.setURL(m_request.url()); | 784 request.setURL(m_request.url()); |
| 808 setRequest(request); | 785 m_request = request; |
| 809 } | 786 } |
| 810 | 787 |
| 811 void DocumentLoader::cancelMainResourceLoad(const ResourceError& resourceError) | 788 void DocumentLoader::cancelMainResourceLoad(const ResourceError& resourceError) |
| 812 { | 789 { |
| 813 RefPtr<DocumentLoader> protect(this); | 790 RefPtr<DocumentLoader> protect(this); |
| 814 ResourceError error = resourceError.isNull() ? ResourceError::cancelledError (m_request.url()) : resourceError; | 791 ResourceError error = resourceError.isNull() ? ResourceError::cancelledError (m_request.url()) : resourceError; |
| 815 | 792 |
| 816 if (mainResourceLoader()) | 793 if (mainResourceLoader()) |
| 817 mainResourceLoader()->cancel(error); | 794 mainResourceLoader()->cancel(error); |
| 818 | 795 |
| 819 mainReceivedError(error); | 796 mainReceivedError(error); |
| 820 } | 797 } |
| 821 | 798 |
| 822 DocumentWriter* DocumentLoader::beginWriting(const AtomicString& mimeType, const AtomicString& encoding, const KURL& url) | |
| 823 { | |
| 824 m_writer = createWriterFor(m_frame, 0, url, mimeType, encoding, false, true) ; | |
| 825 return m_writer.get(); | |
| 826 } | |
| 827 | |
| 828 void DocumentLoader::endWriting(DocumentWriter* writer) | 799 void DocumentLoader::endWriting(DocumentWriter* writer) |
| 829 { | 800 { |
| 830 ASSERT_UNUSED(writer, m_writer == writer); | 801 ASSERT_UNUSED(writer, m_writer == writer); |
| 831 m_writer->end(); | 802 m_writer->end(); |
| 832 m_writer.clear(); | 803 m_writer.clear(); |
| 833 } | 804 } |
| 834 | 805 |
| 835 PassRefPtr<DocumentWriter> DocumentLoader::createWriterFor(Frame* frame, const D ocument* ownerDocument, const KURL& url, const AtomicString& mimeType, const Ato micString& encoding, bool userChosen, bool dispatch) | 806 PassRefPtr<DocumentWriter> DocumentLoader::createWriterFor(Frame* frame, const D ocument* ownerDocument, const KURL& url, const AtomicString& mimeType, const Ato micString& encoding, bool userChosen, bool dispatch) |
| 836 { | 807 { |
| 837 // Create a new document before clearing the frame, because it may need to | 808 // Create a new document before clearing the frame, because it may need to |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 888 void DocumentLoader::replaceDocument(const String& source, Document* ownerDocume nt) | 859 void DocumentLoader::replaceDocument(const String& source, Document* ownerDocume nt) |
| 889 { | 860 { |
| 890 m_frame->loader().stopAllLoaders(); | 861 m_frame->loader().stopAllLoaders(); |
| 891 m_writer = createWriterFor(m_frame, ownerDocument, m_frame->document()->url( ), mimeType(), m_writer ? m_writer->encoding() : emptyAtom, m_writer ? m_writer ->encodingWasChosenByUser() : false, true); | 862 m_writer = createWriterFor(m_frame, ownerDocument, m_frame->document()->url( ), mimeType(), m_writer ? m_writer->encoding() : emptyAtom, m_writer ? m_writer ->encodingWasChosenByUser() : false, true); |
| 892 if (!source.isNull()) | 863 if (!source.isNull()) |
| 893 m_writer->appendReplacingData(source); | 864 m_writer->appendReplacingData(source); |
| 894 endWriting(m_writer.get()); | 865 endWriting(m_writer.get()); |
| 895 } | 866 } |
| 896 | 867 |
| 897 } // namespace WebCore | 868 } // namespace WebCore |
| OLD | NEW |