Chromium Code Reviews| Index: chrome/browser/android/foreign_session_helper.cc |
| diff --git a/chrome/browser/android/foreign_session_helper.cc b/chrome/browser/android/foreign_session_helper.cc |
| index 7d7f48684fe29e25978c518271bb5836399ea8e2..df1d396d796394e66326abb51a6de063f763e311 100644 |
| --- a/chrome/browser/android/foreign_session_helper.cc |
| +++ b/chrome/browser/android/foreign_session_helper.cc |
| @@ -7,7 +7,9 @@ |
| #include <jni.h> |
| #include "base/android/jni_string.h" |
| +#include "base/prefs/pref_service.h" |
| #include "base/prefs/scoped_user_pref_update.h" |
| +#include "chrome/browser/android/tab_android.h" |
| #include "chrome/browser/chrome_notification_types.h" |
| #include "chrome/browser/profiles/profile_android.h" |
| #include "chrome/browser/sync/glue/session_model_associator.h" |
| @@ -244,8 +246,54 @@ jboolean ForeignSessionHelper::GetForeignSessions(JNIEnv* env, |
| return true; |
| } |
| +// TODO (apiccion): Remove this method once the downstream CL lands. |
| +// See: https://code.google.com/p/chromium/issues/detail?id=257102 |
| +jboolean ForeignSessionHelper::OpenForeignSessionTabOld(JNIEnv* env, |
| + jobject obj, |
|
newt (away)
2013/11/01 23:41:32
don't need this method
apiccion
2013/11/02 01:01:14
Done.
|
| + jstring session_tag, |
| + jint tab_id) { |
| + SessionModelAssociator* associator = GetSessionModelAssociator(profile_); |
| + if (!associator) { |
| + LOG(ERROR) << "Null SessionModelAssociator returned."; |
| + return false; |
| + } |
| + |
| + const SessionTab* tab; |
| + |
| + if (!associator->GetForeignTab(ConvertJavaStringToUTF8(env, session_tag), |
| + tab_id, &tab)) { |
| + LOG(ERROR) << "Failed to load foreign tab."; |
| + return false; |
| + } |
| + |
| + if (tab->navigations.empty()) { |
| + LOG(ERROR) << "Foreign tab no longer has valid navigations."; |
| + return false; |
| + } |
| + |
| + TabModel* tab_model = TabModelList::GetTabModelWithProfile(profile_); |
| + DCHECK(tab_model); |
| + if (!tab_model) |
| + return false; |
| + |
| + std::vector<content::NavigationEntry*> entries = |
| + sessions::SerializedNavigationEntry::ToNavigationEntries( |
| + tab->navigations, profile_); |
| + content::WebContents* new_web_contents = content::WebContents::Create( |
| + content::WebContents::CreateParams(profile_)); |
| + int selected_index = tab->normalized_navigation_index(); |
| + new_web_contents->GetController().Restore( |
| + selected_index, |
| + content::NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, |
| + &entries); |
| + tab_model->CreateTab(new_web_contents); |
| + |
| + return true; |
| +} |
| + |
| jboolean ForeignSessionHelper::OpenForeignSessionTab(JNIEnv* env, |
| jobject obj, |
| + jobject j_tab, |
| jstring session_tag, |
| jint tab_id) { |
| SessionModelAssociator* associator = GetSessionModelAssociator(profile_); |
| @@ -282,7 +330,12 @@ jboolean ForeignSessionHelper::OpenForeignSessionTab(JNIEnv* env, |
| selected_index, |
| content::NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, |
| &entries); |
| - tab_model->CreateTab(new_web_contents); |
| + |
| + content::WebContents* old_web_contents = |
| + tab_model->GetWebContentsAt(tab_model->GetActiveIndex()); |
| + |
| + TabAndroid* currentTab = TabAndroid::GetNativeTab(env, j_tab); |
| + currentTab->SwapTabContents(old_web_contents, new_web_contents); |
| return true; |
| } |