Title: [138766] trunk
Revision
138766
Author
rn...@webkit.org
Date
2013-01-03 16:33:32 -0800 (Thu, 03 Jan 2013)

Log Message

onload callback for <track> element attached to <video> does not fire
https://bugs.webkit.org/show_bug.cgi?id=103258

Patch by Antoine Quint <grao...@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.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (138765 => 138766)


--- trunk/LayoutTests/ChangeLog	2013-01-04 00:32:02 UTC (rev 138765)
+++ trunk/LayoutTests/ChangeLog	2013-01-04 00:33:32 UTC (rev 138766)
@@ -1,3 +1,36 @@
+2013-01-03  Antoine Quint  <grao...@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  <jon...@apple.com>
 
         REGRESSION(r138729): crash and assertion failures in WebKit::WebProcess::plugInDidReceiveUserInteraction

Modified: trunk/LayoutTests/fast/events/constructors/track-event-constructor.html (138765 => 138766)


--- trunk/LayoutTests/fast/events/constructors/track-event-constructor.html	2013-01-04 00:32:02 UTC (rev 138765)
+++ trunk/LayoutTests/fast/events/constructors/track-event-constructor.html	2013-01-04 00:33:32 UTC (rev 138766)
@@ -55,6 +55,7 @@
 
         trackElement = document.createElement('track');
         video.appendChild(trackElement);
+        trackElement.track.mode = "hidden";
         trackElement.addEventListener('load', test);
         trackElement.src='';
 

Modified: trunk/LayoutTests/http/tests/security/text-track-crossorigin.html (138765 => 138766)


--- trunk/LayoutTests/http/tests/security/text-track-crossorigin.html	2013-01-04 00:32:02 UTC (rev 138765)
+++ trunk/LayoutTests/http/tests/security/text-track-crossorigin.html	2013-01-04 00:33:32 UTC (rev 138766)
@@ -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 = ""
                 trackElement.setAttribute('src', url);

Modified: trunk/LayoutTests/media/track/track-add-track-expected.txt (138765 => 138766)


--- trunk/LayoutTests/media/track/track-add-track-expected.txt	2013-01-04 00:32:02 UTC (rev 138765)
+++ trunk/LayoutTests/media/track/track-add-track-expected.txt	2013-01-04 00:33:32 UTC (rev 138766)
@@ -4,8 +4,9 @@
 RUN(trackElement = document.createElement('track'))
 RUN(video.appendChild(trackElement))
 RUN(trackElement.src = '')
+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

Modified: trunk/LayoutTests/media/track/track-add-track.html (138765 => 138766)


--- trunk/LayoutTests/media/track/track-add-track.html	2013-01-04 00:32:02 UTC (rev 138765)
+++ trunk/LayoutTests/media/track/track-add-track.html	2013-01-04 00:33:32 UTC (rev 138766)
@@ -41,8 +41,9 @@
                 video.textTracks.addEventListener("addtrack", trackAdded);
 
                 run("trackElement.src = ''");
+                run("trackElement.track.mode = 'hidden'");
                 testExpected("video.textTracks.length", 1);
-                testExpected("trackElement.readyState", HTMLTrackElement.LOADING);
+                testExpected("trackElement.readyState", HTMLTrackElement.NONE);
             }
 
         </script>

Added: trunk/LayoutTests/media/track/track-element-load-event-expected.txt (0 => 138766)


--- trunk/LayoutTests/media/track/track-element-load-event-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/media/track/track-element-load-event-expected.txt	2013-01-04 00:33:32 UTC (rev 138766)
@@ -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 
+

Added: trunk/LayoutTests/media/track/track-element-load-event.html (0 => 138766)


--- trunk/LayoutTests/media/track/track-element-load-event.html	                        (rev 0)
+++ trunk/LayoutTests/media/track/track-element-load-event.html	2013-01-04 00:33:32 UTC (rev 138766)
@@ -0,0 +1,73 @@
+<!doctype html>
+<html>
+    <head>
+        <title>Load event on the track element</title>
+        <script src=""
+        <script src=""
+    </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 = "" + 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>

Modified: trunk/LayoutTests/media/track/track-load-from-src-readyState.html (138765 => 138766)


--- trunk/LayoutTests/media/track/track-load-from-src-readyState.html	2013-01-04 00:32:02 UTC (rev 138765)
+++ trunk/LayoutTests/media/track/track-load-from-src-readyState.html	2013-01-04 00:33:32 UTC (rev 138766)
@@ -24,7 +24,7 @@
             testExpected("track.readyState", HTMLTrackElement.NONE);
             track.addEventListener("load", function () { trackLoaded(); }, true);
             track.src = ""   
-            track.mode = "hidden";
+            track.track.mode = "hidden";
 
         </script>
     </body>

Modified: trunk/LayoutTests/platform/chromium/TestExpectations (138765 => 138766)


--- trunk/LayoutTests/platform/chromium/TestExpectations	2013-01-04 00:32:02 UTC (rev 138765)
+++ trunk/LayoutTests/platform/chromium/TestExpectations	2013-01-04 00:33:32 UTC (rev 138766)
@@ -3017,6 +3017,12 @@
 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 ]

