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

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

Issue 1229263003: Add an empty boolean to WebFrameClient::didFinishDocumentLoad (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: empty -> documentIsEmpty Created 5 years, 5 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/EmptyClients.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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 { 80 {
81 return equalIgnoringCase("multipart/related", mimeType); 81 return equalIgnoringCase("multipart/related", mimeType);
82 } 82 }
83 83
84 DocumentLoader::DocumentLoader(LocalFrame* frame, const ResourceRequest& req, co nst SubstituteData& substituteData) 84 DocumentLoader::DocumentLoader(LocalFrame* frame, const ResourceRequest& req, co nst SubstituteData& substituteData)
85 : m_frame(frame) 85 : m_frame(frame)
86 , m_fetcher(FrameFetchContext::createContextAndFetcher(this)) 86 , m_fetcher(FrameFetchContext::createContextAndFetcher(this))
87 , m_originalRequest(req) 87 , m_originalRequest(req)
88 , m_substituteData(substituteData) 88 , m_substituteData(substituteData)
89 , m_request(req) 89 , m_request(req)
90 , m_committed(false)
91 , m_isClientRedirect(false) 90 , m_isClientRedirect(false)
92 , m_replacesCurrentHistoryItem(false) 91 , m_replacesCurrentHistoryItem(false)
93 , m_navigationType(NavigationTypeOther) 92 , m_navigationType(NavigationTypeOther)
94 , m_loadingMainResource(false)
95 , m_timeOfLastDataReceived(0.0) 93 , m_timeOfLastDataReceived(0.0)
96 , m_applicationCacheHost(ApplicationCacheHost::create(this)) 94 , m_applicationCacheHost(ApplicationCacheHost::create(this))
95 , m_state(NotStarted)
97 { 96 {
98 } 97 }
99 98
100 FrameLoader* DocumentLoader::frameLoader() const 99 FrameLoader* DocumentLoader::frameLoader() const
101 { 100 {
102 if (!m_frame) 101 if (!m_frame)
103 return nullptr; 102 return nullptr;
104 return &m_frame->loader(); 103 return &m_frame->loader();
105 } 104 }
106 105
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 197
199 void DocumentLoader::mainReceivedError(const ResourceError& error) 198 void DocumentLoader::mainReceivedError(const ResourceError& error)
200 { 199 {
201 ASSERT(!error.isNull()); 200 ASSERT(!error.isNull());
202 ASSERT(!mainResourceLoader() || !mainResourceLoader()->defersLoading() || In spectorInstrumentation::isDebuggerPaused(m_frame)); 201 ASSERT(!mainResourceLoader() || !mainResourceLoader()->defersLoading() || In spectorInstrumentation::isDebuggerPaused(m_frame));
203 if (m_applicationCacheHost) 202 if (m_applicationCacheHost)
204 m_applicationCacheHost->failedLoadingMainResource(); 203 m_applicationCacheHost->failedLoadingMainResource();
205 if (!frameLoader()) 204 if (!frameLoader())
206 return; 205 return;
207 m_mainDocumentError = error; 206 m_mainDocumentError = error;
208 clearMainResourceLoader(); 207 m_state = MainResourceDone;
209 frameLoader()->receivedMainResourceError(this, error); 208 frameLoader()->receivedMainResourceError(this, error);
210 clearMainResourceHandle(); 209 clearMainResourceHandle();
211 } 210 }
212 211
213 // Cancels the data source's pending loads. Conceptually, a data source only lo ads 212 // Cancels the data source's pending loads. Conceptually, a data source only lo ads
214 // one document at a time, but one document may have many related resources. 213 // one document at a time, but one document may have many related resources.
215 // stopLoading will stop all loads initiated by the data source, 214 // stopLoading will stop all loads initiated by the data source,
216 // but not loads initiated by child frames' data sources -- that's the WebFrame' s job. 215 // but not loads initiated by child frames' data sources -- that's the WebFrame' s job.
217 void DocumentLoader::stopLoading() 216 void DocumentLoader::stopLoading()
218 { 217 {
219 RefPtrWillBeRawPtr<LocalFrame> protectFrame(m_frame.get()); 218 RefPtrWillBeRawPtr<LocalFrame> protectFrame(m_frame.get());
220 RefPtrWillBeRawPtr<DocumentLoader> protectLoader(this); 219 RefPtrWillBeRawPtr<DocumentLoader> protectLoader(this);
221 220
222 if (isLoading()) 221 if (isLoading())
223 cancelMainResourceLoad(ResourceError::cancelledError(m_request.url())); 222 cancelMainResourceLoad(ResourceError::cancelledError(m_request.url()));
224 m_fetcher->stopFetching(); 223 m_fetcher->stopFetching();
225 } 224 }
226 225
227 void DocumentLoader::commitIfReady() 226 void DocumentLoader::commitIfReady()
228 { 227 {
229 if (!m_committed) { 228 if (m_state < Committed) {
230 m_committed = true; 229 m_state = Committed;
231 frameLoader()->commitProvisionalLoad(); 230 frameLoader()->commitProvisionalLoad();
232 } 231 }
233 } 232 }
234 233
235 bool DocumentLoader::isLoading() const 234 bool DocumentLoader::isLoading() const
236 { 235 {
237 if (document() && document()->hasActiveParser()) 236 if (document() && document()->hasActiveParser())
238 return true; 237 return true;
239 238
240 return m_loadingMainResource || m_fetcher->isFetching(); 239 return (m_state > NotStarted && m_state < MainResourceDone) || m_fetcher->is Fetching();
241 } 240 }
242 241
243 void DocumentLoader::notifyFinished(Resource* resource) 242 void DocumentLoader::notifyFinished(Resource* resource)
244 { 243 {
245 ASSERT_UNUSED(resource, m_mainResource == resource); 244 ASSERT_UNUSED(resource, m_mainResource == resource);
246 ASSERT(m_mainResource); 245 ASSERT(m_mainResource);
247 246
248 RefPtrWillBeRawPtr<DocumentLoader> protect(this); 247 RefPtrWillBeRawPtr<DocumentLoader> protect(this);
249 248
250 if (!m_mainResource->errorOccurred() && !m_mainResource->wasCanceled()) { 249 if (!m_mainResource->errorOccurred() && !m_mainResource->wasCanceled()) {
(...skipping 25 matching lines...) Expand all
276 // If this is an empty document, it will not have actually been created yet. Commit dummy data so that 275 // If this is an empty document, it will not have actually been created yet. Commit dummy data so that
277 // DocumentWriter::begin() gets called and creates the Document. 276 // DocumentWriter::begin() gets called and creates the Document.
278 if (!m_writer) 277 if (!m_writer)
279 commitData(0, 0); 278 commitData(0, 0);
280 } 279 }
281 280
282 endWriting(m_writer.get()); 281 endWriting(m_writer.get());
283 282
284 if (!m_mainDocumentError.isNull()) 283 if (!m_mainDocumentError.isNull())
285 return; 284 return;
286 clearMainResourceLoader(); 285 m_state = MainResourceDone;
287 286
288 // If the document specified an application cache manifest, it violates the author's intent if we store it in the memory cache 287 // If the document specified an application cache manifest, it violates the author's intent if we store it in the memory cache
289 // and deny the appcache the chance to intercept it in the future, so remove from the memory cache. 288 // and deny the appcache the chance to intercept it in the future, so remove from the memory cache.
290 if (m_frame) { 289 if (m_frame) {
291 if (m_mainResource && m_frame->document()->hasAppCacheManifest()) 290 if (m_mainResource && m_frame->document()->hasAppCacheManifest())
292 memoryCache()->remove(m_mainResource.get()); 291 memoryCache()->remove(m_mainResource.get());
293 } 292 }
294 m_applicationCacheHost->finishedLoadingMainResource(); 293 m_applicationCacheHost->finishedLoadingMainResource();
295 clearMainResourceHandle(); 294 clearMainResourceHandle();
296 } 295 }
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 if (!overridingURL.isEmpty()) 522 if (!overridingURL.isEmpty())
524 m_frame->document()->setBaseURLOverride(overridingURL); 523 m_frame->document()->setBaseURLOverride(overridingURL);
525 524
526 // Call receivedFirstData() exactly once per load. 525 // Call receivedFirstData() exactly once per load.
527 frameLoader()->receivedFirstData(); 526 frameLoader()->receivedFirstData();
528 m_frame->document()->maybeHandleHttpRefresh(m_response.httpHeaderField("Refr esh"), Document::HttpRefreshFromHeader); 527 m_frame->document()->maybeHandleHttpRefresh(m_response.httpHeaderField("Refr esh"), Document::HttpRefreshFromHeader);
529 } 528 }
530 529
531 void DocumentLoader::commitData(const char* bytes, size_t length) 530 void DocumentLoader::commitData(const char* bytes, size_t length)
532 { 531 {
532 ASSERT(m_state < MainResourceDone);
533 ensureWriter(m_response.mimeType()); 533 ensureWriter(m_response.mimeType());
534 534
535 // This can happen if document.close() is called by an event handler while 535 // This can happen if document.close() is called by an event handler while
536 // there's still pending incoming data. 536 // there's still pending incoming data.
537 if (m_frame && !m_frame->document()->parsing()) { 537 if (m_frame && !m_frame->document()->parsing()) {
538 cancelMainResourceLoad(ResourceError::cancelledError(m_request.url())); 538 cancelMainResourceLoad(ResourceError::cancelledError(m_request.url()));
539 return; 539 return;
540 } 540 }
541 541
542 if (length)
543 m_state = DataReceived;
544
542 m_writer->addData(bytes, length); 545 m_writer->addData(bytes, length);
543 } 546 }
544 547
545 void DocumentLoader::dataReceived(Resource* resource, const char* data, unsigned length) 548 void DocumentLoader::dataReceived(Resource* resource, const char* data, unsigned length)
546 { 549 {
547 ASSERT(data); 550 ASSERT(data);
548 ASSERT(length); 551 ASSERT(length);
549 ASSERT_UNUSED(resource, resource == m_mainResource); 552 ASSERT_UNUSED(resource, resource == m_mainResource);
550 ASSERT(!m_response.isNull()); 553 ASSERT(!m_response.isNull());
551 ASSERT(!mainResourceLoader() || !mainResourceLoader()->defersLoading()); 554 ASSERT(!mainResourceLoader() || !mainResourceLoader()->defersLoading());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 606
604 m_fetcher->clearContext(); 607 m_fetcher->clearContext();
605 608
606 m_applicationCacheHost->detachFromDocumentLoader(); 609 m_applicationCacheHost->detachFromDocumentLoader();
607 m_applicationCacheHost.clear(); 610 m_applicationCacheHost.clear();
608 WeakIdentifierMap<DocumentLoader>::notifyObjectDestroyed(this); 611 WeakIdentifierMap<DocumentLoader>::notifyObjectDestroyed(this);
609 clearMainResourceHandle(); 612 clearMainResourceHandle();
610 m_frame = nullptr; 613 m_frame = nullptr;
611 } 614 }
612 615
613 void DocumentLoader::clearMainResourceLoader()
614 {
615 m_loadingMainResource = false;
616 }
617
618 void DocumentLoader::clearMainResourceHandle() 616 void DocumentLoader::clearMainResourceHandle()
619 { 617 {
620 if (!m_mainResource) 618 if (!m_mainResource)
621 return; 619 return;
622 m_mainResource->removeClient(this); 620 m_mainResource->removeClient(this);
623 m_mainResource = nullptr; 621 m_mainResource = nullptr;
624 } 622 }
625 623
626 bool DocumentLoader::maybeCreateArchive() 624 bool DocumentLoader::maybeCreateArchive()
627 { 625 {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 finishedLoading(monotonicallyIncreasingTime()); 705 finishedLoading(monotonicallyIncreasingTime());
708 return true; 706 return true;
709 } 707 }
710 708
711 void DocumentLoader::startLoadingMainResource() 709 void DocumentLoader::startLoadingMainResource()
712 { 710 {
713 RefPtrWillBeRawPtr<DocumentLoader> protect(this); 711 RefPtrWillBeRawPtr<DocumentLoader> protect(this);
714 m_mainDocumentError = ResourceError(); 712 m_mainDocumentError = ResourceError();
715 timing().markNavigationStart(); 713 timing().markNavigationStart();
716 ASSERT(!m_mainResource); 714 ASSERT(!m_mainResource);
717 ASSERT(!m_loadingMainResource); 715 ASSERT(m_state == NotStarted);
718 m_loadingMainResource = true; 716 m_state = Provisional;
719 717
720 if (maybeLoadEmpty()) 718 if (maybeLoadEmpty())
721 return; 719 return;
722 720
723 ASSERT(timing().navigationStart()); 721 ASSERT(timing().navigationStart());
724 ASSERT(!timing().fetchStart()); 722 ASSERT(!timing().fetchStart());
725 timing().markFetchStart(); 723 timing().markFetchStart();
726 willSendRequest(m_request, ResourceResponse()); 724 willSendRequest(m_request, ResourceResponse());
727 725
728 // willSendRequest() may lead to our LocalFrame being detached or cancelling the load via nulling the ResourceRequest. 726 // willSendRequest() may lead to our LocalFrame being detached or cancelling the load via nulling the ResourceRequest.
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 { 820 {
823 m_writer = createWriterFor(ownerDocument, init, mimeType(), m_writer ? m_wri ter->encoding() : emptyAtom, true, ForceSynchronousParsing); 821 m_writer = createWriterFor(ownerDocument, init, mimeType(), m_writer ? m_wri ter->encoding() : emptyAtom, true, ForceSynchronousParsing);
824 if (!source.isNull()) 822 if (!source.isNull())
825 m_writer->appendReplacingData(source); 823 m_writer->appendReplacingData(source);
826 endWriting(m_writer.get()); 824 endWriting(m_writer.get());
827 } 825 }
828 826
829 DEFINE_WEAK_IDENTIFIER_MAP(DocumentLoader); 827 DEFINE_WEAK_IDENTIFIER_MAP(DocumentLoader);
830 828
831 } // namespace blink 829 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/loader/DocumentLoader.h ('k') | Source/core/loader/EmptyClients.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698