OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights | 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights |
3 * reserved. | 3 * reserved. |
4 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 4 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
5 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. | 5 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. |
6 * (http://www.torchmobile.com/) | 6 * (http://www.torchmobile.com/) |
7 * Copyright (C) 2008 Alp Toker <alp@atoker.com> | 7 * Copyright (C) 2008 Alp Toker <alp@atoker.com> |
8 * Copyright (C) Research In Motion Limited 2009. All rights reserved. | 8 * Copyright (C) Research In Motion Limited 2009. All rights reserved. |
9 * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com> | 9 * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com> |
10 * Copyright (C) 2011 Google Inc. All rights reserved. | 10 * Copyright (C) 2011 Google Inc. All rights reserved. |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 if (Client()) { | 389 if (Client()) { |
390 ScriptForbiddenScope forbid_scripts; | 390 ScriptForbiddenScope forbid_scripts; |
391 Client()->DispatchDidFinishDocumentLoad(); | 391 Client()->DispatchDidFinishDocumentLoad(); |
392 } | 392 } |
393 | 393 |
394 if (Client()) { | 394 if (Client()) { |
395 Client()->RunScriptsAtDocumentReady( | 395 Client()->RunScriptsAtDocumentReady( |
396 document_loader_ ? document_loader_->IsCommittedButEmpty() : true); | 396 document_loader_ ? document_loader_->IsCommittedButEmpty() : true); |
397 } | 397 } |
398 | 398 |
399 frame_->GetDocument()->CheckCompleted(); | 399 CheckCompleted(); |
400 | 400 |
401 if (!frame_->View()) | 401 if (!frame_->View()) |
402 return; | 402 return; |
403 | 403 |
404 // Check if the scrollbars are really needed for the content. If not, remove | 404 // Check if the scrollbars are really needed for the content. If not, remove |
405 // them, relayout, and repaint. | 405 // them, relayout, and repaint. |
406 frame_->View()->RestoreScrollbar(); | 406 frame_->View()->RestoreScrollbar(); |
407 ProcessFragment(frame_->GetDocument()->Url(), document_loader_->LoadType(), | 407 ProcessFragment(frame_->GetDocument()->Url(), document_loader_->LoadType(), |
408 kNavigationToDifferentDocument); | 408 kNavigationToDifferentDocument); |
409 } | 409 } |
410 | 410 |
| 411 static bool AllDescendantsAreComplete(Frame* frame) { |
| 412 for (Frame* child = frame->Tree().FirstChild(); child; |
| 413 child = child->Tree().TraverseNext(frame)) { |
| 414 if (child->IsLoading()) |
| 415 return false; |
| 416 } |
| 417 return true; |
| 418 } |
| 419 |
411 bool FrameLoader::AllAncestorsAreComplete() const { | 420 bool FrameLoader::AllAncestorsAreComplete() const { |
412 for (Frame* ancestor = frame_; ancestor; | 421 for (Frame* ancestor = frame_; ancestor; |
413 ancestor = ancestor->Tree().Parent()) { | 422 ancestor = ancestor->Tree().Parent()) { |
414 if (ancestor->IsLoading()) | 423 if (ancestor->IsLoading()) |
415 return false; | 424 return false; |
416 } | 425 } |
417 return true; | 426 return true; |
418 } | 427 } |
419 | 428 |
420 void FrameLoader::DidFinishNavigation() { | 429 static bool ShouldComplete(Document* document) { |
421 // We should have either finished the provisional or committed navigation if | 430 if (!document->GetFrame()) |
422 // this is called. Only delcare the whole frame finished if neither is in | 431 return false; |
423 // progress. | 432 if (document->Parsing() || document->IsInDOMContentLoaded()) |
424 DCHECK(document_loader_->SentDidFinishLoad() || !HasProvisionalNavigation()); | 433 return false; |
425 if (!document_loader_->SentDidFinishLoad() || HasProvisionalNavigation()) | 434 if (!document->HaveImportsLoaded()) |
| 435 return false; |
| 436 if (document->Fetcher()->BlockingRequestCount()) |
| 437 return false; |
| 438 if (document->IsDelayingLoadEvent()) |
| 439 return false; |
| 440 return AllDescendantsAreComplete(document->GetFrame()); |
| 441 } |
| 442 |
| 443 static bool ShouldSendFinishNotification(LocalFrame* frame) { |
| 444 // Don't send didFinishLoad more than once per DocumentLoader. |
| 445 if (frame->Loader().GetDocumentLoader()->SentDidFinishLoad()) |
| 446 return false; |
| 447 |
| 448 // We might have declined to run the load event due to an imminent |
| 449 // content-initiated navigation. |
| 450 if (!frame->GetDocument()->LoadEventFinished()) |
| 451 return false; |
| 452 |
| 453 // An event might have restarted a child frame. |
| 454 if (!AllDescendantsAreComplete(frame)) |
| 455 return false; |
| 456 |
| 457 // Don't notify if the frame is being detached. |
| 458 if (!frame->IsAttached()) |
| 459 return false; |
| 460 |
| 461 return true; |
| 462 } |
| 463 |
| 464 static bool ShouldSendCompleteNotification(LocalFrame* frame) { |
| 465 // FIXME: We might have already sent stop notifications and be re-completing. |
| 466 if (!frame->IsLoading()) |
| 467 return false; |
| 468 // Only send didStopLoading() if there are no navigations in progress at all, |
| 469 // whether committed, provisional, or pending. |
| 470 return frame->Loader().GetDocumentLoader()->SentDidFinishLoad() && |
| 471 !frame->Loader().HasProvisionalNavigation(); |
| 472 } |
| 473 |
| 474 void FrameLoader::CheckCompleted() { |
| 475 if (!ShouldComplete(frame_->GetDocument())) |
426 return; | 476 return; |
427 | 477 |
428 if (frame_->IsLoading()) { | 478 if (Client()) { |
| 479 Client()->RunScriptsAtDocumentIdle(); |
| 480 |
| 481 // Injected scripts may have disconnected this frame. |
| 482 if (!Client()) |
| 483 return; |
| 484 |
| 485 // Check again, because runScriptsAtDocumentIdle() may have delayed the load |
| 486 // event. |
| 487 if (!ShouldComplete(frame_->GetDocument())) |
| 488 return; |
| 489 } |
| 490 |
| 491 // OK, completed. |
| 492 frame_->GetDocument()->SetReadyState(Document::kComplete); |
| 493 if (frame_->GetDocument()->LoadEventStillNeeded()) |
| 494 frame_->GetDocument()->ImplicitClose(); |
| 495 |
| 496 frame_->GetNavigationScheduler().StartTimer(); |
| 497 |
| 498 if (frame_->View()) |
| 499 frame_->View()->HandleLoadCompleted(); |
| 500 |
| 501 // The readystatechanged or load event may have disconnected this frame. |
| 502 if (!frame_->Client()) |
| 503 return; |
| 504 |
| 505 if (ShouldSendFinishNotification(frame_)) { |
| 506 // Report mobile vs. desktop page statistics. This will only report on |
| 507 // Android. |
| 508 if (frame_->IsMainFrame()) |
| 509 frame_->GetDocument()->GetViewportDescription().ReportMobilePageStats( |
| 510 frame_); |
| 511 document_loader_->SetSentDidFinishLoad(); |
| 512 Client()->DispatchDidFinishLoad(); |
| 513 // Finishing the load can detach the frame when running layout tests. |
| 514 if (!frame_->Client()) |
| 515 return; |
| 516 } |
| 517 |
| 518 if (ShouldSendCompleteNotification(frame_)) { |
429 progress_tracker_->ProgressCompleted(); | 519 progress_tracker_->ProgressCompleted(); |
430 // Retry restoring scroll offset since finishing loading disables content | 520 // Retry restoring scroll offset since finishing loading disables content |
431 // size clamping. | 521 // size clamping. |
432 RestoreScrollPositionAndViewState(); | 522 RestoreScrollPositionAndViewState(); |
433 if (document_loader_) | 523 if (document_loader_) |
434 document_loader_->SetLoadType(kFrameLoadTypeStandard); | 524 document_loader_->SetLoadType(kFrameLoadTypeStandard); |
435 frame_->DomWindow()->FinishedLoading(); | 525 frame_->DomWindow()->FinishedLoading(); |
436 } | 526 } |
437 | 527 |
438 Frame* parent = frame_->Tree().Parent(); | 528 Frame* parent = frame_->Tree().Parent(); |
439 if (parent && parent->IsLocalFrame()) | 529 if (parent && parent->IsLocalFrame()) |
440 ToLocalFrame(parent)->GetDocument()->CheckCompleted(); | 530 ToLocalFrame(parent)->Loader().CheckCompleted(); |
441 } | 531 } |
442 | 532 |
443 void FrameLoader::CheckTimerFired(TimerBase*) { | 533 void FrameLoader::CheckTimerFired(TimerBase*) { |
444 if (Page* page = frame_->GetPage()) { | 534 if (Page* page = frame_->GetPage()) { |
445 if (page->Suspended()) | 535 if (page->Suspended()) |
446 return; | 536 return; |
447 } | 537 } |
448 frame_->GetDocument()->CheckCompleted(); | 538 CheckCompleted(); |
449 } | 539 } |
450 | 540 |
451 void FrameLoader::ScheduleCheckCompleted() { | 541 void FrameLoader::ScheduleCheckCompleted() { |
452 if (!check_timer_.IsActive()) | 542 if (!check_timer_.IsActive()) |
453 check_timer_.StartOneShot(0, BLINK_FROM_HERE); | 543 check_timer_.StartOneShot(0, BLINK_FROM_HERE); |
454 } | 544 } |
455 | 545 |
456 Frame* FrameLoader::Opener() { | 546 Frame* FrameLoader::Opener() { |
457 return Client() ? Client()->Opener() : 0; | 547 return Client() ? Client()->Opener() : 0; |
458 } | 548 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 document_loader_->SetIsClientRedirect(client_redirect == | 636 document_loader_->SetIsClientRedirect(client_redirect == |
547 ClientRedirectPolicy::kClientRedirect); | 637 ClientRedirectPolicy::kClientRedirect); |
548 if (history_item) | 638 if (history_item) |
549 document_loader_->SetItemForHistoryNavigation(history_item); | 639 document_loader_->SetItemForHistoryNavigation(history_item); |
550 UpdateForSameDocumentNavigation(url, kSameDocumentNavigationDefault, nullptr, | 640 UpdateForSameDocumentNavigation(url, kSameDocumentNavigationDefault, nullptr, |
551 kScrollRestorationAuto, frame_load_type, | 641 kScrollRestorationAuto, frame_load_type, |
552 initiating_document); | 642 initiating_document); |
553 | 643 |
554 document_loader_->GetInitialScrollState().was_scrolled_by_user = false; | 644 document_loader_->GetInitialScrollState().was_scrolled_by_user = false; |
555 | 645 |
556 frame_->GetDocument()->CheckCompleted(); | 646 CheckCompleted(); |
557 | 647 |
558 frame_->DomWindow()->StatePopped(state_object | 648 frame_->DomWindow()->StatePopped(state_object |
559 ? std::move(state_object) | 649 ? std::move(state_object) |
560 : SerializedScriptValue::NullValue()); | 650 : SerializedScriptValue::NullValue()); |
561 | 651 |
562 if (history_item) | 652 if (history_item) |
563 RestoreScrollPositionAndViewStateForLoadType(frame_load_type); | 653 RestoreScrollPositionAndViewStateForLoadType(frame_load_type); |
564 | 654 |
565 // We need to scroll to the fragment whether or not a hash change occurred, | 655 // We need to scroll to the fragment whether or not a hash change occurred, |
566 // since the user might have scrolled since the previous navigation. | 656 // since the user might have scrolled since the previous navigation. |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 return; | 998 return; |
909 | 999 |
910 in_stop_all_loaders_ = true; | 1000 in_stop_all_loaders_ = true; |
911 | 1001 |
912 for (Frame* child = frame_->Tree().FirstChild(); child; | 1002 for (Frame* child = frame_->Tree().FirstChild(); child; |
913 child = child->Tree().NextSibling()) { | 1003 child = child->Tree().NextSibling()) { |
914 if (child->IsLocalFrame()) | 1004 if (child->IsLocalFrame()) |
915 ToLocalFrame(child)->Loader().StopAllLoaders(); | 1005 ToLocalFrame(child)->Loader().StopAllLoaders(); |
916 } | 1006 } |
917 | 1007 |
918 frame_->GetDocument()->CancelParsing(); | 1008 frame_->GetDocument()->SuppressLoadEvent(); |
919 if (document_loader_) | 1009 if (document_loader_) |
920 document_loader_->Fetcher()->StopFetching(); | 1010 document_loader_->Fetcher()->StopFetching(); |
| 1011 frame_->GetDocument()->CancelParsing(); |
921 if (!protect_provisional_loader_) | 1012 if (!protect_provisional_loader_) |
922 DetachDocumentLoader(provisional_document_loader_); | 1013 DetachDocumentLoader(provisional_document_loader_); |
923 | 1014 |
924 check_timer_.Stop(); | 1015 check_timer_.Stop(); |
925 frame_->GetNavigationScheduler().Cancel(); | 1016 frame_->GetNavigationScheduler().Cancel(); |
926 | 1017 |
927 // It's possible that the above actions won't have stopped loading if load | 1018 // It's possible that the above actions won't have stopped loading if load |
928 // completion had been blocked on parsing or if we were in the middle of | 1019 // completion had been blocked on parsing or if we were in the middle of |
929 // committing an empty document. In that case, emulate a failed navigation. | 1020 // committing an empty document. In that case, emulate a failed navigation. |
930 if (!provisional_document_loader_ && document_loader_ && | 1021 if (!provisional_document_loader_ && document_loader_ && |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1157 progress_tracker_.Clear(); | 1248 progress_tracker_.Clear(); |
1158 } | 1249 } |
1159 | 1250 |
1160 TRACE_EVENT_OBJECT_DELETED_WITH_ID("loading", "FrameLoader", this); | 1251 TRACE_EVENT_OBJECT_DELETED_WITH_ID("loading", "FrameLoader", this); |
1161 detached_ = true; | 1252 detached_ = true; |
1162 } | 1253 } |
1163 | 1254 |
1164 void FrameLoader::DetachProvisionalDocumentLoader(DocumentLoader* loader) { | 1255 void FrameLoader::DetachProvisionalDocumentLoader(DocumentLoader* loader) { |
1165 DCHECK_EQ(loader, provisional_document_loader_); | 1256 DCHECK_EQ(loader, provisional_document_loader_); |
1166 DetachDocumentLoader(provisional_document_loader_); | 1257 DetachDocumentLoader(provisional_document_loader_); |
1167 DidFinishNavigation(); | |
1168 } | 1258 } |
1169 | 1259 |
1170 bool FrameLoader::ShouldPerformFragmentNavigation(bool is_form_submission, | 1260 bool FrameLoader::ShouldPerformFragmentNavigation(bool is_form_submission, |
1171 const String& http_method, | 1261 const String& http_method, |
1172 FrameLoadType load_type, | 1262 FrameLoadType load_type, |
1173 const KURL& url) { | 1263 const KURL& url) { |
1174 // We don't do this if we are submitting a form with method other than "GET", | 1264 // We don't do this if we are submitting a form with method other than "GET", |
1175 // explicitly reloading, currently displaying a frameset, or if the URL does | 1265 // explicitly reloading, currently displaying a frameset, or if the URL does |
1176 // not have a fragment. | 1266 // not have a fragment. |
1177 return DeprecatedEqualIgnoringCase(http_method, HTTPNames::GET) && | 1267 return DeprecatedEqualIgnoringCase(http_method, HTTPNames::GET) && |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1684 // TODO(japhet): This is needed because the browser process DCHECKs if the | 1774 // TODO(japhet): This is needed because the browser process DCHECKs if the |
1685 // first entry we commit in a new frame has replacement set. It's unclear | 1775 // first entry we commit in a new frame has replacement set. It's unclear |
1686 // whether the DCHECK is right, investigate removing this special case. | 1776 // whether the DCHECK is right, investigate removing this special case. |
1687 bool replace_current_item = load_type == kFrameLoadTypeReplaceCurrentItem && | 1777 bool replace_current_item = load_type == kFrameLoadTypeReplaceCurrentItem && |
1688 (!Opener() || !request.Url().IsEmpty()); | 1778 (!Opener() || !request.Url().IsEmpty()); |
1689 loader->SetReplacesCurrentHistoryItem(replace_current_item); | 1779 loader->SetReplacesCurrentHistoryItem(replace_current_item); |
1690 return loader; | 1780 return loader; |
1691 } | 1781 } |
1692 | 1782 |
1693 } // namespace blink | 1783 } // namespace blink |
OLD | NEW |