| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/tab_contents/navigation_controller.h" | 5 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 6 | 6 |
| 7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 // TODO(brettw) this seems slightly bogus as we don't really know if the | 458 // TODO(brettw) this seems slightly bogus as we don't really know if the |
| 459 // pending entry is what this navigation is for. There is a similar TODO | 459 // pending entry is what this navigation is for. There is a similar TODO |
| 460 // w.r.t. the pending entry in RendererDidNavigateToNewPage. | 460 // w.r.t. the pending entry in RendererDidNavigateToNewPage. |
| 461 if (pending_entry_index_ >= 0) | 461 if (pending_entry_index_ >= 0) |
| 462 pending_entry_->set_site_instance(tab_contents_->GetSiteInstance()); | 462 pending_entry_->set_site_instance(tab_contents_->GetSiteInstance()); |
| 463 | 463 |
| 464 // Do navigation-type specific actions. These will make and commit an entry. | 464 // Do navigation-type specific actions. These will make and commit an entry. |
| 465 details->type = ClassifyNavigation(params); | 465 details->type = ClassifyNavigation(params); |
| 466 switch (details->type) { | 466 switch (details->type) { |
| 467 case NavigationType::NEW_PAGE: | 467 case NavigationType::NEW_PAGE: |
| 468 RendererDidNavigateToNewPage(params); | 468 RendererDidNavigateToNewPage(params, &(details->did_replace_entry)); |
| 469 break; | 469 break; |
| 470 case NavigationType::EXISTING_PAGE: | 470 case NavigationType::EXISTING_PAGE: |
| 471 RendererDidNavigateToExistingPage(params); | 471 RendererDidNavigateToExistingPage(params); |
| 472 break; | 472 break; |
| 473 case NavigationType::SAME_PAGE: | 473 case NavigationType::SAME_PAGE: |
| 474 RendererDidNavigateToSamePage(params); | 474 RendererDidNavigateToSamePage(params); |
| 475 break; | 475 break; |
| 476 case NavigationType::IN_PAGE: | 476 case NavigationType::IN_PAGE: |
| 477 RendererDidNavigateInPage(params); | 477 RendererDidNavigateInPage(params, &(details->did_replace_entry)); |
| 478 break; | 478 break; |
| 479 case NavigationType::NEW_SUBFRAME: | 479 case NavigationType::NEW_SUBFRAME: |
| 480 RendererDidNavigateNewSubframe(params); | 480 RendererDidNavigateNewSubframe(params); |
| 481 break; | 481 break; |
| 482 case NavigationType::AUTO_SUBFRAME: | 482 case NavigationType::AUTO_SUBFRAME: |
| 483 if (!RendererDidNavigateAutoSubframe(params)) | 483 if (!RendererDidNavigateAutoSubframe(params)) |
| 484 return false; | 484 return false; |
| 485 break; | 485 break; |
| 486 case NavigationType::NAV_IGNORE: | 486 case NavigationType::NAV_IGNORE: |
| 487 // There is nothing we can do with this navigation, so we just return to | 487 // There is nothing we can do with this navigation, so we just return to |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 } | 610 } |
| 611 return params.redirects.size() > 1; | 611 return params.redirects.size() > 1; |
| 612 } | 612 } |
| 613 | 613 |
| 614 bool NavigationController::IsLikelyAutoNavigation(base::TimeTicks now) { | 614 bool NavigationController::IsLikelyAutoNavigation(base::TimeTicks now) { |
| 615 return !user_gesture_observed_ && | 615 return !user_gesture_observed_ && |
| 616 (now - last_document_loaded_) < kMaxAutoNavigationTimeDelta; | 616 (now - last_document_loaded_) < kMaxAutoNavigationTimeDelta; |
| 617 } | 617 } |
| 618 | 618 |
| 619 void NavigationController::RendererDidNavigateToNewPage( | 619 void NavigationController::RendererDidNavigateToNewPage( |
| 620 const ViewHostMsg_FrameNavigate_Params& params) { | 620 const ViewHostMsg_FrameNavigate_Params& params, bool* did_replace_entry) { |
| 621 NavigationEntry* new_entry; | 621 NavigationEntry* new_entry; |
| 622 if (pending_entry_) { | 622 if (pending_entry_) { |
| 623 // TODO(brettw) this assumes that the pending entry is appropriate for the | 623 // TODO(brettw) this assumes that the pending entry is appropriate for the |
| 624 // new page that was just loaded. I don't think this is necessarily the | 624 // new page that was just loaded. I don't think this is necessarily the |
| 625 // case! We should have some more tracking to know for sure. This goes along | 625 // case! We should have some more tracking to know for sure. This goes along |
| 626 // with a similar TODO at the top of RendererDidNavigate where we blindly | 626 // with a similar TODO at the top of RendererDidNavigate where we blindly |
| 627 // set the site instance on the pending entry. | 627 // set the site instance on the pending entry. |
| 628 new_entry = new NavigationEntry(*pending_entry_); | 628 new_entry = new NavigationEntry(*pending_entry_); |
| 629 | 629 |
| 630 // Don't use the page type from the pending entry. Some interstitial page | 630 // Don't use the page type from the pending entry. Some interstitial page |
| (...skipping 10 matching lines...) Expand all Loading... |
| 641 new_entry->set_transition_type(params.transition); | 641 new_entry->set_transition_type(params.transition); |
| 642 new_entry->set_site_instance(tab_contents_->GetSiteInstance()); | 642 new_entry->set_site_instance(tab_contents_->GetSiteInstance()); |
| 643 new_entry->set_has_post_data(params.is_post); | 643 new_entry->set_has_post_data(params.is_post); |
| 644 | 644 |
| 645 // If the current entry is a redirection source and the redirection has | 645 // If the current entry is a redirection source and the redirection has |
| 646 // occurred within kMaxAutoNavigationTimeDelta since the last document load, | 646 // occurred within kMaxAutoNavigationTimeDelta since the last document load, |
| 647 // this is likely to be machine-initiated redirect and the entry needs to be | 647 // this is likely to be machine-initiated redirect and the entry needs to be |
| 648 // replaced with the new entry to avoid unwanted redirections in navigating | 648 // replaced with the new entry to avoid unwanted redirections in navigating |
| 649 // backward/forward. | 649 // backward/forward. |
| 650 // Otherwise, just insert the new entry. | 650 // Otherwise, just insert the new entry. |
| 651 InsertOrReplaceEntry(new_entry, | 651 *did_replace_entry = IsRedirect(params) && |
| 652 IsRedirect(params) && IsLikelyAutoNavigation(base::TimeTicks::Now())); | 652 IsLikelyAutoNavigation(base::TimeTicks::Now()); |
| 653 InsertOrReplaceEntry(new_entry, *did_replace_entry); |
| 653 } | 654 } |
| 654 | 655 |
| 655 void NavigationController::RendererDidNavigateToExistingPage( | 656 void NavigationController::RendererDidNavigateToExistingPage( |
| 656 const ViewHostMsg_FrameNavigate_Params& params) { | 657 const ViewHostMsg_FrameNavigate_Params& params) { |
| 657 // We should only get here for main frame navigations. | 658 // We should only get here for main frame navigations. |
| 658 DCHECK(PageTransition::IsMainFrame(params.transition)); | 659 DCHECK(PageTransition::IsMainFrame(params.transition)); |
| 659 | 660 |
| 660 // This is a back/forward navigation. The existing page for the ID is | 661 // This is a back/forward navigation. The existing page for the ID is |
| 661 // guaranteed to exist by ClassifyNavigation, and we just need to update it | 662 // guaranteed to exist by ClassifyNavigation, and we just need to update it |
| 662 // with new information from the renderer. | 663 // with new information from the renderer. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 // a regular user-initiated navigation. | 701 // a regular user-initiated navigation. |
| 701 existing_entry->set_unique_id(pending_entry_->unique_id()); | 702 existing_entry->set_unique_id(pending_entry_->unique_id()); |
| 702 | 703 |
| 703 // The URL may have changed due to redirects. | 704 // The URL may have changed due to redirects. |
| 704 existing_entry->set_url(params.url); | 705 existing_entry->set_url(params.url); |
| 705 | 706 |
| 706 DiscardNonCommittedEntries(); | 707 DiscardNonCommittedEntries(); |
| 707 } | 708 } |
| 708 | 709 |
| 709 void NavigationController::RendererDidNavigateInPage( | 710 void NavigationController::RendererDidNavigateInPage( |
| 710 const ViewHostMsg_FrameNavigate_Params& params) { | 711 const ViewHostMsg_FrameNavigate_Params& params, bool* did_replace_entry) { |
| 711 DCHECK(PageTransition::IsMainFrame(params.transition)) << | 712 DCHECK(PageTransition::IsMainFrame(params.transition)) << |
| 712 "WebKit should only tell us about in-page navs for the main frame."; | 713 "WebKit should only tell us about in-page navs for the main frame."; |
| 713 // We're guaranteed to have an entry for this one. | 714 // We're guaranteed to have an entry for this one. |
| 714 NavigationEntry* existing_entry = GetEntryWithPageID( | 715 NavigationEntry* existing_entry = GetEntryWithPageID( |
| 715 tab_contents_->GetSiteInstance(), | 716 tab_contents_->GetSiteInstance(), |
| 716 params.page_id); | 717 params.page_id); |
| 717 | 718 |
| 718 // Reference fragment navigation. We're guaranteed to have the last_committed | 719 // Reference fragment navigation. We're guaranteed to have the last_committed |
| 719 // entry and it will be the same page as the new navigation (minus the | 720 // entry and it will be the same page as the new navigation (minus the |
| 720 // reference fragments, of course). | 721 // reference fragments, of course). |
| 721 NavigationEntry* new_entry = new NavigationEntry(*existing_entry); | 722 NavigationEntry* new_entry = new NavigationEntry(*existing_entry); |
| 722 new_entry->set_page_id(params.page_id); | 723 new_entry->set_page_id(params.page_id); |
| 723 new_entry->set_url(params.url); | 724 new_entry->set_url(params.url); |
| 724 InsertOrReplaceEntry(new_entry, | 725 *did_replace_entry = IsRedirect(params) && |
| 725 IsRedirect(params) && IsLikelyAutoNavigation(base::TimeTicks::Now())); | 726 IsLikelyAutoNavigation(base::TimeTicks::Now()); |
| 727 InsertOrReplaceEntry(new_entry, *did_replace_entry); |
| 726 } | 728 } |
| 727 | 729 |
| 728 void NavigationController::RendererDidNavigateNewSubframe( | 730 void NavigationController::RendererDidNavigateNewSubframe( |
| 729 const ViewHostMsg_FrameNavigate_Params& params) { | 731 const ViewHostMsg_FrameNavigate_Params& params) { |
| 730 if (PageTransition::StripQualifier(params.transition) == | 732 if (PageTransition::StripQualifier(params.transition) == |
| 731 PageTransition::AUTO_SUBFRAME) { | 733 PageTransition::AUTO_SUBFRAME) { |
| 732 // This is not user-initiated. Ignore. | 734 // This is not user-initiated. Ignore. |
| 733 return; | 735 return; |
| 734 } | 736 } |
| 735 if (IsRedirect(params)) { | 737 if (IsRedirect(params)) { |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1019 return i; | 1021 return i; |
| 1020 } | 1022 } |
| 1021 return -1; | 1023 return -1; |
| 1022 } | 1024 } |
| 1023 | 1025 |
| 1024 NavigationEntry* NavigationController::GetTransientEntry() const { | 1026 NavigationEntry* NavigationController::GetTransientEntry() const { |
| 1025 if (transient_entry_index_ == -1) | 1027 if (transient_entry_index_ == -1) |
| 1026 return NULL; | 1028 return NULL; |
| 1027 return entries_[transient_entry_index_].get(); | 1029 return entries_[transient_entry_index_].get(); |
| 1028 } | 1030 } |
| OLD | NEW |