Bug 1463919 - Call Play() when activating attribute based autoplay. r?jya draft
authorChris Pearce <cpearce@mozilla.com>
Tue, 26 Jun 2018 14:16:13 +1200
changeset 811169 5ec30d2124368165db67415e56a78f1a5aca3dd9
parent 811168 e09e70e18c2c96ff027eb9a65f0f0c6ec4e8a282
child 811170 9261e2232aa934944c01a59fe9a1ba62fd303c69
push id114216
push userbmo:cpearce@mozilla.com
push dateWed, 27 Jun 2018 03:52:23 +0000
reviewersjya
bugs1463919
milestone62.0a1
Bug 1463919 - Call Play() when activating attribute based autoplay. r?jya When autoplay is requested by setting the "autoplay" attribute, we should check whether autoplay is allowed in HTMLMediaElement::CheckAutoplayDataReady() and if not we should prompt for user consent. This ensures that <video ... autoplay/> will prompt for consent when used on a page without a pre-existing allow/block permission. MozReview-Commit-ID: 77pJR2Ybn2i
dom/html/HTMLMediaElement.cpp
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -6180,20 +6180,16 @@ HTMLMediaElement::CanActivateAutoplay()
 {
   // For stream inputs, we activate autoplay on HAVE_NOTHING because
   // this element itself might be blocking the stream from making progress by
   // being paused. We only check that it has data by checking its active state.
   // We also activate autoplay when playing a media source since the data
   // download is controlled by the script and there is no way to evaluate
   // MediaDecoder::CanPlayThrough().
 
-  if (!AutoplayPolicy::IsMediaElementAllowedToPlay(WrapNotNull(this))) {
-    return false;
-  }
-
   if (!HasAttr(kNameSpaceID_None, nsGkAtoms::autoplay)) {
     return false;
   }
 
   if (!mAutoplaying) {
     return false;
   }
 
@@ -6235,16 +6231,23 @@ HTMLMediaElement::CanActivateAutoplay()
 
 void
 HTMLMediaElement::CheckAutoplayDataReady()
 {
   if (!CanActivateAutoplay()) {
     return;
   }
 
+  if (!AutoplayPolicy::IsMediaElementAllowedToPlay(WrapNotNull(this))) {
+    if (Preferences::GetBool("media.autoplay.ask-permission", false)) {
+      EnsureAutoplayRequested(false);
+    }
+    return;
+  }
+
   mPaused = false;
   // We changed mPaused which can affect AddRemoveSelfReference
   AddRemoveSelfReference();
   UpdateSrcMediaStreamPlaying();
   UpdateAudioChannelPlayingState();
 
   if (mDecoder) {
     SetPlayedOrSeeked(true);