Index: chrome/browser/android/recently_closed_tabs_bridge.cc |
diff --git a/chrome/browser/android/recently_closed_tabs_bridge.cc b/chrome/browser/android/recently_closed_tabs_bridge.cc |
index 771c815e70b9b7e507f46b5ea43618d09bc9e015..6c0938dbf717e611b7a599a0e3437417cf031300 100644 |
--- a/chrome/browser/android/recently_closed_tabs_bridge.cc |
+++ b/chrome/browser/android/recently_closed_tabs_bridge.cc |
@@ -10,10 +10,15 @@ |
#include "chrome/browser/profiles/profile_android.h" |
#include "chrome/browser/sessions/session_restore.h" |
#include "chrome/browser/sessions/tab_restore_service_factory.h" |
+#include "chrome/browser/ui/android/tab_model/tab_model.h" |
+#include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
+#include "components/sessions/content/content_serialized_navigation_builder.h" |
#include "components/sessions/core/tab_restore_service.h" |
+#include "content/public/browser/navigation_entry.h" |
#include "content/public/browser/web_contents.h" |
#include "jni/RecentlyClosedBridge_jni.h" |
+ |
using base::android::AttachCurrentThread; |
using base::android::ConvertUTF16ToJavaString; |
using base::android::ConvertUTF8ToJavaString; |
@@ -126,6 +131,57 @@ jboolean RecentlyClosedTabsBridge::OpenRecentlyClosedTab( |
return true; |
} |
+// Open most recently closed tab, don't need parent tab. |
+jboolean RecentlyClosedTabsBridge::OpenMostRecentlyClosedTab( |
+ JNIEnv* env, |
+ const base::android::JavaParamRef<jobject>& obj) { |
+ EnsureTabRestoreService(); |
+ if (!tab_restore_service_ || TabModelList::empty()) |
+ return false; |
+ |
+ const sessions::TabRestoreService::Entries& entries = |
+ tab_restore_service_->entries(); |
+ if (entries.empty()) |
+ return false; |
+ |
+ // find the correct tab model based on TabAndroid.window_id |
+ using RestoreTab = const sessions::TabRestoreService::Tab; |
Theresa
2016/06/28 20:47:09
The benefit of implementing AndroidLiveTabContext
xingliu
2016/06/30 05:43:55
This probably need another CL, since it needs some
|
+ RestoreTab* restore_tab = |
+ static_cast<RestoreTab*>(entries.front()); |
+ SessionID::id_type window_id = restore_tab->browser_id; |
+ TabModel* tab_model = TabModelList::FindTabModelWithId(window_id); |
+ |
+ // if no tab model, fall back to first available model. |
+ if (!tab_model) |
+ tab_model = TabModelList::get(0); |
+ if (!tab_model) |
+ return false; |
+ |
+ // remove last tab restore record. |
+ std::unique_ptr<sessions::TabRestoreService::Tab> tab_entry( |
+ tab_restore_service_->RemoveTabEntryById(entries.front()->id)); |
+ if (!tab_entry) |
+ return false; |
+ |
+ // restore navigation history and prepare web content. |
+ sessions::SessionTab session_tab; |
+ session_tab.current_navigation_index = tab_entry->current_navigation_index; |
+ session_tab.navigations = tab_entry->navigations; |
+ std::vector<std::unique_ptr<content::NavigationEntry>> nav_entries = |
+ sessions::ContentSerializedNavigationBuilder::ToNavigationEntries( |
+ session_tab.navigations, profile_); |
+ content::WebContents* web_contents = content::WebContents::Create( |
+ content::WebContents::CreateParams(profile_)); |
+ web_contents->GetController().Restore( |
+ session_tab.normalized_navigation_index(), |
+ content::NavigationController::RESTORE_CURRENT_SESSION, |
+ &nav_entries); |
+ |
+ // create new tab. |
+ tab_model->CreateTab(NULL, web_contents, -1); |
+ return true; |
+} |
+ |
void RecentlyClosedTabsBridge::ClearRecentlyClosedTabs( |
JNIEnv* env, |
const JavaParamRef<jobject>& obj) { |