diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-04 23:26:47 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-04 23:26:47 +0000 |
commit | b6ea741a64dc5cddcfe735d15e68718b0f377363 (patch) | |
tree | 812a7b0874583f68fe7a2c6c07f0bc8eaa0ab027 /chrome/browser | |
parent | 274a2a86145f82814f0a0652a2c255469e256d06 (diff) | |
download | chromium_src-b6ea741a64dc5cddcfe735d15e68718b0f377363.zip chromium_src-b6ea741a64dc5cddcfe735d15e68718b0f377363.tar.gz chromium_src-b6ea741a64dc5cddcfe735d15e68718b0f377363.tar.bz2 |
Lands http://codereview.chromium.org/1744011/show for Hans:
Make reopened tabs with "about:" URLs display properly.
- Rename TabNavigation::url_ to virtual_url_.
Make it more explicit that a TabNavigation stores the *virtual* URL of
a
NavigationEntry.
- Translate virtual URLs when restoring tabs.
Instead of putting the virtual URL in the URL proper field when
creating a
NavigationEntry from a TabNavigation, put it in the virtual URL field,
and
then translate this to a proper URL in
NavigationController::CreateNavigationEntriesFromTabNavigations().
This fixes bug 31905.
Contributed by Hans Wennborg <hans@chromium.org>
BUG=31905
TEST=ui_tests --gtest_filter=TabRestoreUITest.RestoreTabWithSpecialURL*
Review URL: http://codereview.chromium.org/1946002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46406 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/cocoa/history_menu_bridge.mm | 4 | ||||
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui.cc | 4 | ||||
-rw-r--r-- | chrome/browser/jumplist.cc | 4 | ||||
-rw-r--r-- | chrome/browser/sessions/base_session_service.cc | 4 | ||||
-rw-r--r-- | chrome/browser/sessions/session_service_test_helper.cc | 2 | ||||
-rw-r--r-- | chrome/browser/sessions/session_service_unittest.cc | 19 | ||||
-rw-r--r-- | chrome/browser/sessions/session_types.cc | 22 | ||||
-rw-r--r-- | chrome/browser/sessions/session_types.h | 14 | ||||
-rw-r--r-- | chrome/browser/sessions/tab_restore_service.cc | 3 | ||||
-rw-r--r-- | chrome/browser/sessions/tab_restore_service_unittest.cc | 45 | ||||
-rw-r--r-- | chrome/browser/tab_contents/navigation_controller.cc | 87 | ||||
-rw-r--r-- | chrome/browser/tab_contents/navigation_controller.h | 17 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 2 | ||||
-rw-r--r-- | chrome/browser/tab_restore_uitest.cc | 68 |
14 files changed, 192 insertions, 103 deletions
diff --git a/chrome/browser/cocoa/history_menu_bridge.mm b/chrome/browser/cocoa/history_menu_bridge.mm index 342dca4..76daaab 100644 --- a/chrome/browser/cocoa/history_menu_bridge.mm +++ b/chrome/browser/cocoa/history_menu_bridge.mm @@ -344,12 +344,12 @@ bool HistoryMenuBridge::AddNavigationForTab( const TabNavigation& current_navigation = entry.navigations.at(entry.current_navigation_index); - if (current_navigation.url() == GURL(chrome::kChromeUINewTabURL)) + if (current_navigation.virtual_url() == GURL(chrome::kChromeUINewTabURL)) return false; HistoryItem* item = new HistoryItem(); item->title = current_navigation.title(); - item->url = current_navigation.url(); + item->url = current_navigation.virtual_url(); closed_results_.push_back(item); // ScopedVector takes ownership. // Tab navigations don't come with icons, so we always have to request them. diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc index 8ef66a3..39a2289 100644 --- a/chrome/browser/dom_ui/new_tab_ui.cc +++ b/chrome/browser/dom_ui/new_tab_ui.cc @@ -302,11 +302,11 @@ bool RecentlyClosedTabsHandler::TabToValue( const TabNavigation& current_navigation = tab.navigations.at(tab.current_navigation_index); - if (current_navigation.url() == GURL(chrome::kChromeUINewTabURL)) + if (current_navigation.virtual_url() == GURL(chrome::kChromeUINewTabURL)) return false; NewTabUI::SetURLTitleAndDirection(dictionary, current_navigation.title(), - current_navigation.url()); + current_navigation.virtual_url()); dictionary->SetString(L"type", L"tab"); dictionary->SetReal(L"timestamp", tab.timestamp.ToDoubleT()); return true; diff --git a/chrome/browser/jumplist.cc b/chrome/browser/jumplist.cc index 41b257c..bb9e506 100644 --- a/chrome/browser/jumplist.cc +++ b/chrome/browser/jumplist.cc @@ -644,11 +644,11 @@ bool JumpList::AddTab(const TabRestoreService::Tab* tab, const TabNavigation& current_navigation = tab->navigations.at(tab->current_navigation_index); - if (current_navigation.url() == GURL(chrome::kChromeUINewTabURL)) + if (current_navigation.virtual_url() == GURL(chrome::kChromeUINewTabURL)) return false; scoped_refptr<ShellLinkItem> link(new ShellLinkItem); - std::string url = current_navigation.url().spec(); + std::string url = current_navigation.virtual_url().spec(); link->SetArguments(UTF8ToWide(url)); link->SetTitle(current_navigation.title()); list->push_back(link); diff --git a/chrome/browser/sessions/base_session_service.cc b/chrome/browser/sessions/base_session_service.cc index acd685b..45479a9 100644 --- a/chrome/browser/sessions/base_session_service.cc +++ b/chrome/browser/sessions/base_session_service.cc @@ -229,7 +229,7 @@ bool BaseSessionService::RestoreUpdateTabNavigationCommand( navigation->referrer_ = GURL(referrer_spec); } - navigation->url_ = GURL(url_spec); + navigation->virtual_url_ = GURL(url_spec); return true; } @@ -251,7 +251,7 @@ bool BaseSessionService::ShouldTrackEntry(const NavigationEntry& entry) { } bool BaseSessionService::ShouldTrackEntry(const TabNavigation& navigation) { - return navigation.url().is_valid(); + return navigation.virtual_url().is_valid(); } BaseSessionService::Handle BaseSessionService::ScheduleGetLastSessionCommands( diff --git a/chrome/browser/sessions/session_service_test_helper.cc b/chrome/browser/sessions/session_service_test_helper.cc index 7703bc8..a36562d 100644 --- a/chrome/browser/sessions/session_service_test_helper.cc +++ b/chrome/browser/sessions/session_service_test_helper.cc @@ -69,7 +69,7 @@ void SessionServiceTestHelper::AssertTabEquals( void SessionServiceTestHelper::AssertNavigationEquals( const TabNavigation& expected, const TabNavigation& actual) { - EXPECT_TRUE(expected.url() == actual.url()); + EXPECT_TRUE(expected.virtual_url() == actual.virtual_url()); EXPECT_EQ(expected.referrer(), actual.referrer()); EXPECT_EQ(expected.title(), actual.title()); EXPECT_EQ(expected.state(), actual.state()); diff --git a/chrome/browser/sessions/session_service_unittest.cc b/chrome/browser/sessions/session_service_unittest.cc index 3a32b55..3a4e905 100644 --- a/chrome/browser/sessions/session_service_unittest.cc +++ b/chrome/browser/sessions/session_service_unittest.cc @@ -53,7 +53,7 @@ class SessionServiceTest : public BrowserWithTestWindowTest { int index, bool select) { NavigationEntry entry; - entry.set_url(navigation.url()); + entry.set_url(navigation.virtual_url()); entry.set_referrer(navigation.referrer()); entry.set_title(navigation.title()); entry.set_content_state(navigation.state()); @@ -520,9 +520,12 @@ TEST_F(SessionServiceTest, PruneFromFront) { SessionTab* tab = windows[0]->tabs[0]; ASSERT_EQ(1, tab->current_navigation_index); EXPECT_EQ(3U, tab->navigations.size()); - EXPECT_TRUE(GURL(base_url + IntToString(2)) == tab->navigations[0].url()); - EXPECT_TRUE(GURL(base_url + IntToString(3)) == tab->navigations[1].url()); - EXPECT_TRUE(GURL(base_url + IntToString(4)) == tab->navigations[2].url()); + EXPECT_TRUE(GURL(base_url + IntToString(2)) == + tab->navigations[0].virtual_url()); + EXPECT_TRUE(GURL(base_url + IntToString(3)) == + tab->navigations[1].virtual_url()); + EXPECT_TRUE(GURL(base_url + IntToString(4)) == + tab->navigations[2].virtual_url()); } // Prunes from front so that we have no entries. @@ -592,14 +595,14 @@ class GetCurrentSessionCallbackHandler { EXPECT_EQ(2U, (*windows)[0]->tabs.size()); EXPECT_EQ(2U, (*windows)[0]->tabs[0]->navigations.size()); EXPECT_EQ(GURL("http://bar/1"), - (*windows)[0]->tabs[0]->navigations[0].url()); + (*windows)[0]->tabs[0]->navigations[0].virtual_url()); EXPECT_EQ(GURL("http://bar/2"), - (*windows)[0]->tabs[0]->navigations[1].url()); + (*windows)[0]->tabs[0]->navigations[1].virtual_url()); EXPECT_EQ(2U, (*windows)[0]->tabs[1]->navigations.size()); EXPECT_EQ(GURL("http://foo/1"), - (*windows)[0]->tabs[1]->navigations[0].url()); + (*windows)[0]->tabs[1]->navigations[0].virtual_url()); EXPECT_EQ(GURL("http://foo/2"), - (*windows)[0]->tabs[1]->navigations[1].url()); + (*windows)[0]->tabs[1]->navigations[1].virtual_url()); } }; diff --git a/chrome/browser/sessions/session_types.cc b/chrome/browser/sessions/session_types.cc index 852fe8b..27caf057 100644 --- a/chrome/browser/sessions/session_types.cc +++ b/chrome/browser/sessions/session_types.cc @@ -5,30 +5,32 @@ #include "chrome/browser/sessions/session_types.h" #include "base/string_util.h" +#include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/browser/tab_contents/navigation_entry.h" // TabNavigation -------------------------------------------------------------- // static -NavigationEntry* TabNavigation::ToNavigationEntry(int page_id) const { - NavigationEntry* entry = new NavigationEntry( - NULL, // The site instance for restored tabs is sent on navigation - // (TabContents::GetSiteInstanceForEntry). - page_id, - url_, +NavigationEntry* TabNavigation::ToNavigationEntry(int page_id, + Profile *profile) const { + NavigationEntry* entry = NavigationController::CreateNavigationEntry( + virtual_url_, referrer_, - title_, // Use a transition type of reload so that we don't incorrectly // increase the typed count. - PageTransition::RELOAD); - entry->set_virtual_url(url_); + PageTransition::RELOAD, + profile); + + entry->set_page_id(page_id); + entry->set_title(title_); entry->set_content_state(state_); entry->set_has_post_data(type_mask_ & TabNavigation::HAS_POST_DATA); + return entry; } void TabNavigation::SetFromNavigationEntry(const NavigationEntry& entry) { - url_ = entry.virtual_url(); + virtual_url_ = entry.virtual_url(); referrer_ = entry.referrer(); title_ = entry.title(); state_ = entry.content_state(); diff --git a/chrome/browser/sessions/session_types.h b/chrome/browser/sessions/session_types.h index 0d31d15..b6f1dbc 100644 --- a/chrome/browser/sessions/session_types.h +++ b/chrome/browser/sessions/session_types.h @@ -37,12 +37,12 @@ class TabNavigation { } TabNavigation(int index, - const GURL& url, + const GURL& virtual_url, const GURL& referrer, const string16& title, const std::string& state, PageTransition::Type transition) - : url_(url), + : virtual_url_(virtual_url), referrer_(referrer), title_(title), state_(state), @@ -52,14 +52,14 @@ class TabNavigation { // Converts this TabNavigation into a NavigationEntry with a page id of // |page_id|. The caller owns the returned NavigationEntry. - NavigationEntry* ToNavigationEntry(int page_id) const; + NavigationEntry* ToNavigationEntry(int page_id, Profile* profile) const; // Resets this TabNavigation from |entry|. void SetFromNavigationEntry(const NavigationEntry& entry); - // URL of the page. - void set_url(const GURL& url) { url_ = url; } - const GURL& url() const { return url_; } + // Virtual URL of the page. See NavigationEntry::virtual_url() for details. + void set_virtual_url(const GURL& url) { virtual_url_ = url; } + const GURL& virtual_url() const { return virtual_url_; } // The referrer. const GURL& referrer() const { return referrer_; } @@ -92,7 +92,7 @@ class TabNavigation { private: friend class BaseSessionService; - GURL url_; + GURL virtual_url_; GURL referrer_; string16 title_; std::string state_; diff --git a/chrome/browser/sessions/tab_restore_service.cc b/chrome/browser/sessions/tab_restore_service.cc index 47fe4e1..4dea440 100644 --- a/chrome/browser/sessions/tab_restore_service.cc +++ b/chrome/browser/sessions/tab_restore_service.cc @@ -534,7 +534,7 @@ void TabRestoreService::ScheduleCommandsForTab(const Tab& tab, // this, but it simplifies the code and makes it less error prone as we // add new data to NavigationEntry. scoped_ptr<NavigationEntry> entry( - navigations[i].ToNavigationEntry(wrote_count)); + navigations[i].ToNavigationEntry(wrote_count, profile())); ScheduleCommand( CreateUpdateTabNavigationCommand(kCommandUpdateTabNavigation, tab.id, wrote_count++, *entry)); @@ -947,4 +947,3 @@ void TabRestoreService::LoadStateChanged() { Time TabRestoreService::TimeNow() const { return time_factory_ ? time_factory_->TimeNow() : Time::Now(); } - diff --git a/chrome/browser/sessions/tab_restore_service_unittest.cc b/chrome/browser/sessions/tab_restore_service_unittest.cc index 044dfdd..4af768d 100644 --- a/chrome/browser/sessions/tab_restore_service_unittest.cc +++ b/chrome/browser/sessions/tab_restore_service_unittest.cc @@ -129,9 +129,9 @@ TEST_F(TabRestoreServiceTest, Basic) { EXPECT_FALSE(tab->pinned); EXPECT_TRUE(tab->app_extension_id.empty()); ASSERT_EQ(3U, tab->navigations.size()); - EXPECT_TRUE(url1_ == tab->navigations[0].url()); - EXPECT_TRUE(url2_ == tab->navigations[1].url()); - EXPECT_TRUE(url3_ == tab->navigations[2].url()); + EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url()); + EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url()); + EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url()); EXPECT_EQ(2, tab->current_navigation_index); EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(), tab->timestamp.ToInternalValue()); @@ -150,9 +150,9 @@ TEST_F(TabRestoreServiceTest, Basic) { tab = static_cast<TabRestoreService::Tab*>(entry); EXPECT_FALSE(tab->pinned); ASSERT_EQ(3U, tab->navigations.size()); - EXPECT_TRUE(url1_ == tab->navigations[0].url()); - EXPECT_TRUE(url2_ == tab->navigations[1].url()); - EXPECT_TRUE(url3_ == tab->navigations[2].url()); + EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url()); + EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url()); + EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url()); EXPECT_EQ(1, tab->current_navigation_index); EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(), tab->timestamp.ToInternalValue()); @@ -184,9 +184,9 @@ TEST_F(TabRestoreServiceTest, Restore) { TabRestoreService::Tab* tab = static_cast<TabRestoreService::Tab*>(entry); EXPECT_FALSE(tab->pinned); ASSERT_EQ(3U, tab->navigations.size()); - EXPECT_TRUE(url1_ == tab->navigations[0].url()); - EXPECT_TRUE(url2_ == tab->navigations[1].url()); - EXPECT_TRUE(url3_ == tab->navigations[2].url()); + EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url()); + EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url()); + EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url()); EXPECT_EQ(2, tab->current_navigation_index); EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(), tab->timestamp.ToInternalValue()); @@ -223,9 +223,9 @@ TEST_F(TabRestoreServiceTest, RestorePinnedAndApp) { tab = static_cast<TabRestoreService::Tab*>(entry); EXPECT_TRUE(tab->pinned); ASSERT_EQ(3U, tab->navigations.size()); - EXPECT_TRUE(url1_ == tab->navigations[0].url()); - EXPECT_TRUE(url2_ == tab->navigations[1].url()); - EXPECT_TRUE(url3_ == tab->navigations[2].url()); + EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url()); + EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url()); + EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url()); EXPECT_EQ(2, tab->current_navigation_index); EXPECT_TRUE(app_extension_id == tab->app_extension_id); } @@ -297,7 +297,7 @@ TEST_F(TabRestoreServiceTest, LoadPreviousSession) { ASSERT_EQ(1U, window->tabs[0].navigations.size()); EXPECT_EQ(0, window->tabs[0].current_navigation_index); EXPECT_EQ(0, window->tabs[0].timestamp.ToInternalValue()); - EXPECT_TRUE(url1_ == window->tabs[0].navigations[0].url()); + EXPECT_TRUE(url1_ == window->tabs[0].navigations[0].virtual_url()); } // Makes sure we don't attempt to load previous sessions after a restore. @@ -352,7 +352,7 @@ TEST_F(TabRestoreServiceTest, LoadPreviousSessionAndTabs) { ASSERT_EQ(1U, window->tabs[0].navigations.size()); EXPECT_EQ(0, window->tabs[0].current_navigation_index); EXPECT_EQ(0, window->tabs[0].timestamp.ToInternalValue()); - EXPECT_TRUE(url1_ == window->tabs[0].navigations[0].url()); + EXPECT_TRUE(url1_ == window->tabs[0].navigations[0].virtual_url()); // Then the closed tab. entry = *(++service_->entries().begin()); @@ -363,9 +363,9 @@ TEST_F(TabRestoreServiceTest, LoadPreviousSessionAndTabs) { EXPECT_EQ(2, tab->current_navigation_index); EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(), tab->timestamp.ToInternalValue()); - EXPECT_TRUE(url1_ == tab->navigations[0].url()); - EXPECT_TRUE(url2_ == tab->navigations[1].url()); - EXPECT_TRUE(url3_ == tab->navigations[2].url()); + EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url()); + EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url()); + EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url()); } // Make sure pinned state is correctly loaded from session service. @@ -393,7 +393,7 @@ TEST_F(TabRestoreServiceTest, LoadPreviousSessionAndTabsPinned) { EXPECT_TRUE(window->tabs[0].pinned); ASSERT_EQ(1U, window->tabs[0].navigations.size()); EXPECT_EQ(0, window->tabs[0].current_navigation_index); - EXPECT_TRUE(url1_ == window->tabs[0].navigations[0].url()); + EXPECT_TRUE(url1_ == window->tabs[0].navigations[0].virtual_url()); // Then the closed tab. entry = *(++service_->entries().begin()); @@ -402,9 +402,9 @@ TEST_F(TabRestoreServiceTest, LoadPreviousSessionAndTabsPinned) { ASSERT_FALSE(tab->pinned); ASSERT_EQ(3U, tab->navigations.size()); EXPECT_EQ(2, tab->current_navigation_index); - EXPECT_TRUE(url1_ == tab->navigations[0].url()); - EXPECT_TRUE(url2_ == tab->navigations[1].url()); - EXPECT_TRUE(url3_ == tab->navigations[2].url()); + EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url()); + EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url()); + EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url()); } // Creates TabRestoreService::kMaxEntries + 1 windows in the session service @@ -438,7 +438,7 @@ TEST_F(TabRestoreServiceTest, ManyWindowsInSessionService) { ASSERT_EQ(1U, window->tabs[0].navigations.size()); EXPECT_EQ(0, window->tabs[0].current_navigation_index); EXPECT_EQ(0, window->tabs[0].timestamp.ToInternalValue()); - EXPECT_TRUE(url1_ == window->tabs[0].navigations[0].url()); + EXPECT_TRUE(url1_ == window->tabs[0].navigations[0].virtual_url()); } // Makes sure we restore the time stamp correctly. @@ -475,4 +475,3 @@ TEST_F(TabRestoreServiceTest, TimestampSurvivesRestore) { EXPECT_EQ(tab_timestamp.ToInternalValue(), restored_tab->timestamp.ToInternalValue()); } - diff --git a/chrome/browser/tab_contents/navigation_controller.cc b/chrome/browser/tab_contents/navigation_controller.cc index c036c31..e01058f 100644 --- a/chrome/browser/tab_contents/navigation_controller.cc +++ b/chrome/browser/tab_contents/navigation_controller.cc @@ -121,20 +121,6 @@ size_t NavigationController::max_entry_count_ = // static bool NavigationController::check_for_repost_ = true; -// Creates a new NavigationEntry for each TabNavigation in navigations, adding -// the NavigationEntry to entries. This is used during session restore. -static void CreateNavigationEntriesFromTabNavigations( - const std::vector<TabNavigation>& navigations, - std::vector<linked_ptr<NavigationEntry> >* entries) { - // Create a NavigationEntry for each of the navigations. - int page_id = 0; - for (std::vector<TabNavigation>::const_iterator i = - navigations.begin(); i != navigations.end(); ++i, ++page_id) { - entries->push_back( - linked_ptr<NavigationEntry>(i->ToNavigationEntry(page_id))); - } -} - NavigationController::NavigationController(TabContents* contents, Profile* profile) : profile_(profile), @@ -244,6 +230,39 @@ bool NavigationController::IsInitialNavigation() { return last_document_loaded_.is_null(); } +// static +NavigationEntry* NavigationController::CreateNavigationEntry( + const GURL& url, const GURL& referrer, PageTransition::Type transition, + Profile* profile) { + // Allow the browser URL handler to rewrite the URL. This will, for example, + // remove "view-source:" from the beginning of the URL to get the URL that + // will actually be loaded. This real URL won't be shown to the user, just + // used internally. + GURL loaded_url(url); + bool reverse_on_redirect = false; + BrowserURLHandler::RewriteURLIfNecessary( + &loaded_url, profile, &reverse_on_redirect); + + NavigationEntry* entry = new NavigationEntry( + NULL, // The site instance for tabs is sent on navigation + // (TabContents::GetSiteInstance). + -1, + loaded_url, + referrer, + string16(), + transition); + entry->set_virtual_url(url); + entry->set_user_typed_url(url); + entry->set_update_virtual_url_with_url(reverse_on_redirect); + if (url.SchemeIsFile()) { + std::wstring languages = profile->GetPrefs()->GetString( + prefs::kAcceptLanguages); + entry->set_title(WideToUTF16Hack( + file_util::GetFilenameFromPath(net::FormatUrl(url, languages)))); + } + return entry; +} + NavigationEntry* NavigationController::GetEntryWithPageID( SiteInstance* instance, int32 page_id) const { int index = GetEntryIndexWithPageID(instance, page_id); @@ -442,31 +461,6 @@ void NavigationController::RemoveEntryAtIndex(int index, } } -NavigationEntry* NavigationController::CreateNavigationEntry( - const GURL& url, const GURL& referrer, PageTransition::Type transition) { - // Allow the browser URL handler to rewrite the URL. This will, for example, - // remove "view-source:" from the beginning of the URL to get the URL that - // will actually be loaded. This real URL won't be shown to the user, just - // used internally. - GURL loaded_url(url); - bool reverse_on_redirect = false; - BrowserURLHandler::RewriteURLIfNecessary( - &loaded_url, profile_, &reverse_on_redirect); - - NavigationEntry* entry = new NavigationEntry(NULL, -1, loaded_url, referrer, - string16(), transition); - entry->set_virtual_url(url); - entry->set_user_typed_url(url); - entry->set_update_virtual_url_with_url(reverse_on_redirect); - if (url.SchemeIsFile()) { - std::wstring languages = profile()->GetPrefs()->GetString( - prefs::kAcceptLanguages); - entry->set_title(WideToUTF16Hack( - file_util::GetFilenameFromPath(net::FormatUrl(url, languages)))); - } - return entry; -} - void NavigationController::UpdateVirtualURLToURL( NavigationEntry* entry, const GURL& new_url) { GURL new_virtual_url(new_url); @@ -492,7 +486,8 @@ void NavigationController::LoadURL(const GURL& url, const GURL& referrer, // The user initiated a load, we don't need to reload anymore. needs_reload_ = false; - NavigationEntry* entry = CreateNavigationEntry(url, referrer, transition); + NavigationEntry* entry = CreateNavigationEntry(url, referrer, transition, + profile_); LoadEntry(entry); } @@ -701,6 +696,18 @@ bool NavigationController::IsLikelyAutoNavigation(base::TimeTicks now) { (now - last_document_loaded_) < kMaxAutoNavigationTimeDelta; } +void NavigationController::CreateNavigationEntriesFromTabNavigations( + const std::vector<TabNavigation>& navigations, + std::vector<linked_ptr<NavigationEntry> >* entries) { + // Create a NavigationEntry for each of the navigations. + int page_id = 0; + for (std::vector<TabNavigation>::const_iterator i = + navigations.begin(); i != navigations.end(); ++i, ++page_id) { + linked_ptr<NavigationEntry> entry(i->ToNavigationEntry(page_id, profile_)); + entries->push_back(entry); + } +} + void NavigationController::RendererDidNavigateToNewPage( const ViewHostMsg_FrameNavigate_Params& params, bool* did_replace_entry) { NavigationEntry* new_entry; diff --git a/chrome/browser/tab_contents/navigation_controller.h b/chrome/browser/tab_contents/navigation_controller.h index dbbe8e8..71edcfc 100644 --- a/chrome/browser/tab_contents/navigation_controller.h +++ b/chrome/browser/tab_contents/navigation_controller.h @@ -410,6 +410,14 @@ class NavigationController { // Returns true if we are navigating to the URL the tab is opened with. bool IsInitialNavigation(); + // Creates navigation entry and translates the virtual url to a real one. + // Used when restoring a tab from a TabNavigation object and when navigating + // to a new URL using LoadURL. + static NavigationEntry* CreateNavigationEntry(const GURL& url, + const GURL& referrer, + PageTransition::Type transition, + Profile* profile); + private: class RestoreHelper; friend class RestoreHelper; @@ -467,9 +475,6 @@ class NavigationController { // was restored from a previous session. void set_max_restored_page_id(int max_id) { max_restored_page_id_ = max_id; } - NavigationEntry* CreateNavigationEntry(const GURL& url, const GURL& referrer, - PageTransition::Type transition); - // Updates the virtual URL of an entry to match a new URL, for cases where // the real renderer URL is derived from the virtual URL, like view-source: void UpdateVirtualURLToURL(NavigationEntry* entry, const GURL& new_url); @@ -496,6 +501,12 @@ class NavigationController { // user-initiated. bool IsLikelyAutoNavigation(base::TimeTicks now); + // Creates a new NavigationEntry for each TabNavigation in navigations, adding + // the NavigationEntry to entries. This is used during session restore. + void CreateNavigationEntriesFromTabNavigations( + const std::vector<TabNavigation>& navigations, + std::vector<linked_ptr<NavigationEntry> >* entries); + // --------------------------------------------------------------------------- // The user profile associated with this controller diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 4574361..c705ec6 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -1350,7 +1350,7 @@ TabContents* TabContents::CloneAndMakePhantom() { NavigationEntry* entry = controller().GetActiveEntry(); if (app_extension_) - tab_nav.set_url(app_extension_->GetFullLaunchURL()); + tab_nav.set_virtual_url(app_extension_->GetFullLaunchURL()); else if (entry) tab_nav.SetFromNavigationEntry(*entry); diff --git a/chrome/browser/tab_restore_uitest.cc b/chrome/browser/tab_restore_uitest.cc index ec92c36..4939c8c 100644 --- a/chrome/browser/tab_restore_uitest.cc +++ b/chrome/browser/tab_restore_uitest.cc @@ -12,6 +12,7 @@ #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" +#include "chrome/common/url_constants.h" #include "chrome/test/automation/tab_proxy.h" #include "chrome/test/automation/browser_proxy.h" #include "chrome/test/automation/window_proxy.h" @@ -609,3 +610,70 @@ TEST_F(TabRestoreUITest, RestoreWindow) { ASSERT_TRUE(restored_tab_proxy->GetCurrentURL(&url)); EXPECT_TRUE(url == url2_); } + +// Restore tab with special URL about:credits and make sure the page loads +// properly after restore. See http://crbug.com/31905. +TEST_F(TabRestoreUITest, RestoreTabWithSpecialURL) { + scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); + ASSERT_TRUE(browser.get()); + CheckActiveWindow(browser.get()); + + // Navigate new tab to a special URL. + const GURL special_url(chrome::kAboutCreditsURL); + ASSERT_TRUE(browser->AppendTab(special_url)); + scoped_refptr<TabProxy> tab(browser->GetActiveTab()); + ASSERT_TRUE(tab.get()); + + // Close the tab. + ASSERT_TRUE(tab->Close(true)); + + // Restore the closed tab. + RestoreTab(0, 1); + tab = browser->GetTab(1); + ASSERT_TRUE(tab.get()); + ASSERT_TRUE(tab->WaitForTabToBeRestored(action_timeout_ms())); + + // See if content is as expected. + EXPECT_TRUE(tab->FindInPage(std::wstring(L"webkit"), FWD, IGNORE_CASE, false, + NULL)); +} + +// Restore tab with special URL in its navigation history, go back to that +// entry and see that it loads properly. See http://crbug.com/31905 +TEST_F(TabRestoreUITest, RestoreTabWithSpecialURLOnBack) { + const wchar_t kDocRoot[] = L"chrome/test/data"; + scoped_refptr<HTTPTestServer> server = + HTTPTestServer::CreateServer(kDocRoot, NULL); + ASSERT_TRUE(server.get()); + const GURL http_url(server->TestServerPage("files/title1.html")); + + scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); + ASSERT_TRUE(browser.get()); + CheckActiveWindow(browser.get()); + + // Navigate new tab to a special URL. + const GURL special_url(chrome::kAboutCreditsURL); + ASSERT_TRUE(browser->AppendTab(special_url)); + scoped_refptr<TabProxy> tab(browser->GetActiveTab()); + ASSERT_TRUE(tab.get()); + + // Then navigate to a normal URL. + ASSERT_TRUE(tab->NavigateToURL(http_url)); + + // Close the tab. + ASSERT_TRUE(tab->Close(true)); + + // Restore the closed tab. + RestoreTab(0, 1); + tab = browser->GetTab(1); + ASSERT_TRUE(tab.get()); + ASSERT_TRUE(tab->WaitForTabToBeRestored(action_timeout_ms())); + GURL url; + ASSERT_TRUE(tab->GetCurrentURL(&url)); + ASSERT_EQ(http_url, url); + + // Go back, and see if content is as expected. + ASSERT_TRUE(tab->GoBack()); + EXPECT_TRUE(tab->FindInPage(std::wstring(L"webkit"), FWD, IGNORE_CASE, false, + NULL)); +} |