diff options
author | pam@chromium.org <pam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-20 22:01:03 +0000 |
---|---|---|
committer | pam@chromium.org <pam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-20 22:01:03 +0000 |
commit | 77bc673bf31c32bfdcb1bf139c3a58eace23e3ea (patch) | |
tree | a737cc649d4f38a2b96ca2de8d1da4fda0e36451 /chrome/browser/sessions | |
parent | 8c2ea0e34721a2b0bfd8e003937b0617adfddf96 (diff) | |
download | chromium_src-77bc673bf31c32bfdcb1bf139c3a58eace23e3ea.zip chromium_src-77bc673bf31c32bfdcb1bf139c3a58eace23e3ea.tar.gz chromium_src-77bc673bf31c32bfdcb1bf139c3a58eace23e3ea.tar.bz2 |
When restoring a closed tab using either ctrl-shift-T or the context menu, put
it back into the window it came from, at the tabstrip index it occupied before,
and activate (select) both the window and the tab.
Restoring a tab from the New Tab Page replaces the NTP, as before.
If the window the tab was in no longer exists, put the tab at the end of the
current window's tabstrip. This behavior may change in a later patch.
BUG=5278
TEST=Open two windows, with >1 tabs each. Close a tab, not the one at the end,
in one of the windows. Switch to the other window and choose "Undo Closed
Tab" from the tabstrip context menu, or type ctrl-shift-T. The tab should
be restored where it was, and activated (selected and brought to the front).
Review URL: http://codereview.chromium.org/69015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14062 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sessions')
-rw-r--r-- | chrome/browser/sessions/tab_restore_service.cc | 22 | ||||
-rw-r--r-- | chrome/browser/sessions/tab_restore_service.h | 15 |
2 files changed, 34 insertions, 3 deletions
diff --git a/chrome/browser/sessions/tab_restore_service.cc b/chrome/browser/sessions/tab_restore_service.cc index 5892013..d61e42a 100644 --- a/chrome/browser/sessions/tab_restore_service.cc +++ b/chrome/browser/sessions/tab_restore_service.cc @@ -130,6 +130,13 @@ void TabRestoreService::CreateHistoricalTab(NavigationController* tab) { if (local_tab->navigations.empty()) return; + // browser may be NULL when running unit tests. + if (browser) { + local_tab->browser_id = browser->session_id().id(); + local_tab->tabstrip_index = + browser->tabstrip_model()->GetIndexOfController(tab); + } + AddEntry(local_tab.release(), true, true); } @@ -221,8 +228,19 @@ void TabRestoreService::RestoreEntryById(Browser* browser, browser->ReplaceRestoredTab(tab->navigations, tab->current_navigation_index); } else { - browser->AddRestoredTab(tab->navigations, browser->tab_count(), - tab->current_navigation_index, true); + // Use the tab's former browser and index, if available. + Browser* tab_browser = NULL; + int tab_index = -1; + if (tab->has_browser()) + tab_browser = BrowserList::FindBrowserWithID(tab->browser_id); + if (tab_browser) + tab_index = tab->tabstrip_index; + else + tab_browser = browser; + if (tab_index < 0 || tab_index > browser->tab_count()) + tab_index = browser->tab_count(); + tab_browser->AddRestoredTab(tab->navigations, tab_index, + tab->current_navigation_index, true); } } else if (entry->type == WINDOW) { const Window* window = static_cast<Window*>(entry); diff --git a/chrome/browser/sessions/tab_restore_service.h b/chrome/browser/sessions/tab_restore_service.h index b768385..c728652 100644 --- a/chrome/browser/sessions/tab_restore_service.h +++ b/chrome/browser/sessions/tab_restore_service.h @@ -63,13 +63,26 @@ class TabRestoreService : public BaseSessionService { // Represents a previously open tab. struct Tab : public Entry { - Tab() : Entry(TAB), current_navigation_index(-1) {} + Tab() + : Entry(TAB), + current_navigation_index(-1), + browser_id(0), + tabstrip_index(-1) {} + + bool has_browser() const { return browser_id > 0; } // The navigations. std::vector<TabNavigation> navigations; // Index of the selected navigation in navigations. int current_navigation_index; + + // The ID of the browser to which this tab belonged, so it can be restored + // there. May be 0 (an invalid SessionID) when restoring an entire session. + SessionID::id_type browser_id; + + // Index within the tab strip. May be -1 for an unknown index. + int tabstrip_index; }; // Represents a previously open window. |