diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp index 3441630fd900..8bf2a20af823 100644 --- a/dom/html/HTMLMediaElement.cpp +++ b/dom/html/HTMLMediaElement.cpp @@ -6017,6 +6017,48 @@ HTMLMediaElement::IsAllowedToPlay() return true; } +static const char* VisibilityString(Visibility aVisibility) { + switch(aVisibility) { + case Visibility::UNTRACKED: { + return "UNTRACKED"; + } + case Visibility::APPROXIMATELY_NONVISIBLE: { + return "APPROXIMATELY_NONVISIBLE"; + } + case Visibility::APPROXIMATELY_VISIBLE: { + return "APPROXIMATELY_VISIBLE"; + } + } + + return "NAN"; +} + +void +HTMLMediaElement::OnVisibilityChange(Visibility aNewVisibility) +{ + LOG(LogLevel::Debug, ("OnVisibilityChange(): %s\n", + VisibilityString(aNewVisibility))); + + if (!mDecoder) { + return; + } + + switch (aNewVisibility) { + case Visibility::UNTRACKED: { + MOZ_ASSERT_UNREACHABLE("Shouldn't notify for untracked visibility"); + break; + } + case Visibility::APPROXIMATELY_NONVISIBLE: { + mDecoder->NotifyOwnerActivityChanged(false); + break; + } + case Visibility::APPROXIMATELY_VISIBLE: { + mDecoder->NotifyOwnerActivityChanged(true); + break; + } + } + +} #ifdef MOZ_EME MediaKeys* HTMLMediaElement::GetMediaKeys() const diff --git a/dom/interfaces/html/nsIDOMHTMLMediaElement.idl b/dom/interfaces/html/nsIDOMHTMLMediaElement.idl index d7012347f28e..d362cef42629 100644 --- a/dom/interfaces/html/nsIDOMHTMLMediaElement.idl +++ b/dom/interfaces/html/nsIDOMHTMLMediaElement.idl @@ -23,8 +23,11 @@ #ifdef GetCurrentTime #undef GetCurrentTime #endif +#include "Visibility.h" %} +native Visibility(mozilla::Visibility); + [uuid(c041d76c-15ce-47ad-b61d-e8755a6db638)] interface nsIDOMHTMLMediaElement : nsISupports { @@ -129,4 +132,13 @@ interface nsIDOMHTMLMediaElement : nsISupports // * onmozinterruptend - called when the interruption is concluded [notxpcom] boolean isVideo(); + + /** + * Called by layout to announce when the frame associated with this content + * has changed its visibility state. + * + * @param aOldVisibility The previous visibility state. + * @param aNewVisibility The new visibility state. + */ + [noscript, notxpcom] void onVisibilityChange(in Visibility aNewVisibility); };