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

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

Issue 1381003004: Better distinguish didFinishLoad and didStopLoading (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed. 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed.
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
4 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 4 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
5 * Copyright (C) 2008 Alp Toker <alp@atoker.com> 5 * Copyright (C) 2008 Alp Toker <alp@atoker.com>
6 * Copyright (C) Research In Motion Limited 2009. All rights reserved. 6 * Copyright (C) Research In Motion Limited 2009. All rights reserved.
7 * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com> 7 * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com>
8 * Copyright (C) 2011 Google Inc. All rights reserved. 8 * Copyright (C) 2011 Google Inc. All rights reserved.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 return false; 522 return false;
523 if (!document->haveImportsLoaded()) 523 if (!document->haveImportsLoaded())
524 return false; 524 return false;
525 if (document->fetcher()->requestCount()) 525 if (document->fetcher()->requestCount())
526 return false; 526 return false;
527 if (document->isDelayingLoadEvent()) 527 if (document->isDelayingLoadEvent())
528 return false; 528 return false;
529 return allDescendantsAreComplete(document->frame()); 529 return allDescendantsAreComplete(document->frame());
530 } 530 }
531 531
532 static bool shouldSendCompleteNotifications(LocalFrame* frame) 532 static bool shouldSendFinishNotification(LocalFrame* frame)
533 { 533 {
534 // Don't send stop notifications for inital empty documents, since they don' t generate start notifications. 534 // Don't send stop notifications for inital empty documents, since they don' t generate start notifications.
535 if (!frame->loader().stateMachine()->committedFirstRealDocumentLoad()) 535 if (!frame->loader().stateMachine()->committedFirstRealDocumentLoad())
536 return false; 536 return false;
537 537
538 // FIXME: We might have already sent stop notifications and be re-completing . 538 // Don't send didFinishLoad more than once per DocumentLoader.
539 if (!frame->isLoading()) 539 if (frame->loader().documentLoader()->sentDidFinishLoad())
540 return false;
541
542 // The readystatechanged or load event may have disconnected this frame.
dcheng 2015/10/08 05:34:35 Move this comment to 578 in the new file.
Nate Chapin 2015/10/08 21:03:59 Done.
543 if (!frame->client())
544 return false;
545
546 // An event might have restarted a child frame.
547 if (!allDescendantsAreComplete(frame))
548 return false;
549
550 // An event might have restarted this frame by scheduling a new navigation.
551 if (frame->loader().provisionalDocumentLoader())
552 return false;
553
554 // A navigation is still scheduled in the embedder, so don't complete yet.
555 if (frame->loader().client()->hasPendingNavigation())
556 return false; 540 return false;
557 541
558 // We might have declined to run the load event due to an imminent content-i nitiated navigation. 542 // We might have declined to run the load event due to an imminent content-i nitiated navigation.
dcheng 2015/10/08 05:37:40 This is probably a dumb question... content-initia
Nate Chapin 2015/10/08 21:03:59 In this case, it means blink. I think it's the sam
559 if (!frame->document()->loadEventFinished()) 543 if (!frame->document()->loadEventFinished())
560 return false; 544 return false;
561 545
546 // An event might have restarted a child frame.
547 if (!allDescendantsAreComplete(frame))
548 return false;
562 return true; 549 return true;
563 } 550 }
564 551
552 static bool shouldSendCompleteNotification(LocalFrame* frame)
553 {
554 // FIXME: We might have already sent stop notifications and be re-completing .
555 if (!frame->isLoading())
556 return false;
557 // Only send didStopLoading() if there are no navigations in progress at all ,
558 // whether committed, provisional, or pending.
559 return frame->loader().documentLoader()->sentDidFinishLoad() && !frame->load er().provisionalDocumentLoader() && !frame->loader().client()->hasPendingNavigat ion();
560 }
561
565 void FrameLoader::checkCompleted() 562 void FrameLoader::checkCompleted()
566 { 563 {
567 RefPtrWillBeRawPtr<LocalFrame> protect(m_frame.get()); 564 RefPtrWillBeRawPtr<LocalFrame> protect(m_frame.get());
568 if (!shouldComplete(m_frame->document())) 565 if (!shouldComplete(m_frame->document()))
569 return; 566 return;
570 567
571 // OK, completed. 568 // OK, completed.
572 m_frame->document()->setReadyState(Document::Complete); 569 m_frame->document()->setReadyState(Document::Complete);
573 if (m_frame->document()->loadEventStillNeeded()) 570 if (m_frame->document()->loadEventStillNeeded())
574 m_frame->document()->implicitClose(); 571 m_frame->document()->implicitClose();
575 572
576 m_frame->navigationScheduler().startTimer(); 573 m_frame->navigationScheduler().startTimer();
577 574
578 if (m_frame->view()) 575 if (m_frame->view())
579 m_frame->view()->handleLoadCompleted(); 576 m_frame->view()->handleLoadCompleted();
580 577
581 if (shouldSendCompleteNotifications(m_frame)) { 578 if (!m_frame->client())
579 return;
580
581 if (shouldSendFinishNotification(m_frame)) {
582 // Report mobile vs. desktop page statistics. This will only report on A ndroid.
583 if (m_frame->isMainFrame())
584 m_frame->document()->viewportDescription().reportMobilePageStats(m_f rame);
585 m_documentLoader->setSentDidFinishLoad();
586 client()->dispatchDidFinishLoad();
587 // Finishing the load can detach the frame when running layout tests.
dcheng 2015/10/08 05:34:35 Can we fix this, maybe in a followup patch? This i
Nate Chapin 2015/10/08 21:03:59 I think the craziness is tearing down the test. I
dcheng 2015/10/09 18:34:01 Yeah, I think it'd make sense to do it async... wh
Nate Chapin 2015/10/09 18:39:44 Agreed.
588 if (!m_frame->client())
589 return;
590 }
591
592 if (shouldSendCompleteNotification(m_frame)) {
582 m_progressTracker->progressCompleted(); 593 m_progressTracker->progressCompleted();
583 // Retry restoring scroll offset since finishing loading disables conten t 594 // Retry restoring scroll offset since finishing loading disables conten t
584 // size clamping. 595 // size clamping.
585 restoreScrollPositionAndViewState(); 596 restoreScrollPositionAndViewState();
586 597
587 m_loadType = FrameLoadTypeStandard; 598 m_loadType = FrameLoadTypeStandard;
588 m_frame->localDOMWindow()->finishedLoading(); 599 m_frame->localDOMWindow()->finishedLoading();
589
590 // Report mobile vs. desktop page statistics. This will only report on A ndroid.
591 if (m_frame->isMainFrame())
592 m_frame->document()->viewportDescription().reportMobilePageStats(m_f rame);
593 client()->dispatchDidFinishLoad();
594 } 600 }
595 601
596 Frame* parent = m_frame->tree().parent(); 602 Frame* parent = m_frame->tree().parent();
597 if (parent && parent->isLocalFrame()) 603 if (parent && parent->isLocalFrame())
598 toLocalFrame(parent)->loader().checkCompleted(); 604 toLocalFrame(parent)->loader().checkCompleted();
599 } 605 }
600 606
601 void FrameLoader::checkTimerFired(Timer<FrameLoader>*) 607 void FrameLoader::checkTimerFired(Timer<FrameLoader>*)
602 { 608 {
603 if (Page* page = m_frame->page()) { 609 if (Page* page = m_frame->page()) {
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 if (loader == m_provisionalDocumentLoader) { 1222 if (loader == m_provisionalDocumentLoader) {
1217 client()->dispatchDidFailProvisionalLoad(error, historyCommitType); 1223 client()->dispatchDidFailProvisionalLoad(error, historyCommitType);
1218 if (loader != m_provisionalDocumentLoader) 1224 if (loader != m_provisionalDocumentLoader)
1219 return; 1225 return;
1220 detachDocumentLoader(m_provisionalDocumentLoader); 1226 detachDocumentLoader(m_provisionalDocumentLoader);
1221 m_progressTracker->progressCompleted(); 1227 m_progressTracker->progressCompleted();
1222 } else { 1228 } else {
1223 ASSERT(loader == m_documentLoader); 1229 ASSERT(loader == m_documentLoader);
1224 if (m_frame->document()->parser()) 1230 if (m_frame->document()->parser())
1225 m_frame->document()->parser()->stopParsing(); 1231 m_frame->document()->parser()->stopParsing();
1232 m_documentLoader->setSentDidFinishLoad();
1226 if (!m_provisionalDocumentLoader && m_frame->isLoading()) { 1233 if (!m_provisionalDocumentLoader && m_frame->isLoading()) {
1227 client()->dispatchDidFailLoad(error, historyCommitType); 1234 client()->dispatchDidFailLoad(error, historyCommitType);
1228 m_progressTracker->progressCompleted(); 1235 m_progressTracker->progressCompleted();
1229 } 1236 }
1230 } 1237 }
1231 checkCompleted(); 1238 checkCompleted();
1232 } 1239 }
1233 1240
1234 bool FrameLoader::shouldPerformFragmentNavigation(bool isFormSubmission, const S tring& httpMethod, FrameLoadType loadType, const KURL& url) 1241 bool FrameLoader::shouldPerformFragmentNavigation(bool isFormSubmission, const S tring& httpMethod, FrameLoadType loadType, const KURL& url)
1235 { 1242 {
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
1522 // FIXME: We need a way to propagate insecure requests policy flags to 1529 // FIXME: We need a way to propagate insecure requests policy flags to
1523 // out-of-process frames. For now, we'll always use default behavior. 1530 // out-of-process frames. For now, we'll always use default behavior.
1524 if (!parentFrame->isLocalFrame()) 1531 if (!parentFrame->isLocalFrame())
1525 return nullptr; 1532 return nullptr;
1526 1533
1527 ASSERT(toLocalFrame(parentFrame)->document()); 1534 ASSERT(toLocalFrame(parentFrame)->document());
1528 return toLocalFrame(parentFrame)->document()->insecureNavigationsToUpgrade() ; 1535 return toLocalFrame(parentFrame)->document()->insecureNavigationsToUpgrade() ;
1529 } 1536 }
1530 1537
1531 } // namespace blink 1538 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698