Bug 1512362 - hook pref "media.autoplay.allow-muted" to all inaudible autoplay media policy r=cpearce
authorAlastor Wu <alwu@mozilla.com>
Thu, 13 Dec 2018 21:31:42 +0000
changeset 510454 dc450ef62331
parent 510453 f66935a5c80d
child 510455 a99fa97d3917
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1512362
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1512362 - hook pref "media.autoplay.allow-muted" to all inaudible autoplay media policy r=cpearce When talking about autoplay, video without audio track should also be controlled by the pref "media.autoplay.allow-muted". Differential Revision: https://phabricator.services.mozilla.com/D14480
dom/media/AutoplayPolicy.cpp
--- a/dom/media/AutoplayPolicy.cpp
+++ b/dom/media/AutoplayPolicy.cpp
@@ -139,18 +139,19 @@ static uint32_t DefaultAutoplayBehaviour
   if (prefValue < nsIAutoplay::ALLOWED || prefValue > nsIAutoplay::PROMPT) {
     // Invalid pref values are just converted to ALLOWED.
     return nsIAutoplay::ALLOWED;
   }
   return prefValue;
 }
 
 static bool IsMediaElementAllowedToPlay(const HTMLMediaElement& aElement) {
-  if ((aElement.Volume() == 0.0 || aElement.Muted()) &&
-      Preferences::GetBool("media.autoplay.allow-muted", true)) {
+  const bool isAllowedMuted =
+      Preferences::GetBool("media.autoplay.allow-muted", true);
+  if ((aElement.Volume() == 0.0 || aElement.Muted()) && isAllowedMuted) {
     AUTOPLAY_LOG("Allow muted media %p to autoplay.", &aElement);
     return true;
   }
 
   if (IsWindowAllowedToPlay(aElement.OwnerDoc()->GetInnerWindow())) {
     AUTOPLAY_LOG("Autoplay allowed as window is allowed to play, media %p.",
                  &aElement);
     return true;
@@ -159,17 +160,18 @@ static bool IsMediaElementAllowedToPlay(
   nsIDocument* topDocument = ApproverDocOf(*aElement.OwnerDoc());
   if (topDocument && topDocument->MediaDocumentKind() ==
                          nsIDocument::MediaDocumentKind::Video) {
     AUTOPLAY_LOG("Allow video document %p to autoplay", &aElement);
     return true;
   }
 
   if (!aElement.HasAudio() &&
-      aElement.ReadyState() >= HTMLMediaElement_Binding::HAVE_METADATA) {
+      aElement.ReadyState() >= HTMLMediaElement_Binding::HAVE_METADATA &&
+      isAllowedMuted) {
     AUTOPLAY_LOG("Allow media %p without audio track to autoplay", &aElement);
     return true;
   }
 
   return false;
 }
 
 /* static */ bool AutoplayPolicy::WouldBeAllowedToPlayIfAutoplayDisabled(