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/scoped_user_pref_update.h" | 10 #include "base/prefs/scoped_user_pref_update.h" |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 int selected_index = tab->normalized_navigation_index(); | 280 int selected_index = tab->normalized_navigation_index(); |
281 new_web_contents->GetController().Restore( | 281 new_web_contents->GetController().Restore( |
282 selected_index, | 282 selected_index, |
283 content::NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, | 283 content::NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, |
284 &entries); | 284 &entries); |
285 tab_model->CreateTab(new_web_contents); | 285 tab_model->CreateTab(new_web_contents); |
286 | 286 |
287 return true; | 287 return true; |
288 } | 288 } |
289 | 289 |
290 void ForeignSessionHelper::SetForeignSessionCollapsed(JNIEnv* env, jobject obj, | |
291 jstring session_tag, | |
292 jboolean is_collapsed) { | |
293 // Store session tags for collapsed sessions in a preference so that the | |
294 // collapsed state persists. | |
295 PrefService* prefs = profile_->GetPrefs(); | |
296 DictionaryPrefUpdate update(prefs, prefs::kNtpCollapsedForeignSessions); | |
297 if (is_collapsed) | |
298 update.Get()->SetBoolean(ConvertJavaStringToUTF8(env, session_tag), true); | |
299 else | |
300 update.Get()->Remove(ConvertJavaStringToUTF8(env, session_tag), NULL); | |
301 } | |
302 | |
303 jboolean ForeignSessionHelper::GetForeignSessionCollapsed(JNIEnv* env, | |
304 jobject obj, | |
305 jstring session_tag) { | |
306 const DictionaryValue* dict = profile_->GetPrefs()->GetDictionary( | |
307 prefs::kNtpCollapsedForeignSessions); | |
308 return dict && dict->HasKey(ConvertJavaStringToUTF8(env, session_tag)); | |
309 } | |
310 | |
311 void ForeignSessionHelper::DeleteForeignSession(JNIEnv* env, jobject obj, | 290 void ForeignSessionHelper::DeleteForeignSession(JNIEnv* env, jobject obj, |
312 jstring session_tag) { | 291 jstring session_tag) { |
313 SessionModelAssociator* associator = GetSessionModelAssociator(profile_); | 292 SessionModelAssociator* associator = GetSessionModelAssociator(profile_); |
314 if (associator) | 293 if (associator) |
315 associator->DeleteForeignSession(ConvertJavaStringToUTF8(env, session_tag)); | 294 associator->DeleteForeignSession(ConvertJavaStringToUTF8(env, session_tag)); |
316 } | 295 } |
317 | 296 |
318 // static | 297 // static |
319 bool ForeignSessionHelper::RegisterForeignSessionHelper(JNIEnv* env) { | 298 bool ForeignSessionHelper::RegisterForeignSessionHelper(JNIEnv* env) { |
320 return RegisterNativesImpl(env); | 299 return RegisterNativesImpl(env); |
321 } | 300 } |
OLD | NEW |