OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 // Take over the session id from source. | 979 // Take over the session id from source. |
980 session_id_ = source->session_id_; | 980 session_id_ = source->session_id_; |
981 | 981 |
982 // Reset source's session id as we're taking it over. We give it a new id in | 982 // Reset source's session id as we're taking it over. We give it a new id in |
983 // case source is added later on, which can happen with instant enabled if the | 983 // case source is added later on, which can happen with instant enabled if the |
984 // tab has a before unload handler. | 984 // tab has a before unload handler. |
985 source->session_id_ = SessionID(); | 985 source->session_id_ = SessionID(); |
986 } | 986 } |
987 | 987 |
988 void NavigationController::PruneAllButActive() { | 988 void NavigationController::PruneAllButActive() { |
989 int prune_count = entry_count(); | |
990 if (transient_entry_index_ != -1) { | 989 if (transient_entry_index_ != -1) { |
991 // There is a transient entry. Prune up to it. | 990 // There is a transient entry. Prune up to it. |
992 DCHECK_EQ(entry_count() - 1, transient_entry_index_); | 991 DCHECK_EQ(entry_count() - 1, transient_entry_index_); |
993 prune_count = transient_entry_index_; | 992 entries_.erase(entries_.begin(), entries_.begin() + transient_entry_index_); |
994 transient_entry_index_ = 0; | 993 transient_entry_index_ = 0; |
995 last_committed_entry_index_ = -1; | 994 last_committed_entry_index_ = -1; |
996 pending_entry_index_ = -1; | 995 pending_entry_index_ = -1; |
997 } else if (!pending_entry_) { | 996 } else if (!pending_entry_) { |
998 // There's no pending entry. Leave the last entry (if there is one). | 997 // There's no pending entry. Leave the last entry (if there is one). |
999 if (!prune_count) | 998 if (!entry_count()) |
1000 return; | 999 return; |
1001 | 1000 |
1002 prune_count--; | 1001 DCHECK(last_committed_entry_index_ >= 0); |
| 1002 entries_.erase(entries_.begin(), |
| 1003 entries_.begin() + last_committed_entry_index_); |
| 1004 entries_.erase(entries_.begin() + 1, entries_.end()); |
1003 last_committed_entry_index_ = 0; | 1005 last_committed_entry_index_ = 0; |
1004 } else if (pending_entry_index_ != -1) { | 1006 } else if (pending_entry_index_ != -1) { |
1005 DCHECK_EQ(pending_entry_index_, prune_count - 1); | 1007 entries_.erase(entries_.begin(), entries_.begin() + pending_entry_index_); |
| 1008 entries_.erase(entries_.begin() + 1, entries_.end()); |
1006 pending_entry_index_ = 0; | 1009 pending_entry_index_ = 0; |
1007 last_committed_entry_index_ = 0; | 1010 last_committed_entry_index_ = 0; |
1008 prune_count--; | |
1009 } else { | 1011 } else { |
1010 // There is a pending_entry, but it's not in entries_. | 1012 // There is a pending_entry, but it's not in entries_. |
1011 pending_entry_index_ = -1; | 1013 pending_entry_index_ = -1; |
1012 last_committed_entry_index_ = -1; | 1014 last_committed_entry_index_ = -1; |
| 1015 entries_.clear(); |
1013 } | 1016 } |
1014 | 1017 |
1015 if (tab_contents_->interstitial_page()) { | 1018 if (tab_contents_->interstitial_page()) { |
1016 // Normally the interstitial page hides itself if the user doesn't proceeed. | 1019 // Normally the interstitial page hides itself if the user doesn't proceeed. |
1017 // This would result in showing a NavigationEntry we just removed. Set this | 1020 // This would result in showing a NavigationEntry we just removed. Set this |
1018 // so the interstitial triggers a reload if the user doesn't proceed. | 1021 // so the interstitial triggers a reload if the user doesn't proceed. |
1019 tab_contents_->interstitial_page()->set_reload_on_dont_proceed(true); | 1022 tab_contents_->interstitial_page()->set_reload_on_dont_proceed(true); |
1020 } | 1023 } |
1021 | |
1022 entries_.erase(entries_.begin(), entries_.begin() + prune_count); | |
1023 } | 1024 } |
1024 | 1025 |
1025 void NavigationController::DiscardNonCommittedEntries() { | 1026 void NavigationController::DiscardNonCommittedEntries() { |
1026 bool transient = transient_entry_index_ != -1; | 1027 bool transient = transient_entry_index_ != -1; |
1027 DiscardNonCommittedEntriesInternal(); | 1028 DiscardNonCommittedEntriesInternal(); |
1028 | 1029 |
1029 // If there was a transient entry, invalidate everything so the new active | 1030 // If there was a transient entry, invalidate everything so the new active |
1030 // entry state is shown. | 1031 // entry state is shown. |
1031 if (transient) { | 1032 if (transient) { |
1032 tab_contents_->NotifyNavigationStateChanged(kInvalidateAllButShelves); | 1033 tab_contents_->NotifyNavigationStateChanged(kInvalidateAllButShelves); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1201 size_t insert_index = 0; | 1202 size_t insert_index = 0; |
1202 for (int i = 0; i < max_index; i++) { | 1203 for (int i = 0; i < max_index; i++) { |
1203 // When cloning a tab, copy all entries except interstitial pages | 1204 // When cloning a tab, copy all entries except interstitial pages |
1204 if (source.entries_[i].get()->page_type() != INTERSTITIAL_PAGE) { | 1205 if (source.entries_[i].get()->page_type() != INTERSTITIAL_PAGE) { |
1205 entries_.insert(entries_.begin() + insert_index++, | 1206 entries_.insert(entries_.begin() + insert_index++, |
1206 linked_ptr<NavigationEntry>( | 1207 linked_ptr<NavigationEntry>( |
1207 new NavigationEntry(*source.entries_[i]))); | 1208 new NavigationEntry(*source.entries_[i]))); |
1208 } | 1209 } |
1209 } | 1210 } |
1210 } | 1211 } |
OLD | NEW |