Bug 1513039 - part4 : remove permission request logic in AudioContext. r=karlt

AudioContext won't need to ask permission request anymore, and we will report error message in patch5.

Differential Revision: https://phabricator.services.mozilla.com/D14329

--HG--
extra : moz-landing-system : lando
This commit is contained in:
alwu 2019-01-07 18:33:36 +00:00
Родитель 2f88c125de
Коммит 28a21fe0ad
2 изменённых файлов: 3 добавлений и 44 удалений

Просмотреть файл

@ -8,7 +8,6 @@
#include "blink/PeriodicWave.h"
#include "mozilla/AutoplayPermissionManager.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/NotNull.h"
#include "mozilla/OwningNonNull.h"
@ -193,47 +192,10 @@ void AudioContext::NotifyScheduledSourceNodeStarted() {
if (isAllowedToPlay) {
ResumeInternal();
} else {
EnsureAutoplayRequested();
DispatchBlockedEvent();
}
}
void AudioContext::EnsureAutoplayRequested() {
nsPIDOMWindowInner* parent = GetParentObject();
if (!parent || !parent->AsGlobal()) {
return;
}
RefPtr<AutoplayPermissionManager> request =
AutoplayPolicy::RequestFor(*(parent->GetExtantDoc()));
if (!request) {
return;
}
AUTOPLAY_LOG("AudioContext %p EnsureAutoplayRequested %p", this,
request.get());
RefPtr<AudioContext> self = this;
request->RequestWithPrompt()->Then(
parent->AsGlobal()->AbstractMainThreadFor(TaskCategory::Other), __func__,
[self, request](bool aApproved) {
AUTOPLAY_LOG("%p Autoplay request approved request=%p", self.get(),
request.get());
self->mWasAllowedToStart = true;
self->ResumeInternal();
},
[self, request](nsresult aError) {
AUTOPLAY_LOG("%p Autoplay request denied request=%p", self.get(),
request.get());
self->mWasAllowedToStart = false;
self->DispatchBlockedEvent();
Document* doc = self->GetParentObject()
? self->GetParentObject()->GetExtantDoc()
: nullptr;
nsContentUtils::ReportToConsole(
nsIScriptError::warningFlag, NS_LITERAL_CSTRING("Media"), doc,
nsContentUtils::eDOM_PROPERTIES, "BlockAutoplayError");
});
}
nsresult AudioContext::Init() {
if (!mIsOffline) {
nsresult rv = mDestination->CreateAudioChannelAgent();
@ -980,8 +942,8 @@ already_AddRefed<Promise> AudioContext::Resume(ErrorResult& aRv) {
if (isAllowedToPlay) {
mWasAllowedToStart = true;
ResumeInternal();
} else if (!isAllowedToPlay && !mWasAllowedToStart) {
EnsureAutoplayRequested();
} else {
DispatchBlockedEvent();
}
return promise.forget();

Просмотреть файл

@ -319,9 +319,6 @@ class AudioContext final : public DOMEventTargetHelper,
nsTArray<MediaStream*> GetAllStreams() const;
// Request the prompt to ask for user's approval for autoplay.
void EnsureAutoplayRequested();
void ResumeInternal();
void SuspendInternal(void* aPromise);