JSC wrappers for TextTrack and TextTrackCue should not be collected during event...
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Dec 2011 21:32:02 +0000 (21:32 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Dec 2011 21:32:02 +0000 (21:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=72179

Reviewed by Geoff Garen.

Source/WebCore:

Tests: media/track/text-track-cue-is-reachable.html
       media/track/text-track-is-reachable.html

* GNUmakefile.list.am: Add JSTextTrackCueCustom.cpp and JSTextTrackCustom.cpp.
* Target.pri: Ditto.
* WebCore.gypi: Ditto.
* WebCore.xcodeproj/project.pbxproj: Ditto
* bindings/js/JSBindingsAllInOne.cpp: Ditto.

* bindings/js/JSTextTrackCueCustom.cpp: Added.
(WebCore::JSTextTrackCueOwner::isReachableFromOpaqueRoots): New.
(WebCore::JSTextTrackCueOwner::visitChildren): New.

* bindings/js/JSTextTrackCustom.cpp: Added.
(WebCore::JSTextTrackOwner::isReachableFromOpaqueRoots): New.
(WebCore::JSTextTrack::visitChildren): New, mark all cues.
* bindings/js/JSTextTrackCustom.h: Added.
(WebCore::root): New.

* bindings/js/JSTextTrackListCustom.cpp:
(WebCore::JSTextTrackList::visitChildren): New, mark all tracks.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::trackWillBeRemoved): TextTracks::remove now takes a TextTrack*.

* html/LoadableTextTrack.h:
(WebCore::LoadableTextTrack::trackElement): New, return the <track>.

* html/TextTrack.cpp:
(WebCore::TextTrack::TextTrack): Initialize m_mediaElement.
* html/TextTrack.h:
(WebCore::TextTrack::setMediaElement): New.
(WebCore::TextTrack::mediaElement): Ditto.

* html/TextTrack.idl: Add CustomIsReachable and CustomMarkFunction.

* html/TextTrackCue.idl: Add CustomIsReachable.

* html/track/TextTrackList.cpp:
(TextTrackList::append): Set track's media element.
(TextTrackList::remove): Clear track's media element. Take a raw ptr, not a PassRefPtr.
* html/track/TextTrackList.h:
* html/track/TextTrackList.idl: Add CustomMarkFunction

LayoutTests:

* media/track/text-track-cue-is-reachable-expected.txt: Added.
* media/track/text-track-cue-is-reachable.html: Added.
* media/track/text-track-is-reachable-expected.txt: Added.
* media/track/text-track-is-reachable.html: Added.
* platform/chromium/test_expectations.txt:

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

25 files changed:
LayoutTests/ChangeLog
LayoutTests/media/track/text-track-cue-is-reachable-expected.txt [new file with mode: 0644]
LayoutTests/media/track/text-track-cue-is-reachable.html [new file with mode: 0644]
LayoutTests/media/track/text-track-is-reachable-expected.txt [new file with mode: 0644]
LayoutTests/media/track/text-track-is-reachable.html [new file with mode: 0644]
LayoutTests/platform/chromium/test_expectations.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Target.pri
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSBindingsAllInOne.cpp
Source/WebCore/bindings/js/JSTextTrackCueCustom.cpp [new file with mode: 0644]
Source/WebCore/bindings/js/JSTextTrackCustom.cpp [new file with mode: 0644]
Source/WebCore/bindings/js/JSTextTrackCustom.h [new file with mode: 0644]
Source/WebCore/bindings/js/JSTextTrackListCustom.cpp
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/LoadableTextTrack.h
Source/WebCore/html/TextTrack.cpp
Source/WebCore/html/TextTrack.h
Source/WebCore/html/TextTrack.idl
Source/WebCore/html/TextTrackCue.idl
Source/WebCore/html/track/TextTrackList.cpp
Source/WebCore/html/track/TextTrackList.h
Source/WebCore/html/track/TextTrackList.idl

index 862a8ab..b792277 100644 (file)
@@ -1,3 +1,16 @@
+2011-12-09  Eric Carlson  <eric.carlson@apple.com>
+
+        JSC wrappers for TextTrack and TextTrackCue should not be collected during event dispatch or when owner is reachable
+        https://bugs.webkit.org/show_bug.cgi?id=72179
+
+        Reviewed by Geoff Garen.
+
+        * media/track/text-track-cue-is-reachable-expected.txt: Added.
+        * media/track/text-track-cue-is-reachable.html: Added.
+        * media/track/text-track-is-reachable-expected.txt: Added.
+        * media/track/text-track-is-reachable.html: Added.
+        * platform/chromium/test_expectations.txt:
+
 2011-12-09  Chris Fleizach  <cfleizach@apple.com>
 
         WebKit should ignore images with @alt matching only whitespace
diff --git a/LayoutTests/media/track/text-track-cue-is-reachable-expected.txt b/LayoutTests/media/track/text-track-cue-is-reachable-expected.txt
new file mode 100644 (file)
index 0000000..dc5e1d4
--- /dev/null
@@ -0,0 +1,16 @@
+Ensure that a TextTrackCue won't be collected if it has a custom property.
+
+** Validate.
+EXPECTED (video.textTracks[0].cues.length == '4') OK
+EXPECTED (video.textTracks[0].cues[1].startTime == '31') OK
+
+** Add a custom property to a cue.
+RUN(video.textTracks[0].cues[1].myProperty = 'tuna salad?')
+EXPECTED (video.textTracks[0].cues[1].myProperty == 'tuna salad?') OK
+
+** Force garbage collection.
+EXPECTED (video.textTracks[0].cues.length == '4') OK
+EXPECTED (video.textTracks[0].cues[1].myProperty == 'tuna salad?') OK
+
+END OF TEST
+
diff --git a/LayoutTests/media/track/text-track-cue-is-reachable.html b/LayoutTests/media/track/text-track-cue-is-reachable.html
new file mode 100644 (file)
index 0000000..e6122b9
--- /dev/null
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+        <script src=../video-test.js></script>
+        <script>
+
+            function forceGC()
+            {
+                if (window.GCController)
+                    return GCController.collect();
+            
+                // Force garbage collection
+                for (var ndx = 0; ndx < 99000; ndx++)
+                    var str = new String("1234");
+            }
+
+            function trackLoaded()
+            {
+                findMediaElement();
+
+                consoleWrite("** Validate.");
+                testExpected("video.textTracks[0].cues.length", 4);
+                testExpected("video.textTracks[0].cues[1].startTime", 31);
+
+                consoleWrite("<br>** Add a custom property to a cue.");
+                run("video.textTracks[0].cues[1].myProperty = 'tuna salad?'");
+                testExpected("video.textTracks[0].cues[1].myProperty", "tuna salad?");
+
+                consoleWrite("<br>** Force garbage collection.");
+                forceGC();
+                testExpected("video.textTracks[0].cues.length", 4);
+                testExpected("video.textTracks[0].cues[1].myProperty", "tuna salad?");
+
+                consoleWrite("");
+                endTest();
+            }
+
+        </script>
+    </head>
+    <body>
+        <p>Ensure that a TextTrackCue won't be collected if it has a custom property.</p>
+        <video>
+            <track src="captions-webvtt/tc013-settings.vtt" kind="captions" onload="trackLoaded()" default>
+        </video>
+    </body>
+</html>
diff --git a/LayoutTests/media/track/text-track-is-reachable-expected.txt b/LayoutTests/media/track/text-track-is-reachable-expected.txt
new file mode 100644 (file)
index 0000000..b042921
--- /dev/null
@@ -0,0 +1,16 @@
+Ensure that a TextTrack won't be collected if it has a custom property.
+
+** Validate.
+EXPECTED (video.textTracks.length == '1') OK
+EXPECTED (video.textTracks[0].kind == 'captions') OK
+
+** Add a custom property to the track.
+RUN(video.textTracks[0].myProperty = 'egg salad!?')
+EXPECTED (video.textTracks[0].myProperty == 'egg salad!?') OK
+
+** Force garbage collection.
+EXPECTED (video.textTracks[0].cues.length == '4') OK
+EXPECTED (video.textTracks[0].myProperty == 'egg salad!?') OK
+
+END OF TEST
+
diff --git a/LayoutTests/media/track/text-track-is-reachable.html b/LayoutTests/media/track/text-track-is-reachable.html
new file mode 100644 (file)
index 0000000..4d8d7a0
--- /dev/null
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+        <script src=../media-file.js></script>
+        <script src=../video-test.js></script>
+        <script>
+
+            function forceGC()
+            {
+                if (window.GCController)
+                    return GCController.collect();
+            
+                // Force garbage collection
+                for (var ndx = 0; ndx < 99000; ndx++)
+                    var str = new String("1234");
+            }
+
+            function trackLoaded()
+            {
+                findMediaElement();
+
+                consoleWrite("** Validate.");
+                testExpected("video.textTracks.length", 1);
+                testExpected("video.textTracks[0].kind", "captions");
+
+                consoleWrite("<br>** Add a custom property to the track.");
+                run("video.textTracks[0].myProperty = 'egg salad!?'");
+                testExpected("video.textTracks[0].myProperty", "egg salad!?");
+
+                consoleWrite("<br>** Force garbage collection.");
+                forceGC();
+                testExpected("video.textTracks[0].cues.length", 4);
+                testExpected("video.textTracks[0].myProperty", "egg salad!?");
+
+                consoleWrite("");
+                endTest();
+            }
+
+        </script>
+    </head>
+    <body>
+        <p>Ensure that a TextTrack won't be collected if it has a custom property.</p>
+        <video>
+            <track src="captions-webvtt/tc013-settings.vtt" kind="captions" onload="trackLoaded()" default>
+        </video>
+    </body>
+</html>
index 41e431e..a0df3eb 100644 (file)
@@ -3676,7 +3676,9 @@ BUGWK66953 : transitions/default-timing-function.html = PASS FAIL
 BUG_TONY MAC : css3/flexbox/repaint.html = PASS FAIL
 BUG_TONY MAC : css3/flexbox/repaint-rtl-column.html = PASS FAIL
 
-BUGWK72149 : media/track/tracklist-is-reachable.html = TEXT
+BUGWK73865 : media/track/tracklist-is-reachable.html = TEXT
+BUGWK73865 : media/track/text-track-cue-is-reachable.html = TEXT
+BUGWK73865 : media/track/text-track-is-reachable.html = TEXT
 
 BUGWK72133 SKIP MAC : http/tests/inspector-enabled/dedicated-workers-list.html = PASS TIMEOUT
 
index bb407e6..b521ac2 100644 (file)
@@ -1,3 +1,54 @@
+2011-12-09  Eric Carlson  <eric.carlson@apple.com>
+
+        JSC wrappers for TextTrack and TextTrackCue should not be collected during event dispatch or when owner is reachable
+        https://bugs.webkit.org/show_bug.cgi?id=72179
+
+        Reviewed by Geoff Garen.
+
+        Tests: media/track/text-track-cue-is-reachable.html
+               media/track/text-track-is-reachable.html
+
+        * GNUmakefile.list.am: Add JSTextTrackCueCustom.cpp and JSTextTrackCustom.cpp.
+        * Target.pri: Ditto.
+        * WebCore.gypi: Ditto.
+        * WebCore.xcodeproj/project.pbxproj: Ditto
+        * bindings/js/JSBindingsAllInOne.cpp: Ditto.
+
+        * bindings/js/JSTextTrackCueCustom.cpp: Added.
+        (WebCore::JSTextTrackCueOwner::isReachableFromOpaqueRoots): New.
+        (WebCore::JSTextTrackCueOwner::visitChildren): New.
+
+        * bindings/js/JSTextTrackCustom.cpp: Added.
+        (WebCore::JSTextTrackOwner::isReachableFromOpaqueRoots): New.
+        (WebCore::JSTextTrack::visitChildren): New, mark all cues.
+        * bindings/js/JSTextTrackCustom.h: Added.
+        (WebCore::root): New.
+
+        * bindings/js/JSTextTrackListCustom.cpp:
+        (WebCore::JSTextTrackList::visitChildren): New, mark all tracks.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::trackWillBeRemoved): TextTracks::remove now takes a TextTrack*.
+
+        * html/LoadableTextTrack.h:
+        (WebCore::LoadableTextTrack::trackElement): New, return the <track>.
+
+        * html/TextTrack.cpp:
+        (WebCore::TextTrack::TextTrack): Initialize m_mediaElement.
+        * html/TextTrack.h:
+        (WebCore::TextTrack::setMediaElement): New.
+        (WebCore::TextTrack::mediaElement): Ditto.
+
+        * html/TextTrack.idl: Add CustomIsReachable and CustomMarkFunction.
+
+        * html/TextTrackCue.idl: Add CustomIsReachable.
+
+        * html/track/TextTrackList.cpp:
+        (TextTrackList::append): Set track's media element.
+        (TextTrackList::remove): Clear track's media element. Take a raw ptr, not a PassRefPtr.
+        * html/track/TextTrackList.h:
+        * html/track/TextTrackList.idl: Add CustomMarkFunction
+
 2011-12-09  Chris Fleizach  <cfleizach@apple.com>
 
         WebKit should ignore images with @alt matching only whitespace
