Show-site-settings-for-cookies-javascript-and-ads.patch 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. From: csagan5 <32685696+csagan5@users.noreply.github.com>
  2. Date: Sat, 28 Dec 2019 10:23:04 +0100
  3. Subject: Show site settings for cookies, javascript and ads
  4. Avoid displaying info about intrusive ads
  5. ---
  6. .../site_settings/SingleWebsiteSettings.java | 46 +++++++++----------
  7. .../chrome/browser/site_settings/Website.java | 20 ++++++++
  8. 2 files changed, 42 insertions(+), 24 deletions(-)
  9. diff --git a/chrome/android/java/src/org/chromium/chrome/browser/site_settings/SingleWebsiteSettings.java b/chrome/android/java/src/org/chromium/chrome/browser/site_settings/SingleWebsiteSettings.java
  10. --- a/chrome/android/java/src/org/chromium/chrome/browser/site_settings/SingleWebsiteSettings.java
  11. +++ b/chrome/android/java/src/org/chromium/chrome/browser/site_settings/SingleWebsiteSettings.java
  12. @@ -70,6 +70,7 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
  13. // Buttons:
  14. public static final String PREF_RESET_SITE = "reset_site_button";
  15. + public static final String TAG = "SingleWebsitePreferences";
  16. // Website permissions (if adding new, see hasPermissionsPreferences and resetSite below)
  17. // All permissions from the permissions preference category must be listed here.
  18. private static final String[] PERMISSION_PREFERENCE_KEYS = {
  19. @@ -347,7 +348,24 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
  20. } else if (i == ContentSettingException.Type.SOUND) {
  21. setUpSoundPreference(preference);
  22. } else {
  23. - setUpListPreference(preference, mSite.getContentSettingPermission(i));
  24. + // some Bromite-specific overrides for the defaults
  25. + @ContentSettingValues
  26. + @Nullable
  27. + Integer permission = mSite.getContentSettingPermission(i);
  28. + // initialize cookie and javascript with the category global defaults
  29. + if (permission == null) {
  30. + if (i == ContentSettingException.Type.COOKIE)
  31. + permission = WebsitePreferenceBridge.isCategoryEnabled(
  32. + ContentSettingsType.COOKIES)
  33. + ? ContentSettingValues.ALLOW
  34. + : ContentSettingValues.BLOCK;
  35. + else if (i == ContentSettingException.Type.JAVASCRIPT)
  36. + permission = WebsitePreferenceBridge.isCategoryEnabled(
  37. + ContentSettingsType.JAVASCRIPT)
  38. + ? ContentSettingValues.ALLOW
  39. + : ContentSettingValues.BLOCK;
  40. + }
  41. + setUpListPreference(preference, permission);
  42. }
  43. return;
  44. }
  45. @@ -635,17 +653,8 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
  46. }
  47. private void setUpAdsInformationalBanner() {
  48. - // Add the informational banner which shows at the top of the UI if ad blocking is
  49. - // activated on this site.
  50. - boolean adBlockingActivated = SiteSettingsCategory.adsCategoryEnabled()
  51. - && WebsitePreferenceBridge.getAdBlockingActivated(mSite.getAddress().getOrigin())
  52. - && findPreference(PERMISSION_PREFERENCE_KEYS[ContentSettingException.Type.ADS])
  53. - != null;
  54. -
  55. - if (!adBlockingActivated) {
  56. - removePreferenceSafely(PREF_INTRUSIVE_ADS_INFO);
  57. - removePreferenceSafely(PREF_INTRUSIVE_ADS_INFO_DIVIDER);
  58. - }
  59. + removePreferenceSafely(PREF_INTRUSIVE_ADS_INFO);
  60. + removePreferenceSafely(PREF_INTRUSIVE_ADS_INFO_DIVIDER);
  61. }
  62. private SiteSettingsCategory getWarningCategory() {
  63. @@ -724,6 +733,7 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
  64. // TODO(crbug.com/735110): Figure out if this is the correct thing to do - here we are
  65. // effectively treating non-ALLOW values as BLOCK.
  66. int index = (value == ContentSettingValues.ALLOW ? 0 : 1);
  67. +
  68. listPreference.setValueIndex(index);
  69. listPreference.setOnPreferenceChangeListener(this);
  70. listPreference.setSummary("%s");
  71. @@ -793,22 +803,10 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
  72. setUpListPreference(preference, null);
  73. return;
  74. }
  75. - // If the ad blocker is activated, then this site will have ads blocked unless there is an
  76. - // explicit permission disallowing the blocking.
  77. - boolean activated =
  78. - WebsitePreferenceBridge.getAdBlockingActivated(mSite.getAddress().getOrigin());
  79. @ContentSettingValues
  80. @Nullable
  81. Integer permission = mSite.getContentSettingPermission(ContentSettingException.Type.ADS);
  82. - // If |permission| is null, there is no explicit (non-default) permission set for this site.
  83. - // If the site is not considered a candidate for blocking, do the standard thing and remove
  84. - // the preference.
  85. - if (permission == null && !activated) {
  86. - setUpListPreference(preference, null);
  87. - return;
  88. - }
  89. -
  90. // However, if the blocking is activated, we still want to show the permission, even if it
  91. // is in the default state.
  92. if (permission == null) {
  93. diff --git a/chrome/android/java/src/org/chromium/chrome/browser/site_settings/Website.java b/chrome/android/java/src/org/chromium/chrome/browser/site_settings/Website.java
  94. --- a/chrome/android/java/src/org/chromium/chrome/browser/site_settings/Website.java
  95. +++ b/chrome/android/java/src/org/chromium/chrome/browser/site_settings/Website.java
  96. @@ -197,6 +197,26 @@ public class Website implements Serializable {
  97. new ContentSettingException(ContentSettingsType.ADS,
  98. getAddress().getOrigin(), ContentSettingValues.BLOCK, "");
  99. }
  100. + } else if (type == ContentSettingException.Type.COOKIE) {
  101. + // It is possible to set the permission without having an existing exception,
  102. + // because we can show the ALLOW state even when this permission is set to the
  103. + // default. In that case, just set an exception now to ALLOW to enable changing the
  104. + // permission.
  105. + if (mContentSettingException[type] == null) {
  106. + mContentSettingException[type] =
  107. + new ContentSettingException(ContentSettingsType.COOKIES,
  108. + getAddress().getOrigin(), ContentSettingValues.ALLOW, "");
  109. + }
  110. + } else if (type == ContentSettingException.Type.JAVASCRIPT) {
  111. + // It is possible to set the permission without having an existing exception,
  112. + // because we can show the ALLOW state even when this permission is set to the
  113. + // default. In that case, just set an exception now to ALLOW to enable changing the
  114. + // permission.
  115. + if (mContentSettingException[type] == null) {
  116. + mContentSettingException[type] =
  117. + new ContentSettingException(ContentSettingsType.JAVASCRIPT,
  118. + getAddress().getOrigin(), ContentSettingValues.ALLOW, "");
  119. + }
  120. } else if (type == ContentSettingException.Type.SOUND) {
  121. // It is possible to set the permission without having an existing exception,
  122. // because we always show the sound permission in Site Settings.
  123. --
  124. 2.17.1