mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
Bug 1513039 - part5 : log warning when autoplay is blocked. r=cpearce,karlt
Wrap 'nsContentUtils::ReportToConsole()' to reduce necessary input parameters and call it when we need to log error or warning message. Show the warning when autoplay is blocked. For web audio, this restores the console messages removed in part4 and also reports the same message when the AudioContext is blocked in the constructor. Differential Revision: https://phabricator.services.mozilla.com/D14330 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
28a21fe0ad
commit
2e3f453263
@ -757,9 +757,15 @@ HTMLMediaElement::MediaLoadListener::GetInterface(const nsIID& aIID,
|
|||||||
void HTMLMediaElement::ReportLoadError(const char* aMsg,
|
void HTMLMediaElement::ReportLoadError(const char* aMsg,
|
||||||
const char16_t** aParams,
|
const char16_t** aParams,
|
||||||
uint32_t aParamCount) {
|
uint32_t aParamCount) {
|
||||||
nsContentUtils::ReportToConsole(
|
ReportToConsole(nsIScriptError::warningFlag, aMsg, aParams, aParamCount);
|
||||||
nsIScriptError::warningFlag, NS_LITERAL_CSTRING("Media"), OwnerDoc(),
|
}
|
||||||
nsContentUtils::eDOM_PROPERTIES, aMsg, aParams, aParamCount);
|
|
||||||
|
void HTMLMediaElement::ReportToConsole(uint32_t aErrorFlags, const char* aMsg,
|
||||||
|
const char16_t** aParams,
|
||||||
|
uint32_t aParamCount) const {
|
||||||
|
nsContentUtils::ReportToConsole(aErrorFlags, NS_LITERAL_CSTRING("Media"),
|
||||||
|
OwnerDoc(), nsContentUtils::eDOM_PROPERTIES,
|
||||||
|
aMsg, aParams, aParamCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
class HTMLMediaElement::AudioChannelAgentCallback final
|
class HTMLMediaElement::AudioChannelAgentCallback final
|
||||||
@ -3114,10 +3120,8 @@ already_AddRefed<DOMMediaStream> HTMLMediaElement::CaptureStreamInternal(
|
|||||||
if (mSrcStream) {
|
if (mSrcStream) {
|
||||||
// We don't support applying volume and mute to the captured stream, when
|
// We don't support applying volume and mute to the captured stream, when
|
||||||
// capturing a MediaStream.
|
// capturing a MediaStream.
|
||||||
nsContentUtils::ReportToConsole(
|
ReportToConsole(nsIScriptError::errorFlag,
|
||||||
nsIScriptError::errorFlag, NS_LITERAL_CSTRING("Media"), OwnerDoc(),
|
"MediaElementAudioCaptureOfMediaStreamError");
|
||||||
nsContentUtils::eDOM_PROPERTIES,
|
|
||||||
"MediaElementAudioCaptureOfMediaStreamError");
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3650,6 +3654,7 @@ void HTMLMediaElement::DispatchEventsWhenPlayWasNotAllowed() {
|
|||||||
asyncDispatcher->PostDOMEvent();
|
asyncDispatcher->PostDOMEvent();
|
||||||
#endif
|
#endif
|
||||||
OwnerDoc()->MaybeNotifyAutoplayBlocked();
|
OwnerDoc()->MaybeNotifyAutoplayBlocked();
|
||||||
|
ReportToConsole(nsIScriptError::warningFlag, "BlockAutoplayError");
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTMLMediaElement::PlayInternal(bool aHandlingUserInput) {
|
void HTMLMediaElement::PlayInternal(bool aHandlingUserInput) {
|
||||||
|
@ -788,6 +788,13 @@ class HTMLMediaElement : public nsGenericHTMLElement,
|
|||||||
void ReportLoadError(const char* aMsg, const char16_t** aParams = nullptr,
|
void ReportLoadError(const char* aMsg, const char16_t** aParams = nullptr,
|
||||||
uint32_t aParamCount = 0);
|
uint32_t aParamCount = 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log message to web console.
|
||||||
|
*/
|
||||||
|
void ReportToConsole(uint32_t aErrorFlags, const char* aMsg,
|
||||||
|
const char16_t** aParams = nullptr,
|
||||||
|
uint32_t aParamCount = 0) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Changes mHasPlayedOrSeeked to aValue. If mHasPlayedOrSeeked changes
|
* Changes mHasPlayedOrSeeked to aValue. If mHasPlayedOrSeeked changes
|
||||||
* we'll force a reflow so that the video frame gets reflowed to reflect
|
* we'll force a reflow so that the video frame gets reflowed to reflect
|
||||||
|
@ -173,7 +173,7 @@ AudioContext::AudioContext(nsPIDOMWindowInner* aWindow, bool aIsOffline,
|
|||||||
AUTOPLAY_LOG("AudioContext %p is not allowed to start", this);
|
AUTOPLAY_LOG("AudioContext %p is not allowed to start", this);
|
||||||
mWasAllowedToStart = false;
|
mWasAllowedToStart = false;
|
||||||
SuspendInternal(nullptr);
|
SuspendInternal(nullptr);
|
||||||
DispatchBlockedEvent();
|
ReportBlocked();
|
||||||
}
|
}
|
||||||
|
|
||||||
FFTBlock::MainThreadInit();
|
FFTBlock::MainThreadInit();
|
||||||
@ -192,7 +192,7 @@ void AudioContext::NotifyScheduledSourceNodeStarted() {
|
|||||||
if (isAllowedToPlay) {
|
if (isAllowedToPlay) {
|
||||||
ResumeInternal();
|
ResumeInternal();
|
||||||
} else {
|
} else {
|
||||||
DispatchBlockedEvent();
|
ReportBlocked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -943,7 +943,7 @@ already_AddRefed<Promise> AudioContext::Resume(ErrorResult& aRv) {
|
|||||||
mWasAllowedToStart = true;
|
mWasAllowedToStart = true;
|
||||||
ResumeInternal();
|
ResumeInternal();
|
||||||
} else {
|
} else {
|
||||||
DispatchBlockedEvent();
|
ReportBlocked();
|
||||||
}
|
}
|
||||||
|
|
||||||
return promise.forget();
|
return promise.forget();
|
||||||
@ -966,7 +966,9 @@ void AudioContext::ResumeInternal() {
|
|||||||
mSuspendCalled = false;
|
mSuspendCalled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioContext::DispatchBlockedEvent() {
|
void AudioContext::ReportBlocked() {
|
||||||
|
ReportToConsole(nsIScriptError::warningFlag, "BlockAutoplayError");
|
||||||
|
|
||||||
if (!StaticPrefs::MediaBlockEventEnabled()) {
|
if (!StaticPrefs::MediaBlockEventEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1144,6 +1146,15 @@ BasicWaveFormCache* AudioContext::GetBasicWaveFormCache() {
|
|||||||
return mBasicWaveFormCache;
|
return mBasicWaveFormCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AudioContext::ReportToConsole(uint32_t aErrorFlags,
|
||||||
|
const char* aMsg) const {
|
||||||
|
MOZ_ASSERT(aMsg);
|
||||||
|
Document* doc =
|
||||||
|
GetParentObject() ? GetParentObject()->GetExtantDoc() : nullptr;
|
||||||
|
nsContentUtils::ReportToConsole(aErrorFlags, NS_LITERAL_CSTRING("Media"), doc,
|
||||||
|
nsContentUtils::eDOM_PROPERTIES, aMsg);
|
||||||
|
}
|
||||||
|
|
||||||
BasicWaveFormCache::BasicWaveFormCache(uint32_t aSampleRate)
|
BasicWaveFormCache::BasicWaveFormCache(uint32_t aSampleRate)
|
||||||
: mSampleRate(aSampleRate) {
|
: mSampleRate(aSampleRate) {
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
@ -322,8 +322,11 @@ class AudioContext final : public DOMEventTargetHelper,
|
|||||||
void ResumeInternal();
|
void ResumeInternal();
|
||||||
void SuspendInternal(void* aPromise);
|
void SuspendInternal(void* aPromise);
|
||||||
|
|
||||||
// This event is used for testing only.
|
// Will report error message to console and dispatch testing event if needed
|
||||||
void DispatchBlockedEvent();
|
// when AudioContext is blocked by autoplay policy.
|
||||||
|
void ReportBlocked();
|
||||||
|
|
||||||
|
void ReportToConsole(uint32_t aErrorFlags, const char* aMsg) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Each AudioContext has an id, that is passed down the MediaStreams that
|
// Each AudioContext has an id, that is passed down the MediaStreams that
|
||||||
|
Loading…
Reference in New Issue
Block a user