Index: chrome/browser/sessions/tab_restore_service_helper.cc |
diff --git a/chrome/browser/sessions/tab_restore_service_helper.cc b/chrome/browser/sessions/tab_restore_service_helper.cc |
index 7e1ca3a6ad952dc6b80138a22c18bb00ad3f2303..02293aed8ac79f9b57f73932e547f686bcb4bd36 100644 |
--- a/chrome/browser/sessions/tab_restore_service_helper.cc |
+++ b/chrome/browser/sessions/tab_restore_service_helper.cc |
@@ -170,13 +170,14 @@ const TabRestoreService::Entries& TabRestoreServiceHelper::entries() const { |
return entries_; |
} |
-void TabRestoreServiceHelper::RestoreMostRecentEntry( |
+content::WebContents* TabRestoreServiceHelper::RestoreMostRecentEntry( |
TabRestoreServiceDelegate* delegate, |
chrome::HostDesktopType host_desktop_type) { |
if (entries_.empty()) |
- return; |
+ return NULL; |
- RestoreEntryById(delegate, entries_.front()->id, host_desktop_type, UNKNOWN); |
+ return RestoreEntryById(delegate, entries_.front()->id, host_desktop_type, |
+ UNKNOWN); |
} |
TabRestoreService::Tab* TabRestoreServiceHelper::RemoveTabEntryById( |
@@ -194,7 +195,7 @@ TabRestoreService::Tab* TabRestoreServiceHelper::RemoveTabEntryById( |
return tab; |
} |
-void TabRestoreServiceHelper::RestoreEntryById( |
+content::WebContents* TabRestoreServiceHelper::RestoreEntryById( |
TabRestoreServiceDelegate* delegate, |
SessionID::id_type id, |
chrome::HostDesktopType host_desktop_type, |
@@ -202,7 +203,7 @@ void TabRestoreServiceHelper::RestoreEntryById( |
Entries::iterator entry_iterator = GetEntryIteratorById(id); |
if (entry_iterator == entries_.end()) |
// Don't hoark here, we allow an invalid id. |
- return; |
+ return NULL; |
if (observer_) |
observer_->OnRestoreEntryById(id, entry_iterator); |
@@ -221,9 +222,11 @@ void TabRestoreServiceHelper::RestoreEntryById( |
// |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. |
+ WebContents* web_contents = NULL; |
if (entry->type == TabRestoreService::TAB) { |
Tab* tab = static_cast<Tab*>(entry); |
- delegate = RestoreTab(*tab, delegate, host_desktop_type, disposition); |
+ delegate = RestoreTab(*tab, delegate, host_desktop_type, disposition, |
+ &web_contents); |
delegate->ShowBrowserWindow(); |
} else if (entry->type == TabRestoreService::WINDOW) { |
TabRestoreServiceDelegate* current_delegate = delegate; |
@@ -250,6 +253,8 @@ void TabRestoreServiceHelper::RestoreEntryById( |
if (restored_tab) { |
restored_tab->GetController().LoadIfNecessary(); |
RecordAppLaunch(profile_, tab); |
+ // Return the last successfully restored tab for window entries. |
+ web_contents = restored_tab; |
} |
} |
// All the window's tabs had the same former browser_id. |
@@ -264,7 +269,8 @@ void TabRestoreServiceHelper::RestoreEntryById( |
tab_i != window->tabs.end(); ++tab_i) { |
const Tab& tab = *tab_i; |
if (tab.id == id) { |
- delegate = RestoreTab(tab, delegate, host_desktop_type, disposition); |
+ delegate = RestoreTab(tab, delegate, host_desktop_type, disposition, |
+ &web_contents); |
window->tabs.erase(tab_i); |
// If restoring the tab leaves the window with nothing else, delete it |
// as well. |
@@ -302,6 +308,10 @@ void TabRestoreServiceHelper::RestoreEntryById( |
restoring_ = false; |
NotifyTabsChanged(); |
+ // Returns the WebContents of the restored tab if entry is a Tab. In the case |
+ // of restoring type Window, returns the WebContents of the last successfully |
+ // restored tab in the window. |
+ return web_contents; |
} |
void TabRestoreServiceHelper::NotifyTabsChanged() { |
@@ -437,14 +447,17 @@ TabRestoreServiceDelegate* TabRestoreServiceHelper::RestoreTab( |
const Tab& tab, |
TabRestoreServiceDelegate* delegate, |
chrome::HostDesktopType host_desktop_type, |
- WindowOpenDisposition disposition) { |
+ WindowOpenDisposition disposition, |
+ WebContents** contents) { |
+ WebContents* web_contents; |
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.get(), |
- tab.user_agent_override); |
+ web_contents = delegate->ReplaceRestoredTab( |
+ tab.navigations, |
+ tab.current_navigation_index, |
+ tab.from_last_session, |
+ tab.extension_app_id, |
+ tab.session_storage_namespace.get(), |
+ tab.user_agent_override); |
} else { |
// We only respsect the tab's original browser if there's no disposition. |
if (disposition == UNKNOWN && tab.has_browser()) { |
@@ -473,19 +486,21 @@ TabRestoreServiceDelegate* TabRestoreServiceHelper::RestoreTab( |
tab_index = delegate->GetTabCount(); |
} |
- WebContents* web_contents = |
- delegate->AddRestoredTab(tab.navigations, |
- tab_index, |
- tab.current_navigation_index, |
- tab.extension_app_id, |
- disposition != NEW_BACKGROUND_TAB, |
- tab.pinned, |
- tab.from_last_session, |
- tab.session_storage_namespace.get(), |
- tab.user_agent_override); |
+ web_contents = delegate->AddRestoredTab(tab.navigations, |
+ tab_index, |
+ tab.current_navigation_index, |
+ tab.extension_app_id, |
+ disposition != NEW_BACKGROUND_TAB, |
+ tab.pinned, |
+ tab.from_last_session, |
+ tab.session_storage_namespace.get(), |
+ tab.user_agent_override); |
web_contents->GetController().LoadIfNecessary(); |
} |
RecordAppLaunch(profile_, tab); |
+ if (contents) |
+ *contents = web_contents; |
+ |
return delegate; |
} |