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..fe61a57ace48c95ac0f199dbdc49dcade48f58a3 100644 |
| --- a/chrome/browser/android/foreign_session_helper.cc |
| +++ b/chrome/browser/android/foreign_session_helper.cc |
| @@ -7,9 +7,12 @@ |
| #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/sessions/session_restore.h" |
| #include "chrome/browser/sync/glue/session_model_associator.h" |
| #include "chrome/browser/sync/profile_sync_service.h" |
| #include "chrome/browser/sync/profile_sync_service_factory.h" |
| @@ -43,17 +46,17 @@ SessionModelAssociator* GetSessionModelAssociator(Profile* profile) { |
| return service->GetSessionModelAssociator(); |
| } |
| -bool ShouldSkipTab(const SessionTab& tab) { |
| - if (tab.navigations.empty()) |
| +bool ShouldSkipTab(const SessionTab& session_tab) { |
| + if (session_tab.navigations.empty()) |
| return true; |
| - int selected_index = tab.current_navigation_index; |
| + int selected_index = session_tab.current_navigation_index; |
| if (selected_index < 0 || |
| - selected_index >= static_cast<int>(tab.navigations.size())) |
| + selected_index >= static_cast<int>(session_tab.navigations.size())) |
| return true; |
| const ::sessions::SerializedNavigationEntry& current_navigation = |
| - tab.navigations.at(selected_index); |
| + session_tab.navigations.at(selected_index); |
| if (current_navigation.virtual_url().is_empty()) |
| return true; |
| @@ -64,8 +67,8 @@ bool ShouldSkipTab(const SessionTab& tab) { |
| bool ShouldSkipWindow(const SessionWindow& window) { |
| for (std::vector<SessionTab*>::const_iterator tab_it = window.tabs.begin(); |
| tab_it != window.tabs.end(); ++tab_it) { |
| - const SessionTab &tab = **tab_it; |
| - if (!ShouldSkipTab(tab)) |
| + const SessionTab &session_tab = **tab_it; |
| + if (!ShouldSkipTab(session_tab)) |
| return false; |
| } |
| return true; |
| @@ -87,17 +90,17 @@ void CopyTabsToJava( |
| ScopedJavaLocalRef<jobject>& j_window) { |
| for (std::vector<SessionTab*>::const_iterator tab_it = window.tabs.begin(); |
| tab_it != window.tabs.end(); ++tab_it) { |
| - const SessionTab &tab = **tab_it; |
| + const SessionTab &session_tab = **tab_it; |
| - if (ShouldSkipTab(tab)) |
| + if (ShouldSkipTab(session_tab)) |
| continue; |
| - int selected_index = tab.current_navigation_index; |
| + int selected_index = session_tab.current_navigation_index; |
| DCHECK(selected_index >= 0); |
| - DCHECK(selected_index < static_cast<int>(tab.navigations.size())); |
| + DCHECK(selected_index < static_cast<int>(session_tab.navigations.size())); |
| const ::sessions::SerializedNavigationEntry& current_navigation = |
| - tab.navigations.at(selected_index); |
| + session_tab.navigations.at(selected_index); |
| GURL tab_url = current_navigation.virtual_url(); |
| @@ -105,8 +108,8 @@ void CopyTabsToJava( |
| env, j_window.obj(), |
| ConvertUTF8ToJavaString(env, tab_url.spec()).Release(), |
| ConvertUTF16ToJavaString(env, current_navigation.title()).Release(), |
| - tab.timestamp.ToJavaTime(), |
| - tab.tab_id.id()); |
| + session_tab.timestamp.ToJavaTime(), |
| + session_tab.tab_id.id()); |
| } |
| } |
| @@ -244,25 +247,27 @@ jboolean ForeignSessionHelper::GetForeignSessions(JNIEnv* env, |
| return true; |
| } |
| -jboolean ForeignSessionHelper::OpenForeignSessionTab(JNIEnv* env, |
| - jobject obj, |
| - jstring session_tag, |
| - jint tab_id) { |
| +// TODO(apiccion): Remvoe this method once downstream CL Lands. |
| +// See: http://crbug.com/257102 |
| +jboolean ForeignSessionHelper::OpenForeignSessionTabOld(JNIEnv* env, |
| + jobject obj, |
| + jstring session_tag, |
| + jint session_tab_id) { |
| SessionModelAssociator* associator = GetSessionModelAssociator(profile_); |
| if (!associator) { |
| LOG(ERROR) << "Null SessionModelAssociator returned."; |
| return false; |
| } |
| - const SessionTab* tab; |
| + const SessionTab* session_tab; |
| if (!associator->GetForeignTab(ConvertJavaStringToUTF8(env, session_tag), |
| - tab_id, &tab)) { |
| + session_tab_id, &session_tab)) { |
| LOG(ERROR) << "Failed to load foreign tab."; |
| return false; |
| } |
| - if (tab->navigations.empty()) { |
| + if (session_tab->navigations.empty()) { |
| LOG(ERROR) << "Foreign tab no longer has valid navigations."; |
| return false; |
| } |
| @@ -274,10 +279,10 @@ jboolean ForeignSessionHelper::OpenForeignSessionTab(JNIEnv* env, |
| std::vector<content::NavigationEntry*> entries = |
| sessions::SerializedNavigationEntry::ToNavigationEntries( |
| - tab->navigations, profile_); |
| + session_tab->navigations, profile_); |
| content::WebContents* new_web_contents = content::WebContents::Create( |
| content::WebContents::CreateParams(profile_)); |
| - int selected_index = tab->normalized_navigation_index(); |
| + int selected_index = session_tab->normalized_navigation_index(); |
| new_web_contents->GetController().Restore( |
| selected_index, |
| content::NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, |
| @@ -287,6 +292,47 @@ jboolean ForeignSessionHelper::OpenForeignSessionTab(JNIEnv* env, |
| return true; |
| } |
| +jboolean ForeignSessionHelper::OpenForeignSessionTab(JNIEnv* env, |
| + jobject obj, |
| + jobject j_tab, |
| + jstring session_tag, |
| + jint session_tab_id, |
| + jint j_disposition) { |
| + SessionModelAssociator* associator = GetSessionModelAssociator(profile_); |
| + if (!associator) { |
| + LOG(ERROR) << "Null SessionModelAssociator returned."; |
| + return false; |
| + } |
| + |
| + const SessionTab* session_tab; |
| + |
| + if (!associator->GetForeignTab(ConvertJavaStringToUTF8(env, session_tag), |
| + session_tab_id, &session_tab)) { |
|
Ted C
2013/11/04 19:46:28
I think the second param needs to go on it's own l
apiccion
2013/11/04 19:52:30
Done.
|
| + LOG(ERROR) << "Failed to load foreign tab."; |
| + return false; |
| + } |
| + |
| + if (session_tab->navigations.empty()) { |
| + LOG(ERROR) << "Foreign tab no longer has valid navigations."; |
| + return false; |
| + } |
| + |
| + TabAndroid* tab_android = TabAndroid::GetNativeTab(env, j_tab); |
| + if (!tab_android) |
| + return false; |
| + content::WebContents* web_contents = tab_android->web_contents(); |
| + if (!web_contents) |
| + return false; |
| + |
| + WindowOpenDisposition disposition = |
| + static_cast<WindowOpenDisposition>(j_disposition); |
| + SessionRestore::RestoreForeignSessionTab(web_contents, |
| + *session_tab, |
| + disposition); |
| + |
| + return true; |
| +} |
| + |
| void ForeignSessionHelper::SetForeignSessionCollapsed(JNIEnv* env, jobject obj, |
| jstring session_tag, |
| jboolean is_collapsed) { |