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

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: Fix WebFrameTest.CallbackOrdering race 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.
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.
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 // The readystatechanged or load event may have disconnected this frame.
579 if (!m_frame->client())
580 return;
581
582 if (shouldSendFinishNotification(m_frame)) {
583 // Report mobile vs. desktop page statistics. This will only report on A ndroid.
584 if (m_frame->isMainFrame())
585 m_frame->document()->viewportDescription().reportMobilePageStats(m_f rame);
586 m_documentLoader->setSentDidFinishLoad();
587 client()->dispatchDidFinishLoad();
588 // Finishing the load can detach the frame when running layout tests.
589 if (!m_frame->client())
590 return;
591 }
592
593 if (shouldSendCompleteNotification(m_frame)) {
582 m_progressTracker->progressCompleted(); 594 m_progressTracker->progressCompleted();
583 // Retry restoring scroll offset since finishing loading disables conten t 595 // Retry restoring scroll offset since finishing loading disables conten t
584 // size clamping. 596 // size clamping.
585 restoreScrollPositionAndViewState(); 597 restoreScrollPositionAndViewState();
586 598
587 m_loadType = FrameLoadTypeStandard; 599 m_loadType = FrameLoadTypeStandard;
588 m_frame->localDOMWindow()->finishedLoading(); 600 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 } 601 }
595 602
596 Frame* parent = m_frame->tree().parent(); 603 Frame* parent = m_frame->tree().parent();
597 if (parent && parent->isLocalFrame()) 604 if (parent && parent->isLocalFrame())
598 toLocalFrame(parent)->loader().checkCompleted(); 605 toLocalFrame(parent)->loader().checkCompleted();
599 } 606 }
600 607
601 void FrameLoader::checkTimerFired(Timer<FrameLoader>*) 608 void FrameLoader::checkTimerFired(Timer<FrameLoader>*)
602 { 609 {
603 if (Page* page = m_frame->page()) { 610 if (Page* page = m_frame->page()) {
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
1217 if (loader == m_provisionalDocumentLoader) { 1224 if (loader == m_provisionalDocumentLoader) {
1218 client()->dispatchDidFailProvisionalLoad(error, historyCommitType); 1225 client()->dispatchDidFailProvisionalLoad(error, historyCommitType);
1219 if (loader != m_provisionalDocumentLoader) 1226 if (loader != m_provisionalDocumentLoader)
1220 return; 1227 return;
1221 detachDocumentLoader(m_provisionalDocumentLoader); 1228 detachDocumentLoader(m_provisionalDocumentLoader);
1222 m_progressTracker->progressCompleted(); 1229 m_progressTracker->progressCompleted();
1223 } else { 1230 } else {
1224 ASSERT(loader == m_documentLoader); 1231 ASSERT(loader == m_documentLoader);
1225 if (m_frame->document()->parser()) 1232 if (m_frame->document()->parser())
1226 m_frame->document()->parser()->stopParsing(); 1233 m_frame->document()->parser()->stopParsing();
1234 m_documentLoader->setSentDidFinishLoad();
1227 if (!m_provisionalDocumentLoader && m_frame->isLoading()) { 1235 if (!m_provisionalDocumentLoader && m_frame->isLoading()) {
1228 client()->dispatchDidFailLoad(error, historyCommitType); 1236 client()->dispatchDidFailLoad(error, historyCommitType);
1229 m_progressTracker->progressCompleted(); 1237 m_progressTracker->progressCompleted();
1230 } 1238 }
1231 } 1239 }
1232 checkCompleted(); 1240 checkCompleted();
1233 } 1241 }
1234 1242
1235 bool FrameLoader::shouldPerformFragmentNavigation(bool isFormSubmission, const S tring& httpMethod, FrameLoadType loadType, const KURL& url) 1243 bool FrameLoader::shouldPerformFragmentNavigation(bool isFormSubmission, const S tring& httpMethod, FrameLoadType loadType, const KURL& url)
1236 { 1244 {
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
1523 // FIXME: We need a way to propagate insecure requests policy flags to 1531 // FIXME: We need a way to propagate insecure requests policy flags to
1524 // out-of-process frames. For now, we'll always use default behavior. 1532 // out-of-process frames. For now, we'll always use default behavior.
1525 if (!parentFrame->isLocalFrame()) 1533 if (!parentFrame->isLocalFrame())
1526 return nullptr; 1534 return nullptr;
1527 1535
1528 ASSERT(toLocalFrame(parentFrame)->document()); 1536 ASSERT(toLocalFrame(parentFrame)->document());
1529 return toLocalFrame(parentFrame)->document()->insecureNavigationsToUpgrade() ; 1537 return toLocalFrame(parentFrame)->document()->insecureNavigationsToUpgrade() ;
1530 } 1538 }
1531 1539
1532 } // namespace blink 1540 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698