Bug 1346498 part 8 - extract the HTMLMediaElement::NotifyDecoderActivityChanges() method; r?jwwang
Move all the policy rules into this method now, will then move the policies into MediaDecoder at next patch.
MozReview-Commit-ID: ILAYLrTwCJy
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -4308,19 +4308,17 @@ nsresult HTMLMediaElement::BindToTree(ns
IsAutoplayEnabled() && (!aDocument || !aDocument->IsStaticDocument()) &&
!IsEditable();
// The preload action depends on the value of the autoplay attribute.
// It's value may have changed, so update it.
UpdatePreloadAction();
aDocument->AddMediaContent(this);
}
- if (mDecoder) {
- mDecoder->NotifyOwnerActivityChanged(!IsHidden());
- }
+ NotifyDecoderActivityChanges();
return rv;
}
/* static */
void HTMLMediaElement::VideoDecodeSuspendTimerCallback(nsITimer* aTimer, void* aClosure)
{
MOZ_ASSERT(NS_IsMainThread());
@@ -4545,20 +4543,18 @@ void HTMLMediaElement::UnbindFromTree(bo
{
mUnboundFromTree = true;
if (OwnerDoc()) {
OwnerDoc()->RemoveMediaContent(this);
}
nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
- if (mDecoder) {
- MOZ_ASSERT(IsHidden());
- mDecoder->NotifyOwnerActivityChanged(false);
- }
+ MOZ_ASSERT(IsHidden());
+ NotifyDecoderActivityChanges();
RefPtr<HTMLMediaElement> self(this);
nsCOMPtr<nsIRunnable> task = NS_NewRunnableFunction([self] () {
if (self->mUnboundFromTree) {
self->Pause();
}
});
RunInStableState(task);
@@ -6246,17 +6242,17 @@ void HTMLMediaElement::NotifyOwnerDocume
// Visible -> Just pause hidden play time (no-op if already paused).
HiddenVideoStop();
} else if (mPlayTime.IsStarted()) {
// Not visible, play time is running -> Start hidden play time if needed.
HiddenVideoStart();
}
if (mDecoder && !IsBeingDestroyed()) {
- mDecoder->NotifyOwnerActivityChanged(visible);
+ NotifyDecoderActivityChanges();
}
bool pauseElement = ShouldElementBePaused();
SuspendOrResumeElement(pauseElement, !IsActive());
// If the owning document has become inactive we should shutdown the CDM.
if (!OwnerDoc()->IsCurrentActiveDocument() && mMediaKeys) {
mMediaKeys->Shutdown();
@@ -6743,36 +6739,33 @@ HTMLMediaElement::OnVisibilityChange(Vis
if (!mDecoder) {
return;
}
switch (aNewVisibility) {
case Visibility::UNTRACKED: {
MOZ_ASSERT_UNREACHABLE("Shouldn't notify for untracked visibility");
- break;
+ return;
}
case Visibility::APPROXIMATELY_NONVISIBLE: {
if (mPlayTime.IsStarted()) {
// Not visible, play time is running -> Start hidden play time if needed.
HiddenVideoStart();
}
-
- mDecoder->NotifyOwnerActivityChanged(false);
break;
}
case Visibility::APPROXIMATELY_VISIBLE: {
// Visible -> Just pause hidden play time (no-op if already paused).
HiddenVideoStop();
-
- mDecoder->NotifyOwnerActivityChanged(true);
break;
}
}
+ NotifyDecoderActivityChanges();
}
MediaKeys*
HTMLMediaElement::GetMediaKeys() const
{
return mMediaKeys;
}
@@ -7399,16 +7392,28 @@ HTMLMediaElement::GetEMEInfo(nsString& a
mMediaKeys->GetSessionsInfo(sessionsInfo);
aEMEInfo.AppendLiteral("Key System=");
aEMEInfo.Append(keySystem);
aEMEInfo.AppendLiteral(" SessionsInfo=");
aEMEInfo.Append(sessionsInfo);
}
+void
+HTMLMediaElement::NotifyDecoderActivityChanges() const
+{
+ // A element is visible only if its document is visible and the element
+ // itself is visible.
+ const bool visible = !IsHidden() &&
+ mVisibilityState == Visibility::APPROXIMATELY_VISIBLE;
+ if (mDecoder) {
+ mDecoder->NotifyOwnerActivityChanged(visible);
+ }
+}
+
bool HasDebuggerPrivilege(JSContext* aCx, JSObject* aObj)
{
return nsContentUtils::CallerHasPermission(aCx,
NS_LITERAL_STRING("debugger"));
}
} // namespace dom
} // namespace mozilla
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -1294,16 +1294,19 @@ protected:
void AsyncRejectPendingPlayPromises(nsresult aError);
// This method snapshots the mPendingPlayPromises by TakePendingPlayPromises()
// and queues a task to resolve them also to dispatch a "playing" event.
void NotifyAboutPlaying();
already_AddRefed<Promise> CreateDOMPromise(ErrorResult& aRv) const;
+ // Pass information for deciding the video decode mode to decoder.
+ void NotifyDecoderActivityChanges() const;
+
// The current decoder. Load() has been called on this decoder.
// At most one of mDecoder and mSrcStream can be non-null.
RefPtr<MediaDecoder> mDecoder;
// The DocGroup-specific AbstractThread::MainThread() of this HTML element.
RefPtr<AbstractThread> mAbstractMainThread;
// Observers listening to changes to the mDecoder principal.