Skip to content
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

Show autoplay blocked indicator only when play is requested #7436

Merged
merged 1 commit into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include "brave/third_party/blink/renderer/brave_farbling_constants.h"

#define AllowStorageAccessSync \
AllowAutoplay(bool default_value) { return default_value; } \
#define AllowStorageAccessSync \
AllowAutoplay(bool play_requested) { return true; } \
virtual bool AllowFingerprinting(bool enabled_per_settings) { \
return enabled_per_settings; \
} \
Expand All @@ -18,7 +18,6 @@
} \
virtual bool AllowStorageAccessSync


#include "../../../../../../third_party/blink/public/platform/web_content_settings_client.h"

#undef AllowStorageAccessSync
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
namespace blink {
namespace {

bool IsAutoplayAllowedForFrame(LocalFrame* frame) {
bool IsAutoplayAllowedForFrame(LocalFrame* frame, bool play_requested) {
if (!frame)
return false;
if (auto* settings_client = frame->GetContentSettingsClient()) {
bool allow_autoplay =
settings_client->AllowAutoplay(true /* default_value */);
bool allow_autoplay = settings_client->AllowAutoplay(play_requested);
// Clear it in order to block media when refresh or navigate
if (!allow_autoplay) {
frame->ClearUserActivation();
Expand All @@ -26,11 +25,11 @@ bool IsAutoplayAllowedForFrame(LocalFrame* frame) {
}

bool IsAutoplayAllowedForDocument(const Document& document) {
return IsAutoplayAllowedForFrame(document.GetFrame());
return IsAutoplayAllowedForFrame(document.GetFrame(), false);
}

bool IsAutoplayAllowedForElement(Member<HTMLMediaElement> element) {
return IsAutoplayAllowedForFrame(element->GetDocument().GetFrame());
return IsAutoplayAllowedForFrame(element->GetDocument().GetFrame(), true);
}

} // namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ BraveFarblingLevel BraveContentSettingsAgentImpl::GetBraveFarblingLevel() {
}
}

bool BraveContentSettingsAgentImpl::AllowAutoplay(bool default_value) {
bool BraveContentSettingsAgentImpl::AllowAutoplay(bool play_requested) {
blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
auto origin = frame->GetSecurityOrigin();
// default allow local files
Expand All @@ -228,20 +228,22 @@ bool BraveContentSettingsAgentImpl::AllowAutoplay(bool default_value) {
frame, url::Origin(origin).GetURL());
if (setting == CONTENT_SETTING_BLOCK) {
VLOG(1) << "AllowAutoplay=false because rule=CONTENT_SETTING_BLOCK";
DidBlockContentType(ContentSettingsType::AUTOPLAY);
if (play_requested)
DidBlockContentType(ContentSettingsType::AUTOPLAY);
return false;
} else if (setting == CONTENT_SETTING_ALLOW) {
VLOG(1) << "AllowAutoplay=true because rule=CONTENT_SETTING_ALLOW";
return true;
}
}

bool allow = ContentSettingsAgentImpl::AllowAutoplay(default_value);
bool allow = ContentSettingsAgentImpl::AllowAutoplay(play_requested);
if (allow) {
VLOG(1) << "AllowAutoplay=true because "
"ContentSettingsAgentImpl::AllowAutoplay says so";
} else {
DidBlockContentType(ContentSettingsType::AUTOPLAY);
if (play_requested)
DidBlockContentType(ContentSettingsType::AUTOPLAY);
VLOG(1) << "AllowAutoplay=false because "
"ContentSettingsAgentImpl::AllowAutoplay says so";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class BraveContentSettingsAgentImpl : public ContentSettingsAgentImpl {

void BraveSpecificDidBlockJavaScript(const base::string16& details);

bool AllowAutoplay(bool default_value) override;
bool AllowAutoplay(bool play_requested) override;

bool AllowFingerprinting(bool enabled_per_settings) override;
void DidBlockFingerprinting(const base::string16& details);
Expand Down