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..8b7b7c65321ba374474984ce219f54bf6d4c1ccd 100644 |
--- a/chrome/browser/android/recently_closed_tabs_bridge.cc |
+++ b/chrome/browser/android/recently_closed_tabs_bridge.cc |
@@ -10,7 +10,11 @@ |
#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" |
@@ -126,6 +130,63 @@ jboolean RecentlyClosedTabsBridge::OpenRecentlyClosedTab( |
return true; |
} |
+// Open most recently closed tab, don't need parent tab. |
Theresa
2016/06/30 20:50:25
nit: I don't think this comment is necessary.
xingliu
2016/07/01 00:30:38
Done.
|
+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 non-incognito tab model based on TabAndroid.window_id. |
+ using RestoreTab = const sessions::TabRestoreService::Tab; |
Theresa
2016/06/30 20:50:25
reminder to move this up to the top of the file.
xingliu
2016/07/01 00:30:38
This is different from using Someclass, I remember
|
+ 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 non-incognito model. |
Theresa
2016/06/30 20:50:25
nit: "If no tab model matches the window_id, fallb
xingliu
2016/07/01 00:30:38
Done.
|
+ if (!tab_model || tab_model->IsOffTheRecord()) { |
+ for (auto it = TabModelList::begin(); it != TabModelList::end(); ++it) { |
+ TabModel* model = *it; |
+ if (!model->IsOffTheRecord()) { |
+ tab_model = model; |
+ break; |
+ } |
+ } |
+ } |
+ |
+ if (!tab_model) |
+ return false; |
+ |
+ // remove last tab restore record. |
Theresa
2016/06/30 20:50:25
nit: capitalize Remove (same for other code commen
xingliu
2016/07/01 00:30:38
Done.
|
+ std::unique_ptr<sessions::TabRestoreService::Tab> tab_entry( |
+ tab_restore_service_->RemoveTabEntryById(entries.front()->id)); |
Theresa
2016/06/30 20:50:25
use restore_tab->id here instead of entries.front(
xingliu
2016/07/01 00:30:38
Done.
|
+ 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( |
Theresa
2016/06/30 20:50:25
nit: make this a new block? e.g.
// Restore navig
xingliu
2016/07/01 00:30:38
Done.
|
+ 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) { |