index a486818..0973dbc 100644 (file)
@@ -853,6 +853,9 @@ webcore_sources += \
        Source/WebCore/bindings/js/JSStyleSheetCustom.cpp \
        Source/WebCore/bindings/js/JSStyleSheetListCustom.cpp \
        Source/WebCore/bindings/js/JSTextCustom.cpp \
+       Source/WebCore/bindings/js/JSTextTrackCueCustom.cpp \
+       Source/WebCore/bindings/js/JSTextTrackCustom.cpp \
+       Source/WebCore/bindings/js/JSTextTrackCustom.h \
        Source/WebCore/bindings/js/JSTextTrackListCustom.cpp \
        Source/WebCore/bindings/js/JSTouchCustom.cpp \
        Source/WebCore/bindings/js/JSTouchListCustom.cpp \
index fffcba9..221bb89 100644 (file)
@@ -3574,9 +3574,12 @@ contains(DEFINES, ENABLE_VIDEO_TRACK=1) {
             bindings/v8/custom/V8TrackEventCustom.cpp
     } else {
         SOURCES += \
+            bindings/js/JSTextTrackCueCustom.cpp \
+            bindings/js/JSTextTrackCustom.cpp \
+            bindings/js/JSTextTrackCustom.h \
             bindings/js/JSTrackCustom.cpp \
             bindings/js/JSTrackCustom.h \
-            bindings/js/JSTrackEventCustom.cpp
+            bindings/js/JSTrackEventCustom.cpp \
             bindings/js/JSTextTrackListCustom.cpp
     }
 }
