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

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, 1 month 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 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 return false; 518 return false;
519 if (!document->haveImportsLoaded()) 519 if (!document->haveImportsLoaded())
520 return false; 520 return false;
521 if (document->fetcher()->requestCount()) 521 if (document->fetcher()->requestCount())
522 return false; 522 return false;
523 if (document->isDelayingLoadEvent()) 523 if (document->isDelayingLoadEvent())
524 return false; 524 return false;
525 return allDescendantsAreComplete(document->frame()); 525 return allDescendantsAreComplete(document->frame());
526 } 526 }
527 527
528 static bool shouldSendCompleteNotifications(LocalFrame* frame) 528 static bool shouldSendFinishNotification(LocalFrame* frame)
529 { 529 {
530 // Don't send stop notifications for inital empty documents, since they don' t generate start notifications. 530 // Don't send stop notifications for inital empty documents, since they don' t generate start notifications.
531 if (!frame->loader().stateMachine()->committedFirstRealDocumentLoad()) 531 if (!frame->loader().stateMachine()->committedFirstRealDocumentLoad())
532 return false; 532 return false;
533 533
534 // FIXME: We might have already sent stop notifications and be re-completing . 534 // Don't send didFinishLoad more than once per DocumentLoader.
535 if (!frame->isLoading()) 535 if (frame->loader().documentLoader()->sentDidFinishLoad())
536 return false;
537
538 // The readystatechanged or load event may have disconnected this frame.
539 if (!frame->client())
540 return false;
541
542 // An event might have restarted a child frame.
543 if (!allDescendantsAreComplete(frame))
544 return false;
545
546 // An event might have restarted this frame by scheduling a new navigation.
547 if (frame->loader().provisionalDocumentLoader())
548 return false;
549
550 // A navigation is still scheduled in the embedder, so don't complete yet.
551 if (frame->loader().client()->hasPendingNavigation())
552 return false; 536 return false;
553 537
554 // We might have declined to run the load event due to an imminent content-i nitiated navigation. 538 // We might have declined to run the load event due to an imminent content-i nitiated navigation.
555 if (!frame->document()->loadEventFinished()) 539 if (!frame->document()->loadEventFinished())
556 return false; 540 return false;
557 541
542 // An event might have restarted a child frame.
543 if (!allDescendantsAreComplete(frame))
544 return false;
558 return true; 545 return true;
559 } 546 }
560 547
548 static bool shouldSendCompleteNotification(LocalFrame* frame)
549 {
550 // FIXME: We might have already sent stop notifications and be re-completing .
551 if (!frame->isLoading())
552 return false;
553 // Only send didStopLoading() if there are no navigations in progress at all ,
554 // whether committed, provisional, or pending.
555 return frame->loader().documentLoader()->sentDidFinishLoad() && !frame->load er().provisionalDocumentLoader() && !frame->loader().client()->hasPendingNavigat ion();
556 }
557
561 void FrameLoader::checkCompleted() 558 void FrameLoader::checkCompleted()
562 { 559 {
563 RefPtrWillBeRawPtr<LocalFrame> protect(m_frame.get()); 560 RefPtrWillBeRawPtr<LocalFrame> protect(m_frame.get());
564 if (!shouldComplete(m_frame->document())) 561 if (!shouldComplete(m_frame->document()))
565 return; 562 return;
566 563
567 // OK, completed. 564 // OK, completed.
568 m_frame->document()->setReadyState(Document::Complete); 565 m_frame->document()->setReadyState(Document::Complete);
569 if (m_frame->document()->loadEventStillNeeded()) 566 if (m_frame->document()->loadEventStillNeeded())
570 m_frame->document()->implicitClose(); 567 m_frame->document()->implicitClose();
571 568
572 m_frame->navigationScheduler().startTimer(); 569 m_frame->navigationScheduler().startTimer();
573 570
574 if (m_frame->view()) 571 if (m_frame->view())
575 m_frame->view()->handleLoadCompleted(); 572 m_frame->view()->handleLoadCompleted();
576 573
577 if (shouldSendCompleteNotifications(m_frame)) { 574 // The readystatechanged or load event may have disconnected this frame.
575 if (!m_frame->client())
576 return;
577
578 if (shouldSendFinishNotification(m_frame)) {
579 // Report mobile vs. desktop page statistics. This will only report on A ndroid.
580 if (m_frame->isMainFrame())
581 m_frame->document()->viewportDescription().reportMobilePageStats(m_f rame);
582 m_documentLoader->setSentDidFinishLoad();
583 client()->dispatchDidFinishLoad();
584 // Finishing the load can detach the frame when running layout tests.
585 if (!m_frame->client())
586 return;
587 }
588
589 if (shouldSendCompleteNotification(m_frame)) {
578 m_progressTracker->progressCompleted(); 590 m_progressTracker->progressCompleted();
579 // Retry restoring scroll offset since finishing loading disables conten t 591 // Retry restoring scroll offset since finishing loading disables conten t
580 // size clamping. 592 // size clamping.
581 restoreScrollPositionAndViewState(); 593 restoreScrollPositionAndViewState();
582 594
583 m_loadType = FrameLoadTypeStandard; 595 m_loadType = FrameLoadTypeStandard;
584 m_frame->localDOMWindow()->finishedLoading(); 596 m_frame->localDOMWindow()->finishedLoading();
585
586 // Report mobile vs. desktop page statistics. This will only report on A ndroid.
587 if (m_frame->isMainFrame())
588 m_frame->document()->viewportDescription().reportMobilePageStats(m_f rame);
589 client()->dispatchDidFinishLoad();
590 } 597 }
591 598
592 Frame* parent = m_frame->tree().parent(); 599 Frame* parent = m_frame->tree().parent();
593 if (parent && parent->isLocalFrame()) 600 if (parent && parent->isLocalFrame())
594 toLocalFrame(parent)->loader().checkCompleted(); 601 toLocalFrame(parent)->loader().checkCompleted();
595 } 602 }
596 603
597 void FrameLoader::checkTimerFired(Timer<FrameLoader>*) 604 void FrameLoader::checkTimerFired(Timer<FrameLoader>*)
598 { 605 {
599 if (Page* page = m_frame->page()) { 606 if (Page* page = m_frame->page()) {
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 if (loader == m_provisionalDocumentLoader) { 1212 if (loader == m_provisionalDocumentLoader) {
1206 client()->dispatchDidFailProvisionalLoad(error, historyCommitType); 1213 client()->dispatchDidFailProvisionalLoad(error, historyCommitType);
1207 if (loader != m_provisionalDocumentLoader) 1214 if (loader != m_provisionalDocumentLoader)
1208 return; 1215 return;
1209 detachDocumentLoader(m_provisionalDocumentLoader); 1216 detachDocumentLoader(m_provisionalDocumentLoader);
1210 m_progressTracker->progressCompleted(); 1217 m_progressTracker->progressCompleted();
1211 } else { 1218 } else {
1212 ASSERT(loader == m_documentLoader); 1219 ASSERT(loader == m_documentLoader);
1213 if (m_frame->document()->parser()) 1220 if (m_frame->document()->parser())
1214 m_frame->document()->parser()->stopParsing(); 1221 m_frame->document()->parser()->stopParsing();
1222 m_documentLoader->setSentDidFinishLoad();
1215 if (!m_provisionalDocumentLoader && m_frame->isLoading()) { 1223 if (!m_provisionalDocumentLoader && m_frame->isLoading()) {
1216 client()->dispatchDidFailLoad(error, historyCommitType); 1224 client()->dispatchDidFailLoad(error, historyCommitType);
1217 m_progressTracker->progressCompleted(); 1225 m_progressTracker->progressCompleted();
1218 } 1226 }
1219 } 1227 }
1220 checkCompleted(); 1228 checkCompleted();
1221 } 1229 }
1222 1230
1223 bool FrameLoader::shouldPerformFragmentNavigation(bool isFormSubmission, const S tring& httpMethod, FrameLoadType loadType, const KURL& url) 1231 bool FrameLoader::shouldPerformFragmentNavigation(bool isFormSubmission, const S tring& httpMethod, FrameLoadType loadType, const KURL& url)
1224 { 1232 {
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
1538 // FIXME: We need a way to propagate insecure requests policy flags to 1546 // FIXME: We need a way to propagate insecure requests policy flags to
1539 // out-of-process frames. For now, we'll always use default behavior. 1547 // out-of-process frames. For now, we'll always use default behavior.
1540 if (!parentFrame->isLocalFrame()) 1548 if (!parentFrame->isLocalFrame())
1541 return nullptr; 1549 return nullptr;
1542 1550
1543 ASSERT(toLocalFrame(parentFrame)->document()); 1551 ASSERT(toLocalFrame(parentFrame)->document());
1544 return toLocalFrame(parentFrame)->document()->insecureNavigationsToUpgrade() ; 1552 return toLocalFrame(parentFrame)->document()->insecureNavigationsToUpgrade() ;
1545 } 1553 }
1546 1554
1547 } // namespace blink 1555 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/loader/DocumentLoader.cpp ('k') | third_party/WebKit/Source/web/WebFrame.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698