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
--- 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")) {