onload callback for <track> element attached to <video> does not fire
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Jan 2013 00:33:32 +0000 (00:33 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Jan 2013 00:33:32 +0000 (00:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=103258

Patch by Antoine Quint <graouts@apple.com> on 2013-01-03
Reviewed by Eric Carlson.

Source/WebCore:

We now correctly implement the track processing model per the latest spec at
http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#start-the-track-processing-model.

For a <track> to load, three conditions must be met:

1. it must have a non-empty src
2. it must have a mode other than "disabled" (the default)
3. it must have a parent media element

We used to only check if we were able to load upon setting the track's src,
whereas a change of any of those conditions should have done this, which this
patch now correctly implements.

We also correctly implement the load model asynchronously after step 4, per
the spec, hence the split of the code previously entirely contained in
HTMLTrackElement::scheduleLoad() in another method fired on a timer.

Test: media/track/track-element-load-event.html

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::textTrackModeChanged):
* html/HTMLTrackElement.cpp:
(WebCore::HTMLTrackElement::HTMLTrackElement):
(WebCore::HTMLTrackElement::insertedInto):
(WebCore::HTMLTrackElement::parseAttribute):
(WebCore::HTMLTrackElement::scheduleLoad):
(WebCore):
(WebCore::HTMLTrackElement::loadTimerFired):
(WebCore::HTMLTrackElement::textTrackModeChanged):
* html/HTMLTrackElement.h:
* html/track/TextTrack.cpp:
(WebCore::TextTrack::removeAllCues):
(WebCore):
* html/track/TextTrack.h:
(TextTrack):

LayoutTests:

As a result of fixing this bug, a few new failures were uncovered and TestExpectations
needed to be updated to take this into account. Additionally, some existing tests were
incorrect or outdated and were fixed as well. Finally, a new test was added to thoroughly
test the various conditions required for a <track> element to successfully load.

* fast/events/constructors/track-event-constructor.html: Update the test to correctly set
a non-disabled mode on the text track such that it may load per the rules enforced with this patch.
* http/tests/security/text-track-crossorigin.html: Update the test to correctly set a non-disabled
mode on the text track such that it may load per the rules enforced with this patch.
* media/track/track-add-track-expected.txt: Update the output to match changes made to test.
* media/track/track-add-track.html: Update the test to correctly set a non-disabled mode on
the text track such that it may load per the rules enforced with this patch. Also, ensure
the .readyState of the text track is correctly assumed to be NONE vs. LOADING as it would
have to wait until the next run loop to be changed to anything but NONE.
* media/track/track-element-load-event-expected.txt: Added.
* media/track/track-element-load-event.html: Added.
* media/track/track-load-from-src-readyState.html: Update the test to correctly set a
non-disabled mode on the text track such that it may load per the rules enforced with
this patch.
* platform/chromium/TestExpectations: Skip tests that now fail instead of timing out.
* platform/efl/TestExpectations: Skip tests that now fail instead of timing out.
* platform/gtk/TestExpectations: Skip tests that now fail instead of timing out.
* platform/mac/TestExpectations: Skip tests that now fail instead of timing out.
* platform/qt/TestExpectations: Skip tests that now fail instead of timing out.
* platform/win/TestExpectations: Skip tests that now fail instead of timing out.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@138766 268f45cc-cd09-0410-ab3c-d52691b4dbfc

20 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/events/constructors/track-event-constructor.html
LayoutTests/http/tests/security/text-track-crossorigin.html
LayoutTests/media/track/track-add-track-expected.txt
LayoutTests/media/track/track-add-track.html
LayoutTests/media/track/track-element-load-event-expected.txt [new file with mode: 0644]
LayoutTests/media/track/track-element-load-event.html [new file with mode: 0644]
LayoutTests/media/track/track-load-from-src-readyState.html
LayoutTests/platform/chromium/TestExpectations
LayoutTests/platform/efl/TestExpectations
LayoutTests/platform/gtk/TestExpectations
LayoutTests/platform/mac/TestExpectations
LayoutTests/platform/qt/TestExpectations
LayoutTests/platform/win/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLTrackElement.cpp
Source/WebCore/html/HTMLTrackElement.h
Source/WebCore/html/track/TextTrack.cpp
Source/WebCore/html/track/TextTrack.h

index 524b8f4d414c939aef515c920665c8ba132ba8dd..73ded427a3b2a6bcb8da545f3fd4bea7aca8729f 100644 (file)
@@ -1,3 +1,36 @@
+2013-01-03  Antoine Quint  <graouts@apple.com>
+
+        onload callback for <track> element attached to <video> does not fire
+        https://bugs.webkit.org/show_bug.cgi?id=103258
+
+        Reviewed by Eric Carlson.
+
+        As a result of fixing this bug, a few new failures were uncovered and TestExpectations
+        needed to be updated to take this into account. Additionally, some existing tests were
+        incorrect or outdated and were fixed as well. Finally, a new test was added to thoroughly
+        test the various conditions required for a <track> element to successfully load.
+
+        * fast/events/constructors/track-event-constructor.html: Update the test to correctly set
+        a non-disabled mode on the text track such that it may load per the rules enforced with this patch.
+        * http/tests/security/text-track-crossorigin.html: Update the test to correctly set a non-disabled
+        mode on the text track such that it may load per the rules enforced with this patch.
+        * media/track/track-add-track-expected.txt: Update the output to match changes made to test.
+        * media/track/track-add-track.html: Update the test to correctly set a non-disabled mode on
+        the text track such that it may load per the rules enforced with this patch. Also, ensure
+        the .readyState of the text track is correctly assumed to be NONE vs. LOADING as it would
+        have to wait until the next run loop to be changed to anything but NONE.
+        * media/track/track-element-load-event-expected.txt: Added.
+        * media/track/track-element-load-event.html: Added.
+        * media/track/track-load-from-src-readyState.html: Update the test to correctly set a
+        non-disabled mode on the text track such that it may load per the rules enforced with
+        this patch.
+        * platform/chromium/TestExpectations: Skip tests that now fail instead of timing out.
+        * platform/efl/TestExpectations: Skip tests that now fail instead of timing out.
+        * platform/gtk/TestExpectations: Skip tests that now fail instead of timing out.
+        * platform/mac/TestExpectations: Skip tests that now fail instead of timing out.
+        * platform/qt/TestExpectations: Skip tests that now fail instead of timing out.
+        * platform/win/TestExpectations: Skip tests that now fail instead of timing out.
+
 2013-01-03  Jon Lee  <jonlee@apple.com>
 
         REGRESSION(r138729): crash and assertion failures in WebKit::WebProcess::plugInDidReceiveUserInteraction
index 59736b5554017e17d483373076a8d759c941a960..b69d01e92a056a1269610cf6e7956b8ada91f448 100644 (file)
@@ -55,6 +55,7 @@
 
         trackElement = document.createElement('track');
         video.appendChild(trackElement);
+        trackElement.track.mode = "hidden";
         trackElement.addEventListener('load', test);
         trackElement.src='data:text/vtt,WEBVTT FILE \r\r1\r00:00:00.000 --> 00:00:30.500\ronly one caption';
 
index 69d8578038a8c2191ab4134c2628d04626e84368..f9d7f025d7bb165e83acdbf29302acafbeaa2d22 100644 (file)
@@ -79,6 +79,7 @@
             function start()
             {
                 trackElement = document.querySelectorAll('track')[0];
+                trackElement.track.mode = "hidden";
                 log('Loading <b>without</b> Access-Control-Allow-Origin header, no "crossorigin" attribute on &lt;video&gt;');
                 var url = "http://localhost:8000/security/resources/captions-with-access-control-headers.php"
                 trackElement.setAttribute('src', url);
index a2b8ab55b285383cbd784fa6edf90ad6ba01029a..fdb351d684f2e07819cc467f2a34453548afac28 100644 (file)
@@ -4,8 +4,9 @@ Tests that the 'addtrack' event is fired when a TextTrack is created.
 RUN(trackElement = document.createElement('track'))
 RUN(video.appendChild(trackElement))
 RUN(trackElement.src = 'captions-webvtt/tc004-webvtt-file.vtt')
+RUN(trackElement.track.mode = 'hidden')
 EXPECTED (video.textTracks.length == '1') OK
-EXPECTED (trackElement.readyState == '1') OK
+EXPECTED (trackElement.readyState == '0') OK
 EVENT(addtrack)
 EXPECTED (event.target == '[object TextTrackList]') OK
 EXPECTED (event instanceof window.TrackEvent == 'true') OK
index e118c59ee1643ac47eca75a418c77e2fd4ea36b9..a01cc3c9ab2234638adc7a245590191845c531ad 100644 (file)
@@ -41,8 +41,9 @@
                 video.textTracks.addEventListener("addtrack", trackAdded);
 
                 run("trackElement.src = 'captions-webvtt/tc004-webvtt-file.vtt'");
+                run("trackElement.track.mode = 'hidden'");
                 testExpected("video.textTracks.length", 1);
-                testExpected("trackElement.readyState", HTMLTrackElement.LOADING);
+                testExpected("trackElement.readyState", HTMLTrackElement.NONE);
             }
 
         </script>
diff --git a/LayoutTests/media/track/track-element-load-event-expected.txt b/LayoutTests/media/track/track-element-load-event-expected.txt
new file mode 100644 (file)
index 0000000..cb2b796
--- /dev/null
@@ -0,0 +1,8 @@
+PASS Load event on the track element, src / mode / append 
+PASS Load event on the track element, src / append / mode 
+PASS Load event on the track element, mode / append / src 
+PASS Load event on the track element, mode / src / append 
+PASS Load event on the track element, append / src / mode 
+PASS Load event on the track element, append / mode / src 
+
diff --git a/LayoutTests/media/track/track-element-load-event.html b/LayoutTests/media/track/track-element-load-event.html
new file mode 100644 (file)
index 0000000..c4ed102
--- /dev/null
@@ -0,0 +1,73 @@
+<!doctype html>
+<html>
+    <head>
+        <title>Load event on the track element</title>
+        <script src="../../resources/testharness.js"></script>
+        <script src="../../resources/testharnessreport.js"></script>
+    </head>
+    <body>
+        <div id="log"></div>
+        <script type="text/javascript">
+
+            var video;
+
+            // Setup
+
+            setup(function(){
+                video = document.createElement('video');
+                document.body.appendChild(video);
+            }, {timeout: 5000});
+
+            // Tests
+            testCommands(["src", "mode", "append"]);
+            testCommands(["src", "append", "mode"]);
+            testCommands(["mode", "append", "src"]);
+            testCommands(["mode", "src", "append"]);
+            testCommands(["append", "src", "mode"]);
+            testCommands(["append", "mode", "src"]);
+
+            // Utilities
+
+            function testCommands(commands)
+            {
+                var t = async_test(document.title + ", " + commands.join(" / "));
+                t.step(function()
+                {
+                    var count = 0;
+                    // Create the default <track> element.
+                    var track = document.createElement('track');
+                    track.kind = "subtitles";
+                    // Add the "load" event listener.
+                    track.addEventListener("load", t.step_func(function(event)
+                    {
+                        // Clean up for next test.
+                        video.removeChild(track);
+
+                        // Ensure we only got the event after all commands ran.
+                        if (count === commands.length)
+                            t.done();
+                    }));
+                    // Run each command.
+                    commands.forEach(function(command)
+                    {
+                        count++;
+                        runCommand(track, command);
+                    });
+                });
+            };
+
+            function runCommand(track, command)
+            {
+                if (command === "src")
+                    track.src = "data:text/vtt," + encodeURIComponent("WEBVTT\n\n00:00:00.000 --> 00:00:01.000\ntest\n");
+
+                if (command === "mode")
+                    track.track.mode = 'hidden';
+
+                if (command === "append")
+                    video.appendChild(track);
+            };
+
+        </script>
+    </body>
+</html>
index e2d90866a05993d3f7f8d9498bc83f06d404d7b3..cfe0ac05f36ae1e79d4b7351ca00ab8dc775e3d6 100644 (file)
@@ -24,7 +24,7 @@
             testExpected("track.readyState", HTMLTrackElement.NONE);
             track.addEventListener("load", function () { trackLoaded(); }, true);
             track.src = "captions-webvtt/tc004-webvtt-file.vtt";   
-            track.mode = "hidden";
+            track.track.mode = "hidden";
 
         </script>
     </body>
index d4b8958f28efead7e0ab535f95dddea963455065..28b29bfff1c81f2e60e87bc9c19812995247115e 100644 (file)
@@ -3017,6 +3017,12 @@ webkit.org/b/103926 media/track/opera/track/webvtt/parsing-cue-data/tests/tree-b
 webkit.org/b/103926 media/track/opera/track/webvtt/rendering/adhoc/cue_font_size_transition.html [ Skip ]
 webkit.org/b/103926 media/track/opera/track/webvtt/rendering/adhoc/voice_with_evil_timestamp.html [ Skip ]
 
+# After fixing webkit.org/b/103258, these tests fail when they used to simply timeout.
+# At any rate, there is no regression, just a different type of failure.
+webkit.org/b/105536 media/track/opera/interfaces/TextTrack/addCue.html [ Failure ]
+webkit.org/b/105536 media/track/opera/interfaces/TextTrackCue/endTime.html [ Failure ]
+webkit.org/b/105536 media/track/opera/interfaces/TextTrackCue/startTime.html [ Failure ]
+
 webkit.org/b/72271 [ SnowLeopard Debug ] fast/dom/node-iterator-reference-node-moved-crash.html [ Crash Pass ]
 
 webkit.org/b/72376 [ Win ] fast/forms/file/input-file-label.html [ Failure Pass ]
index f971916587dd8239009f829943451b71ef0aa3ef..a86728b2fb8311d056b15c1a0eafc11245caf63b 100644 (file)
@@ -796,6 +796,12 @@ webkit.org/b/103926 media/track/opera/track/webvtt/parsing-cue-data/tests/tree-b
 webkit.org/b/103926 media/track/opera/track/webvtt/rendering/adhoc/cue_font_size_transition.html [ Skip ]
 webkit.org/b/103926 media/track/opera/track/webvtt/rendering/adhoc/voice_with_evil_timestamp.html [ Skip ]
 
+# After fixing webkit.org/b/103258, these tests fail when they used to simply timeout.
+# At any rate, there is no regression, just a different type of failure.
+webkit.org/b/105536 media/track/opera/interfaces/TextTrack/addCue.html [ Failure ]
+webkit.org/b/105536 media/track/opera/interfaces/TextTrackCue/endTime.html [ Failure ]
+webkit.org/b/105536 media/track/opera/interfaces/TextTrackCue/startTime.html [ Failure ]
+
 webkit.org/b/100636 [ Debug ] jquery/traversing.html [ Failure Crash Pass ]
 
 webkit.org/b/102928 svg/foreignObject/viewport-foreignobject-crash.html [ Crash Failure Pass ]
index 4f427b0899b41f9c5a2c9d64e3051063170ad862..0d00c284cac51b7ecd20cec6bc80b7e034ab8caa 100644 (file)
@@ -458,6 +458,12 @@ webkit.org/b/103926 media/track/opera/track/webvtt/parsing-cue-data/tests/tree-b
 webkit.org/b/103926 media/track/opera/track/webvtt/rendering/adhoc/cue_font_size_transition.html [ Skip ]
 webkit.org/b/103926 media/track/opera/track/webvtt/rendering/adhoc/voice_with_evil_timestamp.html [ Skip ]
 
+# After fixing webkit.org/b/103258, these tests fail when they used to simply timeout.
+# At any rate, there is no regression, just a different type of failure.
+webkit.org/b/105536 media/track/opera/interfaces/TextTrack/addCue.html [ Failure ]
+webkit.org/b/105536 media/track/opera/interfaces/TextTrackCue/endTime.html [ Failure ]
+webkit.org/b/105536 media/track/opera/interfaces/TextTrackCue/startTime.html [ Failure ]
+
 # No support for exposing in-band text tracks
 webkit.org/b/103771 media/track/track-in-band.html [ Failure ]
 webkit.org/b/103771 media/track/track-in-band-cues-added-once.html [ Timeout ]
index 7676a66e419fb9a5fbce44deaf04aba99c6f3e4f..59a50c28d161f4110c5e5caf124cd1b3b4d28a2c 100644 (file)
@@ -471,7 +471,6 @@ media/track/track-cue-rendering-snap-to-lines-not-set.html
 media/track/track-cue-rendering-vertical.html
 media/track/track-webvtt-tc028-unsupported-markup.html
 
-# Opera-submitted tests to W3C for <track>, a lot of failures still.
 # Opera-submitted tests to W3C for <track>, a lot of failures still.
 webkit.org/b/103926 media/track/opera/idl/media-idl-tests.html [ Skip ]
 webkit.org/b/103926 media/track/opera/interfaces/HTMLElement/HTMLMediaElement/crossOrigin.html [ Skip ]
@@ -506,6 +505,12 @@ webkit.org/b/103926 media/track/opera/track/webvtt/parsing-cue-data/tests/tree-b
 webkit.org/b/103926 media/track/opera/track/webvtt/rendering/adhoc/cue_font_size_transition.html [ Skip ]
 webkit.org/b/103926 media/track/opera/track/webvtt/rendering/adhoc/voice_with_evil_timestamp.html [ Skip ]
 
+# After fixing webkit.org/b/103258, these tests fail when they used to simply timeout.
+# At any rate, there is no regression, just a different type of failure.
+webkit.org/b/105536 media/track/opera/interfaces/TextTrack/addCue.html [ Failure ]
+webkit.org/b/105536 media/track/opera/interfaces/TextTrackCue/endTime.html [ Failure ]
+webkit.org/b/105536 media/track/opera/interfaces/TextTrackCue/startTime.html [ Failure ]
+
 # Tests for MediaSource API. Feature is not yet functional.
 # https://bugs.webkit.org/show_bug.cgi?id=64731
 http/tests/media/media-source/
index 7ae130454abb9e989627d41d3758d1708dd888dc..5b6ed0c8485dc239b0025a466c8f5e2e1dedae60 100644 (file)
@@ -927,6 +927,12 @@ webkit.org/b/103926 media/track/opera/track/webvtt/parsing-cue-data/tests/tree-b
 webkit.org/b/103926 media/track/opera/track/webvtt/rendering/adhoc/cue_font_size_transition.html [ Skip ]
 webkit.org/b/103926 media/track/opera/track/webvtt/rendering/adhoc/voice_with_evil_timestamp.html [ Skip ]
 
+# After fixing webkit.org/b/103258, these tests fail when they used to simply timeout.
+# At any rate, there is no regression, just a different type of failure.
+webkit.org/b/105536 media/track/opera/interfaces/TextTrack/addCue.html [ Failure ]
+webkit.org/b/105536 media/track/opera/interfaces/TextTrackCue/endTime.html [ Failure ]
+webkit.org/b/105536 media/track/opera/interfaces/TextTrackCue/startTime.html [ Failure ]
+
 # https://bugs.webkit.org/show_bug.cgi?id=38376
 media/media-document-audio-size.html
 
index cef8b9fdc9402c41fb4403c2993bebc6ba34cb13..b30d3373815713ac5925bae2a9e1934f46097249 100644 (file)
@@ -1586,6 +1586,12 @@ webkit.org/b/103926 media/track/opera/track/webvtt/parsing-cue-data/tests/tree-b
 webkit.org/b/103926 media/track/opera/track/webvtt/rendering/adhoc/cue_font_size_transition.html [ Skip ]
 webkit.org/b/103926 media/track/opera/track/webvtt/rendering/adhoc/voice_with_evil_timestamp.html [ Skip ]
 
+# After fixing webkit.org/b/103258, these tests fail when they used to simply timeout.
+# At any rate, there is no regression, just a different type of failure.
+webkit.org/b/105536 media/track/opera/interfaces/TextTrack/addCue.html [ Failure ]
+webkit.org/b/105536 media/track/opera/interfaces/TextTrackCue/endTime.html [ Failure ]
+webkit.org/b/105536 media/track/opera/interfaces/TextTrackCue/startTime.html [ Failure ]
+
 # Tests for MediaSource API. Feature is not yet functional.
 # https://bugs.webkit.org/show_bug.cgi?id=64731
 http/tests/media/media-source/
index b67cf6e044526d1a8d3c9262430cbabb354463e8..fe35b2e95ea0acc5a9a5ec1a21d16a0f7312a01b 100644 (file)
@@ -1,3 +1,46 @@
+2013-01-03  Antoine Quint  <graouts@apple.com>
+
+        onload callback for <track> element attached to <video> does not fire
+        https://bugs.webkit.org/show_bug.cgi?id=103258
+
+        Reviewed by Eric Carlson.
+
+        We now correctly implement the track processing model per the latest spec at
+        http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#start-the-track-processing-model.
+        
+        For a <track> to load, three conditions must be met:
+        
+        1. it must have a non-empty src
+        2. it must have a mode other than "disabled" (the default)
+        3. it must have a parent media element
+        
+        We used to only check if we were able to load upon setting the track's src,
+        whereas a change of any of those conditions should have done this, which this
+        patch now correctly implements.
+        
+        We also correctly implement the load model asynchronously after step 4, per
+        the spec, hence the split of the code previously entirely contained in
+        HTMLTrackElement::scheduleLoad() in another method fired on a timer.
+
+        Test: media/track/track-element-load-event.html
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::textTrackModeChanged):
+        * html/HTMLTrackElement.cpp:
+        (WebCore::HTMLTrackElement::HTMLTrackElement):
+        (WebCore::HTMLTrackElement::insertedInto):
+        (WebCore::HTMLTrackElement::parseAttribute):
+        (WebCore::HTMLTrackElement::scheduleLoad):
+        (WebCore):
+        (WebCore::HTMLTrackElement::loadTimerFired):
+        (WebCore::HTMLTrackElement::textTrackModeChanged):
+        * html/HTMLTrackElement.h:
+        * html/track/TextTrack.cpp:
+        (WebCore::TextTrack::removeAllCues):
+        (WebCore):
+        * html/track/TextTrack.h:
+        (TextTrack):
+
 2013-01-03  Beth Dakin  <bdakin@apple.com>
 
         https://bugs.webkit.org/show_bug.cgi?id=105475
