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

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

Powered by Google App Engine
This is Rietveld 408576698