| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_impl.h" | 5 #include "content/browser/tab_contents/navigation_controller_impl.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_number_conversions.h" // Temporary | 9 #include "base/string_number_conversions.h" // Temporary |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 NavigationEntry* active_entry = GetActiveEntry(); | 405 NavigationEntry* active_entry = GetActiveEntry(); |
| 406 return active_entry && !active_entry->IsViewSourceMode() && | 406 return active_entry && !active_entry->IsViewSourceMode() && |
| 407 is_supported_mime_type && !tab_contents_->GetInterstitialPage(); | 407 is_supported_mime_type && !tab_contents_->GetInterstitialPage(); |
| 408 } | 408 } |
| 409 | 409 |
| 410 int NavigationControllerImpl::GetLastCommittedEntryIndex() const { | 410 int NavigationControllerImpl::GetLastCommittedEntryIndex() const { |
| 411 return last_committed_entry_index_; | 411 return last_committed_entry_index_; |
| 412 } | 412 } |
| 413 | 413 |
| 414 int NavigationControllerImpl::GetEntryCount() const { | 414 int NavigationControllerImpl::GetEntryCount() const { |
| 415 DCHECK(entries_.size() <= max_entry_count()); |
| 415 return static_cast<int>(entries_.size()); | 416 return static_cast<int>(entries_.size()); |
| 416 } | 417 } |
| 417 | 418 |
| 418 NavigationEntry* NavigationControllerImpl::GetEntryAtIndex( | 419 NavigationEntry* NavigationControllerImpl::GetEntryAtIndex( |
| 419 int index) const { | 420 int index) const { |
| 420 return entries_.at(index).get(); | 421 return entries_.at(index).get(); |
| 421 } | 422 } |
| 422 | 423 |
| 423 NavigationEntry* NavigationControllerImpl::GetEntryAtOffset( | 424 NavigationEntry* NavigationControllerImpl::GetEntryAtOffset( |
| 424 int offset) const { | 425 int offset) const { |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1070 DCHECK( | 1071 DCHECK( |
| 1071 (transient_entry_index_ != -1 && | 1072 (transient_entry_index_ != -1 && |
| 1072 transient_entry_index_ == GetEntryCount() - 1) || | 1073 transient_entry_index_ == GetEntryCount() - 1) || |
| 1073 (pending_entry_ && (pending_entry_index_ == -1 || | 1074 (pending_entry_ && (pending_entry_index_ == -1 || |
| 1074 pending_entry_index_ == GetEntryCount() - 1)) || | 1075 pending_entry_index_ == GetEntryCount() - 1)) || |
| 1075 (!pending_entry_ && last_committed_entry_index_ == GetEntryCount() - 1)); | 1076 (!pending_entry_ && last_committed_entry_index_ == GetEntryCount() - 1)); |
| 1076 | 1077 |
| 1077 // Remove all the entries leaving the active entry. | 1078 // Remove all the entries leaving the active entry. |
| 1078 PruneAllButActive(); | 1079 PruneAllButActive(); |
| 1079 | 1080 |
| 1081 // We now have zero or one entries. Ensure that adding the entries from |
| 1082 // source won't put us over the limit. |
| 1083 DCHECK(GetEntryCount() == 0 || GetEntryCount() == 1); |
| 1084 if (GetEntryCount() > 0) |
| 1085 source->PruneOldestEntryIfFull(); |
| 1086 |
| 1080 // Insert the entries from source. Don't use source->GetCurrentEntryIndex as | 1087 // Insert the entries from source. Don't use source->GetCurrentEntryIndex as |
| 1081 // we don't want to copy over the transient entry. | 1088 // we don't want to copy over the transient entry. |
| 1082 int max_source_index = source->pending_entry_index_ != -1 ? | 1089 int max_source_index = source->pending_entry_index_ != -1 ? |
| 1083 source->pending_entry_index_ : source->last_committed_entry_index_; | 1090 source->pending_entry_index_ : source->last_committed_entry_index_; |
| 1084 if (max_source_index == -1) | 1091 if (max_source_index == -1) |
| 1085 max_source_index = source->GetEntryCount(); | 1092 max_source_index = source->GetEntryCount(); |
| 1086 else | 1093 else |
| 1087 max_source_index++; | 1094 max_source_index++; |
| 1088 InsertEntriesFrom(*source, max_source_index); | 1095 InsertEntriesFrom(*source, max_source_index); |
| 1089 | 1096 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1230 int num_pruned = 0; | 1237 int num_pruned = 0; |
| 1231 while (last_committed_entry_index_ < (current_size - 1)) { | 1238 while (last_committed_entry_index_ < (current_size - 1)) { |
| 1232 num_pruned++; | 1239 num_pruned++; |
| 1233 entries_.pop_back(); | 1240 entries_.pop_back(); |
| 1234 current_size--; | 1241 current_size--; |
| 1235 } | 1242 } |
| 1236 if (num_pruned > 0) // Only notify if we did prune something. | 1243 if (num_pruned > 0) // Only notify if we did prune something. |
| 1237 NotifyPrunedEntries(this, false, num_pruned); | 1244 NotifyPrunedEntries(this, false, num_pruned); |
| 1238 } | 1245 } |
| 1239 | 1246 |
| 1240 if (entries_.size() >= max_entry_count()) { | 1247 PruneOldestEntryIfFull(); |
| 1241 DCHECK(last_committed_entry_index_ > 0); | |
| 1242 RemoveEntryAtIndex(0); | |
| 1243 NotifyPrunedEntries(this, true, 1); | |
| 1244 } | |
| 1245 | 1248 |
| 1246 entries_.push_back(linked_ptr<NavigationEntryImpl>(entry)); | 1249 entries_.push_back(linked_ptr<NavigationEntryImpl>(entry)); |
| 1247 last_committed_entry_index_ = static_cast<int>(entries_.size()) - 1; | 1250 last_committed_entry_index_ = static_cast<int>(entries_.size()) - 1; |
| 1248 | 1251 |
| 1249 // This is a new page ID, so we need everybody to know about it. | 1252 // This is a new page ID, so we need everybody to know about it. |
| 1250 tab_contents_->UpdateMaxPageID(entry->GetPageID()); | 1253 tab_contents_->UpdateMaxPageID(entry->GetPageID()); |
| 1251 } | 1254 } |
| 1252 | 1255 |
| 1256 void NavigationControllerImpl::PruneOldestEntryIfFull() { |
| 1257 if (entries_.size() >= max_entry_count()) { |
| 1258 DCHECK_EQ(max_entry_count(), entries_.size()); |
| 1259 DCHECK(last_committed_entry_index_ > 0); |
| 1260 RemoveEntryAtIndex(0); |
| 1261 NotifyPrunedEntries(this, true, 1); |
| 1262 } |
| 1263 } |
| 1264 |
| 1253 void NavigationControllerImpl::NavigateToPendingEntry(ReloadType reload_type) { | 1265 void NavigationControllerImpl::NavigateToPendingEntry(ReloadType reload_type) { |
| 1254 needs_reload_ = false; | 1266 needs_reload_ = false; |
| 1255 | 1267 |
| 1256 // If we were navigating to a slow-to-commit page, and the user performs | 1268 // If we were navigating to a slow-to-commit page, and the user performs |
| 1257 // a session history navigation to the last committed page, RenderViewHost | 1269 // a session history navigation to the last committed page, RenderViewHost |
| 1258 // will force the throbber to start, but WebKit will essentially ignore the | 1270 // will force the throbber to start, but WebKit will essentially ignore the |
| 1259 // navigation, and won't send a message to stop the throbber. To prevent this | 1271 // navigation, and won't send a message to stop the throbber. To prevent this |
| 1260 // from happening, we drop the navigation here and stop the slow-to-commit | 1272 // from happening, we drop the navigation here and stop the slow-to-commit |
| 1261 // page from loading (which would normally happen during the navigation). | 1273 // page from loading (which would normally happen during the navigation). |
| 1262 if (pending_entry_index_ != -1 && | 1274 if (pending_entry_index_ != -1 && |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1414 for (int i = 0; i < max_index; i++) { | 1426 for (int i = 0; i < max_index; i++) { |
| 1415 // When cloning a tab, copy all entries except interstitial pages | 1427 // When cloning a tab, copy all entries except interstitial pages |
| 1416 if (source.entries_[i].get()->GetPageType() != | 1428 if (source.entries_[i].get()->GetPageType() != |
| 1417 content::PAGE_TYPE_INTERSTITIAL) { | 1429 content::PAGE_TYPE_INTERSTITIAL) { |
| 1418 entries_.insert(entries_.begin() + insert_index++, | 1430 entries_.insert(entries_.begin() + insert_index++, |
| 1419 linked_ptr<NavigationEntryImpl>( | 1431 linked_ptr<NavigationEntryImpl>( |
| 1420 new NavigationEntryImpl(*source.entries_[i]))); | 1432 new NavigationEntryImpl(*source.entries_[i]))); |
| 1421 } | 1433 } |
| 1422 } | 1434 } |
| 1423 } | 1435 } |
| OLD | NEW |