Bug 1576627 - Move MaybeNotifyAutoplayBlocked from Document to HTMLMediaElement; r=alwu

Given that it is used only in HTMLMediaElement.

Differential Revision: https://phabricator.services.mozilla.com/D43452
This commit is contained in:
Edgar Chen
2019-08-27 21:22:19 +00:00
parent f04a457e6d
commit db71a8a293
4 changed files with 20 additions and 20 deletions

View File

@@ -3876,12 +3876,26 @@ void HTMLMediaElement::DispatchEventsWhenPlayWasNotAllowed() {
ChromeOnlyDispatch::eYes);
asyncDispatcher->PostDOMEvent();
#endif
OwnerDoc()->MaybeNotifyAutoplayBlocked();
MaybeNotifyAutoplayBlocked();
ReportToConsole(nsIScriptError::warningFlag, "BlockAutoplayError");
mHasPlayEverBeenBlocked = true;
mHasEverBeenBlockedForAutoplay = true;
}
void HTMLMediaElement::MaybeNotifyAutoplayBlocked() {
Document* topLevelDoc = OwnerDoc()->GetTopLevelContentDocument();
if (!topLevelDoc) {
return;
}
// This event is used to notify front-end side that we've blocked autoplay,
// so front-end side should show blocking icon as well.
RefPtr<AsyncEventDispatcher> asyncDispatcher = new AsyncEventDispatcher(
topLevelDoc, NS_LITERAL_STRING("GloballyAutoplayBlocked"),
CanBubble::eYes, ChromeOnlyDispatch::eYes);
asyncDispatcher->PostDOMEvent();
}
void HTMLMediaElement::PlayInternal(bool aHandlingUserInput) {
if (mPreloadAction == HTMLMediaElement::PRELOAD_NONE) {
// The media load algorithm will be initiated by a user interaction.
@@ -6099,7 +6113,7 @@ void HTMLMediaElement::SuspendOrResumeElement(bool aPauseElement,
// blocked.
if (mHasEverBeenBlockedForAutoplay &&
!AutoplayPolicy::IsAllowedToPlay(*this)) {
OwnerDoc()->MaybeNotifyAutoplayBlocked();
MaybeNotifyAutoplayBlocked();
}
}
}