Bug 1216308 - Hoist IsCallerChrome check in HTMLMediaElement::Play to API entry point. r=bz

This commit is contained in:
Bobby Holley
2015-10-19 14:45:18 -07:00
parent 1a76d19bef
commit 5c965d3bd4
2 changed files with 20 additions and 9 deletions

View File

@@ -2221,13 +2221,22 @@ HTMLMediaElement::ResetConnectionState()
void
HTMLMediaElement::Play(ErrorResult& aRv)
{
nsresult rv = PlayInternal(nsContentUtils::IsCallerChrome());
if (NS_FAILED(rv)) {
aRv.Throw(rv);
}
}
nsresult
HTMLMediaElement::PlayInternal(bool aCallerIsChrome)
{
// Prevent media element from being auto-started by a script when
// media.autoplay.enabled=false
if (!mHasUserInteraction
&& !IsAutoplayEnabled()
&& !EventStateManager::IsHandlingUserInput()
&& !nsContentUtils::IsCallerChrome()) {
&& !aCallerIsChrome) {
LOG(LogLevel::Debug, ("%p Blocked attempt to autoplay media.", this));
#if defined(MOZ_WIDGET_ANDROID)
nsContentUtils::DispatchTrustedEvent(OwnerDoc(),
@@ -2236,7 +2245,7 @@ HTMLMediaElement::Play(ErrorResult& aRv)
false,
false);
#endif
return;
return NS_OK;
}
// Play was not blocked so assume user interacted with the element.
@@ -2257,7 +2266,7 @@ HTMLMediaElement::Play(ErrorResult& aRv)
OwnerDoc()->Hidden()) {
LOG(LogLevel::Debug, ("%p Blocked playback because owner hidden.", this));
mPlayBlockedBecauseHidden = true;
return;
return NS_OK;
}
// Even if we just did Load() or ResumeLoad(), we could already have a decoder
@@ -2267,9 +2276,9 @@ HTMLMediaElement::Play(ErrorResult& aRv)
SetCurrentTime(0);
}
if (!mPausedForInactiveDocumentOrChannel) {
aRv = mDecoder->Play();
if (aRv.Failed()) {
return;
nsresult rv = mDecoder->Play();
if (NS_FAILED(rv)) {
return rv;
}
}
}
@@ -2305,13 +2314,13 @@ HTMLMediaElement::Play(ErrorResult& aRv)
AddRemoveSelfReference();
UpdatePreloadAction();
UpdateSrcMediaStreamPlaying();
return NS_OK;
}
NS_IMETHODIMP HTMLMediaElement::Play()
{
ErrorResult rv;
Play(rv);
return rv.StealNSResult();
return PlayInternal(/* aCallerIsChrome = */ true);
}
HTMLMediaElement::WakeLockBoolWrapper&