index d1990a9..9bafa34 100644 (file)
             'bindings/js/JSStyleSheetCustom.cpp',
             'bindings/js/JSStyleSheetListCustom.cpp',
             'bindings/js/JSTextCustom.cpp',
+            'bindings/js/JSTextTrackCueCustom.cpp',
+            'bindings/js/JSTextTrackCustom.cpp',
+            'bindings/js/JSTextTrackCustom.h',
             'bindings/js/JSTextTrackListCustom.cpp',
             'bindings/js/JSTouchCustom.cpp',
             'bindings/js/JSTouchListCustom.cpp',
index 4731a85..d9356bf 100644 (file)
                07B5A2DC1464320A00A81ECE /* JSTextTrackList.h in Headers */ = {isa = PBXBuildFile; fileRef = 07B5A2DA1464320A00A81ECE /* JSTextTrackList.h */; };
                07B5A30D14687D7100A81ECE /* JSTextTrackListCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 07B5A30C14687D7100A81ECE /* JSTextTrackListCustom.cpp */; };
                07BDD6EC1469B4C2009C9F85 /* JSTrackEventCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 07B5A30A14687B8400A81ECE /* JSTrackEventCustom.cpp */; };
+               07E116B11489C9A100EC5ACE /* JSTextTrackCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 07E116B01489C9A100EC5ACE /* JSTextTrackCustom.cpp */; };
+               07E117071489EBEB00EC5ACE /* JSTextTrackCueCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 07E117061489EBEB00EC5ACE /* JSTextTrackCueCustom.cpp */; };
                0806E57A12893045007CED32 /* SVGMatrix.h in Headers */ = {isa = PBXBuildFile; fileRef = 0806E57912893045007CED32 /* SVGMatrix.h */; settings = {ATTRIBUTES = (Private, ); }; };
                080E49261255F3BD00EFCA27 /* SVGTextLayoutEngineBaseline.h in Headers */ = {isa = PBXBuildFile; fileRef = 080E49221255F3BD00EFCA27 /* SVGTextLayoutEngineBaseline.h */; };
                080E49281255F3BD00EFCA27 /* SVGTextLayoutEngineSpacing.h in Headers */ = {isa = PBXBuildFile; fileRef = 080E49241255F3BD00EFCA27 /* SVGTextLayoutEngineSpacing.h */; };
                07B5A3061468537100A81ECE /* TextTrackList.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = TextTrackList.idl; sourceTree = "<group>"; };
                07B5A30A14687B8400A81ECE /* JSTrackEventCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTrackEventCustom.cpp; sourceTree = "<group>"; };
                07B5A30C14687D7100A81ECE /* JSTextTrackListCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTextTrackListCustom.cpp; sourceTree = "<group>"; };
+               07E116B01489C9A100EC5ACE /* JSTextTrackCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTextTrackCustom.cpp; sourceTree = "<group>"; };
+               07E117061489EBEB00EC5ACE /* JSTextTrackCueCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTextTrackCueCustom.cpp; sourceTree = "<group>"; };
+               07E38A0B148FCF0C006E1ECC /* JSTextTrackCustom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSTextTrackCustom.h; sourceTree = "<group>"; };
                0806E57912893045007CED32 /* SVGMatrix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGMatrix.h; sourceTree = "<group>"; };
                080E49211255F3BD00EFCA27 /* SVGTextLayoutEngineBaseline.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGTextLayoutEngineBaseline.cpp; sourceTree = "<group>"; };
                080E49221255F3BD00EFCA27 /* SVGTextLayoutEngineBaseline.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGTextLayoutEngineBaseline.h; sourceTree = "<group>"; };
                BC4EDEF70C08F414007EDD49 /* Custom */ = {
                        isa = PBXGroup;
                        children = (
+                               07E38A0B148FCF0C006E1ECC /* JSTextTrackCustom.h */,
                                BC275CB211C5E85C00C9206C /* JSArrayBufferCustom.cpp */,
                                86243D0011BC31F700CC006A /* JSArrayBufferViewHelper.h */,
                                BC2ED6BB0C6BD2F000920BFF /* JSAttrCustom.cpp */,
                                08E4FE450E2BD41400F4CAE0 /* JSSVGLengthCustom.cpp */,
                                B2C96D8C0B3AF2B7005E80EC /* JSSVGPathSegCustom.cpp */,
                                1A2C40AA0DEB55AA005AF19E /* JSTextCustom.cpp */,
+                               07E116B01489C9A100EC5ACE /* JSTextTrackCustom.cpp */,
+                               07E117061489EBEB00EC5ACE /* JSTextTrackCueCustom.cpp */,
                                07B5A30C14687D7100A81ECE /* JSTextTrackListCustom.cpp */,
                                070334E8145A1F35008D8D45 /* JSTrackCustom.cpp */,
                                07846384145B1B8E00A58DF1 /* JSTrackCustom.h */,
                                7AA51DD5148506A900AD2752 /* InspectorMemoryAgent.cpp in Sources */,
                                5038BF2A14750F190095E0D1 /* FilterOperations.cpp in Sources */,
                                6E3FAD3814733F4000E42306 /* JSWebGLCompressedTextures.cpp in Sources */,
+                               07E116B11489C9A100EC5ACE /* JSTextTrackCustom.cpp in Sources */,
+                               07E117071489EBEB00EC5ACE /* JSTextTrackCueCustom.cpp in Sources */,
                                6E3FAE8E14733FDB00E42306 /* WebGLCompressedTextures.cpp in Sources */,
                                2655413A1489811C000DFC5D /* KeyEventIOS.mm in Sources */,
                                26F40D4A14904A6300CA67C4 /* EventLoopIOS.mm in Sources */,
index b337dc4..2f1eeb1 100644 (file)
 #include "JSStyleSheetCustom.cpp"
 #include "JSStyleSheetListCustom.cpp"
 #include "JSTextCustom.cpp"
+#include "JSTextTrackCueCustom.cpp"
+#include "JSTextTrackCustom.cpp"
 #include "JSTextTrackListCustom.cpp"
 #include "JSTouchCustom.cpp"
 #include "JSTouchListCustom.cpp"
diff --git a/Source/WebCore/bindings/js/JSTextTrackCueCustom.cpp b/Source/WebCore/bindings/js/JSTextTrackCueCustom.cpp
new file mode 100644 (file)
index 0000000..c6de15f
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+
+#if ENABLE(VIDEO_TRACK)
+
+#include "JSTextTrackCue.h"
+#include "JSTextTrackCustom.h"
+
+using namespace JSC;
+
+namespace WebCore {
+
+bool JSTextTrackCueOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
+{
+    JSTextTrackCue* jsTextTrackCue = static_cast<JSTextTrackCue*>(handle.get().asCell());
+    TextTrackCue* textTrackCue = static_cast<TextTrackCue*>(jsTextTrackCue->impl());
+
+    // If the cue is firing event listeners, its wrapper is reachable because
+    // the wrapper is responsible for marking those event listeners.
+    if (textTrackCue->isFiringEventListeners())
+        return true;
+
+    // If the cue has no event listeners and has no custom properties, it is not reachable.
+    if (!textTrackCue->hasEventListeners() && !jsTextTrackCue->hasCustomProperties())
+        return false;
+
+    // If the cue is not associated with a track, it is not reachable.
+    if (!textTrackCue->track())
+        return false;
+
+    return visitor.containsOpaqueRoot(root(textTrackCue->track()));
+}
+
+void JSTextTrackCue::visitChildren(JSCell* cell, SlotVisitor& visitor)
+{
+    JSTextTrackCue* jsTextTrackCue = jsCast<JSTextTrackCue*>(cell);
+    ASSERT_GC_OBJECT_INHERITS(jsTextTrackCue, &s_info);
+    COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
+    ASSERT(jsTextTrackCue->structure()->typeInfo().overridesVisitChildren());
+    Base::visitChildren(jsTextTrackCue, visitor);
+    
+    // Mark the cue's track root if it has one.
+    TextTrackCue* textTrackCue = static_cast<TextTrackCue*>(jsTextTrackCue->impl());
+    if (TextTrack* textTrack = textTrackCue->track())
+        visitor.addOpaqueRoot(root(textTrack));
+    
+    textTrackCue->visitJSEventListeners(visitor);
+}
+
+} // namespace WebCore
+
+#endif
diff --git a/Source/WebCore/bindings/js/JSTextTrackCustom.cpp b/Source/WebCore/bindings/js/JSTextTrackCustom.cpp
new file mode 100644 (file)
index 0000000..613bbe3
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+
+#if ENABLE(VIDEO_TRACK)
+#include "JSTextTrackCustom.h"
+
+#include "JSTextTrack.h"
+#include "JSTextTrackCueList.h"
+
+using namespace JSC;
+
+namespace WebCore {
+
+bool JSTextTrackOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
+{
+    JSTextTrack* jsTextTrack = static_cast<JSTextTrack*>(handle.get().asCell());
+    TextTrack* textTrack = static_cast<TextTrack*>(jsTextTrack->impl());
+
+    // If the cue is firing event listeners, its wrapper is reachable because
+    // the wrapper is responsible for marking those event listeners.
+    if (textTrack->isFiringEventListeners())
+        return true;
+
+    // If the cue has no event listeners and has no custom properties, it is not reachable.
+    if (!textTrack->hasEventListeners() && !jsTextTrack->hasCustomProperties())
+        return false;
+
+    return visitor.containsOpaqueRoot(root(textTrack));
+}
+
+void JSTextTrack::visitChildren(JSCell* cell, SlotVisitor& visitor)
+{
+    JSTextTrack* jsTextTrack = jsCast<JSTextTrack*>(cell);
+    ASSERT_GC_OBJECT_INHERITS(jsTextTrack, &s_info);
+    COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
+    ASSERT(jsTextTrack->structure()->typeInfo().overridesVisitChildren());
+    Base::visitChildren(jsTextTrack, visitor);
+
+    TextTrack* textTrack = static_cast<TextTrack*>(jsTextTrack->impl());
+    visitor.addOpaqueRoot(root(textTrack));
+
+    textTrack->visitJSEventListeners(visitor);
+}
+
+} // namespace WebCore
+
+#endif
diff --git a/Source/WebCore/bindings/js/JSTextTrackCustom.h b/Source/WebCore/bindings/js/JSTextTrackCustom.h
new file mode 100644 (file)
index 0000000..0de522c
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2011 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef JSTextTrackCustom_h
+#define JSTextTrackCustom_h
+
+#if ENABLE(VIDEO_TRACK)
+#include "JSTextTrack.h"
+
+#include "HTMLMediaElement.h"
+#include "HTMLTrackElement.h"
+#include "LoadableTextTrack.h"
+
+using namespace JSC;
+
+namespace WebCore {
+
+inline void* root(TextTrack* track)
+{
+    // If this track corresponds to a <track> element, return that element's root.
+    if (track->trackType() == TextTrack::TrackElement) {
+        if (HTMLTrackElement* trackElement = static_cast<LoadableTextTrack*>(track)->trackElement())
+            return root(trackElement);
+    }
+
+    // No, return the media element's root if it has one.
+    if (track->mediaElement())
+        return root(track->mediaElement());
+
+    // No track element and no media element, return the text track.
+    return track;
+}
+
+}
+
+#endif
+#endif
index 559e0fa..8fc1e56 100644 (file)
@@ -52,6 +52,19 @@ bool JSTextTrackListOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown>
     return visitor.containsOpaqueRoot(root(textTrackList->owner()));
 }
 
+void JSTextTrackList::visitChildren(JSCell* cell, SlotVisitor& visitor)
+{
+    JSTextTrackList* jsTextTrackList = jsCast<JSTextTrackList*>(cell);
+    ASSERT_GC_OBJECT_INHERITS(jsTextTrackList, &s_info);
+    COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
+    ASSERT(jsTextTrackList->structure()->typeInfo().overridesVisitChildren());
+    Base::visitChildren(jsTextTrackList, visitor);
+    
+    TextTrackList* textTrackList = static_cast<TextTrackList*>(jsTextTrackList->impl());
+    visitor.addOpaqueRoot(root(textTrackList->owner()));
+    textTrackList->visitJSEventListeners(visitor);
+}
+    
 } // namespace WebCore
 
 #endif
