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

Side by Side Diff: chrome/browser/tab_contents/navigation_controller.cc

Issue 67150: Make the Go Back navigation work even when redirection is involved.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/tab_contents/navigation_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 new_entry = new NavigationEntry; 598 new_entry = new NavigationEntry;
599 } 599 }
600 600
601 new_entry->set_url(params.url); 601 new_entry->set_url(params.url);
602 new_entry->set_referrer(params.referrer); 602 new_entry->set_referrer(params.referrer);
603 new_entry->set_page_id(params.page_id); 603 new_entry->set_page_id(params.page_id);
604 new_entry->set_transition_type(params.transition); 604 new_entry->set_transition_type(params.transition);
605 new_entry->set_site_instance(tab_contents_->GetSiteInstance()); 605 new_entry->set_site_instance(tab_contents_->GetSiteInstance());
606 new_entry->set_has_post_data(params.is_post); 606 new_entry->set_has_post_data(params.is_post);
607 607
608 InsertEntry(new_entry); 608 if (PageTransition::IsRedirect(new_entry->transition_type())) {
609 // The current entry is a redirection source. It needs to be replaced with
610 // the new entry to avoid unwanted redirections in navigating backward /
611 // forward.
612 ReplaceCurrentEntry(new_entry);
613 } else {
614 InsertEntry(new_entry);
615 }
609 } 616 }
610 617
611 void NavigationController::RendererDidNavigateToExistingPage( 618 void NavigationController::RendererDidNavigateToExistingPage(
612 const ViewHostMsg_FrameNavigate_Params& params) { 619 const ViewHostMsg_FrameNavigate_Params& params) {
613 // We should only get here for main frame navigations. 620 // We should only get here for main frame navigations.
614 DCHECK(PageTransition::IsMainFrame(params.transition)); 621 DCHECK(PageTransition::IsMainFrame(params.transition));
615 622
616 // This is a back/forward navigation. The existing page for the ID is 623 // This is a back/forward navigation. The existing page for the ID is
617 // guaranteed to exist by ClassifyNavigation, and we just need to update it 624 // guaranteed to exist by ClassifyNavigation, and we just need to update it
618 // with new information from the renderer. 625 // with new information from the renderer.
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 808
802 // If there was a transient entry, invalidate everything so the new active 809 // If there was a transient entry, invalidate everything so the new active
803 // entry state is shown. 810 // entry state is shown.
804 if (transient) { 811 if (transient) {
805 tab_contents_->NotifyNavigationStateChanged( 812 tab_contents_->NotifyNavigationStateChanged(
806 TabContents::INVALIDATE_EVERYTHING); 813 TabContents::INVALIDATE_EVERYTHING);
807 } 814 }
808 } 815 }
809 816
810 void NavigationController::InsertEntry(NavigationEntry* entry) { 817 void NavigationController::InsertEntry(NavigationEntry* entry) {
818 InsertOrReplaceEntry(entry, false);
819 }
820
821 void NavigationController::ReplaceCurrentEntry(NavigationEntry* entry) {
822 InsertOrReplaceEntry(entry, true);
823 }
824
825 void NavigationController::InsertOrReplaceEntry(
brettw 2009/04/24 20:57:59 When all the args fit, we usually like to wrap the
826 NavigationEntry* entry, bool replace) {
811 DCHECK(entry->transition_type() != PageTransition::AUTO_SUBFRAME); 827 DCHECK(entry->transition_type() != PageTransition::AUTO_SUBFRAME);
812 828
813 // Copy the pending entry's unique ID to the committed entry. 829 // Copy the pending entry's unique ID to the committed entry.
814 // I don't know if pending_entry_index_ can be other than -1 here. 830 // I don't know if pending_entry_index_ can be other than -1 here.
815 const NavigationEntry* const pending_entry = (pending_entry_index_ == -1) ? 831 const NavigationEntry* const pending_entry = (pending_entry_index_ == -1) ?
816 pending_entry_ : entries_[pending_entry_index_].get(); 832 pending_entry_ : entries_[pending_entry_index_].get();
817 if (pending_entry) 833 if (pending_entry)
818 entry->set_unique_id(pending_entry->unique_id()); 834 entry->set_unique_id(pending_entry->unique_id());
819 835
820 DiscardNonCommittedEntriesInternal(); 836 DiscardNonCommittedEntriesInternal();
821 837
822 int current_size = static_cast<int>(entries_.size()); 838 int current_size = static_cast<int>(entries_.size());
823 839
824 // Prune any entries which are in front of the current entry.
825 if (current_size > 0) { 840 if (current_size > 0) {
841 // Prune any entries which are in front of the current entry.
842 // Also prune the current entry if we are to replace the current entry.
843 int prune_up_to = replace ? last_committed_entry_index_ - 1
844 : last_committed_entry_index_;
826 int num_pruned = 0; 845 int num_pruned = 0;
827 while (last_committed_entry_index_ < (current_size - 1)) { 846 while (prune_up_to < (current_size - 1)) {
828 num_pruned++; 847 num_pruned++;
829 entries_.pop_back(); 848 entries_.pop_back();
830 current_size--; 849 current_size--;
831 } 850 }
832 if (num_pruned > 0) // Only notify if we did prune something. 851 if (num_pruned > 0) // Only notify if we did prune something.
833 NotifyPrunedEntries(this, false, num_pruned); 852 NotifyPrunedEntries(this, false, num_pruned);
834 } 853 }
835 854
836 if (entries_.size() >= max_entry_count_) { 855 if (entries_.size() >= max_entry_count_) {
837 RemoveEntryAtIndex(0, GURL()); 856 RemoveEntryAtIndex(0, GURL());
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 return i; 968 return i;
950 } 969 }
951 return -1; 970 return -1;
952 } 971 }
953 972
954 NavigationEntry* NavigationController::GetTransientEntry() const { 973 NavigationEntry* NavigationController::GetTransientEntry() const {
955 if (transient_entry_index_ == -1) 974 if (transient_entry_index_ == -1)
956 return NULL; 975 return NULL;
957 return entries_[transient_entry_index_].get(); 976 return entries_[transient_entry_index_].get();
958 } 977 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/navigation_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698