Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: Source/core/loader/DocumentLoader.cpp

Issue 120513004: Don't expose DocumentWriter to embedding layer (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/loader/DocumentLoader.h ('k') | Source/core/loader/SubstituteData.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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);
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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 if (((status >= 301 && status <= 303) || status == 307) 298 if (((status >= 301 && status <= 303) || status == 307)
318 && m_originalRequest.httpMethod() == "POST") 299 && m_originalRequest.httpMethod() == "POST")
319 return true; 300 return true;
320 301
321 return false; 302 return false;
322 } 303 }
323 304
324 bool DocumentLoader::shouldContinueForNavigationPolicy(const ResourceRequest& re quest, PolicyCheckLoadType policyCheckLoadType) 305 bool DocumentLoader::shouldContinueForNavigationPolicy(const ResourceRequest& re quest, PolicyCheckLoadType policyCheckLoadType)
325 { 306 {
326 // Don't ask if we are loading an empty URL. 307 // Don't ask if we are loading an empty URL.
327 if (request.url().isEmpty()) 308 if (request.url().isEmpty() || m_substituteData.isValid())
328 return true;
329
330 // We are always willing to show alternate content for unreachable URLs.
331 if (m_substituteData.isValid() && !m_substituteData.failingURL().isEmpty())
332 return true; 309 return true;
333 310
334 // If we're loading content into a subframe, check against the parent's Cont ent Security Policy 311 // If we're loading content into a subframe, check against the parent's Cont ent Security Policy
335 // and kill the load if that check fails. 312 // and kill the load if that check fails.
336 if (m_frame->ownerElement() && !m_frame->ownerElement()->document().contentS ecurityPolicy()->allowChildFrameFromSource(request.url())) 313 if (m_frame->ownerElement() && !m_frame->ownerElement()->document().contentS ecurityPolicy()->allowChildFrameFromSource(request.url()))
337 return false; 314 return false;
338 315
339 NavigationPolicy policy = m_triggeringAction.policy(); 316 NavigationPolicy policy = m_triggeringAction.policy();
340 if (policyCheckLoadType != PolicyCheckFragment) 317 if (policyCheckLoadType != PolicyCheckFragment)
341 policy = frameLoader()->client()->decidePolicyForNavigation(request, thi s, policy); 318 policy = frameLoader()->client()->decidePolicyForNavigation(request, thi s, policy);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 newRequest.setCachePolicy(ReloadIgnoringCacheData); 374 newRequest.setCachePolicy(ReloadIgnoringCacheData);
398 375
399 Frame* parent = m_frame->tree().parent(); 376 Frame* parent = m_frame->tree().parent();
400 if (parent) { 377 if (parent) {
401 if (!parent->loader().mixedContentChecker()->canRunInsecureContent(paren t->document()->securityOrigin(), newRequest.url())) { 378 if (!parent->loader().mixedContentChecker()->canRunInsecureContent(paren t->document()->securityOrigin(), newRequest.url())) {
402 cancelMainResourceLoad(ResourceError::cancelledError(newRequest.url( ))); 379 cancelMainResourceLoad(ResourceError::cancelledError(newRequest.url( )));
403 return; 380 return;
404 } 381 }
405 } 382 }
406 383
407 setRequest(newRequest); 384 m_request = newRequest;
408 385
409 if (redirectResponse.isNull()) 386 if (redirectResponse.isNull())
410 return; 387 return;
411 388
412 appendRedirect(newRequest.url()); 389 appendRedirect(newRequest.url());
413 frameLoader()->client()->dispatchDidReceiveServerRedirectForProvisionalLoad( ); 390 frameLoader()->client()->dispatchDidReceiveServerRedirectForProvisionalLoad( );
414 if (!shouldContinueForNavigationPolicy(newRequest, PolicyCheckStandard)) 391 if (!shouldContinueForNavigationPolicy(newRequest, PolicyCheckStandard))
415 cancelMainResourceLoad(ResourceError::cancelledError(m_request.url())); 392 cancelMainResourceLoad(ResourceError::cancelledError(m_request.url()));
416 } 393 }
417 394
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 765
789 m_applicationCacheHost->willStartLoadingMainResource(m_request); 766 m_applicationCacheHost->willStartLoadingMainResource(m_request);
790 prepareSubframeArchiveLoadIfNeeded(); 767 prepareSubframeArchiveLoadIfNeeded();
791 768
792 ResourceRequest request(m_request); 769 ResourceRequest request(m_request);
793 DEFINE_STATIC_LOCAL(ResourceLoaderOptions, mainResourceLoadOptions, 770 DEFINE_STATIC_LOCAL(ResourceLoaderOptions, mainResourceLoadOptions,
794 (SniffContent, DoNotBufferData, AllowStoredCredentials, ClientRequestedC redentials, AskClientForCrossOriginCredentials, SkipSecurityCheck, CheckContentS ecurityPolicy, DocumentContext)); 771 (SniffContent, DoNotBufferData, AllowStoredCredentials, ClientRequestedC redentials, AskClientForCrossOriginCredentials, SkipSecurityCheck, CheckContentS ecurityPolicy, DocumentContext));
795 FetchRequest cachedResourceRequest(request, FetchInitiatorTypeNames::documen t, mainResourceLoadOptions); 772 FetchRequest cachedResourceRequest(request, FetchInitiatorTypeNames::documen t, mainResourceLoadOptions);
796 m_mainResource = m_fetcher->fetchMainResource(cachedResourceRequest, m_subst ituteData); 773 m_mainResource = m_fetcher->fetchMainResource(cachedResourceRequest, m_subst ituteData);
797 if (!m_mainResource) { 774 if (!m_mainResource) {
798 setRequest(ResourceRequest()); 775 m_request = ResourceRequest();
799 // If the load was aborted by clearing m_request, it's possible the Appl icationCacheHost 776 // If the load was aborted by clearing m_request, it's possible the Appl icationCacheHost
800 // is now in a state where starting an empty load will be inconsistent. Replace it with 777 // is now in a state where starting an empty load will be inconsistent. Replace it with
801 // a new ApplicationCacheHost. 778 // a new ApplicationCacheHost.
802 m_applicationCacheHost = adoptPtr(new ApplicationCacheHost(this)); 779 m_applicationCacheHost = adoptPtr(new ApplicationCacheHost(this));
803 maybeLoadEmpty(); 780 maybeLoadEmpty();
804 return; 781 return;
805 } 782 }
806 m_mainResource->addClient(this); 783 m_mainResource->addClient(this);
807 784
808 // A bunch of headers are set when the underlying ResourceLoader is created, and m_request needs to include those. 785 // A bunch of headers are set when the underlying ResourceLoader is created, and m_request needs to include those.
809 if (mainResourceLoader()) 786 if (mainResourceLoader())
810 request = mainResourceLoader()->originalRequest(); 787 request = mainResourceLoader()->originalRequest();
811 // If there was a fragment identifier on m_request, the cache will have stri pped it. m_request should include 788 // If there was a fragment identifier on m_request, the cache will have stri pped it. m_request should include
812 // the fragment identifier, so add that back in. 789 // the fragment identifier, so add that back in.
813 if (equalIgnoringFragmentIdentifier(m_request.url(), request.url())) 790 if (equalIgnoringFragmentIdentifier(m_request.url(), request.url()))
814 request.setURL(m_request.url()); 791 request.setURL(m_request.url());
815 setRequest(request); 792 m_request = request;
816 } 793 }
817 794
818 void DocumentLoader::cancelMainResourceLoad(const ResourceError& resourceError) 795 void DocumentLoader::cancelMainResourceLoad(const ResourceError& resourceError)
819 { 796 {
820 RefPtr<DocumentLoader> protect(this); 797 RefPtr<DocumentLoader> protect(this);
821 ResourceError error = resourceError.isNull() ? ResourceError::cancelledError (m_request.url()) : resourceError; 798 ResourceError error = resourceError.isNull() ? ResourceError::cancelledError (m_request.url()) : resourceError;
822 799
823 if (mainResourceLoader()) 800 if (mainResourceLoader())
824 mainResourceLoader()->cancel(error); 801 mainResourceLoader()->cancel(error);
825 802
826 mainReceivedError(error); 803 mainReceivedError(error);
827 } 804 }
828 805
829 DocumentWriter* DocumentLoader::beginWriting(const AtomicString& mimeType, const AtomicString& encoding, const KURL& url)
830 {
831 m_writer = createWriterFor(m_frame, 0, url, mimeType, encoding, false, true) ;
832 return m_writer.get();
833 }
834
835 void DocumentLoader::endWriting(DocumentWriter* writer) 806 void DocumentLoader::endWriting(DocumentWriter* writer)
836 { 807 {
837 ASSERT_UNUSED(writer, m_writer == writer); 808 ASSERT_UNUSED(writer, m_writer == writer);
838 m_writer->end(); 809 m_writer->end();
839 m_writer.clear(); 810 m_writer.clear();
840 } 811 }
841 812
842 PassRefPtr<DocumentWriter> DocumentLoader::createWriterFor(Frame* frame, const D ocument* ownerDocument, const KURL& url, const AtomicString& mimeType, const Ato micString& encoding, bool userChosen, bool dispatch) 813 PassRefPtr<DocumentWriter> DocumentLoader::createWriterFor(Frame* frame, const D ocument* ownerDocument, const KURL& url, const AtomicString& mimeType, const Ato micString& encoding, bool userChosen, bool dispatch)
843 { 814 {
844 // Create a new document before clearing the frame, because it may need to 815 // 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
895 void DocumentLoader::replaceDocument(const String& source, Document* ownerDocume nt) 866 void DocumentLoader::replaceDocument(const String& source, Document* ownerDocume nt)
896 { 867 {
897 m_frame->loader().stopAllLoaders(); 868 m_frame->loader().stopAllLoaders();
898 m_writer = createWriterFor(m_frame, ownerDocument, m_frame->document()->url( ), mimeType(), m_writer ? m_writer->encoding() : emptyAtom, m_writer ? m_writer ->encodingWasChosenByUser() : false, true); 869 m_writer = createWriterFor(m_frame, ownerDocument, m_frame->document()->url( ), mimeType(), m_writer ? m_writer->encoding() : emptyAtom, m_writer ? m_writer ->encodingWasChosenByUser() : false, true);
899 if (!source.isNull()) 870 if (!source.isNull())
900 m_writer->appendReplacingData(source); 871 m_writer->appendReplacingData(source);
901 endWriting(m_writer.get()); 872 endWriting(m_writer.get());
902 } 873 }
903 874
904 } // namespace WebCore 875 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/loader/DocumentLoader.h ('k') | Source/core/loader/SubstituteData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698