Bug 1317167 - only need to do the untrust JS checking in play().
The first checking condition in the IsAllowedPlay() is used to prevent the play() operation
is called by untrusted JS when media.autoplay.enabled=false. Therefore, we don't need to check
that in CanActivateAutoplay().
MozReview-Commit-ID: 6yqoG8ISyra
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -4980,17 +4980,17 @@ bool HTMLMediaElement::CanActivateAutopl
if (!mPaused) {
return false;
}
if (mPausedForInactiveDocumentOrChannel) {
return false;
}
- if (!IsAllowedToPlay()) {
+ if (!IsAllowedToPlayByAudioChannel()) {
return false;
}
bool hasData =
(mDecoder && mReadyState >= nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA) ||
(mSrcStream && mSrcStream->Active()) ||
mMediaSource;
@@ -6030,16 +6030,22 @@ HTMLMediaElement::IsAllowedToPlay()
static_cast<nsIContent*>(this),
NS_LITERAL_STRING("MozAutoplayMediaBlocked"),
false,
false);
#endif
return false;
}
+ return IsAllowedToPlayByAudioChannel();
+}
+
+bool
+HTMLMediaElement::IsAllowedToPlayByAudioChannel()
+{
// The media element has already been paused or blocked, so it can't start
// playback again by script or user's intend until resuming by audio channel.
if (mAudioChannelSuspended == nsISuspendedTypes::SUSPENDED_PAUSE ||
mAudioChannelSuspended == nsISuspendedTypes::SUSPENDED_BLOCK) {
return false;
}
// If the tab hasn't been activated yet, the media element in that tab can't
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -1268,16 +1268,17 @@ protected:
void ResumeFromAudioChannelPaused(SuspendTypes aSuspend);
void ResumeFromAudioChannelBlocked();
bool IsSuspendedByAudioChannel() const;
void SetAudioChannelSuspended(SuspendTypes aSuspend);
// A method to check whether the media element is allowed to start playback.
bool IsAllowedToPlay();
+ bool IsAllowedToPlayByAudioChannel();
// If the network state is empty and then we would trigger DoLoad().
void MaybeDoLoad();
// True if the tab which media element belongs to has been to foreground at
// least once or activated by manually clicking the unblocking tab icon.
bool IsTabActivated() const;