index 3161490..4d164c8 100644 (file)
@@ -2208,7 +2208,7 @@ void HTMLMediaElement::trackWillBeRemoved(HTMLTrackElement* trackElement)
     // When a track element's parent element changes and the old parent was a media element, 
     // then the user agent must remove the track element's corresponding text track from the 
     // media element's list of text tracks.
-    m_textTracks->remove(textTrack);
+    m_textTracks->remove(textTrack.get());
 }
 #endif
 
index add3618..b701225 100644 (file)
@@ -59,6 +59,7 @@ public:
     virtual void clearClient();
     
     size_t trackElementIndex();
+    HTMLTrackElement* trackElement() { return m_trackElement; }
 
 private:
     // TextTrackLoaderClient
index 786bdab..acbe53c 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2011 Google Inc.  All rights reserved.
+ * Copyright (C) 2011 Apple Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -73,6 +74,7 @@ const AtomicString& TextTrack::metadataKeyword()
 
 TextTrack::TextTrack(ScriptExecutionContext* context, TextTrackClient* client, const String& kind, const String& label, const String& language, TextTrackType type)
     : TrackBase(context, TrackBase::TextTrack)
+    , m_mediaElement(0)
     , m_label(label)
     , m_language(language)
     , m_mode(TextTrack::HIDDEN)
