Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3435)

Unified Diff: chrome/browser/android/recently_closed_tabs_bridge.cc

Issue 2088443003: Shortcut ctrl+shift+T added on android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove commented code, my bad. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..62be732e02c066e8015ba330ba0a4aafea9776fc 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,65 @@ jboolean RecentlyClosedTabsBridge::OpenRecentlyClosedTab(
return true;
}
+jboolean RecentlyClosedTabsBridge::OpenMostRecentlyClosedTab(
Theresa 2016/07/02 01:00:36 I did some testing, and we can change this to use
+ 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;
+ RestoreTab* restore_tab = static_cast<RestoreTab*>(entries.front());
+ SessionID::id_type window_id = restore_tab->browser_id;
Theresa 2016/07/02 01:00:37 In my prototyping, I hadn't come up with a differe
+ TabModel* tab_model = TabModelList::FindTabModelWithId(window_id);
+ // If no tab model matched the window id, fall back to first non-incognito
+ // model.
+ 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 most recent tab restore entry.
+ std::unique_ptr<sessions::TabRestoreService::Tab> tab_entry(
+ tab_restore_service_->RemoveTabEntryById(restore_tab->id));
+ if (!tab_entry)
+ return false;
+
+ // Restore navigation history.
+ 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_);
+
+ // Prepare web content.
+ 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) {

Powered by Google App Engine
This is Rietveld 408576698