| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/website_preference_bridge.h" | 5 #include "chrome/browser/android/preferences/website_preference_bridge.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/android/callback_android.h" | 11 #include "base/android/callback_android.h" |
| 12 #include "base/android/jni_android.h" | 12 #include "base/android/jni_android.h" |
| 13 #include "base/android/jni_string.h" | 13 #include "base/android/jni_string.h" |
| 14 #include "base/android/scoped_java_ref.h" | 14 #include "base/android/scoped_java_ref.h" |
| 15 #include "base/bind.h" | 15 #include "base/bind.h" |
| 16 #include "base/bind_helpers.h" | 16 #include "base/bind_helpers.h" |
| 17 #include "base/json/json_reader.h" | 17 #include "base/json/json_reader.h" |
| 18 #include "base/json/json_writer.h" | 18 #include "base/json/json_writer.h" |
| 19 #include "base/logging.h" | 19 #include "base/logging.h" |
| 20 #include "base/macros.h" | 20 #include "base/macros.h" |
| 21 #include "chrome/browser/browsing_data/browsing_data_flash_lso_helper.h" | 21 #include "chrome/browser/browsing_data/browsing_data_flash_lso_helper.h" |
| 22 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" | 22 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" |
| 23 #include "chrome/browser/browsing_data/browsing_data_quota_helper.h" | 23 #include "chrome/browser/browsing_data/browsing_data_quota_helper.h" |
| 24 #include "chrome/browser/browsing_data/cookies_tree_model.h" | 24 #include "chrome/browser/browsing_data/cookies_tree_model.h" |
| 25 #include "chrome/browser/browsing_data/local_data_container.h" | 25 #include "chrome/browser/browsing_data/local_data_container.h" |
| 26 #include "chrome/browser/browsing_data/origin_filter_builder.h" | |
| 27 #include "chrome/browser/content_settings/cookie_settings_factory.h" | 26 #include "chrome/browser/content_settings/cookie_settings_factory.h" |
| 28 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 27 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 29 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 28 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 30 #include "chrome/browser/content_settings/web_site_settings_uma_util.h" | 29 #include "chrome/browser/content_settings/web_site_settings_uma_util.h" |
| 31 #include "chrome/browser/engagement/important_sites_util.h" | 30 #include "chrome/browser/engagement/important_sites_util.h" |
| 32 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 31 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
| 33 #include "chrome/browser/permissions/permission_uma_util.h" | 32 #include "chrome/browser/permissions/permission_uma_util.h" |
| 34 #include "chrome/browser/permissions/permission_util.h" | 33 #include "chrome/browser/permissions/permission_util.h" |
| 35 #include "chrome/browser/profiles/profile.h" | 34 #include "chrome/browser/profiles/profile.h" |
| 36 #include "chrome/browser/profiles/profile_manager.h" | 35 #include "chrome/browser/profiles/profile_manager.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 if (is_incognito) | 67 if (is_incognito) |
| 69 profile = profile->GetOffTheRecordProfile(); | 68 profile = profile->GetOffTheRecordProfile(); |
| 70 return profile; | 69 return profile; |
| 71 } | 70 } |
| 72 | 71 |
| 73 HostContentSettingsMap* GetHostContentSettingsMap(bool is_incognito) { | 72 HostContentSettingsMap* GetHostContentSettingsMap(bool is_incognito) { |
| 74 return HostContentSettingsMapFactory::GetForProfile( | 73 return HostContentSettingsMapFactory::GetForProfile( |
| 75 GetActiveUserProfile(is_incognito)); | 74 GetActiveUserProfile(is_incognito)); |
| 76 } | 75 } |
| 77 | 76 |
| 78 bool ForwardPrimaryPatternCallback( | |
| 79 const base::Callback<bool(const ContentSettingsPattern&)> predicate, | |
| 80 const ContentSettingsPattern& primary_pattern, | |
| 81 const ContentSettingsPattern& secondary_pattern) { | |
| 82 return predicate.Run(primary_pattern); | |
| 83 } | |
| 84 | |
| 85 typedef void (*InfoListInsertionFunction)( | 77 typedef void (*InfoListInsertionFunction)( |
| 86 JNIEnv*, | 78 JNIEnv*, |
| 87 const base::android::JavaRefOrBare<jobject>&, | 79 const base::android::JavaRefOrBare<jobject>&, |
| 88 const base::android::JavaRefOrBare<jstring>&, | 80 const base::android::JavaRefOrBare<jstring>&, |
| 89 const base::android::JavaRefOrBare<jstring>&); | 81 const base::android::JavaRefOrBare<jstring>&); |
| 90 | 82 |
| 91 void GetOrigins(JNIEnv* env, | 83 void GetOrigins(JNIEnv* env, |
| 92 ContentSettingsType content_type, | 84 ContentSettingsType content_type, |
| 93 InfoListInsertionFunction insertionFunc, | 85 InfoListInsertionFunction insertionFunc, |
| 94 jobject list, | 86 jobject list, |
| (...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 Profile* profile = ProfileManager::GetActiveUserProfile(); | 729 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 738 GURL url(ConvertJavaStringToUTF8(env, jorigin)); | 730 GURL url(ConvertJavaStringToUTF8(env, jorigin)); |
| 739 scoped_refptr<SiteDataDeleteHelper> site_data_deleter( | 731 scoped_refptr<SiteDataDeleteHelper> site_data_deleter( |
| 740 new SiteDataDeleteHelper(profile, url)); | 732 new SiteDataDeleteHelper(profile, url)); |
| 741 site_data_deleter->Run(); | 733 site_data_deleter->Run(); |
| 742 } | 734 } |
| 743 | 735 |
| 744 static void ClearBannerData(JNIEnv* env, | 736 static void ClearBannerData(JNIEnv* env, |
| 745 const JavaParamRef<jclass>& clazz, | 737 const JavaParamRef<jclass>& clazz, |
| 746 const JavaParamRef<jstring>& jorigin) { | 738 const JavaParamRef<jstring>& jorigin) { |
| 747 OriginFilterBuilder builder(OriginFilterBuilder::WHITELIST); | 739 GetHostContentSettingsMap(false)->SetWebsiteSettingDefaultScope( |
| 748 builder.AddOrigin(url::Origin(GURL(ConvertJavaStringToUTF8(env, jorigin)))); | 740 GURL(ConvertJavaStringToUTF8(env, jorigin)), GURL(), |
| 749 GetHostContentSettingsMap(false) | 741 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr); |
| 750 ->ClearSettingsForOneTypeWithPredicate( | |
| 751 CONTENT_SETTINGS_TYPE_APP_BANNER, | |
| 752 base::Bind(&ForwardPrimaryPatternCallback, | |
| 753 builder.BuildWebsiteSettingsPatternMatchesFilter())); | |
| 754 } | 742 } |
| 755 | 743 |
| 756 // Register native methods | 744 // Register native methods |
| 757 bool RegisterWebsitePreferenceBridge(JNIEnv* env) { | 745 bool RegisterWebsitePreferenceBridge(JNIEnv* env) { |
| 758 return RegisterNativesImpl(env); | 746 return RegisterNativesImpl(env); |
| 759 } | 747 } |
| OLD | NEW |