index 65914bc..533e3ba 100644 (file)
@@ -36,6 +36,7 @@
 
 namespace WebCore {
 
+class HTMLMediaElement;
 class TextTrack;
 class TextTrackCue;
 class TextTrackCueList;
@@ -58,6 +59,9 @@ public:
         return adoptRef(new TextTrack(context, client, kind, label, language, AddTrack));
     }
     virtual ~TextTrack();
+    
+    void setMediaElement(HTMLMediaElement* element) { m_mediaElement = element; }
+    HTMLMediaElement* mediaElement() { return m_mediaElement; }
 
     String kind() const { return m_kind; }
     void setKind(const String&);
@@ -104,6 +108,7 @@ protected:
     RefPtr<TextTrackCueList> m_cues;
 
 private:
+    HTMLMediaElement* m_mediaElement;
     String m_kind;
     String m_label;
     String m_language;
index c62812e..0ac01b4 100644 (file)
@@ -28,7 +28,9 @@ module html {
     interface [
         Conditional=VIDEO_TRACK,
         EnabledAtRuntime=webkitVideoTrack,
-        EventTarget
+        EventTarget,
+        CustomMarkFunction,
+        CustomIsReachable
     ] TextTrack {
         readonly attribute DOMString kind;
         readonly attribute DOMString label;
index 11bd445..8f43aba 100644 (file)
@@ -31,7 +31,9 @@ module html {
         GenerateNativeConverter,
         Constructor(in DOMString id, in double startTime, in double endTime, in DOMString text, in [Optional=CallWithDefaultValue] DOMString settings, in [Optional=CallWithDefaultValue] boolean pauseOnExit),
         CallWith=ScriptExecutionContext,
-        EventTarget
+        EventTarget,
+        CustomMarkFunction,
+        CustomIsReachable
     ] TextTrackCue {
         readonly attribute TextTrack track;
         readonly attribute DOMString id;
index 0ecc42f..77d9673 100644 (file)
@@ -74,23 +74,26 @@ TextTrack* TextTrackList::item(unsigned index)
     return 0;
 }
 
-void TextTrackList::append(PassRefPtr<TextTrack> track)
+void TextTrackList::append(PassRefPtr<TextTrack> prpTrack)
 {
-    RefPtr<TextTrack> trackRef = track;
+    RefPtr<TextTrack> track = prpTrack;
     
-    if (trackRef->trackType() == TextTrack::AddTrack)
-        m_addTrackTracks.append(trackRef);
-    else if (trackRef->trackType() == TextTrack::TrackElement) {
+    if (track->trackType() == TextTrack::AddTrack)
+        m_addTrackTracks.append(track);
+    else if (track->trackType() == TextTrack::TrackElement) {
         // Insert tracks added for <track> element in tree order.
-        size_t index = static_cast<LoadableTextTrack*>(trackRef.get())->trackElementIndex();
-        m_elementTracks.insert(index, trackRef);
+        size_t index = static_cast<LoadableTextTrack*>(track.get())->trackElementIndex();
+        m_elementTracks.insert(index, track);
     } else
         ASSERT_NOT_REACHED();
 
-    scheduleAddTrackEvent(trackRef);
+    ASSERT(!track->mediaElement() || track->mediaElement() == owner());
+    track->setMediaElement(owner());
+
+    scheduleAddTrackEvent(track.release());
 }
 
-void TextTrackList::remove(PassRefPtr<TextTrack> track)
+void TextTrackList::remove(TextTrack* track)
 {
     Vector<RefPtr<TextTrack> >* tracks = 0;
 
@@ -104,8 +107,11 @@ void TextTrackList::remove(PassRefPtr<TextTrack> track)
     size_t index = tracks->find(track);
     if (index == notFound)
         return;
-    tracks->remove(index);
 
+    ASSERT(track->mediaElement() == owner());
+    track->setMediaElement(0);
+
+    tracks->remove(index);
 }
 
 const AtomicString& TextTrackList::interfaceName() const
index 3165697..88d9af6 100644 (file)
@@ -53,7 +53,7 @@ public:
     unsigned length() const;
     TextTrack* item(unsigned index);
     void append(PassRefPtr<TextTrack>);
-    void remove(PassRefPtr<TextTrack>);
+    void remove(TextTrack*);
 
     // EventTarget
     virtual const AtomicString& interfaceName() const;
index 58a0398..f1460b6 100644 (file)
@@ -30,6 +30,7 @@ module html {
         EnabledAtRuntime=webkitVideoTrack,
         HasIndexGetter,
         EventTarget,
+        CustomMarkFunction,
         CustomIsReachable
     ] TextTrackList {
         readonly attribute unsigned long length;