Skip to content

Commit b418243

Browse files
committed
Bug 1707584 - part6 : defer pausing video element during the style refresh. r=emilio
During the style refresh, it is prohibited to change the element state. Therefore, we should defer pausing the video element, which could change the element state, until the refresh has settled. Differential Revision: https://phabricator.services.mozilla.com/D282114
1 parent b6a6bba commit b418243

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

dom/media/mediaelement/HTMLMediaElement.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,6 +1842,8 @@ class HTMLMediaElement : public nsGenericHTMLElement,
18421842
// https://html.spec.whatwg.org/multipage/media.html#pending-text-track-change-notification-flag
18431843
bool mPendingTextTrackChanged = false;
18441844

1845+
Visibility mVisibilityState = Visibility::Untracked;
1846+
18451847
public:
18461848
// This function will be called whenever a text track that is in a media
18471849
// element's list of text tracks has its text track mode change value
@@ -1898,8 +1900,6 @@ class HTMLMediaElement : public nsGenericHTMLElement,
18981900
// https://html.spec.whatwg.org/multipage/media.html#is-currently-stalled
18991901
bool mIsCurrentlyStalled = false;
19001902

1901-
Visibility mVisibilityState = Visibility::Untracked;
1902-
19031903
UniquePtr<ErrorSink> mErrorSink;
19041904

19051905
// This wrapper will handle all audio channel related stuffs, eg. the

dom/media/mediaelement/HTMLVideoElement.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -768,9 +768,19 @@ void HTMLVideoElement::OnVisibilityChange(Visibility aNewVisibility) {
768768
if ((aNewVisibility == Visibility::ApproximatelyNonVisible &&
769769
!IsCloningElementVisually()) &&
770770
mCanAutoplayFlag) {
771-
LOG("pause non-audible autoplay video when it's invisible");
772-
PauseInternal();
773-
mCanAutoplayFlag = true;
771+
// Defer pausing the element to avoid changing the element state during the
772+
// style refresh.
773+
NS_DispatchToMainThread(NS_NewRunnableFunction(
774+
__func__, [self = RefPtr<HTMLMediaElement>(this), this] {
775+
// https://html.spec.whatwg.org/multipage/media.html#ready-states:intersect-the-viewport-3
776+
if (mVisibilityState != Visibility::ApproximatelyNonVisible ||
777+
!mCanAutoplayFlag) {
778+
return;
779+
}
780+
LOG("pause non-audible autoplay video when it's invisible");
781+
PauseInternal();
782+
mCanAutoplayFlag = true;
783+
}));
774784
return;
775785
}
776786
}

0 commit comments

Comments
 (0)