mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
Bug 1550633 - part6 : clear track's cues list whenever track element's src attribute set, changed or removed. r=jya,baku
According to the spec [1], we should empty track's cue list whenever a track element has its src attribute set, changed, or removed. [1] https://html.spec.whatwg.org/multipage/media.html#sourcing-out-of-band-text-tracks:attr-track-src Differential Revision: https://phabricator.services.mozilla.com/D31552 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
339990cb09
commit
973b2aec17
@ -214,17 +214,11 @@ bool HTMLTrackElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
||||
|
||||
void HTMLTrackElement::SetSrc(const nsAString& aSrc, ErrorResult& aError) {
|
||||
SetHTMLAttr(nsGkAtoms::src, aSrc, aError);
|
||||
uint16_t oldReadyState = ReadyState();
|
||||
SetReadyState(TextTrackReadyState::NotLoaded);
|
||||
if (!mMediaParent) {
|
||||
return;
|
||||
}
|
||||
if (mTrack && (oldReadyState != TextTrackReadyState::NotLoaded)) {
|
||||
// Remove all the cues in MediaElement.
|
||||
mMediaParent->RemoveTextTrack(mTrack);
|
||||
// Recreate mTrack.
|
||||
CreateTextTrack();
|
||||
}
|
||||
|
||||
// Stop WebVTTListener.
|
||||
mListener = nullptr;
|
||||
if (mChannel) {
|
||||
@ -235,6 +229,16 @@ void HTMLTrackElement::SetSrc(const nsAString& aSrc, ErrorResult& aError) {
|
||||
MaybeDispatchLoadResource();
|
||||
}
|
||||
|
||||
void HTMLTrackElement::MaybeClearAllCues() {
|
||||
// Empty track's cue list whenever the track element's `src` attribute set,
|
||||
// changed, or removed,
|
||||
// https://html.spec.whatwg.org/multipage/media.html#sourcing-out-of-band-text-tracks:attr-track-src
|
||||
if (!mTrack) {
|
||||
return;
|
||||
}
|
||||
mTrack->ClearAllCues();
|
||||
}
|
||||
|
||||
// This function will run partial steps from `start-the-track-processing-model`
|
||||
// and finish the rest of steps in `LoadResource()` during the stable state.
|
||||
// https://html.spec.whatwg.org/multipage/media.html#start-the-track-processing-model
|
||||
@ -463,5 +467,17 @@ void HTMLTrackElement::NotifyShutdown() {
|
||||
mListener = nullptr;
|
||||
}
|
||||
|
||||
nsresult HTMLTrackElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
|
||||
const nsAttrValue* aValue,
|
||||
const nsAttrValue* aOldValue,
|
||||
nsIPrincipal* aMaybeScriptedPrincipal,
|
||||
bool aNotify) {
|
||||
if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::src) {
|
||||
MaybeClearAllCues();
|
||||
}
|
||||
return nsGenericHTMLElement::AfterSetAttr(
|
||||
aNameSpaceID, aName, aValue, aOldValue, aMaybeScriptedPrincipal, aNotify);
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
@ -87,6 +87,12 @@ class HTMLTrackElement final : public nsGenericHTMLElement {
|
||||
nsIContent* aBindingParent) override;
|
||||
virtual void UnbindFromTree(bool aDeep, bool aNullParent) override;
|
||||
|
||||
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
|
||||
const nsAttrValue* aValue,
|
||||
const nsAttrValue* aOldValue,
|
||||
nsIPrincipal* aMaybeScriptedPrincipal,
|
||||
bool aNotify) override;
|
||||
|
||||
void DispatchTrackRunnable(const nsString& aEventName);
|
||||
void DispatchTrustedEvent(const nsAString& aName);
|
||||
|
||||
@ -121,6 +127,8 @@ class HTMLTrackElement final : public nsGenericHTMLElement {
|
||||
void LoadResource(RefPtr<WebVTTListener>&& aWebVTTListener);
|
||||
bool mLoadResourceDispatched;
|
||||
|
||||
void MaybeClearAllCues();
|
||||
|
||||
RefPtr<WindowDestroyObserver> mWindowDestroyObserver;
|
||||
};
|
||||
|
||||
|
@ -197,6 +197,14 @@ void TextTrack::RemoveCue(TextTrackCue& aCue, ErrorResult& aRv) {
|
||||
}
|
||||
}
|
||||
|
||||
void TextTrack::ClearAllCues() {
|
||||
WEBVTT_LOG("ClearAllCues");
|
||||
ErrorResult dummy;
|
||||
while (!mCueList->IsEmpty()) {
|
||||
RemoveCue(*(*mCueList)[0], dummy);
|
||||
}
|
||||
}
|
||||
|
||||
void TextTrack::SetCuesDirty() {
|
||||
for (uint32_t i = 0; i < mCueList->Length(); i++) {
|
||||
((*mCueList)[i])->Reset();
|
||||
|
@ -114,6 +114,8 @@ class TextTrack final : public DOMEventTargetHelper {
|
||||
RefPtr<TextTrackCueList>& aOtherCues,
|
||||
const media::TimeInterval& aInterval) const;
|
||||
|
||||
void ClearAllCues();
|
||||
|
||||
private:
|
||||
~TextTrack();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user