Chromium Code Reviews| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/android/build_info.h" | 11 #include "base/android/build_info.h" |
| 12 #include "base/android/jni_android.h" | 12 #include "base/android/jni_android.h" |
| 13 #include "base/android/jni_array.h" | |
| 13 #include "base/android/jni_string.h" | 14 #include "base/android/jni_string.h" |
| 14 #include "base/android/jni_weak_ref.h" | 15 #include "base/android/jni_weak_ref.h" |
| 15 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 16 #include "base/files/file_util.h" | 17 #include "base/files/file_util.h" |
| 17 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/prefs/pref_service.h" | 19 #include "base/prefs/pref_service.h" |
| 19 #include "base/scoped_observer.h" | 20 #include "base/scoped_observer.h" |
| 20 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 21 #include "base/values.h" | 22 #include "base/values.h" |
| 22 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
| 24 #include "chrome/browser/browsing_data/browsing_data_counter_utils.h" | |
| 23 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 25 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 24 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 26 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
| 25 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | 27 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" |
| 26 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 28 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 27 #include "chrome/browser/net/prediction_options.h" | 29 #include "chrome/browser/net/prediction_options.h" |
| 28 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 30 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 29 #include "chrome/browser/profiles/profile_manager.h" | 31 #include "chrome/browser/profiles/profile_manager.h" |
| 30 #include "chrome/browser/translate/chrome_translate_client.h" | 32 #include "chrome/browser/translate/chrome_translate_client.h" |
| 31 #include "chrome/browser/ui/android/android_about_app_info.h" | 33 #include "chrome/browser/ui/android/android_about_app_info.h" |
| 32 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 493 env, weak_chrome_native_preferences_.get(env).obj()); | 495 env, weak_chrome_native_preferences_.get(env).obj()); |
| 494 } | 496 } |
| 495 | 497 |
| 496 private: | 498 private: |
| 497 JavaObjectWeakGlobalRef weak_chrome_native_preferences_; | 499 JavaObjectWeakGlobalRef weak_chrome_native_preferences_; |
| 498 ScopedObserver<BrowsingDataRemover, BrowsingDataRemover::Observer> observer_; | 500 ScopedObserver<BrowsingDataRemover, BrowsingDataRemover::Observer> observer_; |
| 499 }; | 501 }; |
| 500 | 502 |
| 501 } // namespace | 503 } // namespace |
| 502 | 504 |
| 505 static jboolean GetBrowsingDataDeletionPreference( | |
| 506 JNIEnv* env, | |
| 507 const JavaParamRef<jobject>& obj, | |
| 508 jint data_type) { | |
| 509 DCHECK_GE(data_type, 0); | |
| 510 DCHECK_LT(data_type, BrowsingDataType::NUM_TYPES); | |
| 511 | |
| 512 // If there is no corresponding preference for this |data_type|, pretend | |
| 513 // that it's set to false. | |
| 514 // TODO(msramek): Consider defining native-side preferences for all Java UI | |
| 515 // data types for consistency. | |
| 516 std::string pref; | |
| 517 if (GetDeletionPreferenceFromDataType( | |
| 518 static_cast<BrowsingDataType>(data_type), &pref)) { | |
| 519 return false; | |
| 520 } | |
| 521 | |
| 522 return GetOriginalProfile()->GetPrefs()->GetBoolean(pref); | |
| 523 } | |
| 524 | |
| 525 static void SetBrowsingDataDeletionPreference( | |
| 526 JNIEnv* env, | |
| 527 const JavaParamRef<jobject>& obj, | |
| 528 jint data_type, | |
| 529 jboolean value) { | |
| 530 DCHECK_GE(data_type, 0); | |
| 531 DCHECK_LT(data_type, BrowsingDataType::NUM_TYPES); | |
| 532 | |
| 533 std::string pref; | |
| 534 if (!GetDeletionPreferenceFromDataType( | |
| 535 static_cast<BrowsingDataType>(data_type), &pref)) { | |
| 536 return; | |
| 537 } | |
| 538 | |
| 539 GetOriginalProfile()->GetPrefs()->SetBoolean(pref, value); | |
| 540 } | |
| 541 | |
| 503 static void ClearBrowsingData(JNIEnv* env, | 542 static void ClearBrowsingData(JNIEnv* env, |
| 504 const JavaParamRef<jobject>& obj, | 543 const JavaParamRef<jobject>& obj, |
| 505 jboolean history, | 544 const JavaParamRef<jintArray>& data_types) { |
| 506 jboolean cache, | |
| 507 jboolean cookies_and_site_data, | |
| 508 jboolean passwords, | |
| 509 jboolean form_data) { | |
| 510 BrowsingDataRemover* browsing_data_remover = | 545 BrowsingDataRemover* browsing_data_remover = |
| 511 BrowsingDataRemoverFactory::GetForBrowserContext(GetOriginalProfile()); | 546 BrowsingDataRemoverFactory::GetForBrowserContext(GetOriginalProfile()); |
| 512 // ClearBrowsingDataObserver removes itself when |browsing_data_remover| is | 547 // ClearBrowsingDataObserver removes itself when |browsing_data_remover| is |
|
newt (away)
2016/01/13 20:01:49
s/removes/deletes/ ?
msramek
2016/01/14 15:45:43
Done. Although this is from the rebase, not mine :
| |
| 513 // done. | 548 // done. |
| 514 new ClearBrowsingDataObserver(env, obj, browsing_data_remover); | 549 new ClearBrowsingDataObserver(env, obj, browsing_data_remover); |
| 515 | 550 |
| 551 std::vector<int> data_types_vector; | |
| 552 base::android::JavaIntArrayToIntVector(env, data_types, &data_types_vector); | |
| 553 | |
| 516 int remove_mask = 0; | 554 int remove_mask = 0; |
| 517 if (history) | 555 for (const int data_type : data_types_vector) { |
| 518 remove_mask |= BrowsingDataRemover::REMOVE_HISTORY; | 556 switch (static_cast<BrowsingDataType>(data_type)) { |
| 519 if (cache) | 557 case HISTORY: |
| 520 remove_mask |= BrowsingDataRemover::REMOVE_CACHE; | 558 remove_mask |= BrowsingDataRemover::REMOVE_HISTORY; |
| 521 if (cookies_and_site_data) { | 559 break; |
| 522 remove_mask |= BrowsingDataRemover::REMOVE_COOKIES; | 560 case CACHE: |
| 523 remove_mask |= BrowsingDataRemover::REMOVE_SITE_DATA; | 561 remove_mask |= BrowsingDataRemover::REMOVE_CACHE; |
| 562 break; | |
| 563 case COOKIES: | |
| 564 remove_mask |= BrowsingDataRemover::REMOVE_COOKIES; | |
| 565 remove_mask |= BrowsingDataRemover::REMOVE_SITE_DATA; | |
| 566 break; | |
| 567 case PASSWORDS: | |
| 568 remove_mask |= BrowsingDataRemover::REMOVE_PASSWORDS; | |
| 569 break; | |
| 570 case FORM_DATA: | |
| 571 remove_mask |= BrowsingDataRemover::REMOVE_FORM_DATA; | |
| 572 break; | |
| 573 default: | |
| 574 NOTREACHED(); | |
| 575 } | |
| 524 } | 576 } |
| 525 if (passwords) | 577 |
| 526 remove_mask |= BrowsingDataRemover::REMOVE_PASSWORDS; | |
| 527 if (form_data) | |
| 528 remove_mask |= BrowsingDataRemover::REMOVE_FORM_DATA; | |
| 529 browsing_data_remover->Remove(BrowsingDataRemover::Unbounded(), remove_mask, | 578 browsing_data_remover->Remove(BrowsingDataRemover::Unbounded(), remove_mask, |
| 530 BrowsingDataHelper::UNPROTECTED_WEB); | 579 BrowsingDataHelper::UNPROTECTED_WEB); |
| 531 } | 580 } |
| 532 | 581 |
| 533 static jboolean CanDeleteBrowsingHistory(JNIEnv* env, | 582 static jboolean CanDeleteBrowsingHistory(JNIEnv* env, |
| 534 const JavaParamRef<jobject>& obj) { | 583 const JavaParamRef<jobject>& obj) { |
| 535 return GetPrefService()->GetBoolean(prefs::kAllowDeletingBrowserHistory); | 584 return GetPrefService()->GetBoolean(prefs::kAllowDeletingBrowserHistory); |
| 536 } | 585 } |
| 537 | 586 |
| 538 static void SetAllowCookiesEnabled(JNIEnv* env, | 587 static void SetAllowCookiesEnabled(JNIEnv* env, |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 966 | 1015 |
| 967 return ConvertJavaStringToUTF8(android_permission); | 1016 return ConvertJavaStringToUTF8(android_permission); |
| 968 } | 1017 } |
| 969 | 1018 |
| 970 static void SetSupervisedUserId(JNIEnv* env, | 1019 static void SetSupervisedUserId(JNIEnv* env, |
| 971 const JavaParamRef<jobject>& obj, | 1020 const JavaParamRef<jobject>& obj, |
| 972 const JavaParamRef<jstring>& pref) { | 1021 const JavaParamRef<jstring>& pref) { |
| 973 GetPrefService()->SetString(prefs::kSupervisedUserId, | 1022 GetPrefService()->SetString(prefs::kSupervisedUserId, |
| 974 ConvertJavaStringToUTF8(env, pref)); | 1023 ConvertJavaStringToUTF8(env, pref)); |
| 975 } | 1024 } |
| OLD | NEW |