From d44c8978b24920d28bc3b6a845b5206bfde5542d Mon Sep 17 00:00:00 2001 From: ctai Date: Tue, 13 Dec 2016 15:45:59 +0800 Subject: [PATCH] Bug 1222980 - Dispatch |QueueLoadFromSourceTask| to main thread. And end the synchronous section and asynchronously await a stable state when the src is not set. r=jwwang. Dispatch |QueueLoadFromSourceTask| to main thread to make sure the task will be executed later than loadstart event. And when the src get errors, we need to end the synchronous section. MozReview-Commit-ID: EQ0jVIMnqoZ --HG-- extra : rebase_source : 6651826ad8de361deda5bdc0a49b2c68dcf86220 --- dom/html/HTMLMediaElement.cpp | 24 ++++++++++++++++-------- dom/html/HTMLMediaElement.h | 8 ++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp index 15f895475d6a..9fc9cd9c51b8 100644 --- a/dom/html/HTMLMediaElement.cpp +++ b/dom/html/HTMLMediaElement.cpp @@ -2068,6 +2068,14 @@ void HTMLMediaElement::NotifyMediaStreamTracksAvailable(DOMMediaStream* aStream) mWatchManager.ManualNotify(&HTMLMediaElement::UpdateReadyStateInternal); } +void HTMLMediaElement::DealWithFailedElement(nsIContent* aSourceElement) +{ + DispatchAsyncSourceError(aSourceElement); + nsCOMPtr event = + NewRunnableMethod(this, &HTMLMediaElement::QueueLoadFromSourceTask); + NS_DispatchToMainThread(event); +} + void HTMLMediaElement::NotifyOutputTrackStopped(DOMMediaStream* aOwningStream, TrackID aDestinationTrackID) @@ -2125,8 +2133,8 @@ void HTMLMediaElement::LoadFromSourceChildren() nsAutoString src; if (!child->GetAttr(kNameSpaceID_None, nsGkAtoms::src, src)) { ReportLoadError("MediaLoadSourceMissingSrc"); - DispatchAsyncSourceError(child); - continue; + DealWithFailedElement(child); + return; } // If we have a type attribute, it must be a supported type. @@ -2137,20 +2145,20 @@ void HTMLMediaElement::LoadFromSourceChildren() diagnostics.StoreFormatDiagnostics( OwnerDoc(), type, canPlay != CANPLAY_NO, __func__); if (canPlay == CANPLAY_NO) { - DispatchAsyncSourceError(child); const char16_t* params[] = { type.get(), src.get() }; ReportLoadError("MediaLoadUnsupportedTypeAttribute", params, ArrayLength(params)); - continue; + DealWithFailedElement(child); + return; } } nsAutoString media; HTMLSourceElement *childSrc = HTMLSourceElement::FromContent(child); MOZ_ASSERT(childSrc, "Expect child to be HTMLSourceElement"); if (childSrc && !childSrc->MatchesCurrentMedia()) { - DispatchAsyncSourceError(child); const char16_t* params[] = { media.get(), src.get() }; ReportLoadError("MediaLoadSourceMediaNotMatched", params, ArrayLength(params)); - continue; + DealWithFailedElement(child); + return; } LOG(LogLevel::Debug, ("%p Trying load from =%s type=%s media=%s", this, NS_ConvertUTF16toUTF8(src).get(), NS_ConvertUTF16toUTF8(type).get(), @@ -2159,10 +2167,10 @@ void HTMLMediaElement::LoadFromSourceChildren() nsCOMPtr uri; NewURIFromString(src, getter_AddRefs(uri)); if (!uri) { - DispatchAsyncSourceError(child); const char16_t* params[] = { src.get() }; ReportLoadError("MediaLoadInvalidURI", params, ArrayLength(params)); - continue; + DealWithFailedElement(child); + return; } RemoveMediaElementFromURITable(); diff --git a/dom/html/HTMLMediaElement.h b/dom/html/HTMLMediaElement.h index e7eff165eb7b..28fcb187ffa5 100644 --- a/dom/html/HTMLMediaElement.h +++ b/dom/html/HTMLMediaElement.h @@ -964,6 +964,14 @@ protected: */ void NoSupportedMediaSourceError(const nsACString& aErrorDetails = nsCString()); + /** + * Per spec, Failed with elements: Queue a task, using the DOM manipulation + * task source, to fire a simple event named error at the candidate element. + * So dispatch |QueueLoadFromSourceTask| to main thread to make sure the task + * will be executed later than loadstart event. + */ + void DealWithFailedElement(nsIContent* aSourceElement); + /** * Attempts to load resources from the children. This is a * substep of the resource selection algorithm. Do not call this directly,