summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorcreis@chromium.org <creis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-30 19:01:19 +0000
committercreis@chromium.org <creis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-30 19:01:19 +0000
commit867e1f971f72724f87bfa7c68c8b4742bfaab9ea (patch)
treec5c5670d23d6bf9f9689d997a8d052b84e262ca0 /content
parent1c34932902e6462e70980112ee045907492602c8 (diff)
downloadchromium_src-867e1f971f72724f87bfa7c68c8b4742bfaab9ea.zip
chromium_src-867e1f971f72724f87bfa7c68c8b4742bfaab9ea.tar.gz
chromium_src-867e1f971f72724f87bfa7c68c8b4742bfaab9ea.tar.bz2
Don't update URL bar or SSL icon for pending history navs until they commit.
BUG=89564 TEST=Go back or forward to a slow URL. No omnibox change until it commits. Review URL: http://codereview.chromium.org/7790018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98853 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/tab_contents/navigation_controller.cc9
-rw-r--r--content/browser/tab_contents/navigation_controller.h11
-rw-r--r--content/browser/tab_contents/navigation_controller_unittest.cc9
3 files changed, 27 insertions, 2 deletions
diff --git a/content/browser/tab_contents/navigation_controller.cc b/content/browser/tab_contents/navigation_controller.cc
index 315a4711..85780cd 100644
--- a/content/browser/tab_contents/navigation_controller.cc
+++ b/content/browser/tab_contents/navigation_controller.cc
@@ -285,6 +285,15 @@ NavigationEntry* NavigationController::GetActiveEntry() const {
return GetLastCommittedEntry();
}
+NavigationEntry* NavigationController::GetVisibleEntry() const {
+ if (transient_entry_index_ != -1)
+ return entries_[transient_entry_index_].get();
+ // Only return pending_entry for new navigations.
+ if (pending_entry_ && pending_entry_->page_id() == -1)
+ return pending_entry_;
+ return GetLastCommittedEntry();
+}
+
int NavigationController::GetCurrentEntryIndex() const {
if (transient_entry_index_ != -1)
return transient_entry_index_;
diff --git a/content/browser/tab_contents/navigation_controller.h b/content/browser/tab_contents/navigation_controller.h
index a01262d..c7d9d03 100644
--- a/content/browser/tab_contents/navigation_controller.h
+++ b/content/browser/tab_contents/navigation_controller.h
@@ -78,9 +78,18 @@ class NavigationController {
// NOTE: This can be NULL!!
//
// If you are trying to get the current state of the NavigationController,
- // this is the method you will typically want to call.
+ // this is the method you will typically want to call. If you want to display
+ // the active entry to the user (e.g., in the location bar), use
+ // GetVisibleEntry instead.
NavigationEntry* GetActiveEntry() const;
+ // Returns the same entry as GetActiveEntry, except that it ignores pending
+ // history navigation entries. This should be used when displaying info to
+ // the user, so that the location bar and other indicators do not update for
+ // a back/forward navigation until the pending entry commits. This approach
+ // guards against URL spoofs on slow history navigations.
+ NavigationEntry* GetVisibleEntry() const;
+
// Returns the index from which we would go back/forward or reload. This is
// the last_committed_entry_index_ if pending_entry_index_ is -1. Otherwise,
// it is the pending_entry_index_.
diff --git a/content/browser/tab_contents/navigation_controller_unittest.cc b/content/browser/tab_contents/navigation_controller_unittest.cc
index 4e1ec10..0830650 100644
--- a/content/browser/tab_contents/navigation_controller_unittest.cc
+++ b/content/browser/tab_contents/navigation_controller_unittest.cc
@@ -1724,7 +1724,10 @@ TEST_F(NavigationControllerTest, TransientEntry) {
controller().GoToIndex(1);
// The navigation should have been initiated, transient entry should be gone.
EXPECT_EQ(url1, controller().GetActiveEntry()->url());
+ // Visible entry does not update for history navigations until commit.
+ EXPECT_EQ(url3, controller().GetVisibleEntry()->url());
rvh()->SendNavigate(1, url1);
+ EXPECT_EQ(url1, controller().GetVisibleEntry()->url());
// Add a transient and go to an entry after the current one.
transient_entry = new NavigationEntry;
@@ -1734,9 +1737,11 @@ TEST_F(NavigationControllerTest, TransientEntry) {
controller().GoToIndex(3);
// The navigation should have been initiated, transient entry should be gone.
// Because of the transient entry that is removed, going to index 3 makes us
- // land on url2.
+ // land on url2 (which is visible after the commit).
EXPECT_EQ(url2, controller().GetActiveEntry()->url());
+ EXPECT_EQ(url1, controller().GetVisibleEntry()->url());
rvh()->SendNavigate(2, url2);
+ EXPECT_EQ(url2, controller().GetVisibleEntry()->url());
// Add a transient and go forward.
transient_entry = new NavigationEntry;
@@ -1747,7 +1752,9 @@ TEST_F(NavigationControllerTest, TransientEntry) {
controller().GoForward();
// We should have navigated, transient entry should be gone.
EXPECT_EQ(url3, controller().GetActiveEntry()->url());
+ EXPECT_EQ(url2, controller().GetVisibleEntry()->url());
rvh()->SendNavigate(3, url3);
+ EXPECT_EQ(url3, controller().GetVisibleEntry()->url());
// Ensure the URLS are correct.
EXPECT_EQ(controller().entry_count(), 5);