Disable automatic HTML5 videos playing in Firefox
authorHugo Villeneuve <hugo@hugovil.com>
Thu, 13 Aug 2015 22:06:10 +0000 (18:06 -0400)
committerHugo Villeneuve <hugo@hugovil.com>
Fri, 14 Aug 2015 05:20:05 +0000 (01:20 -0400)
stage5/patches/common/firefox-34.0.5-no-autoplay.patch [new file with mode: 0644]

diff --git a/stage5/patches/common/firefox-34.0.5-no-autoplay.patch b/stage5/patches/common/firefox-34.0.5-no-autoplay.patch
new file mode 100644 (file)
index 0000000..134e4a4
--- /dev/null
@@ -0,0 +1,33 @@
+From: Randall Barker <rbarker@mozilla.com>
+Bug 659285 - Extend media.autoplay.enabled to provide a way to disable
+             untrusted play() invocations
+
+       (prevent HTML5 videos from starting automatically when
+        media.autoplay.enabled is set to false)
+
+diff -Naur mozilla-release/content/html/content/src/HTMLMediaElement.cpp mozilla-release.patched/content/html/content/src/HTMLMediaElement.cpp
+--- mozilla-release/content/html/content/src/HTMLMediaElement.cpp      2014-11-26 07:29:56.000000000 -0500
++++ mozilla-release.patched/content/html/content/src/HTMLMediaElement.cpp      2015-08-13 22:01:23.224642252 -0400
+@@ -15,6 +15,8 @@
+ #include "mozilla/dom/MediaEncryptedEvent.h"
+ #endif
++#include "mozilla/EventStateManager.h"
++
+ #include "base/basictypes.h"
+ #include "nsIDOMHTMLMediaElement.h"
+ #include "nsIDOMHTMLSourceElement.h"
+@@ -2157,6 +2159,13 @@
+ 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(LogLevel::Debug, ("%p Blocked attempt to autoplay media.", this));
++    return;
++  }
++
+   StopSuspendingAfterFirstFrame();
+   SetPlayedOrSeeked(true);