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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Edgar Chen 2019-08-27 21:22:19 +00:00
Родитель 586f010000
Коммит ff387f6937
4 изменённых файлов: 20 добавлений и 20 удалений

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

@ -14822,20 +14822,6 @@ bool Document::HasBeenUserGestureActivated() {
return bc->GetUserGestureActivation();
}
void Document::MaybeNotifyAutoplayBlocked() {
Document* topLevelDoc = 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 Document::ClearUserGestureActivation() {
if (!HasBeenUserGestureActivated()) {
return;

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

@ -4117,10 +4117,6 @@ class Document : public nsINode,
void ReportShadowDOMUsage();
// When the doc is blocked permanantly, we would dispatch event to notify
// front-end side to show blocking icon.
void MaybeNotifyAutoplayBlocked();
// Sets flags for media autoplay telemetry.
void SetDocTreeHadAudibleMedia();
void SetDocTreeHadPlayRevoked();

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

@ -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();
}
}
}

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

@ -1306,6 +1306,10 @@ class HTMLMediaElement : public nsGenericHTMLElement,
// testing or changing control UI.
void DispatchEventsWhenPlayWasNotAllowed();
// When the doc is blocked permanantly, we would dispatch event to notify
// front-end side to show blocking icon.
void MaybeNotifyAutoplayBlocked();
// The current decoder. Load() has been called on this decoder.
// At most one of mDecoder and mSrcStream can be non-null.
RefPtr<MediaDecoder> mDecoder;