Modified: trunk/LayoutTests/platform/efl/TestExpectations (138765 => 138766)


--- trunk/LayoutTests/platform/efl/TestExpectations	2013-01-04 00:32:02 UTC (rev 138765)
+++ trunk/LayoutTests/platform/efl/TestExpectations	2013-01-04 00:33:32 UTC (rev 138766)
@@ -796,6 +796,12 @@
 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 ]

Modified: trunk/LayoutTests/platform/gtk/TestExpectations (138765 => 138766)


--- trunk/LayoutTests/platform/gtk/TestExpectations	2013-01-04 00:32:02 UTC (rev 138765)
+++ trunk/LayoutTests/platform/gtk/TestExpectations	2013-01-04 00:33:32 UTC (rev 138766)
@@ -458,6 +458,12 @@
 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 ]

Modified: trunk/LayoutTests/platform/mac/TestExpectations (138765 => 138766)


--- trunk/LayoutTests/platform/mac/TestExpectations	2013-01-04 00:32:02 UTC (rev 138765)
+++ trunk/LayoutTests/platform/mac/TestExpectations	2013-01-04 00:33:32 UTC (rev 138766)
@@ -472,7 +472,6 @@
 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 ]
 webkit.org/b/103926 media/track/opera/interfaces/HTMLElement/HTMLTrackElement/kind.html [ Skip ]
@@ -506,6 +505,12 @@
 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/

Modified: trunk/LayoutTests/platform/qt/TestExpectations (138765 => 138766)


--- trunk/LayoutTests/platform/qt/TestExpectations	2013-01-04 00:32:02 UTC (rev 138765)
+++ trunk/LayoutTests/platform/qt/TestExpectations	2013-01-04 00:33:32 UTC (rev 138766)
@@ -927,6 +927,12 @@
 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
 

Modified: trunk/LayoutTests/platform/win/TestExpectations (138765 => 138766)


--- trunk/LayoutTests/platform/win/TestExpectations	2013-01-04 00:32:02 UTC (rev 138765)
+++ trunk/LayoutTests/platform/win/TestExpectations	2013-01-04 00:33:32 UTC (rev 138766)
@@ -1586,6 +1586,12 @@
 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/

Modified: trunk/Source/WebCore/ChangeLog (138765 => 138766)


--- trunk/Source/WebCore/ChangeLog	2013-01-04 00:32:02 UTC (rev 138765)
+++ trunk/Source/WebCore/ChangeLog	2013-01-04 00:33:32 UTC (rev 138766)
@@ -1,3 +1,46 @@
+2013-01-03  Antoine Quint  <grao...@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  <bda...@apple.com>
 
         https://bugs.webkit.org/show_bug.cgi?id=105475

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (138765 => 138766)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2013-01-04 00:32:02 UTC (rev 138765)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2013-01-04 00:33:32 UTC (rev 138766)
@@ -1351,8 +1351,6 @@
             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)

Modified: trunk/Source/WebCore/html/HTMLTrackElement.cpp (138765 => 138766)


--- trunk/Source/WebCore/html/HTMLTrackElement.cpp	2013-01-04 00:32:02 UTC (rev 138765)
+++ trunk/Source/WebCore/html/HTMLTrackElement.cpp	2013-01-04 00:33:32 UTC (rev 138766)
@@ -56,6 +56,7 @@
     
 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 @@
 
 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 @@
 {
     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 @@
 
 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 = ""
+
+    // 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::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);
 }

Modified: trunk/Source/WebCore/html/HTMLTrackElement.h (138765 => 138766)


--- trunk/Source/WebCore/html/HTMLTrackElement.h	2013-01-04 00:32:02 UTC (rev 138765)
+++ trunk/Source/WebCore/html/HTMLTrackElement.h	2013-01-04 00:33:32 UTC (rev 138766)
@@ -79,6 +79,8 @@
     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 @@
     virtual bool canLoadUrl(const KURL&);
 
     RefPtr<LoadableTextTrack> m_track;
+    Timer<HTMLTrackElement> m_loadTimer;
 };
 
 }

Modified: trunk/Source/WebCore/html/track/TextTrack.cpp (138765 => 138766)


--- trunk/Source/WebCore/html/track/TextTrack.cpp	2013-01-04 00:32:02 UTC (rev 138765)
+++ trunk/Source/WebCore/html/track/TextTrack.cpp	2013-01-04 00:33:32 UTC (rev 138766)
@@ -201,6 +201,20 @@
     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,

Modified: trunk/Source/WebCore/html/track/TextTrack.h (138765 => 138766)


--- trunk/Source/WebCore/html/track/TextTrack.h	2013-01-04 00:32:02 UTC (rev 138765)
+++ trunk/Source/WebCore/html/track/TextTrack.h	2013-01-04 00:33:32 UTC (rev 138766)
@@ -123,6 +123,8 @@
     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);
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to