| 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..235b81e9b68b123ee6aaef8fcfb617e0b9aa2973 100644
|
| --- a/chrome/browser/android/recently_closed_tabs_bridge.cc
|
| +++ b/chrome/browser/android/recently_closed_tabs_bridge.cc
|
| @@ -10,10 +10,16 @@
|
| #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_platform_specific_tab_data.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 +132,59 @@ 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 according to restore data.
|
| + // if no window id, fall back to first tab model.
|
| + sessions::TabRestoreService::Tab* restore_tab =
|
| + static_cast<sessions::TabRestoreService::Tab*> (entries.front());
|
| + using ContentData = sessions::ContentPlatformSpecificTabData;
|
| + ContentData* platform_data =
|
| + static_cast<ContentData*> (restore_tab->platform_data.get());
|
| +
|
| + TabModel* tab_model =
|
| + TabModelList::FindTabModelWithId(platform_data->window_id());
|
| + 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) {
|
|
|