Bug 659285 - Extend media.autoplay.enabled to provide a way to disable untrusted play() invocations. r=cpearce
☠☠ backed out by 6c79ffd73d9d ☠ ☠
authorRandall Barker <rbarker@mozilla.com>
Tue, 26 May 2015 10:32:00 +0200
changeset 247341 32aea59e702fd570e754d999547fef63578ffbeb
parent 247340 94fcc63014b32ed6e5bbf819ce83c8555f660e7b
child 247342 52661b02eaad68b3f8b4ad272a14c70d451766a7
push id28864
push userkwierso@gmail.com
push dateFri, 05 Jun 2015 21:49:37 +0000
treeherdermozilla-central@97a39c939c51 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs659285
milestone41.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 659285 - Extend media.autoplay.enabled to provide a way to disable untrusted play() invocations. r=cpearce
dom/html/HTMLMediaElement.cpp
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -100,16 +100,18 @@ static PRLogModuleInfo* gMediaElementEve
 #include "nsIContentSecurityPolicy.h"
 
 #include "mozilla/Preferences.h"
 #include "mozilla/FloatingPoint.h"
 
 #include "nsIPermissionManager.h"
 #include "nsContentTypeParser.h"
 
+#include "mozilla/EventStateManager.h"
+
 using namespace mozilla::layers;
 using mozilla::net::nsMediaFragmentURIParser;
 
 namespace mozilla {
 namespace dom {
 
 // Number of milliseconds between progress events as defined by spec
 static const uint32_t PROGRESS_MS = 350;
@@ -2178,16 +2180,23 @@ HTMLMediaElement::ResetConnectionState()
   ChangeNetworkState(nsIDOMHTMLMediaElement::NETWORK_EMPTY);
   ChangeDelayLoadStatus(false);
   ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_NOTHING);
 }
 
 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);
 
   if (mNetworkState == nsIDOMHTMLMediaElement::NETWORK_EMPTY) {
     aRv = Load();
     if (aRv.Failed()) {
       return;
     }