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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 | 52 +++++++++----------
  7. .../browser_ui/site_settings/Website.java | 14 +++--
  8. 2 files changed, 35 insertions(+), 31 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. @@ -492,6 +492,8 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
  13. setUpSoundPreference(preference);
  14. } else if (type == ContentSettingsType.JAVASCRIPT) {
  15. setUpJavascriptPreference(preference);
  16. + } else if (type == ContentSettingsType.COOKIES) {
  17. + setUpCookiesPreference(preference);
  18. } else if (type == ContentSettingsType.GEOLOCATION) {
  19. setUpLocationPreference(preference);
  20. } else if (type == ContentSettingsType.NOTIFICATIONS) {
  21. @@ -818,16 +820,8 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
  22. private void setUpAdsInformationalBanner() {
  23. // Add the informational banner which shows at the top of the UI if ad blocking is
  24. // activated on this site.
  25. - boolean adBlockingActivated = SiteSettingsCategory.adsCategoryEnabled()
  26. - && WebsitePreferenceBridge.getAdBlockingActivated(
  27. - getSiteSettingsDelegate().getBrowserContextHandle(),
  28. - mSite.getAddress().getOrigin())
  29. - && findPreference(getPreferenceKey(ContentSettingsType.ADS)) != null;
  30. -
  31. - if (!adBlockingActivated) {
  32. removePreferenceSafely(PREF_INTRUSIVE_ADS_INFO);
  33. removePreferenceSafely(PREF_INTRUSIVE_ADS_INFO_DIVIDER);
  34. - }
  35. }
  36. private SiteSettingsCategory getWarningCategory() {
  37. @@ -989,17 +983,35 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
  38. @Nullable
  39. Integer currentValue =
  40. mSite.getContentSetting(browserContextHandle, ContentSettingsType.JAVASCRIPT);
  41. - // If Javascript is blocked by default, then always show a Javascript permission.
  42. - // To do this, set it to the default value (blocked).
  43. - if ((currentValue == null)
  44. - && !WebsitePreferenceBridge.isCategoryEnabled(
  45. - browserContextHandle, ContentSettingsType.JAVASCRIPT)) {
  46. - currentValue = ContentSettingValues.BLOCK;
  47. + // Always show the Javascript permission
  48. + if (currentValue == null) {
  49. + currentValue = WebsitePreferenceBridge.isCategoryEnabled(
  50. + browserContextHandle, ContentSettingsType.JAVASCRIPT)
  51. + ? ContentSettingValues.ALLOW
  52. + : ContentSettingValues.BLOCK;
  53. }
  54. // Not possible to embargo JAVASCRIPT.
  55. setupContentSettingsPreference(preference, currentValue, false /* isEmbargoed */);
  56. }
  57. + private void setUpCookiesPreference(Preference preference) {
  58. + BrowserContextHandle browserContextHandle =
  59. + getSiteSettingsDelegate().getBrowserContextHandle();
  60. + @ContentSettingValues
  61. + @Nullable
  62. + Integer currentValue =
  63. + mSite.getContentSetting(browserContextHandle, ContentSettingsType.COOKIES);
  64. + // Always show the cookies permission
  65. + if (currentValue == null || currentValue == ContentSettingValues.DEFAULT) {
  66. + currentValue = WebsitePreferenceBridge.isCategoryEnabled(
  67. + browserContextHandle, ContentSettingsType.COOKIES)
  68. + ? ContentSettingValues.ALLOW
  69. + : ContentSettingValues.BLOCK;
  70. + }
  71. + // Not possible to embargo COOKIES.
  72. + setupContentSettingsPreference(preference, currentValue, false /* isEmbargoed */);
  73. + }
  74. +
  75. /**
  76. * Updates the ads list preference based on whether the site is a candidate for blocking. This
  77. * has some custom behavior.
  78. @@ -1015,22 +1027,10 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
  79. setupContentSettingsPreference(preference, null, false);
  80. return;
  81. }
  82. - // If the ad blocker is activated, then this site will have ads blocked unless there is an
  83. - // explicit permission disallowing the blocking.
  84. - boolean activated = WebsitePreferenceBridge.getAdBlockingActivated(
  85. - browserContextHandle, mSite.getAddress().getOrigin());
  86. @ContentSettingValues
  87. @Nullable
  88. Integer permission = mSite.getContentSetting(browserContextHandle, ContentSettingsType.ADS);
  89. - // If |permission| is null, there is no explicit (non-default) permission set for this site.
  90. - // If the site is not considered a candidate for blocking, do the standard thing and remove
  91. - // the preference.
  92. - if (permission == null && !activated) {
  93. - setupContentSettingsPreference(preference, null, false);
  94. - return;
  95. - }
  96. -
  97. // However, if the blocking is activated, we still want to show the permission, even if it
  98. // is in the default state.
  99. if (permission == null) {
  100. 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
  101. --- a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/Website.java
  102. +++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/Website.java
  103. @@ -187,13 +187,17 @@ public final class Website implements Serializable {
  104. ContentSettingException exception = getContentSettingException(type);
  105. if (type == ContentSettingsType.ADS) {
  106. - // It is possible to set the permission without having an existing exception,
  107. - // because we can show the BLOCK state even when this permission is set to the
  108. - // default. In that case, just set an exception now to BLOCK to enable changing the
  109. - // permission.
  110. + // It is possible to set the permission without having an existing exception
  111. if (exception == null) {
  112. exception = new ContentSettingException(ContentSettingsType.ADS,
  113. - getAddress().getOrigin(), ContentSettingValues.BLOCK, "");
  114. + getAddress().getOrigin(), value, "");
  115. + setContentSettingException(type, exception);
  116. + }
  117. + } else if (type == ContentSettingsType.COOKIES) {
  118. + // It is possible to set the permission without having an existing exception
  119. + if (exception == null) {
  120. + exception = new ContentSettingException(ContentSettingsType.COOKIES,
  121. + getAddress().getOrigin(), value, "");
  122. setContentSettingException(type, exception);
  123. }
  124. } else if (type == ContentSettingsType.JAVASCRIPT) {
  125. --
  126. 2.25.1