| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/preferences/pref_service_bridge.h" | 5 #include "chrome/browser/android/preferences/pref_service_bridge.h" |
| 6 | 6 |
| 7 #include <jni.h> | 7 #include <jni.h> |
| 8 #include <vector> |
| 8 | 9 |
| 9 #include "base/android/build_info.h" | 10 #include "base/android/build_info.h" |
| 10 #include "base/android/jni_android.h" | 11 #include "base/android/jni_android.h" |
| 11 #include "base/android/jni_string.h" | 12 #include "base/android/jni_string.h" |
| 12 #include "base/android/jni_weak_ref.h" | 13 #include "base/android/jni_weak_ref.h" |
| 13 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 14 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 15 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
| 17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 18 #include "base/values.h" | 19 #include "base/values.h" |
| 19 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/browsing_data/browsing_data_counter.h" |
| 22 #include "chrome/browser/browsing_data/browsing_data_counter_utils.h" |
| 20 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 23 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 21 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 24 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
| 22 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 25 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 23 #include "chrome/browser/net/prediction_options.h" | 26 #include "chrome/browser/net/prediction_options.h" |
| 24 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 27 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 25 #include "chrome/browser/profiles/profile_manager.h" | 28 #include "chrome/browser/profiles/profile_manager.h" |
| 26 #include "chrome/browser/translate/chrome_translate_client.h" | 29 #include "chrome/browser/translate/chrome_translate_client.h" |
| 27 #include "chrome/browser/ui/android/android_about_app_info.h" | 30 #include "chrome/browser/ui/android/android_about_app_info.h" |
| 28 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 29 #include "chrome/grit/locale_settings.h" | 32 #include "chrome/grit/locale_settings.h" |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 if (weak_chrome_native_preferences_.get(env).is_null()) | 476 if (weak_chrome_native_preferences_.get(env).is_null()) |
| 474 return; | 477 return; |
| 475 | 478 |
| 476 Java_PrefServiceBridge_browsingDataCleared( | 479 Java_PrefServiceBridge_browsingDataCleared( |
| 477 env, weak_chrome_native_preferences_.get(env).obj()); | 480 env, weak_chrome_native_preferences_.get(env).obj()); |
| 478 } | 481 } |
| 479 | 482 |
| 480 private: | 483 private: |
| 481 JavaObjectWeakGlobalRef weak_chrome_native_preferences_; | 484 JavaObjectWeakGlobalRef weak_chrome_native_preferences_; |
| 482 }; | 485 }; |
| 486 |
| 487 static const char* GetDeletionPreferenceFromCheckboxIndex(int index) { |
| 488 // This enumeration of preferences must match the data types we offer for |
| 489 // deletion in ClearBrowsingDataDialogFragment. |
| 490 static const char* pref_names[] = { |
| 491 prefs::kDeleteBrowsingHistory, |
| 492 prefs::kDeleteCache, |
| 493 prefs::kDeleteCookies, |
| 494 prefs::kDeletePasswords, |
| 495 prefs::kDeleteFormData |
| 496 }; |
| 497 DCHECK_GE(index, 0); |
| 498 DCHECK_LT(index, (int)arraysize(pref_names)); |
| 499 |
| 500 return pref_names[index]; |
| 501 } |
| 502 |
| 483 } // namespace | 503 } // namespace |
| 484 | 504 |
| 505 static jboolean GetBrowsingDataDeletionPreference( |
| 506 JNIEnv* env, |
| 507 const JavaParamRef<jobject>& obj, |
| 508 jint index) { |
| 509 return GetOriginalProfile()->GetPrefs()->GetBoolean( |
| 510 GetDeletionPreferenceFromCheckboxIndex(index)); |
| 511 } |
| 512 |
| 513 static void SetBrowsingDataDeletionPreference( |
| 514 JNIEnv* env, |
| 515 const JavaParamRef<jobject>& obj, |
| 516 jint index, |
| 517 jboolean value) { |
| 518 GetOriginalProfile()->GetPrefs()->SetBoolean( |
| 519 GetDeletionPreferenceFromCheckboxIndex(index), value); |
| 520 } |
| 521 |
| 485 static void ClearBrowsingData(JNIEnv* env, | 522 static void ClearBrowsingData(JNIEnv* env, |
| 486 const JavaParamRef<jobject>& obj, | 523 const JavaParamRef<jobject>& obj, |
| 487 jboolean history, | 524 jboolean history, |
| 488 jboolean cache, | 525 jboolean cache, |
| 489 jboolean cookies_and_site_data, | 526 jboolean cookies_and_site_data, |
| 490 jboolean passwords, | 527 jboolean passwords, |
| 491 jboolean form_data) { | 528 jboolean form_data) { |
| 492 // BrowsingDataRemover deletes itself. | 529 // BrowsingDataRemover deletes itself. |
| 493 BrowsingDataRemover* browsing_data_remover = | 530 BrowsingDataRemover* browsing_data_remover = |
| 494 BrowsingDataRemover::CreateForPeriod( | 531 BrowsingDataRemover::CreateForPeriod( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 512 remove_mask |= BrowsingDataRemover::REMOVE_FORM_DATA; | 549 remove_mask |= BrowsingDataRemover::REMOVE_FORM_DATA; |
| 513 browsing_data_remover->Remove(remove_mask, | 550 browsing_data_remover->Remove(remove_mask, |
| 514 BrowsingDataHelper::UNPROTECTED_WEB); | 551 BrowsingDataHelper::UNPROTECTED_WEB); |
| 515 } | 552 } |
| 516 | 553 |
| 517 static jboolean CanDeleteBrowsingHistory(JNIEnv* env, | 554 static jboolean CanDeleteBrowsingHistory(JNIEnv* env, |
| 518 const JavaParamRef<jobject>& obj) { | 555 const JavaParamRef<jobject>& obj) { |
| 519 return GetPrefService()->GetBoolean(prefs::kAllowDeletingBrowserHistory); | 556 return GetPrefService()->GetBoolean(prefs::kAllowDeletingBrowserHistory); |
| 520 } | 557 } |
| 521 | 558 |
| 559 static void BrowsingDataCounterCallback( |
| 560 JavaObjectWeakGlobalRef caller, |
| 561 JavaObjectWeakGlobalRef owner, |
| 562 scoped_ptr<BrowsingDataCounter::Result> result) { |
| 563 JNIEnv* env = AttachCurrentThread(); |
| 564 if (caller.get(env).is_null()) |
| 565 return; |
| 566 |
| 567 ScopedJavaLocalRef<jstring> resultString = |
| 568 base::android::ConvertUTF16ToJavaString( |
| 569 env, browsing_data::GetCounterTextFromResult(result.get())); |
| 570 Java_PrefServiceBridge_onBrowsingDataCounterFinished( |
| 571 env, caller.get(env).obj(), owner.get(env).obj(), resultString.obj()); |
| 572 } |
| 573 |
| 574 static jlong CreateBrowsingDataCounter(JNIEnv* env, |
| 575 const JavaParamRef<jobject>& obj, |
| 576 const JavaParamRef<jobject>& owner, |
| 577 jint index) { |
| 578 BrowsingDataCounter* counter = |
| 579 browsing_data::CreateCounterForPreference( |
| 580 GetDeletionPreferenceFromCheckboxIndex(index)); |
| 581 if (!counter) |
| 582 return reinterpret_cast<intptr_t>(nullptr); |
| 583 |
| 584 JavaObjectWeakGlobalRef caller_ref(env, obj); |
| 585 JavaObjectWeakGlobalRef owner_ref(env, owner); |
| 586 |
| 587 counter->Init( |
| 588 GetOriginalProfile(), |
| 589 base::Bind(&BrowsingDataCounterCallback, |
| 590 caller_ref, |
| 591 owner_ref)); |
| 592 counter->Restart(); |
| 593 return reinterpret_cast<intptr_t>(counter); |
| 594 } |
| 595 |
| 596 static void DestroyBrowsingDataCounter(JNIEnv* env, |
| 597 const JavaParamRef<jobject>& obj, |
| 598 jlong counter) { |
| 599 scoped_ptr<BrowsingDataCounter> to_destroy( |
| 600 reinterpret_cast<BrowsingDataCounter*>(counter)); |
| 601 } |
| 602 |
| 522 static void SetAllowCookiesEnabled(JNIEnv* env, | 603 static void SetAllowCookiesEnabled(JNIEnv* env, |
| 523 const JavaParamRef<jobject>& obj, | 604 const JavaParamRef<jobject>& obj, |
| 524 jboolean allow) { | 605 jboolean allow) { |
| 525 HostContentSettingsMap* host_content_settings_map = | 606 HostContentSettingsMap* host_content_settings_map = |
| 526 HostContentSettingsMapFactory::GetForProfile(GetOriginalProfile()); | 607 HostContentSettingsMapFactory::GetForProfile(GetOriginalProfile()); |
| 527 host_content_settings_map->SetDefaultContentSetting( | 608 host_content_settings_map->SetDefaultContentSetting( |
| 528 CONTENT_SETTINGS_TYPE_COOKIES, | 609 CONTENT_SETTINGS_TYPE_COOKIES, |
| 529 allow ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); | 610 allow ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); |
| 530 } | 611 } |
| 531 | 612 |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 935 ContentSettingsType content_type) { | 1016 ContentSettingsType content_type) { |
| 936 JNIEnv* env = AttachCurrentThread(); | 1017 JNIEnv* env = AttachCurrentThread(); |
| 937 base::android::ScopedJavaLocalRef<jstring> android_permission = | 1018 base::android::ScopedJavaLocalRef<jstring> android_permission = |
| 938 Java_PrefServiceBridge_getAndroidPermissionForContentSetting( | 1019 Java_PrefServiceBridge_getAndroidPermissionForContentSetting( |
| 939 env, content_type); | 1020 env, content_type); |
| 940 if (android_permission.is_null()) | 1021 if (android_permission.is_null()) |
| 941 return std::string(); | 1022 return std::string(); |
| 942 | 1023 |
| 943 return ConvertJavaStringToUTF8(android_permission); | 1024 return ConvertJavaStringToUTF8(android_permission); |
| 944 } | 1025 } |
| OLD | NEW |