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 and |remove_first_entry| is true, |
| 903 // it needs to be pruned. This is accomplished by specifying a larger |
| 904 // |minimum_page_id| than the committed entry's page_id in the |
| 905 // ViewMsg_SetHistoryLengthAndPrune message. However, any pages which are |
| 906 // committed between now and when the RenderView handles the message will |
| 907 // need to be retained. Both constraints can be met by incrementing the |
| 908 // |minimum_page_id| by 1. |
| 909 DCHECK(minimum_page_id >= 0); |
| 910 if (entry_count() == 1) |
| 911 ++minimum_page_id; |
894 // Save then restore the pending entry (RemoveEntryAtIndexInternal chucks | 912 // Save then restore the pending entry (RemoveEntryAtIndexInternal chucks |
895 // the pending entry). | 913 // the pending entry). |
896 NavigationEntry* pending_entry = pending_entry_; | 914 NavigationEntry* pending_entry = pending_entry_; |
897 pending_entry_ = NULL; | 915 pending_entry_ = NULL; |
898 int pending_entry_index = pending_entry_index_; | 916 int pending_entry_index = pending_entry_index_; |
899 RemoveEntryAtIndexInternal(0); | 917 RemoveEntryAtIndexInternal(0); |
900 // Restore the pending entry. | 918 // Restore the pending entry. |
901 if (pending_entry_index != -1) { | 919 if (pending_entry_index != -1) { |
902 pending_entry_index_ = pending_entry_index - 1; | 920 pending_entry_index_ = pending_entry_index - 1; |
903 if (pending_entry_index_ != -1) | 921 if (pending_entry_index_ != -1) |
(...skipping 21 matching lines...) Expand all Loading... |
925 if (pending_entry_index_ != -1) | 943 if (pending_entry_index_ != -1) |
926 pending_entry_index_ = entry_count() - 1; | 944 pending_entry_index_ = entry_count() - 1; |
927 if (transient_entry_index_ != -1) { | 945 if (transient_entry_index_ != -1) { |
928 // There's a transient entry. In this case we want the last committed to | 946 // There's a transient entry. In this case we want the last committed to |
929 // point to the previous entry. | 947 // point to the previous entry. |
930 transient_entry_index_ = entry_count() - 1; | 948 transient_entry_index_ = entry_count() - 1; |
931 if (last_committed_entry_index_ != -1) | 949 if (last_committed_entry_index_ != -1) |
932 last_committed_entry_index_--; | 950 last_committed_entry_index_--; |
933 } | 951 } |
934 | 952 |
935 // Update the history in the RenderView. | 953 tab_contents_->SetHistoryLengthAndPrune(site_instance, |
936 tab_contents_->SetHistoryLengthAndClear(max_source_index); | 954 max_source_index, |
| 955 minimum_page_id); |
937 } | 956 } |
938 | 957 |
939 void NavigationController::PruneAllButActive() { | 958 void NavigationController::PruneAllButActive() { |
940 if (transient_entry_index_ != -1) { | 959 if (transient_entry_index_ != -1) { |
941 // There is a transient entry. Prune up to it. | 960 // There is a transient entry. Prune up to it. |
942 DCHECK_EQ(entry_count() - 1, transient_entry_index_); | 961 DCHECK_EQ(entry_count() - 1, transient_entry_index_); |
943 entries_.erase(entries_.begin(), entries_.begin() + transient_entry_index_); | 962 entries_.erase(entries_.begin(), entries_.begin() + transient_entry_index_); |
944 transient_entry_index_ = 0; | 963 transient_entry_index_ = 0; |
945 last_committed_entry_index_ = -1; | 964 last_committed_entry_index_ = -1; |
946 pending_entry_index_ = -1; | 965 pending_entry_index_ = -1; |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1171 size_t insert_index = 0; | 1190 size_t insert_index = 0; |
1172 for (int i = 0; i < max_index; i++) { | 1191 for (int i = 0; i < max_index; i++) { |
1173 // When cloning a tab, copy all entries except interstitial pages | 1192 // When cloning a tab, copy all entries except interstitial pages |
1174 if (source.entries_[i].get()->page_type() != INTERSTITIAL_PAGE) { | 1193 if (source.entries_[i].get()->page_type() != INTERSTITIAL_PAGE) { |
1175 entries_.insert(entries_.begin() + insert_index++, | 1194 entries_.insert(entries_.begin() + insert_index++, |
1176 linked_ptr<NavigationEntry>( | 1195 linked_ptr<NavigationEntry>( |
1177 new NavigationEntry(*source.entries_[i]))); | 1196 new NavigationEntry(*source.entries_[i]))); |
1178 } | 1197 } |
1179 } | 1198 } |
1180 } | 1199 } |
OLD | NEW |