| Index: third_party/WebKit/Source/core/loader/FrameLoader.cpp
|
| diff --git a/third_party/WebKit/Source/core/loader/FrameLoader.cpp b/third_party/WebKit/Source/core/loader/FrameLoader.cpp
|
| index 09ca5483360ea06dd8ecf235d5b208404284439b..8cd77648a4dd0116286c5cf0df7be66d44d27041 100644
|
| --- a/third_party/WebKit/Source/core/loader/FrameLoader.cpp
|
| +++ b/third_party/WebKit/Source/core/loader/FrameLoader.cpp
|
| @@ -396,7 +396,7 @@
|
| document_loader_ ? document_loader_->IsCommittedButEmpty() : true);
|
| }
|
|
|
| - frame_->GetDocument()->CheckCompleted();
|
| + CheckCompleted();
|
|
|
| if (!frame_->View())
|
| return;
|
| @@ -408,6 +408,15 @@
|
| kNavigationToDifferentDocument);
|
| }
|
|
|
| +static bool AllDescendantsAreComplete(Frame* frame) {
|
| + for (Frame* child = frame->Tree().FirstChild(); child;
|
| + child = child->Tree().TraverseNext(frame)) {
|
| + if (child->IsLoading())
|
| + return false;
|
| + }
|
| + return true;
|
| +}
|
| +
|
| bool FrameLoader::AllAncestorsAreComplete() const {
|
| for (Frame* ancestor = frame_; ancestor;
|
| ancestor = ancestor->Tree().Parent()) {
|
| @@ -417,15 +426,96 @@
|
| return true;
|
| }
|
|
|
| -void FrameLoader::DidFinishNavigation() {
|
| - // We should have either finished the provisional or committed navigation if
|
| - // this is called. Only delcare the whole frame finished if neither is in
|
| - // progress.
|
| - DCHECK(document_loader_->SentDidFinishLoad() || !HasProvisionalNavigation());
|
| - if (!document_loader_->SentDidFinishLoad() || HasProvisionalNavigation())
|
| - return;
|
| -
|
| - if (frame_->IsLoading()) {
|
| +static bool ShouldComplete(Document* document) {
|
| + if (!document->GetFrame())
|
| + return false;
|
| + if (document->Parsing() || document->IsInDOMContentLoaded())
|
| + return false;
|
| + if (!document->HaveImportsLoaded())
|
| + return false;
|
| + if (document->Fetcher()->BlockingRequestCount())
|
| + return false;
|
| + if (document->IsDelayingLoadEvent())
|
| + return false;
|
| + return AllDescendantsAreComplete(document->GetFrame());
|
| +}
|
| +
|
| +static bool ShouldSendFinishNotification(LocalFrame* frame) {
|
| + // Don't send didFinishLoad more than once per DocumentLoader.
|
| + if (frame->Loader().GetDocumentLoader()->SentDidFinishLoad())
|
| + return false;
|
| +
|
| + // We might have declined to run the load event due to an imminent
|
| + // content-initiated navigation.
|
| + if (!frame->GetDocument()->LoadEventFinished())
|
| + return false;
|
| +
|
| + // An event might have restarted a child frame.
|
| + if (!AllDescendantsAreComplete(frame))
|
| + return false;
|
| +
|
| + // Don't notify if the frame is being detached.
|
| + if (!frame->IsAttached())
|
| + return false;
|
| +
|
| + return true;
|
| +}
|
| +
|
| +static bool ShouldSendCompleteNotification(LocalFrame* frame) {
|
| + // FIXME: We might have already sent stop notifications and be re-completing.
|
| + if (!frame->IsLoading())
|
| + return false;
|
| + // Only send didStopLoading() if there are no navigations in progress at all,
|
| + // whether committed, provisional, or pending.
|
| + return frame->Loader().GetDocumentLoader()->SentDidFinishLoad() &&
|
| + !frame->Loader().HasProvisionalNavigation();
|
| +}
|
| +
|
| +void FrameLoader::CheckCompleted() {
|
| + if (!ShouldComplete(frame_->GetDocument()))
|
| + return;
|
| +
|
| + if (Client()) {
|
| + Client()->RunScriptsAtDocumentIdle();
|
| +
|
| + // Injected scripts may have disconnected this frame.
|
| + if (!Client())
|
| + return;
|
| +
|
| + // Check again, because runScriptsAtDocumentIdle() may have delayed the load
|
| + // event.
|
| + if (!ShouldComplete(frame_->GetDocument()))
|
| + return;
|
| + }
|
| +
|
| + // OK, completed.
|
| + frame_->GetDocument()->SetReadyState(Document::kComplete);
|
| + if (frame_->GetDocument()->LoadEventStillNeeded())
|
| + frame_->GetDocument()->ImplicitClose();
|
| +
|
| + frame_->GetNavigationScheduler().StartTimer();
|
| +
|
| + if (frame_->View())
|
| + frame_->View()->HandleLoadCompleted();
|
| +
|
| + // The readystatechanged or load event may have disconnected this frame.
|
| + if (!frame_->Client())
|
| + return;
|
| +
|
| + if (ShouldSendFinishNotification(frame_)) {
|
| + // Report mobile vs. desktop page statistics. This will only report on
|
| + // Android.
|
| + if (frame_->IsMainFrame())
|
| + frame_->GetDocument()->GetViewportDescription().ReportMobilePageStats(
|
| + frame_);
|
| + document_loader_->SetSentDidFinishLoad();
|
| + Client()->DispatchDidFinishLoad();
|
| + // Finishing the load can detach the frame when running layout tests.
|
| + if (!frame_->Client())
|
| + return;
|
| + }
|
| +
|
| + if (ShouldSendCompleteNotification(frame_)) {
|
| progress_tracker_->ProgressCompleted();
|
| // Retry restoring scroll offset since finishing loading disables content
|
| // size clamping.
|
| @@ -437,7 +527,7 @@
|
|
|
| Frame* parent = frame_->Tree().Parent();
|
| if (parent && parent->IsLocalFrame())
|
| - ToLocalFrame(parent)->GetDocument()->CheckCompleted();
|
| + ToLocalFrame(parent)->Loader().CheckCompleted();
|
| }
|
|
|
| void FrameLoader::CheckTimerFired(TimerBase*) {
|
| @@ -445,7 +535,7 @@
|
| if (page->Suspended())
|
| return;
|
| }
|
| - frame_->GetDocument()->CheckCompleted();
|
| + CheckCompleted();
|
| }
|
|
|
| void FrameLoader::ScheduleCheckCompleted() {
|
| @@ -553,7 +643,7 @@
|
|
|
| document_loader_->GetInitialScrollState().was_scrolled_by_user = false;
|
|
|
| - frame_->GetDocument()->CheckCompleted();
|
| + CheckCompleted();
|
|
|
| frame_->DomWindow()->StatePopped(state_object
|
| ? std::move(state_object)
|
| @@ -915,9 +1005,10 @@
|
| ToLocalFrame(child)->Loader().StopAllLoaders();
|
| }
|
|
|
| - frame_->GetDocument()->CancelParsing();
|
| + frame_->GetDocument()->SuppressLoadEvent();
|
| if (document_loader_)
|
| document_loader_->Fetcher()->StopFetching();
|
| + frame_->GetDocument()->CancelParsing();
|
| if (!protect_provisional_loader_)
|
| DetachDocumentLoader(provisional_document_loader_);
|
|
|
| @@ -1164,7 +1255,6 @@
|
| void FrameLoader::DetachProvisionalDocumentLoader(DocumentLoader* loader) {
|
| DCHECK_EQ(loader, provisional_document_loader_);
|
| DetachDocumentLoader(provisional_document_loader_);
|
| - DidFinishNavigation();
|
| }
|
|
|
| bool FrameLoader::ShouldPerformFragmentNavigation(bool is_form_submission,
|
|
|