Skip to content

Commit

Permalink
Autoplay: add Feature/Runtime flags to turn on/off restrictions on We…
Browse files Browse the repository at this point in the history
…b Audio.

This is adding a flag to be able to control whether Web Audio should be
restricted by autoplay. It will allow testing and experimenting.

Bug: 841933
Change-Id: Icdec2e74b210f0cf49db87f79ac9a1cb60d94d63
Reviewed-on: https://chromium-review.googlesource.com/1067148
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Reviewed-by: Chrome Cunningham <chcunningham@chromium.org>
Commit-Queue: Mounir Lamouri <mlamouri@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560350}
  • Loading branch information
mounirlamouri authored and Commit Bot committed May 21, 2018
1 parent a19d7e5 commit a7f95fa
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 4 deletions.
3 changes: 3 additions & 0 deletions content/child/runtime_features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,9 @@ void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
WebRuntimeFeatures::EnableOriginTrialControlledFeatures(false);
}

WebRuntimeFeatures::EnableAutoplayIgnoresWebAudio(
base::FeatureList::IsEnabled(media::kAutoplayIgnoreWebAudio));

// Enable explicitly enabled features, and then disable explicitly disabled
// ones.
for (const std::string& feature :
Expand Down
6 changes: 6 additions & 0 deletions media/base/media_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,12 @@ const base::Feature kLowDelayVideoRenderingOnLiveStream{
"low-delay-video-rendering-on-live-stream",
base::FEATURE_ENABLED_BY_DEFAULT};

// Whether the autoplay policy should ignore Web Audio. When ignored, the
// autoplay policy will be hardcoded to be the legacy one on based on the
// platform
const base::Feature kAutoplayIgnoreWebAudio{"AutoplayIgnoreWebAudio",
base::FEATURE_ENABLED_BY_DEFAULT};

#if defined(OS_ANDROID)
// Lock the screen orientation when a video goes fullscreen.
const base::Feature kVideoFullscreenOrientationLock{
Expand Down
1 change: 1 addition & 0 deletions media/base/media_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ namespace media {
// All features in alphabetical order. The features should be documented
// alongside the definition of their values in the .cc file.

MEDIA_EXPORT extern const base::Feature kAutoplayIgnoreWebAudio;
MEDIA_EXPORT extern const base::Feature kAv1Decoder;
MEDIA_EXPORT extern const base::Feature kBackgroundVideoPauseOptimization;
MEDIA_EXPORT extern const base::Feature kBackgroundVideoTrackOptimization;
Expand Down
1 change: 1 addition & 0 deletions third_party/blink/public/platform/web_runtime_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ class WebRuntimeFeatures {
BLINK_PLATFORM_EXPORT static void EnableOffMainThreadWebSocket(bool);
BLINK_PLATFORM_EXPORT static void EnableExperimentalProductivityFeatures(
bool);
BLINK_PLATFORM_EXPORT static void EnableAutoplayIgnoresWebAudio(bool);

private:
WebRuntimeFeatures();
Expand Down
14 changes: 10 additions & 4 deletions third_party/blink/renderer/modules/webaudio/base_audio_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -684,13 +684,19 @@ Document* BaseAudioContext::GetDocument() const {
}

AutoplayPolicy::Type BaseAudioContext::GetAutoplayPolicy() const {
// The policy is different on Android compared to Desktop.
if (RuntimeEnabledFeatures::AutoplayIgnoresWebAudioEnabled()) {
// When ignored, the policy is different on Android compared to Desktop.
#if defined(OS_ANDROID)
return AutoplayPolicy::Type::kUserGestureRequired;
return AutoplayPolicy::Type::kUserGestureRequired;
#else
// Force no user gesture required on desktop.
return AutoplayPolicy::Type::kNoUserGestureRequired;
// Force no user gesture required on desktop.
return AutoplayPolicy::Type::kNoUserGestureRequired;
#endif
}

Document* document = GetDocument();
DCHECK(document);
return AutoplayPolicy::GetAutoplayPolicyForDocument(*document);
}

bool BaseAudioContext::AreAutoplayRequirementsFulfilled() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,4 +520,8 @@ void WebRuntimeFeatures::EnableDisplayCutoutViewportFit(bool enable) {
RuntimeEnabledFeatures::SetDisplayCutoutViewportFitEnabled(enable);
}

void WebRuntimeFeatures::EnableAutoplayIgnoresWebAudio(bool enable) {
RuntimeEnabledFeatures::SetAutoplayIgnoresWebAudioEnabled(enable);
}

} // namespace blink
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@
name: "AutomationControlled",
settable_from_internals: true,
},
{
// Flag set by the media::kAutoplayIgnoreWebAudio feature flag.
name: "AutoplayIgnoresWebAudio",
},
{
name: "AutoplayMutedVideos",
settable_from_internals: true,
Expand Down

0 comments on commit a7f95fa

Please sign in to comment.