Chromium Code Reviews| Index: chrome/browser/tab_contents/navigation_controller.cc |
| =================================================================== |
| --- chrome/browser/tab_contents/navigation_controller.cc (revision 14058) |
| +++ chrome/browser/tab_contents/navigation_controller.cc (working copy) |
| @@ -605,7 +605,14 @@ |
| new_entry->set_site_instance(tab_contents_->GetSiteInstance()); |
| new_entry->set_has_post_data(params.is_post); |
| - InsertEntry(new_entry); |
| + if (PageTransition::IsRedirect(new_entry->transition_type())) { |
| + // The current entry is a redirection source. It needs to be replaced with |
| + // the new entry to avoid unwanted redirections in navigating backward / |
| + // forward. |
| + ReplaceCurrentEntry(new_entry); |
| + } else { |
| + InsertEntry(new_entry); |
| + } |
| } |
| void NavigationController::RendererDidNavigateToExistingPage( |
| @@ -808,6 +815,15 @@ |
| } |
| void NavigationController::InsertEntry(NavigationEntry* entry) { |
| + InsertOrReplaceEntry(entry, false); |
| +} |
| + |
| +void NavigationController::ReplaceCurrentEntry(NavigationEntry* entry) { |
| + InsertOrReplaceEntry(entry, true); |
| +} |
| + |
| +void NavigationController::InsertOrReplaceEntry( |
|
brettw
2009/04/24 20:57:59
When all the args fit, we usually like to wrap the
|
| + NavigationEntry* entry, bool replace) { |
| DCHECK(entry->transition_type() != PageTransition::AUTO_SUBFRAME); |
| // Copy the pending entry's unique ID to the committed entry. |
| @@ -821,10 +837,13 @@ |
| int current_size = static_cast<int>(entries_.size()); |
| - // Prune any entries which are in front of the current entry. |
| if (current_size > 0) { |
| + // Prune any entries which are in front of the current entry. |
| + // Also prune the current entry if we are to replace the current entry. |
| + int prune_up_to = replace ? last_committed_entry_index_ - 1 |
| + : last_committed_entry_index_; |
| int num_pruned = 0; |
| - while (last_committed_entry_index_ < (current_size - 1)) { |
| + while (prune_up_to < (current_size - 1)) { |
| num_pruned++; |
| entries_.pop_back(); |
| current_size--; |