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 450469 dc450ef62331efdf418c7955e0b660302c41f792
parent 450468 f66935a5c80de7fde4812634ba9d4a2fcab97388
child 450470 a99fa97d39170b51f73cc31b2c706f31ff32b990
push id35202
push userbtara@mozilla.com
push dateFri, 14 Dec 2018 05:43:22 +0000
treeherdermozilla-central@f758b5149686 [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(