Bug 659285 - Extend media.autoplay.enabled to provide a way to disable untrusted play() invocations. r=cpearce

This commit is contained in:
Randall Barker 2015-05-26 10:32:00 +02:00
parent 8bb1e5d240
commit ae954847c2

View File

@ -105,6 +105,8 @@ static PRLogModuleInfo* gMediaElementEventsLog;
#include "nsIPermissionManager.h"
#include "nsContentTypeParser.h"
#include "mozilla/EventStateManager.h"
using namespace mozilla::layers;
using mozilla::net::nsMediaFragmentURIParser;
@ -2183,6 +2185,13 @@ HTMLMediaElement::ResetConnectionState()
void
HTMLMediaElement::Play(ErrorResult& aRv)
{
// Prevent media element from being auto-started by a script when
// media.autoplay.enabled=false
if (!IsAutoplayEnabled() && !EventStateManager::IsHandlingUserInput() && !nsContentUtils::IsCallerChrome()) {
LOG(PR_LOG_WARN, ("%p Blocked attempt to autoplay media.", this));
return;
}
StopSuspendingAfterFirstFrame();
SetPlayedOrSeeked(true);