Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/foreign_session_helper.h" | 5 #include "chrome/browser/android/foreign_session_helper.h" |
| 6 | 6 |
| 7 #include <jni.h> | 7 #include <jni.h> |
| 8 | 8 |
| 9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 10 #include "base/prefs/pref_service.h" | |
| 10 #include "base/prefs/scoped_user_pref_update.h" | 11 #include "base/prefs/scoped_user_pref_update.h" |
| 12 #include "chrome/browser/android/tab_android.h" | |
| 11 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/profiles/profile_android.h" | 14 #include "chrome/browser/profiles/profile_android.h" |
| 15 #include "chrome/browser/sessions/session_restore.h" | |
| 13 #include "chrome/browser/sync/glue/session_model_associator.h" | 16 #include "chrome/browser/sync/glue/session_model_associator.h" |
| 14 #include "chrome/browser/sync/profile_sync_service.h" | 17 #include "chrome/browser/sync/profile_sync_service.h" |
| 15 #include "chrome/browser/sync/profile_sync_service_factory.h" | 18 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 16 #include "chrome/browser/ui/android/tab_model/tab_model.h" | 19 #include "chrome/browser/ui/android/tab_model/tab_model.h" |
| 17 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" | 20 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
| 18 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 19 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
| 20 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
| 21 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 22 #include "jni/ForeignSessionHelper_jni.h" | 25 #include "jni/ForeignSessionHelper_jni.h" |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 ConvertUTF8ToJavaString(env, session.session_name).Release(), | 240 ConvertUTF8ToJavaString(env, session.session_name).Release(), |
| 238 session.device_type, | 241 session.device_type, |
| 239 session.modified_time.ToJavaTime())); | 242 session.modified_time.ToJavaTime())); |
| 240 | 243 |
| 241 CopyWindowsToJava(env, session, last_pushed_session); | 244 CopyWindowsToJava(env, session, last_pushed_session); |
| 242 } | 245 } |
| 243 | 246 |
| 244 return true; | 247 return true; |
| 245 } | 248 } |
| 246 | 249 |
| 247 jboolean ForeignSessionHelper::OpenForeignSessionTab(JNIEnv* env, | 250 jboolean ForeignSessionHelper::OpenForeignSessionTabOld(JNIEnv* env, |
| 248 jobject obj, | 251 jobject obj, |
| 249 jstring session_tag, | 252 jstring session_tag, |
| 250 jint tab_id) { | 253 jint tab_id) { |
| 251 SessionModelAssociator* associator = GetSessionModelAssociator(profile_); | 254 SessionModelAssociator* associator = GetSessionModelAssociator(profile_); |
| 252 if (!associator) { | 255 if (!associator) { |
| 253 LOG(ERROR) << "Null SessionModelAssociator returned."; | 256 LOG(ERROR) << "Null SessionModelAssociator returned."; |
| 254 return false; | 257 return false; |
| 255 } | 258 } |
| 256 | 259 |
| 257 const SessionTab* tab; | 260 const SessionTab* tab; |
| 258 | 261 |
| 259 if (!associator->GetForeignTab(ConvertJavaStringToUTF8(env, session_tag), | 262 if (!associator->GetForeignTab(ConvertJavaStringToUTF8(env, session_tag), |
| 260 tab_id, &tab)) { | 263 tab_id, &tab)) { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 280 int selected_index = tab->normalized_navigation_index(); | 283 int selected_index = tab->normalized_navigation_index(); |
| 281 new_web_contents->GetController().Restore( | 284 new_web_contents->GetController().Restore( |
| 282 selected_index, | 285 selected_index, |
| 283 content::NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, | 286 content::NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, |
| 284 &entries); | 287 &entries); |
| 285 tab_model->CreateTab(new_web_contents); | 288 tab_model->CreateTab(new_web_contents); |
| 286 | 289 |
| 287 return true; | 290 return true; |
| 288 } | 291 } |
| 289 | 292 |
| 293 jboolean ForeignSessionHelper::OpenForeignSessionTab(JNIEnv* env, | |
| 294 jobject obj, | |
| 295 jobject j_tab, | |
| 296 jstring session_tag, | |
| 297 jint tab_id, | |
| 298 jint j_disposition) { | |
| 299 SessionModelAssociator* associator = GetSessionModelAssociator(profile_); | |
| 300 if (!associator) { | |
| 301 LOG(ERROR) << "Null SessionModelAssociator returned."; | |
| 302 return false; | |
| 303 } | |
| 304 | |
| 305 const SessionTab* tab; | |
|
newt (away)
2013/11/02 02:04:42
call this session_tab or foreign_tab? It's confusi
apiccion
2013/11/02 02:48:27
Done. And changed the names throughout the file fo
| |
| 306 | |
| 307 if (!associator->GetForeignTab(ConvertJavaStringToUTF8(env, session_tag), | |
| 308 tab_id, &tab)) { | |
| 309 LOG(ERROR) << "Failed to load foreign tab."; | |
| 310 return false; | |
| 311 } | |
| 312 | |
| 313 if (tab->navigations.empty()) { | |
| 314 LOG(ERROR) << "Foreign tab no longer has valid navigations."; | |
| 315 return false; | |
| 316 } | |
| 317 | |
| 318 TabAndroid* tab_android = TabAndroid::GetNativeTab(env, j_tab); | |
| 319 if (!tab_android) | |
| 320 return false; | |
| 321 content::WebContents* web_contents = tab_android->web_contents(); | |
| 322 if (!web_contents) | |
| 323 return false; | |
| 324 | |
| 325 WindowOpenDisposition disposition = | |
| 326 static_cast<WindowOpenDisposition>(j_disposition); | |
| 327 SessionRestore::RestoreForeignSessionTab(web_contents, | |
| 328 *tab, | |
| 329 disposition); | |
| 330 | |
| 331 return true; | |
| 332 } | |
| 333 | |
| 290 void ForeignSessionHelper::SetForeignSessionCollapsed(JNIEnv* env, jobject obj, | 334 void ForeignSessionHelper::SetForeignSessionCollapsed(JNIEnv* env, jobject obj, |
| 291 jstring session_tag, | 335 jstring session_tag, |
| 292 jboolean is_collapsed) { | 336 jboolean is_collapsed) { |
| 293 // Store session tags for collapsed sessions in a preference so that the | 337 // Store session tags for collapsed sessions in a preference so that the |
| 294 // collapsed state persists. | 338 // collapsed state persists. |
| 295 PrefService* prefs = profile_->GetPrefs(); | 339 PrefService* prefs = profile_->GetPrefs(); |
| 296 DictionaryPrefUpdate update(prefs, prefs::kNtpCollapsedForeignSessions); | 340 DictionaryPrefUpdate update(prefs, prefs::kNtpCollapsedForeignSessions); |
| 297 if (is_collapsed) | 341 if (is_collapsed) |
| 298 update.Get()->SetBoolean(ConvertJavaStringToUTF8(env, session_tag), true); | 342 update.Get()->SetBoolean(ConvertJavaStringToUTF8(env, session_tag), true); |
| 299 else | 343 else |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 312 jstring session_tag) { | 356 jstring session_tag) { |
| 313 SessionModelAssociator* associator = GetSessionModelAssociator(profile_); | 357 SessionModelAssociator* associator = GetSessionModelAssociator(profile_); |
| 314 if (associator) | 358 if (associator) |
| 315 associator->DeleteForeignSession(ConvertJavaStringToUTF8(env, session_tag)); | 359 associator->DeleteForeignSession(ConvertJavaStringToUTF8(env, session_tag)); |
| 316 } | 360 } |
| 317 | 361 |
| 318 // static | 362 // static |
| 319 bool ForeignSessionHelper::RegisterForeignSessionHelper(JNIEnv* env) { | 363 bool ForeignSessionHelper::RegisterForeignSessionHelper(JNIEnv* env) { |
| 320 return RegisterNativesImpl(env); | 364 return RegisterNativesImpl(env); |
| 321 } | 365 } |
| OLD | NEW |