summaryrefslogtreecommitdiffstats
path: root/dom/html/HTMLMediaElement.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'dom/html/HTMLMediaElement.cpp')
-rw-r--r--dom/html/HTMLMediaElement.cpp48
1 files changed, 41 insertions, 7 deletions
diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp
index 877f3ec3ba..2db729fa2f 100644
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -318,7 +318,7 @@ class HTMLMediaElement::MediaControlKeyListener final
MOZ_INIT_OUTSIDE_CTOR explicit MediaControlKeyListener(
HTMLMediaElement* aElement)
- : mElement(aElement) {
+ : mElement(aElement), mElementId(nsID::GenerateUUID()) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aElement);
}
@@ -411,6 +411,33 @@ class HTMLMediaElement::MediaControlKeyListener final
}
}
+ void NotifyMediaPositionState() {
+ if (!IsStarted()) {
+ return;
+ }
+
+ MOZ_ASSERT(mControlAgent);
+ auto* owner = Owner();
+ PositionState state(owner->Duration(), owner->PlaybackRate(),
+ owner->CurrentTime(), TimeStamp::Now());
+ MEDIACONTROL_LOG(
+ "Notify media position state (duration=%f, playbackRate=%f, "
+ "position=%f)",
+ state.mDuration, state.mPlaybackRate,
+ state.mLastReportedPlaybackPosition);
+ mControlAgent->UpdateGuessedPositionState(mOwnerBrowsingContextId,
+ mElementId, Some(state));
+ }
+
+ void Shutdown() {
+ StopIfNeeded();
+ if (!mControlAgent) {
+ return;
+ }
+ mControlAgent->UpdateGuessedPositionState(mOwnerBrowsingContextId,
+ mElementId, Nothing());
+ }
+
// This method can be called before the listener starts, which would cache
// the audible state and update after the listener starts.
void UpdateMediaAudibleState(bool aIsOwnerAudible) {
@@ -543,6 +570,10 @@ class HTMLMediaElement::MediaControlKeyListener final
MOZ_ASSERT(mState != aState, "Should not notify same state again!");
mState = aState;
mControlAgent->NotifyMediaPlaybackChanged(mOwnerBrowsingContextId, mState);
+
+ if (aState == MediaPlaybackState::ePlayed) {
+ NotifyMediaPositionState();
+ }
}
void NotifyAudibleStateChanged(MediaAudibleState aState) {
@@ -557,6 +588,7 @@ class HTMLMediaElement::MediaControlKeyListener final
bool mIsPictureInPictureEnabled = false;
bool mIsOwnerAudible = false;
MOZ_INIT_OUTSIDE_CTOR uint64_t mOwnerBrowsingContextId;
+ const nsID mElementId;
};
class HTMLMediaElement::MediaStreamTrackListener
@@ -994,7 +1026,7 @@ class HTMLMediaElement::MediaStreamRenderer {
graph->CreateSourceTrack(MediaSegment::AUDIO));
}
- void ResolveAudioDevicePromiseIfExists(const char* aMethodName) {
+ void ResolveAudioDevicePromiseIfExists(StaticString aMethodName) {
if (mSetAudioDevicePromise.IsEmpty()) {
return;
}
@@ -2065,7 +2097,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLMediaElement,
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSeekDOMPromise)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSetMediaKeysDOMPromise)
if (tmp->mMediaControlKeyListener) {
- tmp->mMediaControlKeyListener->StopIfNeeded();
+ tmp->mMediaControlKeyListener->Shutdown();
}
if (tmp->mEventBlocker) {
tmp->mEventBlocker->Shutdown();
@@ -3384,6 +3416,8 @@ void HTMLMediaElement::Seek(double aTime, SeekTarget::Type aSeekType,
// We changed whether we're seeking so we need to AddRemoveSelfReference.
AddRemoveSelfReference();
+
+ mMediaControlKeyListener->NotifyMediaPositionState();
}
double HTMLMediaElement::Duration() const {
@@ -4804,10 +4838,9 @@ void HTMLMediaElement::DoneCreatingElement() {
}
}
-bool HTMLMediaElement::IsHTMLFocusable(bool aWithMouse, bool* aIsFocusable,
- int32_t* aTabIndex) {
- if (nsGenericHTMLElement::IsHTMLFocusable(aWithMouse, aIsFocusable,
- aTabIndex)) {
+bool HTMLMediaElement::IsHTMLFocusable(IsFocusableFlags aFlags,
+ bool* aIsFocusable, int32_t* aTabIndex) {
+ if (nsGenericHTMLElement::IsHTMLFocusable(aFlags, aIsFocusable, aTabIndex)) {
return true;
}
@@ -6871,6 +6904,7 @@ void HTMLMediaElement::SetPlaybackRate(double aPlaybackRate, ErrorResult& aRv) {
mDecoder->SetPlaybackRate(ClampPlaybackRate(mPlaybackRate));
}
DispatchAsyncEvent(u"ratechange"_ns);
+ mMediaControlKeyListener->NotifyMediaPositionState();
}
void HTMLMediaElement::SetPreservesPitch(bool aPreservesPitch) {