Bug 1513039 - part3 : remove permission request codes in MediaElement. r=cpearce
Depends on D14326 Differential Revision: https://phabricator.services.mozilla.com/D14327
This commit is contained in:
@@ -49,7 +49,6 @@
|
||||
#include "jsapi.h"
|
||||
#include "mozilla/ArrayUtils.h"
|
||||
#include "mozilla/AsyncEventDispatcher.h"
|
||||
#include "mozilla/AutoplayPermissionManager.h"
|
||||
#include "mozilla/EMEUtils.h"
|
||||
#include "mozilla/EventDispatcher.h"
|
||||
#include "mozilla/EventStateManager.h"
|
||||
@@ -1820,10 +1819,6 @@ void HTMLMediaElement::AbortExistingLoads() {
|
||||
UpdateAudioChannelPlayingState();
|
||||
}
|
||||
|
||||
// Disconnect requests for permission to play. We'll make a new request
|
||||
// if required should the new media resource try to play.
|
||||
mAutoplayPermissionRequest.DisconnectIfExists();
|
||||
|
||||
// We may have changed mPaused, mAutoplaying, and other
|
||||
// things which can affect AddRemoveSelfReference
|
||||
AddRemoveSelfReference();
|
||||
@@ -3483,7 +3478,6 @@ HTMLMediaElement::~HTMLMediaElement() {
|
||||
UnregisterActivityObserver();
|
||||
|
||||
mSetCDMRequest.DisconnectIfExists();
|
||||
mAutoplayPermissionRequest.DisconnectIfExists();
|
||||
if (mDecoder) {
|
||||
ShutdownDecoder();
|
||||
}
|
||||
@@ -3632,61 +3626,19 @@ already_AddRefed<Promise> HTMLMediaElement::Play(ErrorResult& aRv) {
|
||||
UpdateHadAudibleAutoplayState();
|
||||
|
||||
const bool handlingUserInput = EventStateManager::IsHandlingUserInput();
|
||||
mPendingPlayPromises.AppendElement(promise);
|
||||
|
||||
if (AutoplayPolicy::IsAllowedToPlay(*this)) {
|
||||
mPendingPlayPromises.AppendElement(promise);
|
||||
AUTOPLAY_LOG("allow MediaElement %p to play", this);
|
||||
PlayInternal(handlingUserInput);
|
||||
UpdateCustomPolicyAfterPlayed();
|
||||
} else {
|
||||
// Prompt the user for permission to play.
|
||||
mPendingPlayPromises.AppendElement(promise);
|
||||
EnsureAutoplayRequested(handlingUserInput);
|
||||
AUTOPLAY_LOG("reject MediaElement %p to play", this);
|
||||
AsyncRejectPendingPlayPromises(NS_ERROR_DOM_MEDIA_NOT_ALLOWED_ERR);
|
||||
}
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
void HTMLMediaElement::EnsureAutoplayRequested(bool aHandlingUserInput) {
|
||||
if (mAutoplayPermissionRequest.Exists()) {
|
||||
// Autoplay has already been requested in a previous play() call.
|
||||
// Await for the previous request to be approved or denied. This
|
||||
// play request's promise will be fulfilled with all other pending
|
||||
// promises when the permission prompt is resolved.
|
||||
AUTOPLAY_LOG("%p EnsureAutoplayRequested() existing request, bailing.",
|
||||
this);
|
||||
return;
|
||||
}
|
||||
|
||||
RefPtr<AutoplayPermissionManager> request =
|
||||
AutoplayPolicy::RequestFor(*OwnerDoc());
|
||||
if (!request) {
|
||||
AsyncRejectPendingPlayPromises(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
return;
|
||||
}
|
||||
RefPtr<HTMLMediaElement> self = this;
|
||||
request->RequestWithPrompt()
|
||||
->Then(mAbstractMainThread, __func__,
|
||||
[self, handlingUserInput = aHandlingUserInput,
|
||||
request](bool aApproved) {
|
||||
self->mAutoplayPermissionRequest.Complete();
|
||||
AUTOPLAY_LOG("%p Autoplay request approved request=%p",
|
||||
self.get(), request.get());
|
||||
self->PlayInternal(handlingUserInput);
|
||||
self->UpdateCustomPolicyAfterPlayed();
|
||||
},
|
||||
[self, request](nsresult aError) {
|
||||
self->mAutoplayPermissionRequest.Complete();
|
||||
AUTOPLAY_LOG("%p Autoplay request denied request=%p", self.get(),
|
||||
request.get());
|
||||
LOG(LogLevel::Debug, ("%s rejecting play promises", __func__));
|
||||
self->AsyncRejectPendingPlayPromises(
|
||||
NS_ERROR_DOM_MEDIA_NOT_ALLOWED_ERR);
|
||||
nsContentUtils::ReportToConsole(
|
||||
nsIScriptError::warningFlag, NS_LITERAL_CSTRING("Media"),
|
||||
self->OwnerDoc(), nsContentUtils::eDOM_PROPERTIES,
|
||||
"BlockAutoplayError");
|
||||
})
|
||||
->Track(mAutoplayPermissionRequest);
|
||||
}
|
||||
|
||||
void HTMLMediaElement::DispatchEventsWhenPlayWasNotAllowed() {
|
||||
if (StaticPrefs::MediaBlockEventEnabled()) {
|
||||
DispatchAsyncEvent(NS_LITERAL_STRING("blocked"));
|
||||
@@ -5597,7 +5549,7 @@ void HTMLMediaElement::CheckAutoplayDataReady() {
|
||||
|
||||
UpdateHadAudibleAutoplayState();
|
||||
if (!AutoplayPolicy::IsAllowedToPlay(*this)) {
|
||||
EnsureAutoplayRequested(false);
|
||||
DispatchEventsWhenPlayWasNotAllowed();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -6005,9 +5957,6 @@ void HTMLMediaElement::AddRemoveSelfReference() {
|
||||
|
||||
void HTMLMediaElement::NotifyShutdownEvent() {
|
||||
mShuttingDown = true;
|
||||
// Since target thread had been shutdown, it's no chance to execute the Then()
|
||||
// afterward. Therefore, we should disconnect the request.
|
||||
mAutoplayPermissionRequest.DisconnectIfExists();
|
||||
ResetState();
|
||||
AddRemoveSelfReference();
|
||||
}
|
||||
@@ -7023,12 +6972,6 @@ already_AddRefed<Promise> HTMLMediaElement::CreateDOMPromise(
|
||||
}
|
||||
|
||||
void HTMLMediaElement::AsyncResolvePendingPlayPromises() {
|
||||
// Disconnect requests for permission to play. We're playing either way,
|
||||
// so there's no point keeping the promise connected. Note: the front
|
||||
// end permission prompt code will detect that we've started playing, and
|
||||
// hide the permission prompt.
|
||||
mAutoplayPermissionRequest.DisconnectIfExists();
|
||||
|
||||
if (mShuttingDown) {
|
||||
return;
|
||||
}
|
||||
@@ -7040,8 +6983,6 @@ void HTMLMediaElement::AsyncResolvePendingPlayPromises() {
|
||||
}
|
||||
|
||||
void HTMLMediaElement::AsyncRejectPendingPlayPromises(nsresult aError) {
|
||||
mAutoplayPermissionRequest.DisconnectIfExists();
|
||||
|
||||
if (!mPaused) {
|
||||
mPaused = true;
|
||||
DispatchAsyncEvent(NS_LITERAL_STRING("pause"));
|
||||
|
||||
Reference in New Issue
Block a user