| 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 "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/android/scoped_java_ref.h" | 9 #include "base/android/scoped_java_ref.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 GetActiveUserProfile(is_incognito)); | 52 GetActiveUserProfile(is_incognito)); |
| 53 } | 53 } |
| 54 | 54 |
| 55 typedef void (*InfoListInsertionFunction)(JNIEnv*, jobject, jstring, jstring); | 55 typedef void (*InfoListInsertionFunction)(JNIEnv*, jobject, jstring, jstring); |
| 56 | 56 |
| 57 void GetOrigins(JNIEnv* env, | 57 void GetOrigins(JNIEnv* env, |
| 58 ContentSettingsType content_type, | 58 ContentSettingsType content_type, |
| 59 InfoListInsertionFunction insertionFunc, | 59 InfoListInsertionFunction insertionFunc, |
| 60 jobject list, | 60 jobject list, |
| 61 jboolean managedOnly) { | 61 jboolean managedOnly) { |
| 62 using ProviderType = HostContentSettingsMap::ProviderType; |
| 62 ContentSettingsForOneType all_settings; | 63 ContentSettingsForOneType all_settings; |
| 63 HostContentSettingsMap* content_settings_map = | 64 HostContentSettingsMap* content_settings_map = |
| 64 GetHostContentSettingsMap(false); | 65 GetHostContentSettingsMap(false); |
| 65 content_settings_map->GetSettingsForOneType( | 66 content_settings_map->GetSettingsForOneType( |
| 66 content_type, std::string(), &all_settings); | 67 content_type, std::string(), &all_settings); |
| 67 ContentSetting default_content_setting = content_settings_map-> | 68 ContentSetting default_content_setting = content_settings_map-> |
| 68 GetDefaultContentSetting(content_type, NULL); | 69 GetDefaultContentSetting(content_type, NULL); |
| 69 // Now add all origins that have a non-default setting to the list. | 70 // Now add all origins that have a non-default setting to the list. |
| 70 for (const auto& settings_it : all_settings) { | 71 for (const auto& settings_it : all_settings) { |
| 71 if (settings_it.setting == default_content_setting) | 72 if (settings_it.setting == default_content_setting) |
| 72 continue; | 73 continue; |
| 73 if (managedOnly && | 74 if (managedOnly) { |
| 74 HostContentSettingsMap::GetProviderTypeFromSource(settings_it.source) != | 75 ProviderType provider = |
| 75 HostContentSettingsMap::ProviderType::POLICY_PROVIDER) { | 76 HostContentSettingsMap::GetProviderTypeFromSource(settings_it.source); |
| 76 continue; | 77 if (provider != ProviderType::POLICY_PROVIDER && |
| 78 provider != ProviderType::RECOMMENDED_POLICY_PROVIDER) { |
| 79 continue; |
| 80 } |
| 77 } | 81 } |
| 78 const std::string origin = settings_it.primary_pattern.ToString(); | 82 const std::string origin = settings_it.primary_pattern.ToString(); |
| 79 const std::string embedder = settings_it.secondary_pattern.ToString(); | 83 const std::string embedder = settings_it.secondary_pattern.ToString(); |
| 80 | 84 |
| 81 // The string |jorigin| is used to group permissions together in the Site | 85 // The string |jorigin| is used to group permissions together in the Site |
| 82 // Settings list. In order to group sites with the same origin, remove any | 86 // Settings list. In order to group sites with the same origin, remove any |
| 83 // standard port from the end of the URL if it's present (i.e. remove :443 | 87 // standard port from the end of the URL if it's present (i.e. remove :443 |
| 84 // for HTTPS sites and :80 for HTTP sites). | 88 // for HTTPS sites and :80 for HTTP sites). |
| 85 // TODO(sashab,lgarron): Find out which settings are being saved with the | 89 // TODO(sashab,lgarron): Find out which settings are being saved with the |
| 86 // port and omit it if it's the standard port. | 90 // port and omit it if it's the standard port. |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 static scoped_refptr<content_settings::CookieSettings> GetCookieSettings() { | 420 static scoped_refptr<content_settings::CookieSettings> GetCookieSettings() { |
| 417 // A single cookie setting applies to both incognito and non-incognito. | 421 // A single cookie setting applies to both incognito and non-incognito. |
| 418 Profile* profile = ProfileManager::GetActiveUserProfile(); | 422 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 419 return CookieSettingsFactory::GetForProfile(profile); | 423 return CookieSettingsFactory::GetForProfile(profile); |
| 420 } | 424 } |
| 421 | 425 |
| 422 static void GetCookieOrigins(JNIEnv* env, | 426 static void GetCookieOrigins(JNIEnv* env, |
| 423 const JavaParamRef<jclass>& clazz, | 427 const JavaParamRef<jclass>& clazz, |
| 424 const JavaParamRef<jobject>& list, | 428 const JavaParamRef<jobject>& list, |
| 425 jboolean managedOnly) { | 429 jboolean managedOnly) { |
| 430 using ProviderType = HostContentSettingsMap::ProviderType; |
| 426 ContentSettingsForOneType all_settings; | 431 ContentSettingsForOneType all_settings; |
| 427 GetCookieSettings()->GetCookieSettings(&all_settings); | 432 GetCookieSettings()->GetCookieSettings(&all_settings); |
| 428 const ContentSetting default_setting = | 433 const ContentSetting default_setting = |
| 429 GetCookieSettings()->GetDefaultCookieSetting(nullptr); | 434 GetCookieSettings()->GetDefaultCookieSetting(nullptr); |
| 430 for (const auto& settings_it : all_settings) { | 435 for (const auto& settings_it : all_settings) { |
| 431 if (settings_it.setting == default_setting) | 436 if (settings_it.setting == default_setting) |
| 432 continue; | 437 continue; |
| 433 if (managedOnly && | 438 if (managedOnly) { |
| 434 HostContentSettingsMap::GetProviderTypeFromSource(settings_it.source) != | 439 ProviderType provider = |
| 435 HostContentSettingsMap::ProviderType::POLICY_PROVIDER) { | 440 HostContentSettingsMap::GetProviderTypeFromSource(settings_it.source); |
| 436 continue; | 441 if (provider != ProviderType::POLICY_PROVIDER && |
| 442 provider != ProviderType::RECOMMENDED_POLICY_PROVIDER) { |
| 443 continue; |
| 444 } |
| 437 } | 445 } |
| 438 const std::string& origin = settings_it.primary_pattern.ToString(); | 446 const std::string& origin = settings_it.primary_pattern.ToString(); |
| 439 const std::string& embedder = settings_it.secondary_pattern.ToString(); | 447 const std::string& embedder = settings_it.secondary_pattern.ToString(); |
| 440 ScopedJavaLocalRef<jstring> jorigin = ConvertUTF8ToJavaString(env, origin); | 448 ScopedJavaLocalRef<jstring> jorigin = ConvertUTF8ToJavaString(env, origin); |
| 441 ScopedJavaLocalRef<jstring> jembedder; | 449 ScopedJavaLocalRef<jstring> jembedder; |
| 442 if (embedder != origin) | 450 if (embedder != origin) |
| 443 jembedder = ConvertUTF8ToJavaString(env, embedder); | 451 jembedder = ConvertUTF8ToJavaString(env, embedder); |
| 444 Java_WebsitePreferenceBridge_insertCookieInfoIntoList(env, list, | 452 Java_WebsitePreferenceBridge_insertCookieInfoIntoList(env, list, |
| 445 jorigin.obj(), jembedder.obj()); | 453 jorigin.obj(), jembedder.obj()); |
| 446 } | 454 } |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 GURL url(ConvertJavaStringToUTF8(env, jorigin)); | 767 GURL url(ConvertJavaStringToUTF8(env, jorigin)); |
| 760 scoped_refptr<SiteDataDeleteHelper> site_data_deleter( | 768 scoped_refptr<SiteDataDeleteHelper> site_data_deleter( |
| 761 new SiteDataDeleteHelper(profile, url)); | 769 new SiteDataDeleteHelper(profile, url)); |
| 762 site_data_deleter->Run(); | 770 site_data_deleter->Run(); |
| 763 } | 771 } |
| 764 | 772 |
| 765 // Register native methods | 773 // Register native methods |
| 766 bool RegisterWebsitePreferenceBridge(JNIEnv* env) { | 774 bool RegisterWebsitePreferenceBridge(JNIEnv* env) { |
| 767 return RegisterNativesImpl(env); | 775 return RegisterNativesImpl(env); |
| 768 } | 776 } |
| OLD | NEW |