From: uazo Date: Tue, 5 Oct 2021 08:38:52 +0000 Subject: Site setting for images Original License: GPL-2.0-or-later - https://spdx.org/licenses/GPL-2.0-or-later.html License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html Require: Content-settings-infrastructure.patch --- .../res/drawable-hdpi/permission_images.png | Bin 0 -> 257 bytes .../res/drawable-mdpi/permission_images.png | Bin 0 -> 186 bytes .../res/drawable-xhdpi/permission_images.png | Bin 0 -> 316 bytes .../res/drawable-xxhdpi/permission_images.png | Bin 0 -> 449 bytes .../drawable-xxxhdpi/permission_images.png | Bin 0 -> 532 bytes .../impl/BromiteImagesContentSetting.java | 92 ++++++++++++++++++ .../bromite_content_settings/images.grdp | 23 +++++ .../bromite_content_settings/images.inc | 6 ++ .../core/browser/content_settings_registry.cc | 2 +- .../core/browser/content_settings_utils.cc | 7 +- 10 files changed, 123 insertions(+), 7 deletions(-) create mode 100644 components/browser_ui/site_settings/android/java/res/drawable-hdpi/permission_images.png create mode 100644 components/browser_ui/site_settings/android/java/res/drawable-mdpi/permission_images.png create mode 100644 components/browser_ui/site_settings/android/java/res/drawable-xhdpi/permission_images.png create mode 100644 components/browser_ui/site_settings/android/java/res/drawable-xxhdpi/permission_images.png create mode 100644 components/browser_ui/site_settings/android/java/res/drawable-xxxhdpi/permission_images.png create mode 100644 components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/impl/BromiteImagesContentSetting.java create mode 100644 components/browser_ui/strings/bromite_content_settings/images.grdp create mode 100644 components/content_settings/core/browser/bromite_content_settings/images.inc diff --git a/components/browser_ui/site_settings/android/java/res/drawable-hdpi/permission_images.png b/components/browser_ui/site_settings/android/java/res/drawable-hdpi/permission_images.png new file mode 100644 index 0000000000000000000000000000000000000000..cafee5acf2299e534676a15fb029192e066551c9 GIT binary patch literal 257 zcmV+c0sj7pP)B>S3zFJ)`~-FbLEB zAW2Bk5_vR~8KEwso}fXP_D5Pq{*3w0DQX)*gD~xnN{fodD3paF?-Mi#Y(GH| zZWQ&MkU`N5M1hFpL7hb?uSFuCQmA700000NkvXX Hu0mjfaQkDG literal 0 HcmV?d00001 diff --git a/components/browser_ui/site_settings/android/java/res/drawable-mdpi/permission_images.png b/components/browser_ui/site_settings/android/java/res/drawable-mdpi/permission_images.png new file mode 100644 index 0000000000000000000000000000000000000000..52435094e69ea5278e5c2a60238c7c374961ef08 GIT binary patch literal 186 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM0wlfaz7_+iMo$;VkP60Ri7g6uj9(RAslQ|J zDR75+7h6ZspQr%SKk7Uy7bS)`KY4!Q!HV@QrgIuMJ4s3?32|iJ5IZHaQ|QdA<`XV@ z2No-Ss#_tz?5vUgmdKI;Vst089i%5C8xG literal 0 HcmV?d00001 diff --git a/components/browser_ui/site_settings/android/java/res/drawable-xhdpi/permission_images.png b/components/browser_ui/site_settings/android/java/res/drawable-xhdpi/permission_images.png new file mode 100644 index 0000000000000000000000000000000000000000..cf3b7d0e10cd0e660db9b2532c54a317c7ea4c6c GIT binary patch literal 316 zcmV-C0mJ@@P)Azp{U()nEK1|&NKBkysSq;cA4gBBN7g$J>!_JSCeAA(yrc_l zumk&deC;*l3{ApVAXgFg@$^(4g07sPNoWexRp1z|cnOE!aw0MoP!$Bs#Y~li#6Un* z=s=S&5Kt95&?K}4RD}s5`k&X-@#hyZwIFr*eRscr*soBS(+b5f^_@FBh3KYE{OnEu O0000YU6vy#j)Ir6`sdRGHQCx+t4o-6IId=*)FW?jO3G@jZvg!kL>E_acI_m1An@ca% zLHq+j4wj_lLUKbY=X)QZAIixkYa|WJi7=R~LvKd=fwnXDL7mQjmfaq#y+;NI?oxkb>CpiJdkG zWDP)ZV?cb4EKVB%;+xJIvW_?HLp`9o1)vwxf@JpWG(2cvR{5%!!yj~rnJ5kn;wQ5W zm<_%y0?`?AaT*fz-rYwQwfQ**x<)RUq%a`rL81eG`^(`+vxQtTNkKrDn2AsMOE|8( zi@8x80(9S5&;3weum%g`v|CFrwzgrc(NO|C-8W0J~&sE@f( z+xPP>#Z`d@SV1LmS`s8zVfkc|N`mAnET2qLDG>EgaTNdmS6BtHs|_@1`0}Os>#6z| rcuTqBlqE2a!;CjO|0S@dX_|%~l|w?sH+N5m00000NkvXXu0mjfPvFC^ literal 0 HcmV?d00001 diff --git a/components/browser_ui/site_settings/android/java/res/drawable-xxxhdpi/permission_images.png b/components/browser_ui/site_settings/android/java/res/drawable-xxxhdpi/permission_images.png new file mode 100644 index 0000000000000000000000000000000000000000..cca41100e76e81974b4c22d1d9a1fdffabe9cf60 GIT binary patch literal 532 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD0wg^q?%&M7z4urJLS>(KvDJM1I5sSeVC!Qr--l?HpO;{)S8Tk~J#v^^72Y!=i?d{cQE)Ag;b*t31_vH9nV zHE+q!GY^>%($(j4E91N6`!0s(yqgp{MPz5Sl(mY-3OzXbj%l?Y=bDW0B`>bE=rS;J zI502?G%&CzU@&c->ZCM25B&cuB92+~LH~=K&+k8LyEK}{Uu@Ih3sBg#T-SozH^Gg4 zORL(#T*i5ynspDne;jWMK{8MQcJJ6zdmUy znIZIt^-b7CyHznp%AEI@%2rSLmEqQ&vKXj-L$vGf6?;<3penTVXY!_lRAk79>d&0Z z;?9^WDsRH+$8<~UoXf_^4coe`=U8%Ntp2gcvp~Qg>Zmp6Z*GaTkLIwgb>bq=Zve-^0sWl|`X($0(Fg}|Jzf1=);T3K F0RV{K+KvDK literal 0 HcmV?d00001 diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/impl/BromiteImagesContentSetting.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/impl/BromiteImagesContentSetting.java new file mode 100644 --- /dev/null +++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/impl/BromiteImagesContentSetting.java @@ -0,0 +1,92 @@ +/* + This file is part of Bromite. + + Bromite is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bromite is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bromite. If not, see . +*/ + +package org.chromium.components.browser_ui.site_settings.impl; + +import org.chromium.components.browser_ui.site_settings.R; + +import org.chromium.components.browser_ui.site_settings.BromiteCustomContentSetting; +import org.chromium.components.browser_ui.site_settings.ContentSettingsResources; +import org.chromium.components.browser_ui.site_settings.SiteSettingsCategory; +import org.chromium.components.content_settings.ContentSettingValues; +import org.chromium.components.content_settings.ContentSettingsType; +import org.chromium.content_public.browser.BrowserContextHandle; + +import androidx.annotation.Nullable; +import androidx.preference.Preference; +import androidx.preference.PreferenceScreen; + +import java.util.ArrayList; + +public class BromiteImagesContentSetting extends BromiteCustomContentSetting { + public BromiteImagesContentSetting() { + super(/*contentSettingsType*/ ContentSettingsType.IMAGES, + /*defaultEnabledValue*/ ContentSettingValues.ALLOW, + /*defaultDisabledValue*/ ContentSettingValues.BLOCK, + /*allowException*/ true, + /*preferenceKey*/ "images", + /*profilePrefKey*/ "images"); + } + + @Override + public ContentSettingsResources.ResourceItem getResourceItem() { + return new ContentSettingsResources.ResourceItem( + /*icon*/ R.drawable.permission_images, + /*title*/ R.string.images_permission_title, + /*defaultEnabledValue*/ getDefaultEnabledValue(), + /*defaultDisabledValue*/ getDefaultDisabledValue(), + /*enabledSummary*/ R.string.website_settings_category_images_enabled, + /*disabledSummary*/ R.string.website_settings_category_images_disabled); + } + + @Override + public int getCategorySummary(@Nullable @ContentSettingValues int value) { + switch (value) { + case ContentSettingValues.ALLOW: + return R.string.website_settings_category_images_enabled; + case ContentSettingValues.BLOCK: + return R.string.website_settings_category_images_disabled; + default: + return 0; + } + } + + @Override + public int getCategoryDescription() { + return 0; + } + + @Override + public boolean requiresTriStateContentSetting() { + return false; + } + + @Override + public boolean showOnlyDescriptions() { + return true; + } + + @Override + public int getAddExceptionDialogMessage() { + return R.string.website_settings_category_images_enabled; + } + + @Override + public @Nullable Boolean considerException(SiteSettingsCategory category, @ContentSettingValues int value) { + return value != ContentSettingValues.BLOCK; + } +} diff --git a/components/browser_ui/strings/bromite_content_settings/images.grdp b/components/browser_ui/strings/bromite_content_settings/images.grdp new file mode 100644 --- /dev/null +++ b/components/browser_ui/strings/bromite_content_settings/images.grdp @@ -0,0 +1,23 @@ + + + + + Images + + + Images + + + + Images + + + Allow images on websites you specify while blocking them for the rest of the web + + + Allow sites to load images + + + Disallow sites to load images + + diff --git a/components/content_settings/core/browser/bromite_content_settings/images.inc b/components/content_settings/core/browser/bromite_content_settings/images.inc new file mode 100644 --- /dev/null +++ b/components/content_settings/core/browser/bromite_content_settings/images.inc @@ -0,0 +1,6 @@ + content_settings::WebsiteSettingsRegistry::GetInstance() + ->GetMutable(ContentSettingsType::IMAGES) + ->set_show_into_info_page() + .set_is_renderer_content_setting() + .set_title_ui(IDS_SITE_SETTINGS_TYPE_IMAGES) + .set_mid_sentence_ui(IDS_SITE_SETTINGS_TYPE_IMAGES_MID_SENTENCE); diff --git a/components/content_settings/core/browser/content_settings_registry.cc b/components/content_settings/core/browser/content_settings_registry.cc --- a/components/content_settings/core/browser/content_settings_registry.cc +++ b/components/content_settings/core/browser/content_settings_registry.cc @@ -96,7 +96,7 @@ void ContentSettingsRegistry::Init() { {kChromeUIScheme, kChromeDevToolsScheme, kExtensionScheme}, /*valid_settings=*/{CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK}, WebsiteSettingsInfo::TOP_ORIGIN_WITH_RESOURCE_EXCEPTIONS_SCOPE, - WebsiteSettingsRegistry::DESKTOP, + WebsiteSettingsRegistry::DESKTOP | WebsiteSettingsRegistry::PLATFORM_ANDROID, ContentSettingsInfo::INHERIT_IN_INCOGNITO, ContentSettingsInfo::EXCEPTIONS_ON_SECURE_AND_INSECURE_ORIGINS); diff --git a/components/content_settings/core/browser/content_settings_utils.cc b/components/content_settings/core/browser/content_settings_utils.cc --- a/components/content_settings/core/browser/content_settings_utils.cc +++ b/components/content_settings/core/browser/content_settings_utils.cc @@ -145,12 +145,7 @@ void GetRendererContentSettingRules(const HostContentSettingsMap* map, ContentSettingToValue(CONTENT_SETTING_ALLOW), std::string(), map->IsOffTheRecord())); #else - // Android doesn't use image content settings, so ALLOW rule is added for - // all origins. - rules->image_rules.push_back(ContentSettingPatternSource( - ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(), - ContentSettingToValue(CONTENT_SETTING_ALLOW), std::string(), - map->IsOffTheRecord())); + rules->image_rules = map->GetSettingsForOneType(ContentSettingsType::IMAGES); // In Android active mixed content is hard blocked, with no option to allow // it. rules->mixed_content_rules.push_back(ContentSettingPatternSource( -- 2.25.1