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

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: Wire android tab model with LiveTabContext, so when access tab restore service, we don't hurt its c… 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
21
17 using base::android::AttachCurrentThread; 22 using base::android::AttachCurrentThread;
18 using base::android::ConvertUTF16ToJavaString; 23 using base::android::ConvertUTF16ToJavaString;
19 using base::android::ConvertUTF8ToJavaString; 24 using base::android::ConvertUTF8ToJavaString;
20 using base::android::ScopedJavaLocalRef; 25 using base::android::ScopedJavaLocalRef;
21 26
22 namespace { 27 namespace {
23 28
24 void AddTabToList(JNIEnv* env, 29 void AddTabToList(JNIEnv* env,
25 sessions::TabRestoreService::Entry* entry, 30 sessions::TabRestoreService::Entry* entry,
26 jobject jtabs_list) { 31 jobject jtabs_list) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 session_tab.navigations = tab_entry->navigations; 124 session_tab.navigations = tab_entry->navigations;
120 125
121 WindowOpenDisposition disposition = 126 WindowOpenDisposition disposition =
122 static_cast<WindowOpenDisposition>(j_disposition); 127 static_cast<WindowOpenDisposition>(j_disposition);
123 SessionRestore::RestoreForeignSessionTab(web_contents, 128 SessionRestore::RestoreForeignSessionTab(web_contents,
124 session_tab, 129 session_tab,
125 disposition); 130 disposition);
126 return true; 131 return true;
127 } 132 }
128 133
134 // Open most recently closed tab, don't need parent tab.
135 jboolean RecentlyClosedTabsBridge::OpenMostRecentlyClosedTab(
136 JNIEnv* env,
137 const base::android::JavaParamRef<jobject>& obj) {
138 EnsureTabRestoreService();
139 if (!tab_restore_service_ || TabModelList::empty())
140 return false;
141
142 const sessions::TabRestoreService::Entries& entries =
143 tab_restore_service_->entries();
144 if (entries.empty())
145 return false;
146
147 // find the correct tab model based on TabAndroid.window_id
148 using RestoreTab = const sessions::TabRestoreService::Tab;
Theresa 2016/06/28 20:47:09 The benefit of implementing AndroidLiveTabContext
xingliu 2016/06/30 05:43:55 This probably need another CL, since it needs some
149 RestoreTab* restore_tab =
150 static_cast<RestoreTab*>(entries.front());
151 SessionID::id_type window_id = restore_tab->browser_id;
152 TabModel* tab_model = TabModelList::FindTabModelWithId(window_id);
153
154 // if no tab model, fall back to first available model.
155 if (!tab_model)
156 tab_model = TabModelList::get(0);
157 if (!tab_model)
158 return false;
159
160 // remove last tab restore record.
161 std::unique_ptr<sessions::TabRestoreService::Tab> tab_entry(
162 tab_restore_service_->RemoveTabEntryById(entries.front()->id));
163 if (!tab_entry)
164 return false;
165
166 // restore navigation history and prepare web content.
167 sessions::SessionTab session_tab;
168 session_tab.current_navigation_index = tab_entry->current_navigation_index;
169 session_tab.navigations = tab_entry->navigations;
170 std::vector<std::unique_ptr<content::NavigationEntry>> nav_entries =
171 sessions::ContentSerializedNavigationBuilder::ToNavigationEntries(
172 session_tab.navigations, profile_);
173 content::WebContents* web_contents = content::WebContents::Create(
174 content::WebContents::CreateParams(profile_));
175 web_contents->GetController().Restore(
176 session_tab.normalized_navigation_index(),
177 content::NavigationController::RESTORE_CURRENT_SESSION,
178 &nav_entries);
179
180 // create new tab.
181 tab_model->CreateTab(NULL, web_contents, -1);
182 return true;
183 }
184
129 void RecentlyClosedTabsBridge::ClearRecentlyClosedTabs( 185 void RecentlyClosedTabsBridge::ClearRecentlyClosedTabs(
130 JNIEnv* env, 186 JNIEnv* env,
131 const JavaParamRef<jobject>& obj) { 187 const JavaParamRef<jobject>& obj) {
132 EnsureTabRestoreService(); 188 EnsureTabRestoreService();
133 if (tab_restore_service_) 189 if (tab_restore_service_)
134 tab_restore_service_->ClearEntries(); 190 tab_restore_service_->ClearEntries();
135 } 191 }
136 192
137 void RecentlyClosedTabsBridge::TabRestoreServiceChanged( 193 void RecentlyClosedTabsBridge::TabRestoreServiceChanged(
138 sessions::TabRestoreService* service) { 194 sessions::TabRestoreService* service) {
(...skipping 29 matching lines...) Expand all
168 const JavaParamRef<jobject>& jprofile) { 224 const JavaParamRef<jobject>& jprofile) {
169 RecentlyClosedTabsBridge* bridge = new RecentlyClosedTabsBridge( 225 RecentlyClosedTabsBridge* bridge = new RecentlyClosedTabsBridge(
170 ProfileAndroid::FromProfileAndroid(jprofile)); 226 ProfileAndroid::FromProfileAndroid(jprofile));
171 return reinterpret_cast<intptr_t>(bridge); 227 return reinterpret_cast<intptr_t>(bridge);
172 } 228 }
173 229
174 // static 230 // static
175 bool RecentlyClosedTabsBridge::Register(JNIEnv* env) { 231 bool RecentlyClosedTabsBridge::Register(JNIEnv* env) {
176 return RegisterNativesImpl(env); 232 return RegisterNativesImpl(env);
177 } 233 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698