| 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 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 #include "content/public/browser/browser_thread.h" | 65 #include "content/public/browser/browser_thread.h" |
| 66 #include "jni/PrefServiceBridge_jni.h" | 66 #include "jni/PrefServiceBridge_jni.h" |
| 67 #include "third_party/icu/source/common/unicode/uloc.h" | 67 #include "third_party/icu/source/common/unicode/uloc.h" |
| 68 #include "ui/base/l10n/l10n_util.h" | 68 #include "ui/base/l10n/l10n_util.h" |
| 69 | 69 |
| 70 using base::android::AttachCurrentThread; | 70 using base::android::AttachCurrentThread; |
| 71 using base::android::CheckException; | 71 using base::android::CheckException; |
| 72 using base::android::ConvertJavaStringToUTF8; | 72 using base::android::ConvertJavaStringToUTF8; |
| 73 using base::android::ConvertUTF8ToJavaString; | 73 using base::android::ConvertUTF8ToJavaString; |
| 74 using base::android::JavaParamRef; | 74 using base::android::JavaParamRef; |
| 75 using base::android::JavaRef; |
| 75 using base::android::ScopedJavaLocalRef; | 76 using base::android::ScopedJavaLocalRef; |
| 76 using base::android::ScopedJavaGlobalRef; | 77 using base::android::ScopedJavaGlobalRef; |
| 77 using content::BrowserThread; | 78 using content::BrowserThread; |
| 78 | 79 |
| 79 namespace { | 80 namespace { |
| 80 | 81 |
| 81 const size_t kMaxImportantSites = 5; | 82 const size_t kMaxImportantSites = 5; |
| 82 | 83 |
| 83 Profile* GetOriginalProfile() { | 84 Profile* GetOriginalProfile() { |
| 84 return ProfileManager::GetActiveUserProfile()->GetOriginalProfile(); | 85 return ProfileManager::GetActiveUserProfile()->GetOriginalProfile(); |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 JNIEnv* env, | 726 JNIEnv* env, |
| 726 const JavaParamRef<jclass>& clazz, | 727 const JavaParamRef<jclass>& clazz, |
| 727 const JavaParamRef<jstring>& jorigin) { | 728 const JavaParamRef<jstring>& jorigin) { |
| 728 GURL origin(base::android::ConvertJavaStringToUTF8(jorigin)); | 729 GURL origin(base::android::ConvertJavaStringToUTF8(jorigin)); |
| 729 CHECK(origin.is_valid()); | 730 CHECK(origin.is_valid()); |
| 730 ImportantSitesUtil::MarkOriginAsImportantForTesting(GetOriginalProfile(), | 731 ImportantSitesUtil::MarkOriginAsImportantForTesting(GetOriginalProfile(), |
| 731 origin); | 732 origin); |
| 732 } | 733 } |
| 733 | 734 |
| 734 static void ShowNoticeAboutOtherFormsOfBrowsingHistory( | 735 static void ShowNoticeAboutOtherFormsOfBrowsingHistory( |
| 735 ScopedJavaGlobalRef<jobject>* listener, | 736 const JavaRef<jobject>& listener, |
| 736 bool show) { | 737 bool show) { |
| 737 JNIEnv* env = AttachCurrentThread(); | 738 JNIEnv* env = AttachCurrentThread(); |
| 738 UMA_HISTOGRAM_BOOLEAN( | 739 UMA_HISTOGRAM_BOOLEAN( |
| 739 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated", show); | 740 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated", show); |
| 740 if (!show) | 741 if (!show) |
| 741 return; | 742 return; |
| 742 Java_OtherFormsOfBrowsingHistoryListener_showNoticeAboutOtherFormsOfBrowsingHi
story( | 743 Java_OtherFormsOfBrowsingHistoryListener_showNoticeAboutOtherFormsOfBrowsingHi
story( |
| 743 env, listener->obj()); | 744 env, listener); |
| 744 } | 745 } |
| 745 | 746 |
| 746 static void EnableDialogAboutOtherFormsOfBrowsingHistory( | 747 static void EnableDialogAboutOtherFormsOfBrowsingHistory( |
| 747 ScopedJavaGlobalRef<jobject>* listener, | 748 const JavaRef<jobject>& listener, |
| 748 bool enabled) { | 749 bool enabled) { |
| 749 JNIEnv* env = AttachCurrentThread(); | 750 JNIEnv* env = AttachCurrentThread(); |
| 750 if (!enabled) | 751 if (!enabled) |
| 751 return; | 752 return; |
| 752 Java_OtherFormsOfBrowsingHistoryListener_enableDialogAboutOtherFormsOfBrowsing
History( | 753 Java_OtherFormsOfBrowsingHistoryListener_enableDialogAboutOtherFormsOfBrowsing
History( |
| 753 env, listener->obj()); | 754 env, listener); |
| 754 } | 755 } |
| 755 | 756 |
| 756 static void RequestInfoAboutOtherFormsOfBrowsingHistory( | 757 static void RequestInfoAboutOtherFormsOfBrowsingHistory( |
| 757 JNIEnv* env, | 758 JNIEnv* env, |
| 758 const JavaParamRef<jobject>& obj, | 759 const JavaParamRef<jobject>& obj, |
| 759 const JavaParamRef<jobject>& listener) { | 760 const JavaParamRef<jobject>& listener) { |
| 760 // The permanent notice in the footer. | 761 // The permanent notice in the footer. |
| 761 browsing_data::ShouldShowNoticeAboutOtherFormsOfBrowsingHistory( | 762 browsing_data::ShouldShowNoticeAboutOtherFormsOfBrowsingHistory( |
| 762 ProfileSyncServiceFactory::GetForProfile(GetOriginalProfile()), | 763 ProfileSyncServiceFactory::GetForProfile(GetOriginalProfile()), |
| 763 WebHistoryServiceFactory::GetForProfile(GetOriginalProfile()), | 764 WebHistoryServiceFactory::GetForProfile(GetOriginalProfile()), |
| 764 base::Bind(&ShowNoticeAboutOtherFormsOfBrowsingHistory, | 765 base::Bind(&ShowNoticeAboutOtherFormsOfBrowsingHistory, |
| 765 base::Owned(new ScopedJavaGlobalRef<jobject>(env, listener)))); | 766 ScopedJavaGlobalRef<jobject>(env, listener))); |
| 766 | 767 |
| 767 // The one-time notice in the dialog. | 768 // The one-time notice in the dialog. |
| 768 browsing_data::ShouldPopupDialogAboutOtherFormsOfBrowsingHistory( | 769 browsing_data::ShouldPopupDialogAboutOtherFormsOfBrowsingHistory( |
| 769 ProfileSyncServiceFactory::GetForProfile(GetOriginalProfile()), | 770 ProfileSyncServiceFactory::GetForProfile(GetOriginalProfile()), |
| 770 WebHistoryServiceFactory::GetForProfile(GetOriginalProfile()), | 771 WebHistoryServiceFactory::GetForProfile(GetOriginalProfile()), |
| 771 chrome::GetChannel(), | 772 chrome::GetChannel(), |
| 772 base::Bind(&EnableDialogAboutOtherFormsOfBrowsingHistory, | 773 base::Bind(&EnableDialogAboutOtherFormsOfBrowsingHistory, |
| 773 base::Owned(new ScopedJavaGlobalRef<jobject>(env, listener)))); | 774 ScopedJavaGlobalRef<jobject>(env, listener))); |
| 774 } | 775 } |
| 775 | 776 |
| 776 static void SetAutoplayEnabled(JNIEnv* env, | 777 static void SetAutoplayEnabled(JNIEnv* env, |
| 777 const JavaParamRef<jobject>& obj, | 778 const JavaParamRef<jobject>& obj, |
| 778 jboolean allow) { | 779 jboolean allow) { |
| 779 HostContentSettingsMap* host_content_settings_map = | 780 HostContentSettingsMap* host_content_settings_map = |
| 780 HostContentSettingsMapFactory::GetForProfile(GetOriginalProfile()); | 781 HostContentSettingsMapFactory::GetForProfile(GetOriginalProfile()); |
| 781 host_content_settings_map->SetDefaultContentSetting( | 782 host_content_settings_map->SetDefaultContentSetting( |
| 782 CONTENT_SETTINGS_TYPE_AUTOPLAY, | 783 CONTENT_SETTINGS_TYPE_AUTOPLAY, |
| 783 allow ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); | 784 allow ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1205 | 1206 |
| 1206 return ConvertJavaStringToUTF8(android_permission); | 1207 return ConvertJavaStringToUTF8(android_permission); |
| 1207 } | 1208 } |
| 1208 | 1209 |
| 1209 static void SetSupervisedUserId(JNIEnv* env, | 1210 static void SetSupervisedUserId(JNIEnv* env, |
| 1210 const JavaParamRef<jobject>& obj, | 1211 const JavaParamRef<jobject>& obj, |
| 1211 const JavaParamRef<jstring>& pref) { | 1212 const JavaParamRef<jstring>& pref) { |
| 1212 GetPrefService()->SetString(prefs::kSupervisedUserId, | 1213 GetPrefService()->SetString(prefs::kSupervisedUserId, |
| 1213 ConvertJavaStringToUTF8(env, pref)); | 1214 ConvertJavaStringToUTF8(env, pref)); |
| 1214 } | 1215 } |
| OLD | NEW |