bromite/build/patches/Revert-the-removal-of-an-option-to-block-autoplay.patch
2021-01-26 01:12:38 +01:00

671 lines
39 KiB
Diff

From: uazo <uazo@users.noreply.github.com>
Date: Sat, 7 Nov 2020 21:59:18 +0000
Subject: Revert the removal of an option to block autoplay
---
.../browser_ui/site_settings/android/BUILD.gn | 5 ++++
.../res/drawable-hdpi/settings_autoplay.png | Bin 0 -> 456 bytes
.../res/drawable-mdpi/settings_autoplay.png | Bin 0 -> 296 bytes
.../res/drawable-xhdpi/settings_autoplay.png | Bin 0 -> 551 bytes
.../res/drawable-xxhdpi/settings_autoplay.png | Bin 0 -> 792 bytes
.../drawable-xxxhdpi/settings_autoplay.png | Bin 0 -> 1064 bytes
.../res/xml/single_website_preferences.xml | 2 ++
.../res/xml/site_settings_preferences.xml | 4 +++
.../ContentSettingsResources.java | 4 +++
.../site_settings/SingleCategorySettings.java | 4 +++
.../site_settings/SingleWebsiteSettings.java | 22 ++++++++++++++++
.../site_settings/SiteSettingsCategory.java | 9 +++++--
.../browser_ui/site_settings/Website.java | 8 ++++++
.../WebsitePermissionsFetcher.java | 1 +
.../WebsitePreferenceBridge.java | 4 +++
.../android/website_preference_bridge.cc | 24 +++++++++++++++++-
.../strings/android/site_settings.grdp | 9 +++++++
.../core/browser/content_settings_registry.cc | 2 +-
.../core/browser/content_settings_utils.cc | 2 ++
.../core/common/content_settings.cc | 1 +
.../core/common/content_settings.h | 1 +
.../core/common/content_settings.mojom | 1 +
.../common/content_settings_mojom_traits.cc | 1 +
.../common/content_settings_mojom_traits.h | 5 ++++
.../renderer/content_settings_agent_impl.cc | 11 ++++++++
.../renderer/content_settings_agent_impl.h | 1 +
.../android/page_info_controller_android.cc | 1 +
components/page_info/page_info.cc | 6 +++++
components/page_info/page_info_ui.cc | 1 +
components/page_info_strings.grdp | 3 +++
.../platform/web_content_settings_client.h | 3 +++
.../core/html/media/autoplay_policy.cc | 12 ++++++++-
.../core/html/media/autoplay_policy.h | 4 +++
33 files changed, 146 insertions(+), 5 deletions(-)
create mode 100644 components/browser_ui/site_settings/android/java/res/drawable-hdpi/settings_autoplay.png
create mode 100644 components/browser_ui/site_settings/android/java/res/drawable-mdpi/settings_autoplay.png
create mode 100644 components/browser_ui/site_settings/android/java/res/drawable-xhdpi/settings_autoplay.png
create mode 100644 components/browser_ui/site_settings/android/java/res/drawable-xxhdpi/settings_autoplay.png
create mode 100644 components/browser_ui/site_settings/android/java/res/drawable-xxxhdpi/settings_autoplay.png
diff --git a/components/browser_ui/site_settings/android/BUILD.gn b/components/browser_ui/site_settings/android/BUILD.gn
--- a/components/browser_ui/site_settings/android/BUILD.gn
+++ b/components/browser_ui/site_settings/android/BUILD.gn
@@ -190,6 +190,11 @@ android_resources("java_resources") {
"java/res/drawable-xxxhdpi/settings_storage.png",
"java/res/drawable-xxxhdpi/settings_usb.png",
"java/res/drawable-xxxhdpi/web_asset.png",
+ "java/res/drawable-hdpi/settings_autoplay.png",
+ "java/res/drawable-xhdpi/settings_autoplay.png",
+ "java/res/drawable-xxhdpi/settings_autoplay.png",
+ "java/res/drawable-mdpi/settings_autoplay.png",
+ "java/res/drawable-xxxhdpi/settings_autoplay.png",
"java/res/drawable/ic_person_24dp.xml",
"java/res/drawable/settings_bluetooth.xml",
"java/res/layout/add_site_dialog.xml",
diff --git a/components/browser_ui/site_settings/android/java/res/drawable-hdpi/settings_autoplay.png b/components/browser_ui/site_settings/android/java/res/drawable-hdpi/settings_autoplay.png
new file mode 100644
index 0000000000000000000000000000000000000000..a8a9265f14cd8445ad1f55845099e60dc3c4edf1
GIT binary patch
literal 456
zcmV;(0XP1MP)<h;3K|Lk000e1NJLTq001Na001Ni1ONa4O9@aD0004xNkl<Zcmd^>
zv2MaJ5QYmZs7m@68Tt%)0T}7#GcJmh4B69}fh}W`x!sUhd4N1chpY%8u@-es;cQTy
zGbWY1VQ**q%l&uuT^{am%=;qbIaI7>hvTfF;<*Ut{eMAbL!QB&HFUzBXR~2P41Zx8
z)>!6-O>RP(9xN_j-$FSZiy-wPUj)-Jl(4<5Et;Mc!<K5}jwP!>dwn%v3G5VXX+fR6
zfpz3x+Y|Y)K6`aNHVw{qdv4}^DAdl0F;g<cu%;M_QeJHg8RVIajV_AK%qV!0vEmv1
z#vVbjZa-Q+lSd;emiMaVzX)Z*+nGY^7d%tYY9KFz2z6mO9x2+}RepX<5}`zKxo)iR
zz{m)~NhMClXs`4GHM$vG2T_S4KzpqpIGl{BX8{q3sfX5s0TlVSK=Ataj-&0{v9#{N
z{;&j_q`#yfB8jBm<%OhAge7edm84b@`b2QRo9WRKN#xNwD<h5zoBL8ri$BDs;tw$`
y{$1Kp0i#npN<C~x1#L&}8>IV|-Tf!x{>CqV{oZM{Igf1s0000<MNUMnLSTY>m&@A#
literal 0
HcmV?d00001
diff --git a/components/browser_ui/site_settings/android/java/res/drawable-mdpi/settings_autoplay.png b/components/browser_ui/site_settings/android/java/res/drawable-mdpi/settings_autoplay.png
new file mode 100644
index 0000000000000000000000000000000000000000..49fa10d44f4007532d0d03d15fdcb1a715857e96
GIT binary patch
literal 296
zcmV+@0oVSCP)<h;3K|Lk000e1NJLTq000;O000;W1ONa4N`Cco0002*Nkl<Zc-p;F
zu?>ST5R5=Hk+X;yg9#|y{3AI^L4jN_0yR^lp<y0UAY}`bhK9U}6x+c{;s$?XpYHT`
z_WQ8+DiaXc!3Y!8NIOv`U+9>_9hQ%}W9}t45w<H~z#4hQDkf8`VbB=1O|%hcI?jda
zV;k+`LgB0>TQfw*%xg4TCAk}wycg<C;jW}mI*Sz_g!XRC-~-OCu{Db@O*?8?8^Rj&
zS{^N1H6fiLjCAC#fRLNPkP|W*!URjjT!AiQtzvYZ{t%#iA(xXD1Xz-(u@oBGf2}Be
u*BbnAfuj*Re80yVxjo)NA1L&T?!2C$I@?4>V>|Ky0000<MNUMnLSTX*1bI&Y
literal 0
HcmV?d00001
diff --git a/components/browser_ui/site_settings/android/java/res/drawable-xhdpi/settings_autoplay.png b/components/browser_ui/site_settings/android/java/res/drawable-xhdpi/settings_autoplay.png
new file mode 100644
index 0000000000000000000000000000000000000000..5a4128a5e02949de754f9cab2635824eda8c539c
GIT binary patch
literal 551
zcmV+?0@(eDP)<h;3K|Lk000e1NJLTq001xm001xu1ONa4{R=S+0005*Nkl<Zc-rk(
zy>fy;5RRo0wX?Hwh9Zw(#Vgp}9uO@kj!GT?W_XdLp-A4qiidDg@B~=L$xN`2Fo6Ry
zoC`9!!WnNX*>%6WZ+~v@;l6HTnG5Pb03nIUF_Q>F2&iK&{=v0ABR=d&Dwa&+>$CpO
zN8o1rO<Uv$u0HDF9##;Ow3|Q-tE-%+18~W?=HLW7u&HLKOxcVLm1<yTUrsfUGq~xX
zqx<cUyx0DE0A@`^cGeUaIn=iCwjFlbea(GBJf>jQOd%dgDu@oJ0JqvZU3NJ!T~_A+
zw>7k!d)Tk%U1PSM!@i8g3Qx?K@4o3Chv27xSRb|1lL*LZCn{;7NuQNv<q5!Ftw$V!
zc)av3R5$TCJ)+DZDSW^ao>676eW3vl6flwYSMx=l(G+1kL4+N%tlEhfAQy}(nDFWr
zbXw{Z4tCiO1OTTBcDW68nyP>kgahDIfn8VxO;uQ6Yd8Q-71auD*mMx(DnrEqaH<To
z&_)dhyat$p1K?CKh1bGGfX(<C05JbrZN`P>Q#wV`gM2wnZ5*JY22WGzg(js{SktOi
z^lWxu_H1_Y+jaYe^U~wOk$z>$zx3sgE%FC1e02PlFgl8cUvcTd1Q~vNjPEQT-<g7p
p?=l}ClAlmgAAvHTvG;Wo>j%AMEx!+_@2>y=002ovPDHLkV1fY;_gnw~
literal 0
HcmV?d00001
diff --git a/components/browser_ui/site_settings/android/java/res/drawable-xxhdpi/settings_autoplay.png b/components/browser_ui/site_settings/android/java/res/drawable-xxhdpi/settings_autoplay.png
new file mode 100644
index 0000000000000000000000000000000000000000..7fceb8c2b546970a3720e8ab225799aa03895b7f
GIT binary patch
literal 792
zcmV+z1LypSP)<h;3K|Lk000e1NJLTq002k;002k`1ONa4|Kxkj0008tNkl<ZcmeHN
zv2Nl_5Kd(&P^2J2k<wEAFOV*wK{6%nd}~AH7AGB@E1m)cC{TL;PY?@4L47q{DkQ2)
zgu;oFPN%!E!Ny}lw9<LD9oFB@H#0js!$l#56r!s*CDlL=Bg|=u6>VsP6)iEx2tCzs
zN?!=Ys;Vvm+R!dxZSbnPR`u*)=$?G~q+QDONj}}54UDQIpq+dnupUkhrgMXd90~(9
z>D-*sHYV1z%eSyr=BeO3;m5&Ge2@<pO;xiip5YmGMb*%ROFljhg4(L5++aL|o)4Xt
z#%NjP*f=bsMdO23efEqzx#k+Py)EC-cdk<X`U-t|-#g6Ixz21IO!tgFux}-M*tcpx
z+bE=rR*I5^H|s7_BE7>~l(<Z;9NA<MwvEhAv<UAec5h`y4E^$WnI||NFX<&hz9~zC
z>oA;)6G#{m)`C=tNtmpB)?rp!gtK?*J1gwU@xCMXrLcRedOG_Aoa>~>!hiCJ<GzU?
zU4g;RFi3>{ojT&^9q|2A6eswfXXRwNew}jUlw`DpvbTS<8sy~{`pMeAwZ6%yL!Xy$
zN2*G=JTQ;lS${M|)Hzo?si<yxhaM+sazIk*Xq?iqof0qI(UJg?P=^+O4kR2zHF)`D
zl|_IA)LCU-!l_0)@}9u|IUq50<g;J&;sK4Ankxn*pe__Vqj<GBGo&d7B%n^2OnV;x
zfh7Y}69W=Zr)o@h8E>K0Up2cT1|*=)t}wk-{0CUjdxjX0fI83Mf&Ybo(3S(znzB<m
z^)SCv%fntq6%#ah*z2DdwY@s>U#@89zg#sfKk^r7!;A&m>sd-zwDXs+niu)Z|Ao(>
z;TfMn@`obY`5%hfKBYBiHdqh(w`25gSn1i))3E8OQ(Krf&Sz(7oX<QX`)FaR!DvC-
z;R|!`ZTxsjnS4B@Ou=|cg8`miBTkKmz^eW)jLCUb2{*+b2?DrQRj0pNXexyiQpitx
WnED%yq_MdG0000<MNUMnLSTZmtagO}
literal 0
HcmV?d00001
diff --git a/components/browser_ui/site_settings/android/java/res/drawable-xxxhdpi/settings_autoplay.png b/components/browser_ui/site_settings/android/java/res/drawable-xxxhdpi/settings_autoplay.png
new file mode 100644
index 0000000000000000000000000000000000000000..92a315bb00ac1f4dc675e894bf4af3ba7c68bf39
GIT binary patch
literal 1064
zcmV+@1lRkCP)<h;3K|Lk000e1NJLTq003YB003YJ1ONa4NRhv@000B;Nkl<Zc-rk-
zF-Rjp6x}q5UMCS0#3Pl(5mH&l%1Q;{uKI6w6G2RqfI_g2*e8Om;Gwl(ZGDB6<Z@mY
z41!h)DtJW--GhTGoY}a$GqZ^U^QZnZ|INPr^Z%bejuk6btXQ$4Pc|mmBCFCqouNZL
z+*6<WxThXEbVmEE$`&^!KcwMX<5*@*wCR=nknxH(Yhrn8{DYY8r>Mvd@I-#RfhTrA
zML#uC<7*jKp)UCfqsuC_%t(wck71K;$=5J$u~{A)viWQYSLEv(xME8~Gk$Frr{wD&
zI9;0^#@?^uf&63!9@uK4#y8Tm7iz{GPOt-V=gT=S+ekOkUbdWb=Rw%P3EhS2?={j1
znNJh=@$S+WRQC#g>V2o{6{t=Z?|z3LG~wtMZ-y=hF8Pd>n~yV_n@0=J13_GRGrG;6
z!}Wm09<l3XrRL0HmmUXf$+b79b@vCEkE8V|m6_M4a5NCYj5h8ElLt5Mf{yv!1>6J^
zi6*pop5R{>=jCZ_r}{L`gMViY9x2#y;<%R48&%;r*r_TXTLH$uVB1MRu#FdSHKn7?
z`-}(CeD>8zNbpUBfCq&DBPizKc3=Bf2#S%UBhDc1I|)nBzrdE{;{7Yp^VBj!$TQBx
zU|S+zz^3T;B^;-eQx(qzY{qtLVzw3S*uwXXPwGdTn6<_H_N*cX4be2o$8UU5g&+nP
ztP-!%(B(t6s4>q!uz#qm24H<k2=lrzDi~B0_J233?tcwcDq&ZkQ87A!4)}QA%f<zu
zN+mDL=L_s0dX?>oQ*Am<Tmb4+LW?hjMXctzD}w*YO8`)&lA9OoSdl_b7mgzXK%Gi_
z?u=G6wV#{`bvXd)RH8aJPdie9oUbr@1vvofRPqXZWjjJ~o-Oiq9zP`qK%Gi{imxNF
z#ZV>GxMfcqM;3rOm2koVsD>M`&n>zm4?vwt*x~f|!wop&79@E9>Qn-8+GpV^zc}AJ
zFAqSSO71+T*$FqG_g1BxlLw$qrE-qb>xHV|o^zsEc>wBE^0J)HeYgSrw<?XaJOFhn
zHPW0;|APTQNjCuVDP;an+!=-&MJXXSYW_iHekj4JNd|K$X%6Ph52wvfXhcC<e@cl`
zVkxC4tod=0da3dbmbI2u4)v8)uq;{FLQA%=g_7RFmf@vE<BPjPEU%+9qVl@=7aZzW
zOoyYnVlw}dPjsfExn`|pg0EQ(zvwo+)xh{>55wDS3~zX{EoY-``m=49hBUsaw;r=*
z+}2~(e82VBHh+(@{oX!+2n#ThdxByg0maD|^ghF~58(`dil|N~cLlAek3rFLSGLCO
ib6hJ{tXQ#P#rX?0El=KlH_u1_0000<MNUMnLSTX(y!wd%
literal 0
HcmV?d00001
diff --git a/components/browser_ui/site_settings/android/java/res/xml/single_website_preferences.xml b/components/browser_ui/site_settings/android/java/res/xml/single_website_preferences.xml
--- a/components/browser_ui/site_settings/android/java/res/xml/single_website_preferences.xml
+++ b/components/browser_ui/site_settings/android/java/res/xml/single_website_preferences.xml
@@ -71,6 +71,8 @@
android:key="automatic_downloads_permission_list" />
<ListPreference
android:key="protected_media_identifier_permission_list" />
+ <ListPreference
+ android:key="autoplay_permission_list" />
<ListPreference
android:key="sound_permission_list" />
<ListPreference
diff --git a/components/browser_ui/site_settings/android/java/res/xml/site_settings_preferences.xml b/components/browser_ui/site_settings/android/java/res/xml/site_settings_preferences.xml
--- a/components/browser_ui/site_settings/android/java/res/xml/site_settings_preferences.xml
+++ b/components/browser_ui/site_settings/android/java/res/xml/site_settings_preferences.xml
@@ -65,6 +65,10 @@
<org.chromium.components.browser_ui.settings.ChromeBasePreference
android:fragment="org.chromium.components.browser_ui.site_settings.SingleCategorySettings"
android:key="protected_content" />
+ <!-- Autoplay -->
+ <org.chromium.components.browser_ui.settings.ChromeBasePreference
+ android:fragment="org.chromium.components.browser_ui.site_settings.SingleCategorySettings"
+ android:key="autoplay" />
<!-- Sound -->
<org.chromium.components.browser_ui.settings.ChromeBasePreference
android:fragment="org.chromium.components.browser_ui.site_settings.SingleCategorySettings"
diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/ContentSettingsResources.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/ContentSettingsResources.java
--- a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/ContentSettingsResources.java
+++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/ContentSettingsResources.java
@@ -104,6 +104,10 @@ public class ContentSettingsResources {
new ResourceItem(R.drawable.infobar_downloading,
R.string.automatic_downloads_permission_title, ContentSettingValues.ASK,
ContentSettingValues.BLOCK, R.string.website_settings_category_ask, 0));
+ localMap.put(ContentSettingsType.AUTOPLAY,
+ new ResourceItem(R.drawable.settings_autoplay, R.string.autoplay_title,
+ ContentSettingValues.ALLOW, ContentSettingValues.BLOCK,
+ R.string.website_settings_category_autoplay_allowed, 0));
localMap.put(ContentSettingsType.BACKGROUND_SYNC,
new ResourceItem(R.drawable.permission_background_sync,
R.string.background_sync_permission_title, ContentSettingValues.ALLOW,
diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SingleCategorySettings.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SingleCategorySettings.java
--- a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SingleCategorySettings.java
+++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SingleCategorySettings.java
@@ -533,6 +533,8 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment
int resource = 0;
if (mCategory.showSites(SiteSettingsCategory.Type.AUTOMATIC_DOWNLOADS)) {
resource = R.string.website_settings_add_site_description_automatic_downloads;
+ } else if (mCategory.showSites(SiteSettingsCategory.Type.AUTOPLAY)) {
+ resource = R.string.website_settings_add_site_description_autoplay;
} else if (mCategory.showSites(SiteSettingsCategory.Type.BACKGROUND_SYNC)) {
resource = R.string.website_settings_add_site_description_background_sync;
} else if (mCategory.showSites(SiteSettingsCategory.Type.JAVASCRIPT)) {
@@ -650,6 +652,8 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment
boolean exception = false;
if (mCategory.showSites(SiteSettingsCategory.Type.SOUND)) {
exception = true;
+ } else if (mCategory.showSites(SiteSettingsCategory.Type.AUTOPLAY)) {
+ exception = true;
} else if (mCategory.showSites(SiteSettingsCategory.Type.JAVASCRIPT)) {
exception = true;
} else if (mCategory.showSites(SiteSettingsCategory.Type.COOKIES)) {
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
--- 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
@@ -101,6 +101,8 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
return "bluetooth_scanning_permission_list";
case ContentSettingsType.COOKIES:
return "cookies_permission_list";
+ case ContentSettingsType.AUTOPLAY:
+ return "autoplay_permission_list";
case ContentSettingsType.IDLE_DETECTION:
return "idle_detection_permission_list";
case ContentSettingsType.JAVASCRIPT:
@@ -435,6 +437,8 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
setUpSoundPreference(preference);
} else if (type == ContentSettingsType.JAVASCRIPT) {
setUpJavascriptPreference(preference);
+ } else if (type == ContentSettingsType.AUTOPLAY) {
+ setUpAutoplayPreference(preference);
} else if (type == ContentSettingsType.COOKIES) {
setUpCookiePreference(preference);
} else if (type == ContentSettingsType.GEOLOCATION) {
@@ -921,6 +925,24 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
}
}
+ private void setUpAutoplayPreference(Preference preference) {
+ @ContentSettingValues
+ @Nullable
+ Integer currentValue = mSite.getContentSetting(
+ getSiteSettingsClient().getBrowserContextHandle(), ContentSettingsType.AUTOPLAY);
+ // In order to always show the autoplay permission, set it up with the default value if it
+ // doesn't have a current value.
+ if (currentValue == null) {
+ currentValue = WebsitePreferenceBridge.isCategoryEnabled(
+ getSiteSettingsClient().getBrowserContextHandle(),
+ ContentSettingsType.AUTOPLAY)
+ ? ContentSettingValues.ALLOW
+ : ContentSettingValues.BLOCK;
+ }
+ // Not possible to embargo AUTOPLAY.
+ setUpListPreference(preference, currentValue, false /* isEmbargoed */);
+ }
+
private void setUpSoundPreference(Preference preference) {
BrowserContextHandle browserContextHandle =
getSiteSettingsClient().getBrowserContextHandle();
diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettingsCategory.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettingsCategory.java
--- a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettingsCategory.java
+++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettingsCategory.java
@@ -43,7 +43,7 @@ public class SiteSettingsCategory {
Type.CLIPBOARD, Type.COOKIES, Type.IDLE_DETECTION, Type.DEVICE_LOCATION,
Type.JAVASCRIPT, Type.MICROPHONE, Type.NFC, Type.NOTIFICATIONS, Type.POPUPS,
Type.PROTECTED_MEDIA, Type.SENSORS, Type.SOUND, Type.USB, Type.VIRTUAL_REALITY,
- Type.USE_STORAGE, Type.TIMEZONE_OVERRIDE})
+ Type.USE_STORAGE, Type.TIMEZONE_OVERRIDE, Type.AUTOPLAY})
@Retention(RetentionPolicy.SOURCE)
public @interface Type {
// All updates here must also be reflected in {@link #preferenceKey(int)
@@ -72,10 +72,11 @@ public class SiteSettingsCategory {
int VIRTUAL_REALITY = 21;
int USE_STORAGE = 22;
int TIMEZONE_OVERRIDE = 23;
+ int AUTOPLAY = 24;
/**
* Number of handled categories used for calculating array sizes.
*/
- int NUM_ENTRIES = 24;
+ int NUM_ENTRIES = 25;
}
private final BrowserContextHandle mBrowserContextHandle;
@@ -181,6 +182,8 @@ public class SiteSettingsCategory {
return ContentSettingsType.NFC;
case Type.NOTIFICATIONS:
return ContentSettingsType.NOTIFICATIONS;
+ case Type.AUTOPLAY:
+ return ContentSettingsType.AUTOPLAY;
case Type.POPUPS:
return ContentSettingsType.POPUPS;
case Type.PROTECTED_MEDIA:
@@ -254,6 +257,8 @@ public class SiteSettingsCategory {
return "nfc";
case Type.NOTIFICATIONS:
return "notifications";
+ case Type.AUTOPLAY:
+ return "autoplay";
case Type.POPUPS:
return "popups";
case Type.PROTECTED_MEDIA:
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
--- 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
@@ -216,6 +216,14 @@ public final class Website implements Serializable {
} else {
RecordUserAction.record("JavascriptContentSetting.DisableBy.SiteSettings");
}
+ } else if (type == ContentSettingsType.AUTOPLAY) {
+ // It is possible to set the permission without having an existing exception,
+ // because we always show the autoplay permission in Site Settings.
+ if (exception == null) {
+ exception = new ContentSettingException(
+ ContentSettingsType.AUTOPLAY, getAddress().getHost(), value, "");
+ setContentSettingException(type, exception);
+ }
} else if (type == ContentSettingsType.SOUND) {
// It is possible to set the permission without having an existing exception,
// because we always show the sound permission in Site Settings.
diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/WebsitePermissionsFetcher.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/WebsitePermissionsFetcher.java
--- a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/WebsitePermissionsFetcher.java
+++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/WebsitePermissionsFetcher.java
@@ -60,6 +60,7 @@ public class WebsitePermissionsFetcher {
case ContentSettingsType.AUTOMATIC_DOWNLOADS:
case ContentSettingsType.BACKGROUND_SYNC:
case ContentSettingsType.BLUETOOTH_SCANNING:
+ case ContentSettingsType.AUTOPLAY:
case ContentSettingsType.COOKIES:
case ContentSettingsType.JAVASCRIPT:
case ContentSettingsType.POPUPS:
diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/WebsitePreferenceBridge.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/WebsitePreferenceBridge.java
--- a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/WebsitePreferenceBridge.java
+++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/WebsitePreferenceBridge.java
@@ -366,6 +366,10 @@ public class WebsitePreferenceBridge {
int value);
boolean isPermissionControlledByDSE(BrowserContextHandle browserContextHandle,
@ContentSettingsType int contentSettingsType, String origin);
+ void getAutoplayOrigins(
+ BrowserContextHandle browserContextHandle, Object list, boolean managedOnly);
+ void setAutoplaySettingForOrigin(
+ BrowserContextHandle browserContextHandle, String origin, int value);
boolean getAdBlockingActivated(BrowserContextHandle browserContextHandle, String origin);
boolean isContentSettingEnabled(
BrowserContextHandle browserContextHandle, int contentSettingType);
diff --git a/components/browser_ui/site_settings/android/website_preference_bridge.cc b/components/browser_ui/site_settings/android/website_preference_bridge.cc
--- a/components/browser_ui/site_settings/android/website_preference_bridge.cc
+++ b/components/browser_ui/site_settings/android/website_preference_bridge.cc
@@ -447,6 +447,17 @@ static void JNI_WebsitePreferenceBridge_GetOriginsForPermission(
managedOnly);
}
+static void JNI_WebsitePreferenceBridge_SetAutoplaySettingForOrigin(
+ JNIEnv* env,
+ const JavaParamRef<jobject>& jbrowser_context_handle,
+ const JavaParamRef<jstring>& origin,
+ jint value) {
+ // Here 'nullptr' indicates that autoplay uses wildcard for embedder.
+ SetSettingForOrigin(env, jbrowser_context_handle,
+ ContentSettingsType::AUTOPLAY, origin, nullptr,
+ static_cast<ContentSetting>(value));
+}
+
static jboolean JNI_WebsitePreferenceBridge_IsContentSettingsPatternValid(
JNIEnv* env,
const JavaParamRef<jstring>& pattern) {
@@ -819,6 +830,7 @@ static void JNI_WebsitePreferenceBridge_SetContentSettingEnabled(
case ContentSettingsType::POPUPS:
case ContentSettingsType::SENSORS:
case ContentSettingsType::SOUND:
+ case ContentSettingsType::AUTOPLAY:
value = CONTENT_SETTING_ALLOW;
break;
default:
@@ -899,6 +911,17 @@ static jboolean JNI_WebsitePreferenceBridge_IsContentSettingUserModifiable(
static_cast<ContentSettingsType>(content_settings_type));
}
+static void JNI_WebsitePreferenceBridge_GetAutoplayOrigins(
+ JNIEnv* env,
+ const JavaParamRef<jobject>& jbrowser_context_handle,
+ const JavaParamRef<jobject>& list,
+ jboolean managedOnly) {
+ GetOrigins(env, jbrowser_context_handle,
+ ContentSettingsType::AUTOPLAY,
+ &Java_WebsitePreferenceBridge_insertPermissionInfoIntoList, list,
+ managedOnly);
+}
+
static jboolean JNI_WebsitePreferenceBridge_IsContentSettingManagedByCustodian(
JNIEnv* env,
const JavaParamRef<jobject>& jbrowser_context_handle,
@@ -934,4 +957,3 @@ static base::android::ScopedJavaLocalRef<jstring> JNI_WebsitePreferenceBridge_Ge
GetHostContentSettingsMap(jbrowser_context_handle)->GetTimezoneOverrideValue(timezone);
return ConvertUTF8ToJavaString(env, timezone);
}
-
diff --git a/components/browser_ui/strings/android/site_settings.grdp b/components/browser_ui/strings/android/site_settings.grdp
--- a/components/browser_ui/strings/android/site_settings.grdp
+++ b/components/browser_ui/strings/android/site_settings.grdp
@@ -12,6 +12,15 @@
<message name="IDS_ADS_PERMISSION_TITLE" desc="Title for the ads permission [CHAR-LIMIT=32]">
Ads
</message>
+ <message name="IDS_AUTOPLAY_TITLE" desc='Title for the Autoplay settings screen [CHAR-LIMIT=32]'>
+ Autoplay
+ </message>
+ <message name="IDS_WEBSITE_SETTINGS_ADD_SITE_DESCRIPTION_AUTOPLAY" desc="The description for the allow autoplay of muted videos for website dialog.">
+ Allow autoplay of muted videos for a specific site.
+ </message>
+ <message name="IDS_WEBSITE_SETTINGS_CATEGORY_AUTOPLAY_ALLOWED" desc="Summary text explaining that sites are allowed to automatically play muted videos and that it is the recommended setting.">
+ Allow sites to automatically play muted videos (recommended)
+ </message>
<message name="IDS_AR_PERMISSION_TITLE" desc="Title of the permission to use Augmented Reality [CHAR-LIMIT=32]">
Augmented reality
</message>
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
@@ -323,7 +323,7 @@ void ContentSettingsRegistry::Init() {
ContentSettingsInfo::PERSISTENT,
ContentSettingsInfo::EXCEPTIONS_ON_SECURE_ORIGINS_ONLY);
- Register(ContentSettingsType::AUTOPLAY, "autoplay", CONTENT_SETTING_ALLOW,
+ Register(ContentSettingsType::AUTOPLAY, "autoplay", CONTENT_SETTING_BLOCK,
WebsiteSettingsInfo::UNSYNCABLE, AllowlistedSchemes(),
ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK),
WebsiteSettingsInfo::SINGLE_ORIGIN_ONLY_SCOPE,
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
@@ -143,6 +143,8 @@ void GetRendererContentSettingRules(const HostContentSettingsMap* map,
#endif
map->GetSettingsForOneType(ContentSettingsType::JAVASCRIPT,
&(rules->script_rules));
+ map->GetSettingsForOneType(ContentSettingsType::AUTOPLAY,
+ &(rules->autoplay_rules));
map->GetSettingsForOneType(ContentSettingsType::POPUPS,
&(rules->popup_redirect_rules));
diff --git a/components/content_settings/core/common/content_settings.cc b/components/content_settings/core/common/content_settings.cc
--- a/components/content_settings/core/common/content_settings.cc
+++ b/components/content_settings/core/common/content_settings.cc
@@ -178,6 +178,7 @@ bool RendererContentSettingRules::IsRendererContentSetting(
ContentSettingsType content_type) {
return content_type == ContentSettingsType::IMAGES ||
content_type == ContentSettingsType::JAVASCRIPT ||
+ content_type == ContentSettingsType::AUTOPLAY ||
content_type == ContentSettingsType::CLIENT_HINTS ||
content_type == ContentSettingsType::POPUPS ||
content_type == ContentSettingsType::MIXEDSCRIPT ||
diff --git a/components/content_settings/core/common/content_settings.h b/components/content_settings/core/common/content_settings.h
--- a/components/content_settings/core/common/content_settings.h
+++ b/components/content_settings/core/common/content_settings.h
@@ -77,6 +77,7 @@ struct RendererContentSettingRules {
~RendererContentSettingRules();
ContentSettingsForOneType image_rules;
ContentSettingsForOneType script_rules;
+ ContentSettingsForOneType autoplay_rules;
ContentSettingsForOneType popup_redirect_rules;
ContentSettingsForOneType mixed_content_rules;
ContentSettingsForOneType timezone_override_rules;
diff --git a/components/content_settings/core/common/content_settings.mojom b/components/content_settings/core/common/content_settings.mojom
--- a/components/content_settings/core/common/content_settings.mojom
+++ b/components/content_settings/core/common/content_settings.mojom
@@ -75,6 +75,7 @@ struct ContentSettingPatternSource {
struct RendererContentSettingRules {
array<ContentSettingPatternSource> image_rules;
array<ContentSettingPatternSource> script_rules;
+ array<ContentSettingPatternSource> autoplay_rules;
array<ContentSettingPatternSource> popup_redirect_rules;
array<ContentSettingPatternSource> mixed_content_rules;
array<ContentSettingPatternSource> timezone_override_rules;
diff --git a/components/content_settings/core/common/content_settings_mojom_traits.cc b/components/content_settings/core/common/content_settings_mojom_traits.cc
--- a/components/content_settings/core/common/content_settings_mojom_traits.cc
+++ b/components/content_settings/core/common/content_settings_mojom_traits.cc
@@ -99,6 +99,7 @@ bool StructTraits<content_settings::mojom::RendererContentSettingRulesDataView,
RendererContentSettingRules* out) {
return data.ReadImageRules(&out->image_rules) &&
data.ReadScriptRules(&out->script_rules) &&
+ data.ReadAutoplayRules(&out->autoplay_rules) &&
data.ReadPopupRedirectRules(&out->popup_redirect_rules) &&
data.ReadMixedContentRules(&out->mixed_content_rules) &&
data.ReadTimezoneOverrideRules(&out->timezone_override_rules) &&
diff --git a/components/content_settings/core/common/content_settings_mojom_traits.h b/components/content_settings/core/common/content_settings_mojom_traits.h
--- a/components/content_settings/core/common/content_settings_mojom_traits.h
+++ b/components/content_settings/core/common/content_settings_mojom_traits.h
@@ -135,6 +135,11 @@ struct StructTraits<
return r.script_rules;
}
+ static const std::vector<ContentSettingPatternSource>& autoplay_rules(
+ const RendererContentSettingRules& r) {
+ return r.autoplay_rules;
+ }
+
static const std::vector<ContentSettingPatternSource>& popup_redirect_rules(
const RendererContentSettingRules& r) {
return r.popup_redirect_rules;
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
@@ -430,6 +430,17 @@ bool ContentSettingsAgentImpl::AllowRunningInsecureContent(
return false;
}
+bool ContentSettingsAgentImpl::AllowAutoplay(bool default_value) {
+ if (!content_setting_rules_)
+ return default_value;
+
+ blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
+ return GetContentSettingFromRules(
+ content_setting_rules_->autoplay_rules, frame,
+ url::Origin(frame->GetDocument().GetSecurityOrigin()).GetURL()) ==
+ CONTENT_SETTING_ALLOW;
+}
+
bool ContentSettingsAgentImpl::AllowPopupsAndRedirects(bool default_value) {
if (!content_setting_rules_)
return default_value;
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
@@ -96,6 +96,7 @@ class ContentSettingsAgentImpl
void DidNotAllowScript() override;
bool AllowRunningInsecureContent(bool allowed_per_settings,
const blink::WebURL& url) override;
+ bool AllowAutoplay(bool default_value) override;
bool AllowPopupsAndRedirects(bool default_value) override;
void PassiveInsecureContentFound(const blink::WebURL& resource_url) override;
bool ShouldAutoupgradeMixedContent() override;
diff --git a/components/page_info/android/page_info_controller_android.cc b/components/page_info/android/page_info_controller_android.cc
--- a/components/page_info/android/page_info_controller_android.cc
+++ b/components/page_info/android/page_info_controller_android.cc
@@ -134,6 +134,7 @@ void PageInfoControllerAndroid::SetPermissionInfo(
permissions_to_display.push_back(ContentSettingsType::ADS);
permissions_to_display.push_back(
ContentSettingsType::PROTECTED_MEDIA_IDENTIFIER);
+ permissions_to_display.push_back(ContentSettingsType::AUTOPLAY);
permissions_to_display.push_back(ContentSettingsType::SOUND);
if (base::FeatureList::IsEnabled(features::kWebNfc))
permissions_to_display.push_back(ContentSettingsType::NFC);
diff --git a/components/page_info/page_info.cc b/components/page_info/page_info.cc
--- a/components/page_info/page_info.cc
+++ b/components/page_info/page_info.cc
@@ -99,6 +99,7 @@ ContentSettingsType kPermissionType[] = {
ContentSettingsType::ADS,
ContentSettingsType::BACKGROUND_SYNC,
ContentSettingsType::SOUND,
+ ContentSettingsType::AUTOPLAY,
ContentSettingsType::AUTOMATIC_DOWNLOADS,
#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
ContentSettingsType::PROTECTED_MEDIA_IDENTIFIER,
@@ -141,6 +142,11 @@ bool ShouldShowPermission(const PageInfo::PermissionInfo& info,
return is_subresource_filter_activated;
}
+ // Always show autoplay when it has a site-specific override
+ if (info.type == ContentSettingsType::AUTOPLAY) {
+ return true;
+ }
+
if (info.type == ContentSettingsType::SOUND) {
// The sound content setting should always show up when the tab has played
// audio.
diff --git a/components/page_info/page_info_ui.cc b/components/page_info/page_info_ui.cc
--- a/components/page_info/page_info_ui.cc
+++ b/components/page_info/page_info_ui.cc
@@ -163,6 +163,7 @@ base::span<const PermissionsUIInfo> GetContentSettingsUIInfo() {
IDS_PAGE_INFO_TYPE_PROTECTED_MEDIA_IDENTIFIER},
#endif
{ContentSettingsType::ADS, IDS_PAGE_INFO_TYPE_ADS},
+ {ContentSettingsType::AUTOPLAY, IDS_PAGE_INFO_TYPE_AUTOPLAY},
{ContentSettingsType::SOUND, IDS_PAGE_INFO_TYPE_SOUND},
{ContentSettingsType::CLIPBOARD_READ_WRITE, IDS_PAGE_INFO_TYPE_CLIPBOARD},
{ContentSettingsType::SENSORS,
diff --git a/components/page_info_strings.grdp b/components/page_info_strings.grdp
--- a/components/page_info_strings.grdp
+++ b/components/page_info_strings.grdp
@@ -281,6 +281,9 @@
<message name="IDS_PAGE_INFO_TYPE_SOUND" desc="The label used for the sound permission controls in the Page Info popup.">
Sound
</message>
+ <message name="IDS_PAGE_INFO_TYPE_AUTOPLAY" desc="The label used for the autoplay permission controls in the Page Info popup.">
+ Autoplay
+ </message>
<message name="IDS_PAGE_INFO_TYPE_CLIPBOARD" desc="The label used for the clipboard permission controls in the Page Info popup.">
Clipboard
</message>
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
@@ -87,6 +87,9 @@ class WebContentSettingsClient {
// interface.
virtual bool AllowMutationEvents(bool default_value) { return default_value; }
+ // Controls whether autoplay is allowed for this frame.
+ virtual bool AllowAutoplay(bool default_value) { return default_value; }
+
virtual bool AllowPopupsAndRedirects(bool default_value) {
return default_value;
}
diff --git a/third_party/blink/renderer/core/html/media/autoplay_policy.cc b/third_party/blink/renderer/core/html/media/autoplay_policy.cc
--- a/third_party/blink/renderer/core/html/media/autoplay_policy.cc
+++ b/third_party/blink/renderer/core/html/media/autoplay_policy.cc
@@ -8,6 +8,7 @@
#include "third_party/blink/public/mojom/autoplay/autoplay.mojom-blink.h"
#include "third_party/blink/public/mojom/feature_policy/feature_policy.mojom-blink.h"
#include "third_party/blink/public/mojom/webpreferences/web_preferences.mojom-blink.h"
+#include "third_party/blink/public/platform/web_content_settings_client.h"
#include "third_party/blink/public/platform/web_media_player.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/public/web/web_local_frame_client.h"
@@ -313,7 +314,7 @@ bool AutoplayPolicy::IsGestureNeededForPlayback() const {
// We want to allow muted video to autoplay if the element is allowed to
// autoplay muted.
- return !IsEligibleForAutoplayMuted();
+ return !(IsEligibleForAutoplayMuted() && IsAutoplayAllowedPerSettings());
}
String AutoplayPolicy::GetPlayErrorMessage() const {
@@ -382,6 +383,15 @@ void AutoplayPolicy::MaybeSetAutoplayInitiated() {
}
}
+bool AutoplayPolicy::IsAutoplayAllowedPerSettings() const {
+ LocalFrame* frame = element_->GetDocument().GetFrame();
+ if (!frame)
+ return false;
+ if (auto* settings_client = frame->GetContentSettingsClient())
+ return settings_client->AllowAutoplay(false /* default_value */);
+ return true;
+}
+
bool AutoplayPolicy::ShouldAutoplay() {
if (!element_->GetExecutionContext() ||
element_->GetExecutionContext()->IsSandboxed(
diff --git a/third_party/blink/renderer/core/html/media/autoplay_policy.h b/third_party/blink/renderer/core/html/media/autoplay_policy.h
--- a/third_party/blink/renderer/core/html/media/autoplay_policy.h
+++ b/third_party/blink/renderer/core/html/media/autoplay_policy.h
@@ -131,6 +131,10 @@ class CORE_EXPORT AutoplayPolicy final
// should use, if checking to see if an action is allowed.
bool IsLockedPendingUserGesture() const;
+ // Return true if and only if the settings allow autoplay of media on this
+ // frame.
+ bool IsAutoplayAllowedPerSettings() const;
+
bool IsAutoplayingMutedInternal(bool muted) const;
bool IsOrWillBeAutoplayingMutedInternal(bool muted) const;
--
2.17.1