diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-30 00:19:51 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-30 00:19:51 +0000 |
commit | 3ed1d23411c3e7f1f0a73e52681c2279929073f4 (patch) | |
tree | fcf93e27b601447e125e61bd45c9689a7e706eb4 /chrome/browser/sessions | |
parent | a116410f6ad7062aef21a0f2297dfbf466710524 (diff) | |
download | chromium_src-3ed1d23411c3e7f1f0a73e52681c2279929073f4.zip chromium_src-3ed1d23411c3e7f1f0a73e52681c2279929073f4.tar.gz chromium_src-3ed1d23411c3e7f1f0a73e52681c2279929073f4.tar.bz2 |
recently closed menu: respect middle click
(and other disposition modifiers)
BUG=7678
TEST=manual
Review URL: http://codereview.chromium.org/8678002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112077 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sessions')
-rw-r--r-- | chrome/browser/sessions/tab_restore_service.cc | 42 | ||||
-rw-r--r-- | chrome/browser/sessions/tab_restore_service.h | 20 |
2 files changed, 35 insertions, 27 deletions
diff --git a/chrome/browser/sessions/tab_restore_service.cc b/chrome/browser/sessions/tab_restore_service.cc index 99d1153..ca1081c 100644 --- a/chrome/browser/sessions/tab_restore_service.cc +++ b/chrome/browser/sessions/tab_restore_service.cc @@ -302,12 +302,12 @@ void TabRestoreService::RestoreMostRecentEntry( if (entries_.empty()) return; - RestoreEntryById(delegate, entries_.front()->id, false); + RestoreEntryById(delegate, entries_.front()->id, UNKNOWN); } void TabRestoreService::RestoreEntryById(TabRestoreServiceDelegate* delegate, SessionID::id_type id, - bool replace_existing_tab) { + WindowOpenDisposition disposition) { Entries::iterator i = GetEntryIteratorById(id); if (i == entries_.end()) { // Don't hoark here, we allow an invalid id. @@ -339,7 +339,7 @@ void TabRestoreService::RestoreEntryById(TabRestoreServiceDelegate* delegate, // new browser into which we restore the tabs. if (entry->type == TAB) { Tab* tab = static_cast<Tab*>(entry); - delegate = RestoreTab(*tab, delegate, replace_existing_tab); + delegate = RestoreTab(*tab, delegate, disposition); delegate->ShowBrowserWindow(); } else if (entry->type == WINDOW) { TabRestoreServiceDelegate* current_delegate = delegate; @@ -356,8 +356,8 @@ void TabRestoreService::RestoreEntryById(TabRestoreServiceDelegate* delegate, delegate->AddRestoredTab(tab.navigations, delegate->GetTabCount(), tab.current_navigation_index, tab.extension_app_id, - (static_cast<int>(tab_i) == - window->selected_tab_index), + static_cast<int>(tab_i) == + window->selected_tab_index, tab.pinned, tab.from_last_session, tab.session_storage_namespace); if (restored_tab) { @@ -377,7 +377,7 @@ void TabRestoreService::RestoreEntryById(TabRestoreServiceDelegate* delegate, tab_i != window->tabs.end(); ++tab_i) { const Tab& tab = *tab_i; if (tab.id == id) { - delegate = RestoreTab(tab, delegate, replace_existing_tab); + delegate = RestoreTab(tab, delegate, disposition); window->tabs.erase(tab_i); // If restoring the tab leaves the window with nothing else, delete it // as well. @@ -401,7 +401,7 @@ void TabRestoreService::RestoreEntryById(TabRestoreServiceDelegate* delegate, } delegate->ShowBrowserWindow(); - if (replace_existing_tab && current_delegate && + if (disposition == CURRENT_TAB && current_delegate && current_delegate->GetSelectedTabContents()) { current_delegate->CloseTab(); } @@ -909,31 +909,35 @@ void TabRestoreService::CreateEntriesFromCommands( TabRestoreServiceDelegate* TabRestoreService::RestoreTab( const Tab& tab, TabRestoreServiceDelegate* delegate, - bool replace_existing_tab) { - // |browser| will be NULL in cases where one isn't already available (eg, - // when invoked on Mac OS X with no windows open). In this case, create a - // new browser into which we restore the tabs. - if (replace_existing_tab && delegate) { + WindowOpenDisposition disposition) { + if (disposition == CURRENT_TAB && delegate) { delegate->ReplaceRestoredTab(tab.navigations, tab.current_navigation_index, tab.from_last_session, tab.extension_app_id, tab.session_storage_namespace); } else { - if (tab.has_browser()) + // We only respsect the tab's original browser if there's no disposition. + if (disposition == UNKNOWN && tab.has_browser()) delegate = TabRestoreServiceDelegate::FindDelegateWithID(tab.browser_id); int tab_index = -1; - if (delegate) { + + // |delegate| will be NULL in cases where one isn't already available (eg, + // when invoked on Mac OS X with no windows open). In this case, create a + // new browser into which we restore the tabs. + if (delegate && disposition != NEW_WINDOW) { tab_index = tab.tabstrip_index; } else { delegate = TabRestoreServiceDelegate::Create(profile()); - if (tab.has_browser()) { + if (tab.has_browser()) UpdateTabBrowserIDs(tab.browser_id, delegate->GetSessionID().id()); - } } - if (tab_index < 0 || tab_index > delegate->GetTabCount()) { + // Place the tab at the end if the tab index is no longer valid or + // we were passed a specific disposition. + if (tab_index < 0 || tab_index > delegate->GetTabCount() || + disposition != UNKNOWN) { tab_index = delegate->GetTabCount(); } @@ -941,7 +945,9 @@ TabRestoreServiceDelegate* TabRestoreService::RestoreTab( tab_index, tab.current_navigation_index, tab.extension_app_id, - true, tab.pinned, tab.from_last_session, + disposition != NEW_BACKGROUND_TAB, + tab.pinned, + tab.from_last_session, tab.session_storage_namespace); } RecordAppLaunch(profile(), tab); diff --git a/chrome/browser/sessions/tab_restore_service.h b/chrome/browser/sessions/tab_restore_service.h index ee8dba1..c318050 100644 --- a/chrome/browser/sessions/tab_restore_service.h +++ b/chrome/browser/sessions/tab_restore_service.h @@ -17,6 +17,7 @@ #include "chrome/browser/sessions/session_id.h" #include "chrome/browser/sessions/session_types.h" #include "content/browser/in_process_webkit/session_storage_namespace.h" +#include "webkit/glue/window_open_disposition.h" class NavigationController; class Profile; @@ -153,12 +154,13 @@ class TabRestoreService : public BaseSessionService { void RestoreMostRecentEntry(TabRestoreServiceDelegate* delegate); // Restores an entry by id. If there is no entry with an id matching |id|, - // this does nothing. If |replace_existing_tab| is true and id identifies a - // tab, the newly created tab replaces the selected tab in |delegate|. If - // |delegate| is NULL, this creates a new window for the entry. + // this does nothing. If |delegate| is NULL, this creates a new window for the + // entry. |disposition| is respected, but the attributes (tabstrip index, + // browser window) of the tab when it was closed will be respected if + // disposition is UNKNOWN. void RestoreEntryById(TabRestoreServiceDelegate* delegate, SessionID::id_type id, - bool replace_existing_tab); + WindowOpenDisposition disposition); // Loads the tabs and previous session. This does nothing if the tabs // from the previous session have already been loaded. @@ -263,13 +265,13 @@ class TabRestoreService : public BaseSessionService { std::vector<Entry*>* loaded_entries); // This is a helper function for RestoreEntryById() for restoring a single - // tab. If |replace_existing_tab| is true, the newly created tab replaces the - // selected tab in |delegate|. If |delegate| is NULL, this creates a new - // window for the entry. This returns the TabRestoreServiceDelegate into which - // the tab was restored. + // tab. If |delegate| is NULL, this creates a new window for the entry. This + // returns the TabRestoreServiceDelegate into which the tab was restored. + // |disposition| will be respected, but if it is UNKNOWN then the tab's + // original attributes will be respected instead. TabRestoreServiceDelegate* RestoreTab(const Tab& tab, TabRestoreServiceDelegate* delegate, - bool replace_existing_tab); + WindowOpenDisposition disposition); // Returns true if |tab| has more than one navigation. If |tab| has more // than one navigation |tab->current_navigation_index| is constrained based |