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

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

Issue 36473002: Foreign session pages now load into current tab. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 1 month 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/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;
}

Powered by Google App Engine
This is Rietveld 408576698