506 lines
24 KiB
Diff
506 lines
24 KiB
Diff
From: uazo <uazo@users.noreply.github.com>
|
|
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 | 93 ++++++++++++++++++
|
|
.../bromite_content_settings/images.grdp | 23 +++++
|
|
.../bromite_content_settings/images.inc | 6 ++
|
|
.../core/browser/content_settings_registry.cc | 2 +-
|
|
.../renderer/content_settings_agent_impl.cc | 15 +++
|
|
.../renderer/content_settings_agent_impl.h | 2 +
|
|
.../platform/web_content_settings_client.h | 5 +
|
|
.../blink/renderer/core/frame/local_frame.cc | 7 --
|
|
.../blink/renderer/core/frame/local_frame.h | 6 --
|
|
.../renderer/core/html/image_document.cc | 5 +-
|
|
.../core/loader/frame_fetch_context.cc | 12 +--
|
|
.../core/loader/frame_fetch_context.h | 2 +-
|
|
third_party/blink/renderer/core/page/page.cc | 5 +-
|
|
.../platform/loader/fetch/fetch_context.h | 2 +-
|
|
.../platform/loader/fetch/resource_fetcher.cc | 17 +++-
|
|
.../platform/loader/fetch/resource_fetcher.h | 4 +-
|
|
21 files changed, 175 insertions(+), 31 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)<h;3K|Lk000e1NJLTq001Na001Ni1ONa4O9@aD0002UNkl<ZcmZP|
|
|
z9*lxew#fFVXHox&g^^Dq+e6u~7z8xtKdCUX9g9IA*N_aKVKeAIIdG^OG-}YOL6J+M
|
|
z=1{?)$ormr4jfTui8lyg|4by_p9m|Enh1r+w*(DBw;xzO9fR>B>S3zFJ)`~-FbLEB
|
|
zAW2Bk5_vR~8KEwso}fXP_D5Pq{*3w<p@5>0DQX)*gD~xnN{fodD3paF?-Mi#Y(GH|
|
|
zZWQ&MkU`N5M1hFpL7hb?uSFuCQm<a4yrzwM2CZr74@Ln1pdnSs3x>A700000NkvXX
|
|
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?5vUg<mCxxJ{<wc_;o8*?=Y$1H*fl&w8TkOplD%KVEo3c4v%9~rzs1a
|
|
k;0l{G+5Dws#s($^mqRr#7AM@F4s;BIr>mdKI;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)<h;3K|Lk000e1NJLTq001xm001xu1ONa4{R=S+00034Nkl<ZcwX(7
|
|
zp$@_@5QZ0mAULoyC<KxxKwuEaWxZ2NaJ&Rhft#2akAUGBkO&lNQv*j3gp5D}*APnD
|
|
zbv5Mr>Azp{U()nEK1|&NKBkysSq;cA4gBBN7g$<S{7}G(0v4o70hMD#t`?N_zycO%
|
|
z!vYqtAcn-HU^{9}+qiQifTQR=0>J>!_JSCeAA(yrc_l<tSwK~cnz)hUVj*WBsVtx>
|
|
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
|
|
O0000<MNUMnLSTY+QGR&<
|
|
|
|
literal 0
|
|
HcmV?d00001
|
|
|
|
diff --git a/components/browser_ui/site_settings/android/java/res/drawable-xxhdpi/permission_images.png b/components/browser_ui/site_settings/android/java/res/drawable-xxhdpi/permission_images.png
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..d4d1f0c6e9a59ad9e334daeeb830c953f371706f
|
|
GIT binary patch
|
|
literal 449
|
|
zcmV;y0Y3hTP)<h;3K|Lk000e1NJLTq002k;002k`1ONa4|Kxkj0004qNkl<ZcwX(<
|
|
zze>YU6vy#j)Ir6`sdRGHQCx+t4o-6IId=*)FW?jO3G@jZvg!kL>E_acI_m1An@ca%
|
|
zLHq+j4wj_lLUKbY=X)QZAIixk<iIaY(=;vO#E#h6?*M0FN1Pynf2L)J0tj`6rUlO;
|
|
z;RGgm{!5$)An@VD4>Ya|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|<py(hl-Pzt7tR<|mU>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?%&M7z<Ar!#WAEJ?(J+tzrzVUt-OnZ
|
|
zj<TsIB)#y^ztG6Yc5Kzg<sLaPP0}u>4urJLS>(KvDJM1I5sSeVC!Qr--l?HpO;<zI
|
|
zelGp~lj*0*{_RKXuQCITW?(qR>{)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;j<vY4QX8gzcwZc+BHze1DQPRN&}au8h?uIQReE`FDE=bNX72
|
|
zDbcA#dh@q3^@lX89gIJaC%W^=e6Pmof%Cm)czzJS5El4jUD`>WMK{8MQcJJ6zdmUy
|
|
znIZIt^-b7CyHznp%AEI@%2rSLmEqQ&vKXj-L$vGf6?;<3penTVXY!_lRAk79>d&0Z
|
|
z;?9^WDsRH+$8<~UoXf_^4coe`=U8%Ntp2gcvp~Qg>Zmp6Z*GaTkLIw<kphN9qx`;8
|
|
zMn5h;e$c<a*?vF&A4ZoC{sBz&EFw>gb>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,93 @@
|
|
+/*
|
|
+ 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 <https://www.gnu.org/licenses/>.
|
|
+*/
|
|
+
|
|
+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,
|
|
+ /*summaryOverrideForScreenReader*/ 0);
|
|
+ }
|
|
+
|
|
+ @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 @@
|
|
+<?xml version="1.0" encoding="utf-8"?>
|
|
+<grit-part>
|
|
+<if expr="is_android">
|
|
+ <message name="IDS_SITE_SETTINGS_TYPE_IMAGES" desc="The label used for images site settings controls." formatter_data="android_java">
|
|
+ Images
|
|
+ </message>
|
|
+ <message name="IDS_SITE_SETTINGS_TYPE_IMAGES_MID_SENTENCE" desc="The label used for images site settings controls when used mid-sentence." formatter_data="android_java">
|
|
+ Images
|
|
+ </message>
|
|
+</if>
|
|
+ <message name="IDS_IMAGES_PERMISSION_TITLE" desc="Title of the permission to show images [CHAR-LIMIT=32]" formatter_data="android_java">
|
|
+ Images
|
|
+ </message>
|
|
+ <message name="IDS_WEBSITE_SETTINGS_ADD_SITE_DESCRIPTION_IMAGES" desc="The description for the allow Images on website dialog." formatter_data="android_java">
|
|
+ Allow images on websites you specify while blocking them for the rest of the web
|
|
+ </message>
|
|
+ <message name="IDS_WEBSITE_SETTINGS_CATEGORY_IMAGES_ENABLED" desc="Summary text explaining that sites are allowed to load images." formatter_data="android_java">
|
|
+ Allow sites to load images
|
|
+ </message>
|
|
+ <message name="IDS_WEBSITE_SETTINGS_CATEGORY_IMAGES_DISABLED" desc="Summary text explaining that sites are not allowed to load images." formatter_data="android_java">
|
|
+ Disallow sites to load images
|
|
+ </message>
|
|
+</grit-part>
|
|
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
|
|
@@ -101,7 +101,7 @@ void ContentSettingsRegistry::Init() {
|
|
kChromeUIUntrustedScheme},
|
|
/*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/renderer/content_settings_agent_impl.cc b/components/content_settings/renderer/content_settings_agent_impl.cc
|
|
--- a/components/content_settings/renderer/content_settings_agent_impl.cc
|
|
+++ b/components/content_settings/renderer/content_settings_agent_impl.cc
|
|
@@ -336,6 +336,21 @@ bool ContentSettingsAgentImpl::AllowStorageAccessSync(
|
|
return result;
|
|
}
|
|
|
|
+bool ContentSettingsAgentImpl::AllowImage(bool enabled_per_settings,
|
|
+ const WebURL& image_url) {
|
|
+ bool allow = enabled_per_settings;
|
|
+ if (enabled_per_settings) {
|
|
+ allow = allow || IsAllowlistedForContentSettingsCromite();
|
|
+ if (content_setting_rules_) {
|
|
+ allow = AllowContentSetting(ContentSettingsType::IMAGES,
|
|
+ image_url, enabled_per_settings);
|
|
+ }
|
|
+ }
|
|
+ if (!allow)
|
|
+ DidBlockContentType(ContentSettingsType::IMAGES);
|
|
+ return allow;
|
|
+}
|
|
+
|
|
bool ContentSettingsAgentImpl::AllowReadFromClipboard() {
|
|
return delegate_->AllowReadFromClipboard();
|
|
}
|
|
diff --git a/components/content_settings/renderer/content_settings_agent_impl.h b/components/content_settings/renderer/content_settings_agent_impl.h
|
|
--- a/components/content_settings/renderer/content_settings_agent_impl.h
|
|
+++ b/components/content_settings/renderer/content_settings_agent_impl.h
|
|
@@ -91,6 +91,8 @@ class ContentSettingsAgentImpl
|
|
void AllowStorageAccess(StorageType storage_type,
|
|
base::OnceCallback<void(bool)> callback) override;
|
|
bool AllowStorageAccessSync(StorageType type) override;
|
|
+ bool AllowImage(bool enabled_per_settings,
|
|
+ const blink::WebURL& image_url) override;
|
|
bool AllowReadFromClipboard() override;
|
|
bool AllowWriteToClipboard() override;
|
|
bool AllowMutationEvents(bool default_value) override;
|
|
diff --git a/third_party/blink/public/platform/web_content_settings_client.h b/third_party/blink/public/platform/web_content_settings_client.h
|
|
--- a/third_party/blink/public/platform/web_content_settings_client.h
|
|
+++ b/third_party/blink/public/platform/web_content_settings_client.h
|
|
@@ -55,6 +55,11 @@ class WebContentSettingsClient {
|
|
return enabled_per_settings;
|
|
}
|
|
|
|
+ // Controls whether images are allowed for this frame.
|
|
+ virtual bool AllowImage(bool enabled_per_settings, const WebURL& image_url) {
|
|
+ return enabled_per_settings;
|
|
+ }
|
|
+
|
|
// Controls whether insecure scripts are allowed to execute for this frame.
|
|
virtual bool AllowRunningInsecureContent(bool enabled_per_settings,
|
|
const WebURL&) {
|
|
diff --git a/third_party/blink/renderer/core/frame/local_frame.cc b/third_party/blink/renderer/core/frame/local_frame.cc
|
|
--- a/third_party/blink/renderer/core/frame/local_frame.cc
|
|
+++ b/third_party/blink/renderer/core/frame/local_frame.cc
|
|
@@ -3934,13 +3934,6 @@ const mojom::RendererContentSettingsPtr& LocalFrame::GetContentSettings() {
|
|
return loader_.GetDocumentLoader()->GetContentSettings();
|
|
}
|
|
|
|
-bool LocalFrame::ImagesEnabled() {
|
|
- DCHECK(!IsDetached());
|
|
-
|
|
- bool allow_image_renderer = GetSettings()->GetImagesEnabled();
|
|
- bool allow_image_content_setting = GetContentSettings()->allow_image;
|
|
- return allow_image_renderer && allow_image_content_setting;
|
|
-}
|
|
|
|
bool LocalFrame::ScriptEnabled() {
|
|
DCHECK(!IsDetached());
|
|
diff --git a/third_party/blink/renderer/core/frame/local_frame.h b/third_party/blink/renderer/core/frame/local_frame.h
|
|
--- a/third_party/blink/renderer/core/frame/local_frame.h
|
|
+++ b/third_party/blink/renderer/core/frame/local_frame.h
|
|
@@ -929,12 +929,6 @@ class CORE_EXPORT LocalFrame final
|
|
// Can only be called while the frame is not detached.
|
|
const mojom::RendererContentSettingsPtr& GetContentSettings();
|
|
|
|
- // Returns whether images are allowed to load for the current frame. This is a
|
|
- // convenience method that checks both renderer content settings and frame
|
|
- // settings.
|
|
- // Can only be called while the frame is not detached.
|
|
- bool ImagesEnabled();
|
|
-
|
|
// Returns whether script is allowed to run for the current frame. This is a
|
|
// convenience method that checks both renderer content settings and frame
|
|
// settings.
|
|
diff --git a/third_party/blink/renderer/core/html/image_document.cc b/third_party/blink/renderer/core/html/image_document.cc
|
|
--- a/third_party/blink/renderer/core/html/image_document.cc
|
|
+++ b/third_party/blink/renderer/core/html/image_document.cc
|
|
@@ -138,7 +138,10 @@ void ImageDocumentParser::AppendBytes(const char* data, size_t length) {
|
|
return;
|
|
|
|
LocalFrame* frame = GetDocument()->GetFrame();
|
|
- bool allow_image = frame->ImagesEnabled();
|
|
+ Settings* settings = frame->GetSettings();
|
|
+ bool allow_image_renderer = !settings || settings->GetImagesEnabled();
|
|
+ bool allow_image_content_setting = frame->GetContentSettings()->allow_image;
|
|
+ bool allow_image = allow_image_renderer && allow_image_content_setting;
|
|
if (!allow_image) {
|
|
auto* client = frame->GetContentSettingsClient();
|
|
if (client) {
|
|
diff --git a/third_party/blink/renderer/core/loader/frame_fetch_context.cc b/third_party/blink/renderer/core/loader/frame_fetch_context.cc
|
|
--- a/third_party/blink/renderer/core/loader/frame_fetch_context.cc
|
|
+++ b/third_party/blink/renderer/core/loader/frame_fetch_context.cc
|
|
@@ -242,6 +242,7 @@ ResourceFetcher* FrameFetchContext::CreateFetcherForCommittedDocument(
|
|
fetcher->SetResourceLoadObserver(
|
|
MakeGarbageCollected<ResourceLoadObserverForFrame>(
|
|
loader, document, fetcher->GetProperties()));
|
|
+ fetcher->SetImagesEnabled(frame->GetSettings()->GetImagesEnabled());
|
|
fetcher->SetAutoLoadImages(
|
|
frame->GetSettings()->GetLoadsImagesAutomatically());
|
|
fetcher->SetEarlyHintsPreloadedResources(
|
|
@@ -399,16 +400,11 @@ void FrameFetchContext::AddResourceTiming(
|
|
->AddResourceTiming(std::move(info), initiator_type);
|
|
}
|
|
|
|
-bool FrameFetchContext::AllowImage() const {
|
|
+bool FrameFetchContext::AllowImage(bool images_enabled, const KURL& url) const {
|
|
if (GetResourceFetcherProperties().IsDetached())
|
|
return true;
|
|
-
|
|
- bool images_enabled = GetFrame()->ImagesEnabled();
|
|
- if (!images_enabled) {
|
|
- if (auto* settings_client = GetContentSettingsClient()) {
|
|
- settings_client->DidNotAllowImage();
|
|
- }
|
|
- }
|
|
+ if (auto* settings_client = GetContentSettingsClient())
|
|
+ images_enabled = settings_client->AllowImage(images_enabled, url);
|
|
return images_enabled;
|
|
}
|
|
|
|
diff --git a/third_party/blink/renderer/core/loader/frame_fetch_context.h b/third_party/blink/renderer/core/loader/frame_fetch_context.h
|
|
--- a/third_party/blink/renderer/core/loader/frame_fetch_context.h
|
|
+++ b/third_party/blink/renderer/core/loader/frame_fetch_context.h
|
|
@@ -94,7 +94,7 @@ class CORE_EXPORT FrameFetchContext final : public BaseFetchContext,
|
|
|
|
void AddResourceTiming(mojom::blink::ResourceTimingInfoPtr,
|
|
const AtomicString& initiator_type) override;
|
|
- bool AllowImage() const override;
|
|
+ bool AllowImage(bool images_enabled, const KURL&) const override;
|
|
|
|
void PopulateResourceRequest(ResourceType,
|
|
const std::optional<float> resource_width,
|
|
diff --git a/third_party/blink/renderer/core/page/page.cc b/third_party/blink/renderer/core/page/page.cc
|
|
--- a/third_party/blink/renderer/core/page/page.cc
|
|
+++ b/third_party/blink/renderer/core/page/page.cc
|
|
@@ -875,9 +875,8 @@ void Page::SettingsChanged(ChangeType change_type) {
|
|
for (Frame* frame = MainFrame(); frame;
|
|
frame = frame->Tree().TraverseNext()) {
|
|
if (auto* local_frame = DynamicTo<LocalFrame>(frame)) {
|
|
- // Notify the fetcher that the image loading setting has changed,
|
|
- // which may cause previously deferred requests to load.
|
|
- local_frame->GetDocument()->Fetcher()->ReloadImagesIfNotDeferred();
|
|
+ local_frame->GetDocument()->Fetcher()->SetImagesEnabled(
|
|
+ GetSettings().GetImagesEnabled());
|
|
local_frame->GetDocument()->Fetcher()->SetAutoLoadImages(
|
|
GetSettings().GetLoadsImagesAutomatically());
|
|
}
|
|
diff --git a/third_party/blink/renderer/platform/loader/fetch/fetch_context.h b/third_party/blink/renderer/platform/loader/fetch/fetch_context.h
|
|
--- a/third_party/blink/renderer/platform/loader/fetch/fetch_context.h
|
|
+++ b/third_party/blink/renderer/platform/loader/fetch/fetch_context.h
|
|
@@ -106,7 +106,7 @@ class PLATFORM_EXPORT FetchContext : public GarbageCollected<FetchContext> {
|
|
|
|
virtual void AddResourceTiming(mojom::blink::ResourceTimingInfoPtr,
|
|
const AtomicString& initiator_type);
|
|
- virtual bool AllowImage() const { return false; }
|
|
+ virtual bool AllowImage(bool, const KURL&) const { return false; }
|
|
virtual std::optional<ResourceRequestBlockedReason> CanRequest(
|
|
ResourceType,
|
|
const ResourceRequest&,
|
|
diff --git a/third_party/blink/renderer/platform/loader/fetch/resource_fetcher.cc b/third_party/blink/renderer/platform/loader/fetch/resource_fetcher.cc
|
|
--- a/third_party/blink/renderer/platform/loader/fetch/resource_fetcher.cc
|
|
+++ b/third_party/blink/renderer/platform/loader/fetch/resource_fetcher.cc
|
|
@@ -708,6 +708,7 @@ ResourceFetcher::ResourceFetcher(const ResourceFetcherInit& init)
|
|
blob_registry_remote_(init.context_lifecycle_notifier),
|
|
context_lifecycle_notifier_(init.context_lifecycle_notifier),
|
|
auto_load_images_(true),
|
|
+ images_enabled_(true),
|
|
allow_stale_resources_(false),
|
|
image_fetched_(false) {
|
|
InstanceCounters::IncrementCounter(InstanceCounters::kResourceFetcherCounter);
|
|
@@ -1735,7 +1736,7 @@ bool ResourceFetcher::IsImageResourceDisallowedToBeReused(
|
|
if (existing_resource.GetType() != ResourceType::kImage)
|
|
return false;
|
|
|
|
- return !Context().AllowImage();
|
|
+ return !Context().AllowImage(images_enabled_, existing_resource.Url());
|
|
}
|
|
|
|
ResourceFetcher::RevalidationPolicy
|
|
@@ -1978,8 +1979,20 @@ void ResourceFetcher::SetAutoLoadImages(bool enable) {
|
|
ReloadImagesIfNotDeferred();
|
|
}
|
|
|
|
+void ResourceFetcher::SetImagesEnabled(bool enable) {
|
|
+ if (enable == images_enabled_)
|
|
+ return;
|
|
+
|
|
+ images_enabled_ = enable;
|
|
+
|
|
+ if (!images_enabled_)
|
|
+ return;
|
|
+
|
|
+ ReloadImagesIfNotDeferred();
|
|
+}
|
|
+
|
|
bool ResourceFetcher::ShouldDeferImageLoad(const KURL& url) const {
|
|
- return !Context().AllowImage() ||
|
|
+ return !Context().AllowImage(images_enabled_, url) ||
|
|
(!auto_load_images_ && !url.ProtocolIsData());
|
|
}
|
|
|
|
diff --git a/third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h b/third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h
|
|
--- a/third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h
|
|
+++ b/third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h
|
|
@@ -224,6 +224,7 @@ class PLATFORM_EXPORT ResourceFetcher
|
|
bool StartLoad(Resource*);
|
|
|
|
void SetAutoLoadImages(bool);
|
|
+ void SetImagesEnabled(bool);
|
|
|
|
FetchContext& Context() const;
|
|
void ClearContext();
|
|
@@ -642,8 +643,9 @@ class PLATFORM_EXPORT ResourceFetcher
|
|
// This is not in the bit field below because we want to use AutoReset.
|
|
bool is_in_request_resource_ = false;
|
|
|
|
- // 28 bits left
|
|
+ // 27 bits left
|
|
bool auto_load_images_ : 1;
|
|
+ bool images_enabled_ : 1;
|
|
bool allow_stale_resources_ : 1;
|
|
bool image_fetched_ : 1;
|
|
bool stale_while_revalidate_enabled_ : 1;
|
|
--
|