From: uazo Date: Sat, 7 Nov 2020 21:59:18 +0000 Subject: Add autoplay site setting 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/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 .../impl/BromiteAutoplayContentSetting.java | 92 ++++++++++++++++++ .../bromite_content_settings/autoplay.grdp | 21 ++++ .../bromite_content_settings/autoplay.inc | 12 +++ .../core/browser/content_settings_registry.cc | 2 +- .../core/html/media/autoplay_policy.cc | 14 +++ .../core/html/media/autoplay_policy.h | 4 + 11 files changed, 144 insertions(+), 1 deletion(-) 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 create mode 100644 components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/impl/BromiteAutoplayContentSetting.java create mode 100644 components/browser_ui/strings/bromite_content_settings/autoplay.grdp create mode 100644 components/content_settings/core/browser/bromite_content_settings/autoplay.inc 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) 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!dwn%v3G5VXX+fR6 zfpz3x+Y|Y)K6`aNHVw{qdv4}^DAdl0F;gIV|-Tf!x{>CqV{oZM{Igf1s0000m&@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)ST5R5=Hk+X;yg9#|y{3AI^L4jN_0yR^lp_9hQ%}W9}t45wTQfw*%xg4TCAk}wycgV>|Ky0000fy;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 zN8o1rOjQOd%dgDu@oJ0JqvZU3NJ!T~_A+ zw>7k!d)Tk%U1PSM!@i8g3Qx?K@4o3Chv27xSRb|1lL*LZCn{;7NuQNv676eW3vl6flwYSMx=l(G+1kL4+N%tlEhfAQy}(nDFWr zbXw{Z4tCiO1OTTBcDW68nyP>kgahDIfn8VxO;uQ6Yd8Q-71auD*mMx(DnrEqaHQ#wV`gM2wnZ5*JY22WGzg(js{SktOi z^lWxu_H1_Y+jaYe^U~wOk$z>$zx3sgE%FC1e02PlFgl8cUvcTd1Q~vNjPEQT-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)VsP6)iEx2tCzs zN?!=Ys;Vvm+R!dxZSbnPR`u*)=$?G~q+QDONj}}54UDQIpq+dnupUkhrgMXd90~(9 z>D-*sHYV1z%eSyr=BeO3;m5&Ge2@~l(oA;)6G#{m)`C=tNtmpB)?rp!gtK?*J1gwU@xCMXrLcRedOG_Aoa>~>!hiCJ{ojT&^9q|2A6eswfXXRwNew}jUlw`DpvbTS<8sy~{`pMeAwZ6%yL!Xy$ zN2*G=JTQ;lS${M|)Hzo?siK0Up2cT1|*=)t}wk-{0CUjdxjX0fI83Mf&Ybo(3S(znzBU#@89zg#sfKk^r7!;A&m>sd-zwDXs+niu)Z|Ao(> z;TfMn@`obY`5%hfKBYBiHdqh(w`25gSn1i))3E8OQ(Krf&Sz(7oXMvd@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!}Wm096J^ 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#qm24HoQ*AmGxMfcqM;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)HeYgSrw55wDS3~zX{EoY-``m=49hBUsaw;r=* z+}2~(e82VBHh+(@{oX!+2n#ThdxByg0maD|^ghF~58(`dil|N~cLlAek3rFLSGLCO ib6hJ{tXQ#P#rX?0El=KlH_u1_0000. +*/ + +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 BromiteAutoplayContentSetting extends BromiteCustomContentSetting { + public BromiteAutoplayContentSetting() { + super(/*contentSettingsType*/ ContentSettingsType.AUTOPLAY, + /*defaultEnabledValue*/ ContentSettingValues.ALLOW, + /*defaultDisabledValue*/ ContentSettingValues.BLOCK, + /*allowException*/ true, + /*preferenceKey*/ "autoplay", + /*profilePrefKey*/ "autoplay"); + } + + @Override + public ContentSettingsResources.ResourceItem getResourceItem() { + return new ContentSettingsResources.ResourceItem( + /*icon*/ R.drawable.settings_autoplay, + /*title*/ R.string.autoplay_permission_title, + /*defaultEnabledValue*/ getDefaultEnabledValue(), + /*defaultDisabledValue*/ getDefaultDisabledValue(), + /*enabledSummary*/ R.string.website_settings_category_autoplay_enabled, + /*disabledSummary*/ R.string.website_settings_category_autoplay_disabled); + } + + @Override + public int getCategorySummary(@Nullable @ContentSettingValues int value) { + switch (value) { + case ContentSettingValues.ALLOW: + return R.string.website_settings_category_autoplay_enabled; + case ContentSettingValues.BLOCK: + return R.string.website_settings_category_autoplay_disabled; + default: + return 0; + } + } + + @Override + public int getCategoryDescription() { + return R.string.website_settings_add_site_description_autoplay; + } + + @Override + public boolean requiresTriStateContentSetting() { + return false; + } + + @Override + public boolean showOnlyDescriptions() { + return true; + } + + @Override + public int getAddExceptionDialogMessage() { + return R.string.website_settings_category_autoplay_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/autoplay.grdp b/components/browser_ui/strings/bromite_content_settings/autoplay.grdp new file mode 100644 --- /dev/null +++ b/components/browser_ui/strings/bromite_content_settings/autoplay.grdp @@ -0,0 +1,21 @@ + + + + Autoplay + + + Allow autoplay for a specific site. + + + Allow sites to automatically play muted videos + + + Autoplay disabled + + + Allowed to autoplay + + + Not allowed to autoplay + + diff --git a/components/content_settings/core/browser/bromite_content_settings/autoplay.inc b/components/content_settings/core/browser/bromite_content_settings/autoplay.inc new file mode 100644 --- /dev/null +++ b/components/content_settings/core/browser/bromite_content_settings/autoplay.inc @@ -0,0 +1,12 @@ + content_settings::WebsiteSettingsRegistry::GetInstance() + ->GetMutable(ContentSettingsType::AUTOPLAY) + ->set_show_into_info_page() + .set_desktop_ui() + .set_is_renderer_content_setting() + .set_title_ui(IDS_AUTOPLAY_PERMISSION_TITLE) + .set_description_ui(IDS_WEBSITE_SETTINGS_ADD_SITE_DESCRIPTION_AUTOPLAY) + .set_allowed_ui(IDS_WEBSITE_SETTINGS_CATEGORY_AUTOPLAY_ENABLED) + .set_blocked_ui(IDS_WEBSITE_SETTINGS_CATEGORY_AUTOPLAY_DISABLED) + .set_allowed_exceptions_ui(IDS_SETTINGS_SITE_SETTINGS_AUTOPLAY_ALLOWED_EXCEPTIONS) + .set_blocked_exceptions_ui(IDS_SETTINGS_SITE_SETTINGS_AUTOPLAY_BLOCKED_EXCEPTIONS) + .set_mid_sentence_ui(IDS_AUTOPLAY_PERMISSION_TITLE); 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 @@ -246,7 +246,7 @@ void ContentSettingsRegistry::Init() { ContentSettingsInfo::INHERIT_IN_INCOGNITO, ContentSettingsInfo::EXCEPTIONS_ON_SECURE_ORIGINS_ONLY); - Register(ContentSettingsType::AUTOPLAY, "autoplay", CONTENT_SETTING_ALLOW, + Register(ContentSettingsType::AUTOPLAY, "autoplay", CONTENT_SETTING_BLOCK, WebsiteSettingsInfo::UNSYNCABLE, /*allowlisted_schemes=*/{}, /*valid_settings=*/{CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK}, WebsiteSettingsInfo::TOP_ORIGIN_ONLY_SCOPE, 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/permissions_policy/permissions_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" @@ -310,6 +311,8 @@ void AutoplayPolicy::TryUnlockingUserGesture() { } bool AutoplayPolicy::IsGestureNeededForPlayback() const { + if (!IsAutoplayAllowedPerSettings()) + return true; if (!IsLockedPendingUserGesture()) return false; @@ -408,6 +411,17 @@ 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->AllowContentSetting( + ContentSettingsType::AUTOPLAY, /*default_value*/ false); + } + 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 @@ -133,6 +133,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.25.1