Bug 1464930 - Move AutoplayPolicy Camera/Mic permission test to after gestures-needed pref check. r=bryce draft
authorChris Pearce <cpearce@mozilla.com>
Fri, 18 May 2018 13:43:00 +1200
changeset 804440 fb19fdcc7003d7ba04f5f1ab3a7d51ce63abc3db
parent 804439 990419253ce286a977e578034bb650d4ea79e059
push id112371
push userbmo:cpearce@mozilla.com
push dateTue, 05 Jun 2018 22:09:43 +0000
reviewersbryce
bugs1464930
milestone62.0a1
Bug 1464930 - Move AutoplayPolicy Camera/Mic permission test to after gestures-needed pref check. r=bryce We only should do the camera/mic permission or active capture test in the case where document gesture activation is enabled. MozReview-Commit-ID: 9xSe8FDn5tu
dom/media/AutoplayPolicy.cpp
--- a/dom/media/AutoplayPolicy.cpp
+++ b/dom/media/AutoplayPolicy.cpp
@@ -20,34 +20,34 @@ namespace dom {
 
 /* static */ bool
 AutoplayPolicy::IsMediaElementAllowedToPlay(NotNull<HTMLMediaElement*> aElement)
 {
   if (Preferences::GetBool("media.autoplay.enabled")) {
     return true;
   }
 
+  // TODO : this old way would be removed when user-gestures-needed becomes
+  // as a default option to block autoplay.
+  if (!Preferences::GetBool("media.autoplay.enabled.user-gestures-needed", false)) {
+    // If elelement is blessed, it would always be allowed to play().
+    return aElement->IsBlessed() ||
+           EventStateManager::IsHandlingUserInput();
+  }
+
   // Pages which have been granted permission to capture WebRTC camera or
   // microphone are assumed to be trusted, and are allowed to autoplay.
   MediaManager* manager = MediaManager::GetIfExists();
   if (manager) {
     nsCOMPtr<nsPIDOMWindowInner> window = aElement->OwnerDoc()->GetInnerWindow();
     if (window && manager->IsActivelyCapturingOrHasAPermission(window->WindowID())) {
       return true;
     }
   }
 
-  // TODO : this old way would be removed when user-gestures-needed becomes
-  // as a default option to block autoplay.
-  if (!Preferences::GetBool("media.autoplay.enabled.user-gestures-needed", false)) {
-    // If elelement is blessed, it would always be allowed to play().
-    return aElement->IsBlessed() ||
-           EventStateManager::IsHandlingUserInput();
-  }
-
   // Muted content
   if (aElement->Volume() == 0.0 || aElement->Muted()) {
     return true;
   }
 
   // Whitelisted.
   if (nsContentUtils::IsExactSitePermAllow(
         aElement->NodePrincipal(), "autoplay-media")) {