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

Side by Side 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, 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/recently_closed_tabs_bridge.h" 5 #include "chrome/browser/android/recently_closed_tabs_bridge.h"
6 6
7 #include "base/android/jni_string.h" 7 #include "base/android/jni_string.h"
8 #include "chrome/browser/android/tab_android.h" 8 #include "chrome/browser/android/tab_android.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/profiles/profile_android.h" 10 #include "chrome/browser/profiles/profile_android.h"
11 #include "chrome/browser/sessions/session_restore.h" 11 #include "chrome/browser/sessions/session_restore.h"
12 #include "chrome/browser/sessions/tab_restore_service_factory.h" 12 #include "chrome/browser/sessions/tab_restore_service_factory.h"
13 #include "chrome/browser/ui/android/tab_model/tab_model.h"
14 #include "chrome/browser/ui/android/tab_model/tab_model_list.h"
15 #include "components/sessions/content/content_serialized_navigation_builder.h"
13 #include "components/sessions/core/tab_restore_service.h" 16 #include "components/sessions/core/tab_restore_service.h"
17 #include "content/public/browser/navigation_entry.h"
14 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
15 #include "jni/RecentlyClosedBridge_jni.h" 19 #include "jni/RecentlyClosedBridge_jni.h"
16 20
17 using base::android::AttachCurrentThread; 21 using base::android::AttachCurrentThread;
18 using base::android::ConvertUTF16ToJavaString; 22 using base::android::ConvertUTF16ToJavaString;
19 using base::android::ConvertUTF8ToJavaString; 23 using base::android::ConvertUTF8ToJavaString;
20 using base::android::ScopedJavaLocalRef; 24 using base::android::ScopedJavaLocalRef;
21 25
22 namespace { 26 namespace {
23 27
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 session_tab.navigations = tab_entry->navigations; 123 session_tab.navigations = tab_entry->navigations;
120 124
121 WindowOpenDisposition disposition = 125 WindowOpenDisposition disposition =
122 static_cast<WindowOpenDisposition>(j_disposition); 126 static_cast<WindowOpenDisposition>(j_disposition);
123 SessionRestore::RestoreForeignSessionTab(web_contents, 127 SessionRestore::RestoreForeignSessionTab(web_contents,
124 session_tab, 128 session_tab,
125 disposition); 129 disposition);
126 return true; 130 return true;
127 } 131 }
128 132
133 jboolean RecentlyClosedTabsBridge::OpenMostRecentlyClosedTab(
Theresa 2016/07/02 01:00:36 I did some testing, and we can change this to use
134 JNIEnv* env,
135 const base::android::JavaParamRef<jobject>& obj) {
136 EnsureTabRestoreService();
137 if (!tab_restore_service_ || TabModelList::empty())
138 return false;
139
140 const sessions::TabRestoreService::Entries& entries =
141 tab_restore_service_->entries();
142 if (entries.empty())
143 return false;
144
145 // Find the correct non-incognito tab model based on TabAndroid.window_id.
146 using RestoreTab = const sessions::TabRestoreService::Tab;
147 RestoreTab* restore_tab = static_cast<RestoreTab*>(entries.front());
148 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
149 TabModel* tab_model = TabModelList::FindTabModelWithId(window_id);
150 // If no tab model matched the window id, fall back to first non-incognito
151 // model.
152 if (!tab_model || tab_model->IsOffTheRecord()) {
153 for (auto it = TabModelList::begin(); it != TabModelList::end(); ++it) {
154 TabModel* model = *it;
155 if (!model->IsOffTheRecord()) {
156 tab_model = model;
157 break;
158 }
159 }
160 }
161
162 if (!tab_model)
163 return false;
164
165 // Remove most recent tab restore entry.
166 std::unique_ptr<sessions::TabRestoreService::Tab> tab_entry(
167 tab_restore_service_->RemoveTabEntryById(restore_tab->id));
168 if (!tab_entry)
169 return false;
170
171 // Restore navigation history.
172 sessions::SessionTab session_tab;
173 session_tab.current_navigation_index = tab_entry->current_navigation_index;
174 session_tab.navigations = tab_entry->navigations;
175 std::vector<std::unique_ptr<content::NavigationEntry>> nav_entries =
176 sessions::ContentSerializedNavigationBuilder::ToNavigationEntries(
177 session_tab.navigations, profile_);
178
179 // Prepare web content.
180 content::WebContents* web_contents = content::WebContents::Create(
181 content::WebContents::CreateParams(profile_));
182 web_contents->GetController().Restore(
183 session_tab.normalized_navigation_index(),
184 content::NavigationController::RESTORE_CURRENT_SESSION,
185 &nav_entries);
186
187 // Create new tab.
188 tab_model->CreateTab(NULL, web_contents, -1);
189 return true;
190 }
191
129 void RecentlyClosedTabsBridge::ClearRecentlyClosedTabs( 192 void RecentlyClosedTabsBridge::ClearRecentlyClosedTabs(
130 JNIEnv* env, 193 JNIEnv* env,
131 const JavaParamRef<jobject>& obj) { 194 const JavaParamRef<jobject>& obj) {
132 EnsureTabRestoreService(); 195 EnsureTabRestoreService();
133 if (tab_restore_service_) 196 if (tab_restore_service_)
134 tab_restore_service_->ClearEntries(); 197 tab_restore_service_->ClearEntries();
135 } 198 }
136 199
137 void RecentlyClosedTabsBridge::TabRestoreServiceChanged( 200 void RecentlyClosedTabsBridge::TabRestoreServiceChanged(
138 sessions::TabRestoreService* service) { 201 sessions::TabRestoreService* service) {
(...skipping 29 matching lines...) Expand all
168 const JavaParamRef<jobject>& jprofile) { 231 const JavaParamRef<jobject>& jprofile) {
169 RecentlyClosedTabsBridge* bridge = new RecentlyClosedTabsBridge( 232 RecentlyClosedTabsBridge* bridge = new RecentlyClosedTabsBridge(
170 ProfileAndroid::FromProfileAndroid(jprofile)); 233 ProfileAndroid::FromProfileAndroid(jprofile));
171 return reinterpret_cast<intptr_t>(bridge); 234 return reinterpret_cast<intptr_t>(bridge);
172 } 235 }
173 236
174 // static 237 // static
175 bool RecentlyClosedTabsBridge::Register(JNIEnv* env) { 238 bool RecentlyClosedTabsBridge::Register(JNIEnv* env) {
176 return RegisterNativesImpl(env); 239 return RegisterNativesImpl(env);
177 } 240 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698