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 865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
876 needs_reload_ = true; | 876 needs_reload_ = true; |
877 InsertEntriesFrom(source, source.entry_count()); | 877 InsertEntriesFrom(source, source.entry_count()); |
878 | 878 |
879 session_storage_namespace_ = source.session_storage_namespace_->Clone(); | 879 session_storage_namespace_ = source.session_storage_namespace_->Clone(); |
880 | 880 |
881 FinishRestore(source.last_committed_entry_index_, false); | 881 FinishRestore(source.last_committed_entry_index_, false); |
882 } | 882 } |
883 | 883 |
884 void NavigationController::CopyStateFromAndPrune(NavigationController* source, | 884 void NavigationController::CopyStateFromAndPrune(NavigationController* source, |
885 bool remove_first_entry) { | 885 bool remove_first_entry) { |
886 // The SiteInstance and page_id of the last committed entry needs to be | |
887 // remembered at this point, in case there is only one committed entry | |
888 // and it is pruned. | |
889 NavigationEntry* last_committed = GetLastCommittedEntry(); | |
890 SiteInstance* site_instance = | |
891 last_committed ? last_committed->site_instance() : NULL; | |
892 int32 minimum_page_id = last_committed ? last_committed->page_id() : -1; | |
893 | |
886 // This code is intended for use when the last entry is the active entry. | 894 // This code is intended for use when the last entry is the active entry. |
887 DCHECK((transient_entry_index_ != -1 && | 895 DCHECK((transient_entry_index_ != -1 && |
888 transient_entry_index_ == entry_count() - 1) || | 896 transient_entry_index_ == entry_count() - 1) || |
889 (pending_entry_ && (pending_entry_index_ == -1 || | 897 (pending_entry_ && (pending_entry_index_ == -1 || |
890 pending_entry_index_ == entry_count() - 1)) || | 898 pending_entry_index_ == entry_count() - 1)) || |
891 (!pending_entry_ && last_committed_entry_index_ == entry_count() - 1)); | 899 (!pending_entry_ && last_committed_entry_index_ == entry_count() - 1)); |
892 | 900 |
893 if (remove_first_entry && entry_count()) { | 901 if (remove_first_entry && entry_count()) { |
902 // If there is only one committed entry, then it needs to be erased in the | |
903 // RenderView, but any newly committed entries will be retained. | |
904 DCHECK(minimum_page_id >= 0); | |
905 if (entry_count() == 1) | |
906 ++minimum_page_id; | |
Charlie Reis
2011/08/13 00:29:04
Can you add a comment explaining why this is neces
cbentzel
2011/08/13 02:19:12
Done.
| |
894 // Save then restore the pending entry (RemoveEntryAtIndexInternal chucks | 907 // Save then restore the pending entry (RemoveEntryAtIndexInternal chucks |
895 // the pending entry). | 908 // the pending entry). |
896 NavigationEntry* pending_entry = pending_entry_; | 909 NavigationEntry* pending_entry = pending_entry_; |
897 pending_entry_ = NULL; | 910 pending_entry_ = NULL; |
898 int pending_entry_index = pending_entry_index_; | 911 int pending_entry_index = pending_entry_index_; |
899 RemoveEntryAtIndexInternal(0); | 912 RemoveEntryAtIndexInternal(0); |
900 // Restore the pending entry. | 913 // Restore the pending entry. |
901 if (pending_entry_index != -1) { | 914 if (pending_entry_index != -1) { |
902 pending_entry_index_ = pending_entry_index - 1; | 915 pending_entry_index_ = pending_entry_index - 1; |
903 if (pending_entry_index_ != -1) | 916 if (pending_entry_index_ != -1) |
(...skipping 21 matching lines...) Expand all Loading... | |
925 if (pending_entry_index_ != -1) | 938 if (pending_entry_index_ != -1) |
926 pending_entry_index_ = entry_count() - 1; | 939 pending_entry_index_ = entry_count() - 1; |
927 if (transient_entry_index_ != -1) { | 940 if (transient_entry_index_ != -1) { |
928 // There's a transient entry. In this case we want the last committed to | 941 // There's a transient entry. In this case we want the last committed to |
929 // point to the previous entry. | 942 // point to the previous entry. |
930 transient_entry_index_ = entry_count() - 1; | 943 transient_entry_index_ = entry_count() - 1; |
931 if (last_committed_entry_index_ != -1) | 944 if (last_committed_entry_index_ != -1) |
932 last_committed_entry_index_--; | 945 last_committed_entry_index_--; |
933 } | 946 } |
934 | 947 |
935 // Update the history in the RenderView. | 948 tab_contents_->SetHistoryLengthAndPrune(site_instance, |
936 tab_contents_->SetHistoryLengthAndClear(max_source_index); | 949 max_source_index, |
950 minimum_page_id); | |
937 } | 951 } |
938 | 952 |
939 void NavigationController::PruneAllButActive() { | 953 void NavigationController::PruneAllButActive() { |
940 if (transient_entry_index_ != -1) { | 954 if (transient_entry_index_ != -1) { |
941 // There is a transient entry. Prune up to it. | 955 // There is a transient entry. Prune up to it. |
942 DCHECK_EQ(entry_count() - 1, transient_entry_index_); | 956 DCHECK_EQ(entry_count() - 1, transient_entry_index_); |
943 entries_.erase(entries_.begin(), entries_.begin() + transient_entry_index_); | 957 entries_.erase(entries_.begin(), entries_.begin() + transient_entry_index_); |
944 transient_entry_index_ = 0; | 958 transient_entry_index_ = 0; |
945 last_committed_entry_index_ = -1; | 959 last_committed_entry_index_ = -1; |
946 pending_entry_index_ = -1; | 960 pending_entry_index_ = -1; |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1171 size_t insert_index = 0; | 1185 size_t insert_index = 0; |
1172 for (int i = 0; i < max_index; i++) { | 1186 for (int i = 0; i < max_index; i++) { |
1173 // When cloning a tab, copy all entries except interstitial pages | 1187 // When cloning a tab, copy all entries except interstitial pages |
1174 if (source.entries_[i].get()->page_type() != INTERSTITIAL_PAGE) { | 1188 if (source.entries_[i].get()->page_type() != INTERSTITIAL_PAGE) { |
1175 entries_.insert(entries_.begin() + insert_index++, | 1189 entries_.insert(entries_.begin() + insert_index++, |
1176 linked_ptr<NavigationEntry>( | 1190 linked_ptr<NavigationEntry>( |
1177 new NavigationEntry(*source.entries_[i]))); | 1191 new NavigationEntry(*source.entries_[i]))); |
1178 } | 1192 } |
1179 } | 1193 } |
1180 } | 1194 } |
OLD | NEW |