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

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: Refactor some code to android_live_tab_context from recently_closed_tabs_bridge Created 4 years, 5 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..bd1310f7fbc29e300f48b2c4a6b75d3be8396636 100644
--- a/chrome/browser/android/recently_closed_tabs_bridge.cc
+++ b/chrome/browser/android/recently_closed_tabs_bridge.cc
@@ -10,7 +10,13 @@
#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_live_tab.h"
+#include "components/sessions/content/content_serialized_navigation_builder.h"
+#include "components/sessions/core/live_tab.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"
@@ -18,6 +24,8 @@ using base::android::AttachCurrentThread;
using base::android::ConvertUTF16ToJavaString;
using base::android::ConvertUTF8ToJavaString;
using base::android::ScopedJavaLocalRef;
+using sessions::ContentLiveTab;
+using sessions::LiveTab;
namespace {
@@ -126,6 +134,50 @@ jboolean RecentlyClosedTabsBridge::OpenRecentlyClosedTab(
return true;
}
+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;
+ 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 matched the window id, fall back to first non-incognito
+ // model.
+ if (!tab_model || tab_model->IsOffTheRecord()) {
Theresa 2016/07/06 18:51:05 I think that rather than finding the correct tab m
xingliu 2016/07/06 22:35:41 Smart.. Thanks for making this code much cleaner!
Theresa 2016/07/07 19:00:12 Thanks for reworking it!
+ for (auto it = TabModelList::begin(); it != TabModelList::end(); ++it) {
+ TabModel* model = *it;
+ if (!model->IsOffTheRecord()) {
+ tab_model = model;
+ break;
+ }
+ }
+ }
+
+ if (!tab_model)
+ return false;
+
+ // Restore most recent tab data.
+ std::vector<LiveTab*> restored_tab = tab_restore_service_->
+ RestoreMostRecentEntry(tab_model->GetLiveTabContext());
+ if (restored_tab.empty())
+ return false;
+ ContentLiveTab* content_tab = static_cast<ContentLiveTab*>(restored_tab[0]);
+
+ // Create new tab.
+ tab_model->CreateTab(NULL, content_tab->web_contents(), -1);
Theresa 2016/07/06 18:51:06 This can move to AndroidLiveTabContext::AddRestore
xingliu 2016/07/06 22:35:41 Done.
+ return true;
+}
+
void RecentlyClosedTabsBridge::ClearRecentlyClosedTabs(
JNIEnv* env,
const JavaParamRef<jobject>& obj) {

Powered by Google App Engine
This is Rietveld 408576698