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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 | 60 +++++++++----------
  7. .../browser_ui/site_settings/Website.java | 20 +++++++
  8. 2 files changed, 48 insertions(+), 32 deletions(-)
  9. diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SingleWebsiteSettings.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SingleWebsiteSettings.java
  10. --- a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SingleWebsiteSettings.java
  11. +++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SingleWebsiteSettings.java
  12. @@ -68,6 +68,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. @@ -349,6 +350,8 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
  20. setUpSoundPreference(preference);
  21. } else if (i == ContentSettingException.Type.JAVASCRIPT) {
  22. setUpJavascriptPreference(preference);
  23. + } else if (i == ContentSettingException.Type.COOKIE) {
  24. + setUpCookiePreference(preference);
  25. } else {
  26. setUpListPreference(preference, mSite.getContentSettingPermission(i));
  27. }
  28. @@ -666,19 +669,8 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
  29. }
  30. private void setUpAdsInformationalBanner() {
  31. - // Add the informational banner which shows at the top of the UI if ad blocking is
  32. - // activated on this site.
  33. - boolean adBlockingActivated = SiteSettingsCategory.adsCategoryEnabled()
  34. - && WebsitePreferenceBridge.getAdBlockingActivated(
  35. - getSiteSettingsClient().getBrowserContextHandle(),
  36. - mSite.getAddress().getOrigin())
  37. - && findPreference(PERMISSION_PREFERENCE_KEYS[ContentSettingException.Type.ADS])
  38. - != null;
  39. -
  40. - if (!adBlockingActivated) {
  41. - removePreferenceSafely(PREF_INTRUSIVE_ADS_INFO);
  42. - removePreferenceSafely(PREF_INTRUSIVE_ADS_INFO_DIVIDER);
  43. - }
  44. + removePreferenceSafely(PREF_INTRUSIVE_ADS_INFO);
  45. + removePreferenceSafely(PREF_INTRUSIVE_ADS_INFO_DIVIDER);
  46. }
  47. private SiteSettingsCategory getWarningCategory() {
  48. @@ -831,13 +823,29 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
  49. @Nullable
  50. Integer currentValue =
  51. mSite.getContentSettingPermission(ContentSettingException.Type.JAVASCRIPT);
  52. - // If Javascript is blocked by default, then always show a Javascript permission.
  53. - // To do this, set it to the default value (blocked).
  54. - if ((currentValue == null)
  55. - && !WebsitePreferenceBridge.isCategoryEnabled(
  56. - getSiteSettingsClient().getBrowserContextHandle(),
  57. - ContentSettingsType.JAVASCRIPT)) {
  58. - currentValue = ContentSettingValues.BLOCK;
  59. + // Always show the Javascript permission
  60. + if (currentValue == null) {
  61. + currentValue = WebsitePreferenceBridge.isCategoryEnabled(
  62. + getSiteSettingsClient().getBrowserContextHandle(),
  63. + ContentSettingsType.JAVASCRIPT)
  64. + ? ContentSettingValues.ALLOW
  65. + : ContentSettingValues.BLOCK;
  66. + }
  67. + setUpListPreference(preference, currentValue);
  68. + }
  69. +
  70. + private void setUpCookiePreference(Preference preference) {
  71. + @ContentSettingValues
  72. + @Nullable
  73. + Integer currentValue =
  74. + mSite.getContentSettingPermission(ContentSettingException.Type.COOKIE);
  75. + // Always show the cookies permission
  76. + if (currentValue == null) {
  77. + currentValue = WebsitePreferenceBridge.isCategoryEnabled(
  78. + getSiteSettingsClient().getBrowserContextHandle(),
  79. + ContentSettingsType.COOKIES)
  80. + ? ContentSettingValues.ALLOW
  81. + : ContentSettingValues.BLOCK;
  82. }
  83. setUpListPreference(preference, currentValue);
  84. }
  85. @@ -855,22 +863,10 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
  86. setUpListPreference(preference, null);
  87. return;
  88. }
  89. - // If the ad blocker is activated, then this site will have ads blocked unless there is an
  90. - // explicit permission disallowing the blocking.
  91. - boolean activated = WebsitePreferenceBridge.getAdBlockingActivated(
  92. - getSiteSettingsClient().getBrowserContextHandle(), mSite.getAddress().getOrigin());
  93. @ContentSettingValues
  94. @Nullable
  95. Integer permission = mSite.getContentSettingPermission(ContentSettingException.Type.ADS);
  96. - // If |permission| is null, there is no explicit (non-default) permission set for this site.
  97. - // If the site is not considered a candidate for blocking, do the standard thing and remove
  98. - // the preference.
  99. - if (permission == null && !activated) {
  100. - setUpListPreference(preference, null);
  101. - return;
  102. - }
  103. -
  104. // However, if the blocking is activated, we still want to show the permission, even if it
  105. // is in the default state.
  106. if (permission == null) {
  107. diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/Website.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/Website.java
  108. --- a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/Website.java
  109. +++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/Website.java
  110. @@ -220,6 +220,26 @@ public class Website implements Serializable {
  111. } else {
  112. RecordUserAction.record("JavascriptContentSetting.DisableBy.SiteSettings");
  113. }
  114. + } else if (type == ContentSettingException.Type.COOKIE) {
  115. + // It is possible to set the permission without having an existing exception,
  116. + // because we can show the ALLOW state even when this permission is set to the
  117. + // default. In that case, just set an exception now to ALLOW to enable changing the
  118. + // permission.
  119. + if (mContentSettingException[type] == null) {
  120. + mContentSettingException[type] =
  121. + new ContentSettingException(ContentSettingsType.COOKIES,
  122. + getAddress().getOrigin(), ContentSettingValues.ALLOW, "");
  123. + }
  124. + } else if (type == ContentSettingException.Type.JAVASCRIPT) {
  125. + // It is possible to set the permission without having an existing exception,
  126. + // because we can show the ALLOW state even when this permission is set to the
  127. + // default. In that case, just set an exception now to ALLOW to enable changing the
  128. + // permission.
  129. + if (mContentSettingException[type] == null) {
  130. + mContentSettingException[type] =
  131. + new ContentSettingException(ContentSettingsType.JAVASCRIPT,
  132. + getAddress().getOrigin(), ContentSettingValues.ALLOW, "");
  133. + }
  134. } else if (type == ContentSettingException.Type.SOUND) {
  135. // It is possible to set the permission without having an existing exception,
  136. // because we always show the sound permission in Site Settings.
  137. --
  138. 2.17.1