OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/tab_contents/navigation_controller.h" | 5 #include "content/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 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 needs_reload_ = true; | 881 needs_reload_ = true; |
882 InsertEntriesFrom(source, source.entry_count()); | 882 InsertEntriesFrom(source, source.entry_count()); |
883 | 883 |
884 session_storage_namespace_ = source.session_storage_namespace_->Clone(); | 884 session_storage_namespace_ = source.session_storage_namespace_->Clone(); |
885 | 885 |
886 FinishRestore(source.last_committed_entry_index_, false); | 886 FinishRestore(source.last_committed_entry_index_, false); |
887 } | 887 } |
888 | 888 |
889 void NavigationController::CopyStateFromAndPrune(NavigationController* source, | 889 void NavigationController::CopyStateFromAndPrune(NavigationController* source, |
890 bool remove_first_entry) { | 890 bool remove_first_entry) { |
| 891 // The SiteInstance and page_id of the last committed entry needs to be |
| 892 // remembered at this point, in case there is only one committed entry |
| 893 // and it is pruned. |
| 894 NavigationEntry* last_committed = GetLastCommittedEntry(); |
| 895 SiteInstance* site_instance = |
| 896 last_committed ? last_committed->site_instance() : NULL; |
| 897 int32 minimum_page_id = last_committed ? last_committed->page_id() : -1; |
| 898 |
891 // This code is intended for use when the last entry is the active entry. | 899 // This code is intended for use when the last entry is the active entry. |
892 DCHECK((transient_entry_index_ != -1 && | 900 DCHECK((transient_entry_index_ != -1 && |
893 transient_entry_index_ == entry_count() - 1) || | 901 transient_entry_index_ == entry_count() - 1) || |
894 (pending_entry_ && (pending_entry_index_ == -1 || | 902 (pending_entry_ && (pending_entry_index_ == -1 || |
895 pending_entry_index_ == entry_count() - 1)) || | 903 pending_entry_index_ == entry_count() - 1)) || |
896 (!pending_entry_ && last_committed_entry_index_ == entry_count() - 1)); | 904 (!pending_entry_ && last_committed_entry_index_ == entry_count() - 1)); |
897 | 905 |
898 if (remove_first_entry && entry_count()) { | 906 if (remove_first_entry && entry_count()) { |
| 907 // If there is only one committed entry and |remove_first_entry| is true, |
| 908 // it needs to be pruned. This is accomplished by specifying a larger |
| 909 // |minimum_page_id| than the committed entry's page_id in the |
| 910 // ViewMsg_SetHistoryLengthAndPrune message. However, any pages which are |
| 911 // committed between now and when the RenderView handles the message will |
| 912 // need to be retained. Both constraints can be met by incrementing the |
| 913 // |minimum_page_id| by 1. |
| 914 DCHECK(minimum_page_id >= 0); |
| 915 if (entry_count() == 1) |
| 916 ++minimum_page_id; |
899 // Save then restore the pending entry (RemoveEntryAtIndexInternal chucks | 917 // Save then restore the pending entry (RemoveEntryAtIndexInternal chucks |
900 // the pending entry). | 918 // the pending entry). |
901 NavigationEntry* pending_entry = pending_entry_; | 919 NavigationEntry* pending_entry = pending_entry_; |
902 pending_entry_ = NULL; | 920 pending_entry_ = NULL; |
903 int pending_entry_index = pending_entry_index_; | 921 int pending_entry_index = pending_entry_index_; |
904 RemoveEntryAtIndexInternal(0); | 922 RemoveEntryAtIndexInternal(0); |
905 // Restore the pending entry. | 923 // Restore the pending entry. |
906 if (pending_entry_index != -1) { | 924 if (pending_entry_index != -1) { |
907 pending_entry_index_ = pending_entry_index - 1; | 925 pending_entry_index_ = pending_entry_index - 1; |
908 if (pending_entry_index_ != -1) | 926 if (pending_entry_index_ != -1) |
(...skipping 21 matching lines...) Expand all Loading... |
930 if (pending_entry_index_ != -1) | 948 if (pending_entry_index_ != -1) |
931 pending_entry_index_ = entry_count() - 1; | 949 pending_entry_index_ = entry_count() - 1; |
932 if (transient_entry_index_ != -1) { | 950 if (transient_entry_index_ != -1) { |
933 // There's a transient entry. In this case we want the last committed to | 951 // There's a transient entry. In this case we want the last committed to |
934 // point to the previous entry. | 952 // point to the previous entry. |
935 transient_entry_index_ = entry_count() - 1; | 953 transient_entry_index_ = entry_count() - 1; |
936 if (last_committed_entry_index_ != -1) | 954 if (last_committed_entry_index_ != -1) |
937 last_committed_entry_index_--; | 955 last_committed_entry_index_--; |
938 } | 956 } |
939 | 957 |
940 // Update the history in the RenderView. | 958 tab_contents_->SetHistoryLengthAndPrune(site_instance, |
941 tab_contents_->SetHistoryLengthAndClear(max_source_index); | 959 max_source_index, |
| 960 minimum_page_id); |
942 } | 961 } |
943 | 962 |
944 void NavigationController::PruneAllButActive() { | 963 void NavigationController::PruneAllButActive() { |
945 if (transient_entry_index_ != -1) { | 964 if (transient_entry_index_ != -1) { |
946 // There is a transient entry. Prune up to it. | 965 // There is a transient entry. Prune up to it. |
947 DCHECK_EQ(entry_count() - 1, transient_entry_index_); | 966 DCHECK_EQ(entry_count() - 1, transient_entry_index_); |
948 entries_.erase(entries_.begin(), entries_.begin() + transient_entry_index_); | 967 entries_.erase(entries_.begin(), entries_.begin() + transient_entry_index_); |
949 transient_entry_index_ = 0; | 968 transient_entry_index_ = 0; |
950 last_committed_entry_index_ = -1; | 969 last_committed_entry_index_ = -1; |
951 pending_entry_index_ = -1; | 970 pending_entry_index_ = -1; |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1166 size_t insert_index = 0; | 1185 size_t insert_index = 0; |
1167 for (int i = 0; i < max_index; i++) { | 1186 for (int i = 0; i < max_index; i++) { |
1168 // When cloning a tab, copy all entries except interstitial pages | 1187 // When cloning a tab, copy all entries except interstitial pages |
1169 if (source.entries_[i].get()->page_type() != INTERSTITIAL_PAGE) { | 1188 if (source.entries_[i].get()->page_type() != INTERSTITIAL_PAGE) { |
1170 entries_.insert(entries_.begin() + insert_index++, | 1189 entries_.insert(entries_.begin() + insert_index++, |
1171 linked_ptr<NavigationEntry>( | 1190 linked_ptr<NavigationEntry>( |
1172 new NavigationEntry(*source.entries_[i]))); | 1191 new NavigationEntry(*source.entries_[i]))); |
1173 } | 1192 } |
1174 } | 1193 } |
1175 } | 1194 } |
OLD | NEW |