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

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

Issue 2563423004: Always send a fail or finish notification for each navigation. (Closed)
Patch Set: fix unit tests Created 4 years 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
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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 FrameLoader* DocumentLoader::frameLoader() const { 124 FrameLoader* DocumentLoader::frameLoader() const {
125 if (!m_frame) 125 if (!m_frame)
126 return nullptr; 126 return nullptr;
127 return &m_frame->loader(); 127 return &m_frame->loader();
128 } 128 }
129 129
130 DocumentLoader::~DocumentLoader() { 130 DocumentLoader::~DocumentLoader() {
131 DCHECK(!m_frame); 131 DCHECK(!m_frame);
132 DCHECK(!m_mainResource); 132 DCHECK(!m_mainResource);
133 DCHECK(!m_applicationCacheHost); 133 DCHECK(!m_applicationCacheHost);
134 DCHECK_EQ(m_state, SentDidFinishLoad);
134 } 135 }
135 136
136 DEFINE_TRACE(DocumentLoader) { 137 DEFINE_TRACE(DocumentLoader) {
137 visitor->trace(m_frame); 138 visitor->trace(m_frame);
138 visitor->trace(m_fetcher); 139 visitor->trace(m_fetcher);
139 visitor->trace(m_mainResource); 140 visitor->trace(m_mainResource);
140 visitor->trace(m_writer); 141 visitor->trace(m_writer);
141 visitor->trace(m_documentLoadTiming); 142 visitor->trace(m_documentLoadTiming);
142 visitor->trace(m_applicationCacheHost); 143 visitor->trace(m_applicationCacheHost);
143 visitor->trace(m_contentSecurityPolicy); 144 visitor->trace(m_contentSecurityPolicy);
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 DCHECK_EQ(m_mainResource, resource); 274 DCHECK_EQ(m_mainResource, resource);
274 DCHECK(m_mainResource); 275 DCHECK(m_mainResource);
275 276
276 if (!m_mainResource->errorOccurred() && !m_mainResource->wasCanceled()) { 277 if (!m_mainResource->errorOccurred() && !m_mainResource->wasCanceled()) {
277 finishedLoading(m_mainResource->loadFinishTime()); 278 finishedLoading(m_mainResource->loadFinishTime());
278 return; 279 return;
279 } 280 }
280 281
281 if (m_applicationCacheHost) 282 if (m_applicationCacheHost)
282 m_applicationCacheHost->failedLoadingMainResource(); 283 m_applicationCacheHost->failedLoadingMainResource();
283 m_state = MainResourceDone;
284 frameLoader()->loadFailed(this, m_mainResource->resourceError()); 284 frameLoader()->loadFailed(this, m_mainResource->resourceError());
285 clearMainResourceHandle(); 285 clearMainResourceHandle();
286 } 286 }
287 287
288 void DocumentLoader::finishedLoading(double finishTime) { 288 void DocumentLoader::finishedLoading(double finishTime) {
289 DCHECK(m_frame->loader().stateMachine()->creatingInitialEmptyDocument() || 289 DCHECK(m_frame->loader().stateMachine()->creatingInitialEmptyDocument() ||
290 !m_frame->page()->suspended() || 290 !m_frame->page()->suspended() ||
291 InspectorInstrumentation::isDebuggerPaused(m_frame)); 291 InspectorInstrumentation::isDebuggerPaused(m_frame));
292 292
293 double responseEndTime = finishTime; 293 double responseEndTime = finishTime;
(...skipping 13 matching lines...) Expand all
307 // the Document. 307 // the Document.
308 if (!m_writer) 308 if (!m_writer)
309 commitData(0, 0); 309 commitData(0, 0);
310 } 310 }
311 311
312 if (!m_frame) 312 if (!m_frame)
313 return; 313 return;
314 314
315 m_applicationCacheHost->finishedLoadingMainResource(); 315 m_applicationCacheHost->finishedLoadingMainResource();
316 endWriting(); 316 endWriting();
317 if (m_state < MainResourceDone)
318 m_state = MainResourceDone;
319 clearMainResourceHandle(); 317 clearMainResourceHandle();
320 } 318 }
321 319
322 bool DocumentLoader::redirectReceived( 320 bool DocumentLoader::redirectReceived(
323 Resource* resource, 321 Resource* resource,
324 const ResourceRequest& request, 322 const ResourceRequest& request,
325 const ResourceResponse& redirectResponse) { 323 const ResourceResponse& redirectResponse) {
326 DCHECK_EQ(resource, m_mainResource); 324 DCHECK_EQ(resource, m_mainResource);
327 DCHECK(!redirectResponse.isNull()); 325 DCHECK(!redirectResponse.isNull());
328 m_request = request; 326 m_request = request;
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 541
544 m_writer = createWriterFor(init, mimeType, encoding, false, parsingPolicy, 542 m_writer = createWriterFor(init, mimeType, encoding, false, parsingPolicy,
545 overridingURL); 543 overridingURL);
546 m_writer->setDocumentWasLoadedAsPartOfNavigation(); 544 m_writer->setDocumentWasLoadedAsPartOfNavigation();
547 m_frame->document()->maybeHandleHttpRefresh( 545 m_frame->document()->maybeHandleHttpRefresh(
548 m_response.httpHeaderField(HTTPNames::Refresh), 546 m_response.httpHeaderField(HTTPNames::Refresh),
549 Document::HttpRefreshFromHeader); 547 Document::HttpRefreshFromHeader);
550 } 548 }
551 549
552 void DocumentLoader::commitData(const char* bytes, size_t length) { 550 void DocumentLoader::commitData(const char* bytes, size_t length) {
553 DCHECK_LT(m_state, MainResourceDone); 551 DCHECK_EQ(m_state, Committed);
554 ensureWriter(m_response.mimeType()); 552 ensureWriter(m_response.mimeType());
555 553
556 // This can happen if document.close() is called by an event handler while 554 // This can happen if document.close() is called by an event handler while
557 // there's still pending incoming data. 555 // there's still pending incoming data.
558 if (m_frame && !m_frame->document()->parsing()) 556 if (m_frame && !m_frame->document()->parsing())
559 return; 557 return;
560 558
561 if (length) 559 if (length)
562 m_dataReceived = true; 560 m_dataReceived = true;
563 561
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 m_redirectChain.append(url); 623 m_redirectChain.append(url);
626 } 624 }
627 625
628 void DocumentLoader::detachFromFrame() { 626 void DocumentLoader::detachFromFrame() {
629 DCHECK(m_frame); 627 DCHECK(m_frame);
630 628
631 // It never makes sense to have a document loader that is detached from its 629 // It never makes sense to have a document loader that is detached from its
632 // frame have any loads active, so go ahead and kill all the loads. 630 // frame have any loads active, so go ahead and kill all the loads.
633 m_fetcher->stopFetching(); 631 m_fetcher->stopFetching();
634 632
633 if (frameLoader() && !sentDidFinishLoad())
634 frameLoader()->loadFailed(this, ResourceError::cancelledError(url()));
Nate Chapin 2016/12/12 21:40:37 This feels a little hacky, but it ensures we alway
gsennton 2016/12/13 13:59:55 I'm not sure I understand when we should receive a
635
635 // If that load cancellation triggered another detach, leave. 636 // If that load cancellation triggered another detach, leave.
636 // (fast/frames/detach-frame-nested-no-crash.html is an example of this.) 637 // (fast/frames/detach-frame-nested-no-crash.html is an example of this.)
637 if (!m_frame) 638 if (!m_frame)
638 return; 639 return;
639 640
640 m_fetcher->clearContext(); 641 m_fetcher->clearContext();
641 m_applicationCacheHost->detachFromDocumentLoader(); 642 m_applicationCacheHost->detachFromDocumentLoader();
642 m_applicationCacheHost.clear(); 643 m_applicationCacheHost.clear();
643 WeakIdentifierMap<DocumentLoader>::notifyObjectDestroyed(this); 644 WeakIdentifierMap<DocumentLoader>::notifyObjectDestroyed(this);
644 clearMainResourceHandle(); 645 clearMainResourceHandle();
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 m_writer ? m_writer->encoding() : emptyAtom, true, 802 m_writer ? m_writer->encoding() : emptyAtom, true,
802 ForceSynchronousParsing); 803 ForceSynchronousParsing);
803 if (!source.isNull()) 804 if (!source.isNull())
804 m_writer->appendReplacingData(source); 805 m_writer->appendReplacingData(source);
805 endWriting(); 806 endWriting();
806 } 807 }
807 808
808 DEFINE_WEAK_IDENTIFIER_MAP(DocumentLoader); 809 DEFINE_WEAK_IDENTIFIER_MAP(DocumentLoader);
809 810
810 } // namespace blink 811 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698