Bug 1550633 - part7 : change ready state to 'FAILED_TO_LOAD' and dispatch 'error' event when we have no 'src' or have an empty url. r=jya
☠☠ backed out by 6acae89335b0 ☠ ☠
authoralwu <alwu@mozilla.com>
Thu, 23 May 2019 09:03:37 +0000
changeset 475256 8024fcefe8b13d215211cbfe09f979998f3c5217
parent 475255 224eadc5ef27bdcd41375742314c8360464173b7
child 475257 470d8fae0461968d745100f64c23aa296f0d9a05
push id36058
push useraciure@mozilla.com
push dateFri, 24 May 2019 03:53:25 +0000
treeherdermozilla-central@c87317c41902 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1550633 - part7 : change ready state to 'FAILED_TO_LOAD' and dispatch 'error' event when we have no 'src' or have an empty url. r=jya `Failed to load` [1] indicates that the text track was enabled, but when the user agent attempted to obtain it, this failed in some way. According to the spec [2], if fetching fails for any reason (network error, the server returns an error code, CORS fails, etc), or if URL is the empty string, then queue a task to first change the text track readiness state to `failed to load` and then fire an event named `error` at the track element. And spec [3] also mention that, if the track URL changes so that it is no longer equal to URL while fetching is ongoing, we also need to change the text track readiness state to`failed to load` and dispatch `error`. [1] https://html.spec.whatwg.org/multipage/media.html#text-track-readiness-state [2] https://html.spec.whatwg.org/multipage/media.html#sourcing-out-of-band-text-tracks:text-track-failed-to-load [3] https://html.spec.whatwg.org/multipage/media.html#sourcing-out-of-band-text-tracks:text-track-failed-to-load-3 Differential Revision: https://phabricator.services.mozilla.com/D31556
--- a/dom/html/HTMLTrackElement.cpp
+++ b/dom/html/HTMLTrackElement.cpp
@@ -274,19 +274,20 @@ void HTMLTrackElement::MaybeDispatchLoad
     mLoadResourceDispatched = true;
 void HTMLTrackElement::LoadResource(RefPtr<WebVTTListener>&& aWebVTTListener) {
   mLoadResourceDispatched = false;
-  // Find our 'src' url
   nsAutoString src;
-  if (!GetAttr(kNameSpaceID_None, nsGkAtoms::src, src)) {
+  if (!GetAttr(kNameSpaceID_None, nsGkAtoms::src, src) || src.IsEmpty()) {
+    LOG(LogLevel::Info, ("%p Fail to load because no src", this));
+    SetReadyState(TextTrackReadyState::FailedToLoad);
   nsCOMPtr<nsIURI> uri;
   nsresult rv = NewURIFromString(src, getter_AddRefs(uri));
   LOG(LogLevel::Info, ("%p Trying to load from src=%s", this,
@@ -469,15 +470,22 @@ void HTMLTrackElement::NotifyShutdown() 
 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) {
+    // In spec, `start the track processing model` step10, while fetching is
+    // ongoing, if the track URL changes, then we have to set the `FailedToLoad`
+    // state.
+    // https://html.spec.whatwg.org/multipage/media.html#sourcing-out-of-band-text-tracks:text-track-failed-to-load-3
+    if (ReadyState() == TextTrackReadyState::Loading && aValue != aOldValue) {
+      SetReadyState(TextTrackReadyState::FailedToLoad);
+    }
   return nsGenericHTMLElement::AfterSetAttr(
       aNameSpaceID, aName, aValue, aOldValue, aMaybeScriptedPrincipal, aNotify);
 }  // namespace dom
 }  // namespace mozilla