index 8fb087bce373f9c476e9c6ae857ed11d00cc5e50..1ea3be44ea30d7c0e23282854948a90577390034 100644 (file)
@@ -1351,8 +1351,6 @@ void HTMLMediaElement::textTrackModeChanged(TextTrack* track)
             if (track->mode() != TextTrack::disabledKeyword()) {
                 if (trackElement->readyState() == HTMLTrackElement::LOADED)
                     textTrackAddCues(track, track->cues());
-                else if (trackElement->readyState() == HTMLTrackElement::NONE)
-                    trackElement->scheduleLoad();
 
                 // If this is the first added track, create the list of text tracks.
                 if (!m_textTracks)
index cd99dc45fe43103dc82102c50569d18fcff817bf..89e7152e9b481b986d6dbe19df8ececf325b5a84 100644 (file)
@@ -56,6 +56,7 @@ static String urlForLoggingTrack(const KURL& url)
     
 inline HTMLTrackElement::HTMLTrackElement(const QualifiedName& tagName, Document* document)
     : HTMLElement(tagName, document)
+    , m_loadTimer(this, &HTMLTrackElement::loadTimerFired)
 {
     LOG(Media, "HTMLTrackElement::HTMLTrackElement - %p", this);
     ASSERT(hasTagName(trackTag));
@@ -74,6 +75,9 @@ PassRefPtr<HTMLTrackElement> HTMLTrackElement::create(const QualifiedName& tagNa
 
 Node::InsertionNotificationRequest HTMLTrackElement::insertedInto(ContainerNode* insertionPoint)
 {
+    // Since we've moved to a new parent, we may now be able to load.
+    scheduleLoad();
+
     HTMLElement::insertedInto(insertionPoint);
     HTMLMediaElement* parent = mediaElement();
     if (insertionPoint == parent)
@@ -92,10 +96,13 @@ void HTMLTrackElement::parseAttribute(const QualifiedName& name, const AtomicStr
 {
     if (RuntimeEnabledFeatures::webkitVideoTrackEnabled()) {
         if (name == srcAttr) {
-            if (!value.isEmpty() && mediaElement())
+            if (!value.isEmpty())
                 scheduleLoad();
-            // 4.8.10.12.3 Sourcing out-of-band text tracks
-            // As the kind, label, and srclang attributes are set, changed, or removed, the text track must update accordingly...
+            else if (m_track)
+                m_track->removeAllCues();
+
+        // 4.8.10.12.3 Sourcing out-of-band text tracks
+        // As the kind, label, and srclang attributes are set, changed, or removed, the text track must update accordingly...
         } else if (name == kindAttr)
             track()->setKind(value.lower());
         else if (name == labelAttr)
@@ -188,21 +195,39 @@ bool HTMLTrackElement::isURLAttribute(const Attribute& attribute) const
 
 void HTMLTrackElement::scheduleLoad()
 {
+    // 1. If another occurrence of this algorithm is already running for this text track and its track element,
+    // abort these steps, letting that other algorithm take care of this element.
+    if (m_loadTimer.isActive())
+        return;
+
     if (!RuntimeEnabledFeatures::webkitVideoTrackEnabled())
         return;
 
+    // 2. If the text track's text track mode is not set to one of hidden or showing, abort these steps.
+    if (ensureTrack()->mode() != TextTrack::hiddenKeyword() && ensureTrack()->mode() != TextTrack::showingKeyword())
+        return;
+
+    // 3. If the text track's track element does not have a media element as a parent, abort these steps.
     if (!mediaElement())
         return;
 
+    // 4. Run the remainder of these steps asynchronously, allowing whatever caused these steps to run to continue.
+    m_loadTimer.startOneShot(0);
+}
+
+void HTMLTrackElement::loadTimerFired(Timer<HTMLTrackElement>*)
+{
     if (!fastHasAttribute(srcAttr))
         return;
 
-    // 4.8.10.12.3 Sourcing out-of-band text tracks
-
-    // 1. Set the text track readiness state to loading.
+    // 6. Set the text track readiness state to loading.
     setReadyState(HTMLTrackElement::LOADING);
 
+    // 7. Let URL be the track URL of the track element.
     KURL url = getNonEmptyURLAttribute(srcAttr);
+
+    // 8. If the track element's parent is a media element then let CORS mode be the state of the parent media
+    // element's crossorigin content attribute. Otherwise, let CORS mode be No CORS.
     if (!canLoadUrl(url)) {
         didCompleteLoad(ensureTrack(), HTMLTrackElement::Failure);
         return;
@@ -302,6 +327,10 @@ void HTMLTrackElement::textTrackKindChanged(TextTrack* track)
 
 void HTMLTrackElement::textTrackModeChanged(TextTrack* track)
 {
+    // Since we've moved to a new parent, we may now be able to load.
+    if (readyState() == HTMLTrackElement::NONE)
+        scheduleLoad();
+
     if (HTMLMediaElement* parent = mediaElement())
         return parent->textTrackModeChanged(track);
 }
index 1b659ff52719ff195af37ec5387cd4506789e1fd..4b45adfeb0c0d48fff05ac59e43ee35f3e709668 100644 (file)
@@ -79,6 +79,8 @@ private:
     virtual void removedFrom(ContainerNode*) OVERRIDE;
     virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
 
+    void loadTimerFired(Timer<HTMLTrackElement>*);
+
 #if ENABLE(MICRODATA)
     virtual String itemValueText() const OVERRIDE;
     virtual void setItemValueText(const String&, ExceptionCode&) OVERRIDE;
@@ -98,6 +100,7 @@ private:
     virtual bool canLoadUrl(const KURL&);
 
     RefPtr<LoadableTextTrack> m_track;
+    Timer<HTMLTrackElement> m_loadTimer;
 };
 
 }
index f608563078dd32c169f07229ec5ab56812972c74..5db4924756860c941c57c8926d42103bc720cd11 100644 (file)
@@ -201,6 +201,20 @@ TextTrackCueList* TextTrack::cues()
     return 0;
 }
 
+void TextTrack::removeAllCues()
+{
+    if (!m_cues)
+        return;
+
+    if (m_client)
+        m_client->textTrackRemoveCues(this, m_cues.get());
+    
+    for (size_t i = 0; i < m_cues->length(); ++i)
+        m_cues->item(i)->setTrack(0);
+    
+    m_cues = 0;
+}
+
 TextTrackCueList* TextTrack::activeCues() const
 {
     // 4.8.10.12.5 If the text track mode ... is not the text track disabled mode,
index 63503da50b2ed1853c58c6a5328be59b760e1371..8893aed2782099e91db7b752ac4ee64911aef15d 100644 (file)
@@ -123,6 +123,8 @@ public:
     virtual bool isDefault() const { return false; }
     virtual void setIsDefault(bool) { }
 
+    void removeAllCues();
+
 protected:
     TextTrack(ScriptExecutionContext*, TextTrackClient*, const AtomicString& kind, const AtomicString& label, const AtomicString& language, TextTrackType);