-
Notifications
You must be signed in to change notification settings - Fork 920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable granular control of autoplay #222
Conversation
"list_item_ordinal.h", | ||
"media/autoplay_policy.cc", | ||
"media/autoplay_policy.h", | ||
+ "//third_party/blink/renderer/modules/permissions/permission_utils.cc", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blink/renderer/modules
depends on blink/renderer/core
so if I add deps here will introduce circular deps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain more? This seems really strange.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we use functions of third_party/blink/renderer/modules/permissions/permission_utils.h
in third_party/blink/renderer/core/html/media/autoplay_policy.cc
for requesting permission.
So we need to add dependency for "//third_party/blink/renderer/modules/permissions:permissions"
Unfortunately, it will cause this circular dependency error
ERROR Dependency cycle:
//third_party/blink/renderer/core:core ->
//third_party/blink/renderer/core/html:html ->
//third_party/blink/renderer/modules/permissions:permissions ->
//third_party/blink/renderer/core:core
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but this will effectively build it twice and we don't want that. What build error do you get without it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Undefined symbols for architecture x86_64:
"blink::ConnectToPermissionService(blink::ExecutionContext*, mojo::InterfaceRequest<blink::mojom::blink::PermissionService>)", referenced from:
blink::AutoplayPolicy::IsAutoplayAllowedPerSettings() const in autoplay_policy.o
"blink::CreatePermissionDescriptor(blink::mojom::PermissionName)", referenced from:
blink::AutoplayPolicy::IsAutoplayAllowedPerSettings() const in autoplay_policy.o
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in 2d27548
c9555b0
to
b4ae901
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't have time to make suggestions on everything but we need to try to reduce the patches more. One thing to note is patch and call into src/brave is better than patch and don't. The reason is because maintaining patch files while we have multiple chromium versions is going to be harder for each .patch change. But if we just add in the hooks and then change things in src/brave, those are easy things to pull into different chromium versions that we maintain.
return CONTENT_SETTINGS_TYPE_CLIPBOARD_WRITE; | ||
case PermissionType::PAYMENT_HANDLER: | ||
return CONTENT_SETTINGS_TYPE_PAYMENT_HANDLER; | ||
+ case PermissionType::AUTOPLAY: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe go with rename PermissionTypeToContentSetting to PermissionTypeToContentSetting_ChromiumImpl
in a patch and then chromium_src override to provide a proper definition that uses it. In that way we can add in more types later without touching patching from there on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternately call into something like if(BravePermissionTypeToContentSetting(&permission) return permission` and then have the function inside src/brave.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overrides is not gonna work because there are callers of it in the same file. It will end up no one calling this function.
Second idea doesn't work either unless we turn off this compile time checking
error: enumeration value 'AUTOPLAY' not handled in switch [-Werror,-Wswitch]
error: 16 enumeration values not handled in switch: 'MIDI_SYSEX', 'NOTIFICATIONS', 'GEOLOCATION'... [-Werror,-Wswitch]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we subclass PermissionManager and then override those caller method, it eliminates the patch but that would be too many copy logic. Not sure if it is worthy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@darkdh Chrome already has content settings for allowing sites to play sound, can't we use those?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually didn't Chrome briefly turn off autoplay by default? Can't we just turn back on whatever they turned off? Seems odd that we would need our own permission for something that is already in chrome
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually patch one line default: NOTREACHED()
should allow us to get around [-Werror,-Wswitch]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in 1154635
permission_contexts_[CONTENT_SETTINGS_TYPE_PAYMENT_HANDLER] = | ||
std::make_unique<payments::PaymentHandlerPermissionContext>(profile); | ||
+ permission_contexts_[CONTENT_SETTINGS_TYPE_AUTOPLAY] = | ||
+ std::make_unique<AutoplayPermissionContext>(profile); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer we just use a subclass of PermissionManager and patch instead to instantiate it.
Allowing less patching in the future has value because we'll need to for example rebase changes that land across multiple Chromium versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in ea9e693
WebRuntimeFeatures::EnableWebNfc(true); | ||
#endif | ||
|
||
+#if !defined(BRAVE_CHROMIUM_BUILD) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of patching here can you use chromium_src override and rename away SetRuntimeFeaturesDefaultsAndUpdateFromArgs to SetRuntimeFeaturesDefaultsAndUpdateFromArgs_ChromiumImpl
? Then adjust the value of WebRuntimeFeatures::EnableAutoplayMutedVideos
as you want after your SetRuntimeFeaturesDefaultsAndUpdateFromArgs
calls SetRuntimeFeaturesDefaultsAndUpdateFromArgs_Impl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in e4cc08b
WebsiteSettingsRegistry::PLATFORM_ANDROID, | ||
ContentSettingsInfo::INHERIT_IN_INCOGNITO); | ||
|
||
- Register(CONTENT_SETTINGS_TYPE_AUTOPLAY, "autoplay", CONTENT_SETTING_ALLOW, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can use chromium_src override here and define your own Register function that calls the ChromiumImpl passing on the same args for everything except for when "autoplay"
is encountered, it does what you do here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in a85e50e
|
||
if (base::FeatureList::IsEnabled(media::kUnifiedAutoplay)) | ||
+#if defined(BRAVE_CHROMIUM_BUILD) | ||
+ return switches::autoplay::kUserGestureRequiredPolicy; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chromium_src override for this please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in 2f47e35
{CONTENT_SETTINGS_TYPE_SENSORS, "sensors"}, | ||
{CONTENT_SETTINGS_TYPE_PAYMENT_HANDLER, "payment-handler"}, | ||
{CONTENT_SETTINGS_TYPE_USB_GUARD, "usb-devices"}, | ||
+ {CONTENT_SETTINGS_TYPE_AUTOPLAY, "autoplay"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer chromium_src override method here for HasRegisteredGroupName
, ContentSettingsTypeFromGroupName
, ContentSettingsTypeToGroupName
here. Create own array built from filtered kContentSettingsTypeGroupNames
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in 6557fd8
"list_item_ordinal.h", | ||
"media/autoplay_policy.cc", | ||
"media/autoplay_policy.h", | ||
+ "//third_party/blink/renderer/modules/permissions/permission_utils.cc", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain more? This seems really strange.
@@ -2080,6 +2081,14 @@ void AddSiteSettingsStrings(content::WebUIDataSource* html_source, | ||
IDS_SETTINGS_SITE_SETTINGS_PROTECTED_CONTENT_IDENTIFIERS}, | ||
{"siteSettingsProtectedContentEnable", | ||
IDS_SETTINGS_SITE_SETTINGS_PROTECTED_CONTENT_ENABLE}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rename in patch file for AddSiteSettingsStrings and chromium_src override to use it and add your own things to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
already there, just forgot to remove patch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in 2f47e35
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated fix 2ead047
// Push does not allow permission requests from iframes. | ||
PermissionManager::Get(profile_)->RequestPermission( | ||
- CONTENT_SETTINGS_TYPE_NOTIFICATIONS, web_contents->GetMainFrame(), | ||
+ CONTENT_SETTINGS_TYPE_AUTOPLAY, web_contents->GetMainFrame(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to do this in addition?
Maybe subclass for this and patch the creation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, I forgot to remove this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in 2f47e35
case PermissionRequestType::PERMISSION_PAYMENT_HANDLER: | ||
return "PaymentHandler"; | ||
+ case PermissionRequestType::PERMISSION_AUTOPLAY: | ||
+ return "Autoplay"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like this is only used by RecordEngagementMetric
, is that needed? Maybe if PERMISSION_AUTOPLAY
was just a separate int which is cast where needed it would simplify needing to have all enum values specified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTREACHED()
after this will CHECK failed and crash browser if we don't handle this case.
And I prefer putting it into enum because it can save us from something that we don't handle in compile time when upstream add other usage somewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in 462c5d2
e9bb454
to
8f07aee
Compare
return false; | ||
|
||
+ // brave(darkdh): default allow local files | ||
+ if (element_->GetDocument().origin() == String("null") || element_->GetDocument().origin() == String("file://")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be done with a default content setting
1. Add AutoplayPermissionContext 2. Update PermissionDescriptorToPermissionType 3. RquestPermission from AutoplayPolicy 4. Content setting page & blocked status bubble 5. Auto refresh when clicking allow in permission ask bubble
…pl::GetIconId overrides
There were link errors on Windows ``` ../../third_party/llvm-build/Release+Asserts/bin\lld-link.exe: error: undefined symbol: ?GetForProfile@PermissionManagerFactory@@SAPEAVPermissionManager@@PEAVProfile@@@z >>> referenced by C:\brave-browser\src\chrome\browser\permissions\permission_manager.cc:264 >>> browser.lib(permission_manager.obj):(?Get@PermissionManager@@SAPEAV1@PEAVProfile@@@z) ../../third_party/llvm-build/Release+Asserts/bin\lld-link.exe: error: undefined symbol: ?GetForProfile@PermissionManagerFactory@@SAPEAVPermissionManager@@PEAVProfile@@@z >>> referenced by C:\brave-browser\src\chrome\browser\budget_service\budget_service_impl.cc:56 >>> browser.lib(budget_service_impl.obj):(?GetBudget@BudgetServiceImpl@@UEAAXV?$OnceCallback@$$A6AXW4BudgetServiceErrorType@mojom@blink@@v?$vector@V?$InlinedStructPtr@VBudgetState@mojom@blink@@@mojo@@v?$allocator@V?$InlinedStructPtr@VBudgetState@mojom@blink@@@mojo@@@std@@@std@@@z@base@@@z) ../../third_party/llvm-build/Release+Asserts/bin\lld-link.exe: error: undefined symbol: ?GetForProfile@PermissionManagerFactory@@SAPEAVPermissionManager@@PEAVProfile@@@z >>> referenced by C:\brave-browser\src\chrome\browser\profiles\profile_impl.cc:1094 >>> browser.lib(profile_impl.obj):(?GetPermissionControllerDelegate@ProfileImpl@@UEAAPEAVPermissionControllerDelegate@content@@xz) ../../third_party/llvm-build/Release+Asserts/bin\lld-link.exe: error: undefined symbol: ?GetForProfile@PermissionManagerFactory@@SAPEAVPermissionManager@@PEAVProfile@@@z >>> referenced by C:\brave-browser\src\chrome\browser\profiles\off_the_record_profile_impl.cc:450 >>> browser.lib(off_the_record_profile_impl.obj):(?GetPermissionControllerDelegate@OffTheRecordProfileImpl@@UEAAPEAVPermissionControllerDelegate@content@@xz) ``` because b4842cc#diff-e9e16c8776e75c58827f5f1af6feac31R1 also changes signature of `PermissionManagerFactory::GetForProfile` but we only need `PermissionManagerFactory::BuildServiceInstanceFor`
build and test pass on all platforms. |
#include "content/public/test/mock_render_process_host.h" | ||
#include "content/public/test/web_contents_tester.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: 1 newline
.content_setting); | ||
} | ||
|
||
// There is no way to genearte a request that is automatically accepted in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: generate
} | ||
|
||
// There is no way to genearte a request that is automatically accepted in | ||
// unittest by RequestPermission so we test reverse cases here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: // unittest by RequestPermission, so we test reverse cases here
return GetPermissionRequestString_ChromiumImpl(type); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
} // namespace
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
} // namespace
BraveAddCommonStrings(html_source, profile); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
} // namespace settings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will stop commenting on those but apply everywhere please.
content_type != CONTENT_SETTINGS_TYPE_PPAPI_BROKER && | ||
content_type != CONTENT_SETTINGS_TYPE_MIDI_SYSEX && | ||
content_type != CONTENT_SETTINGS_TYPE_CLIPBOARD_READ && | ||
+ content_type != CONTENT_SETTINGS_TYPE_AUTOPLAY && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can probably improve on this patch in a follow up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you mentioned as followups sounds good, but please post a new issue for those and mark this issue as fixed by this PR.
Followup issue link brave/brave-browser#699 |
by following steps:
fix brave/brave-browser#281
Auditors: @bbondy, @bridiver
Submitter Checklist:
git rebase -i
to squash commits (if needed).Test Plan:
Automatic:
Manual:
a. Allow autoplay
4.a In site detail
4.b In site content setting
4.c In global content setting
b. Block autoplay
c. General behavior

2. If you close permission bubble, that would be automatically blocked
3. Open any local media files should allow autoplay by defaultReviewer Checklist: