Diff
Modified: trunk/LayoutTests/ChangeLog (98806 => 98807)
--- trunk/LayoutTests/ChangeLog 2011-10-29 16:18:44 UTC (rev 98806)
+++ trunk/LayoutTests/ChangeLog 2011-10-29 16:52:23 UTC (rev 98807)
@@ -1,3 +1,13 @@
+2011-10-29 Anna Cavender <ann...@chromium.org>
+
+ Make sure TextTracks are destructed if HTMLMediaElement goes away.
+ https://bugs.webkit.org/show_bug.cgi?id=71148
+
+ Reviewed by Eric Carlson.
+
+ * media/track/track-text-track-destructor-crash-expected.txt: Added.
+ * media/track/track-text-track-destructor-crash.html: Added.
+
2011-10-29 Jochen Eisinger <joc...@chromium.org>
Implement IDBFactory.deleteDatabase
Added: trunk/LayoutTests/media/track/track-text-track-destructor-crash-expected.txt (0 => 98807)
--- trunk/LayoutTests/media/track/track-text-track-destructor-crash-expected.txt (rev 0)
+++ trunk/LayoutTests/media/track/track-text-track-destructor-crash-expected.txt 2011-10-29 16:52:23 UTC (rev 98807)
@@ -0,0 +1,9 @@
+Tests that we don't crash when a media element that has text tracks is destructed.
+
+Create video and add text tracks.
+EXPECTED (tracks.length == '1000') OK
+
+Destroy the video and force a garbage collection.
+SUCCESS: Did not crash
+END OF TEST
+
Added: trunk/LayoutTests/media/track/track-text-track-destructor-crash.html (0 => 98807)
--- trunk/LayoutTests/media/track/track-text-track-destructor-crash.html (rev 0)
+++ trunk/LayoutTests/media/track/track-text-track-destructor-crash.html 2011-10-29 16:52:23 UTC (rev 98807)
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <script src=""
+ <script src=""
+ <script>
+
+ tracks = [];
+
+ function startTest()
+ {
+ consoleWrite("Create video and add text tracks.");
+ var video = document.createElement('video');
+ for (var i = 0; i < 1000; i++)
+ tracks[i] = video.addTrack('captions', 'Captions Track', 'en');
+ testExpected("tracks.length", 1000);
+ consoleWrite("");
+ consoleWrite("Destroy the video and force a garbage collection.");
+ video = 0;
+ forceGC();
+ consoleWrite("SUCCESS: Did not crash");
+ endTest();
+ }
+
+ function forceGC()
+ {
+ if (window.GCController)
+ return GCController.collect();
+
+ // Force garbage collection
+ for (var ndx = 0; ndx < 99000; ndx++)
+ var str = new String("1234");
+ }
+
+ </script>
+ </head>
+ <body _onload_="startTest()">
+ <p>Tests that we don't crash when a media element that has text tracks is destructed.</p>
+ </body>
+</html>
\ No newline at end of file
Modified: trunk/Source/WebCore/ChangeLog (98806 => 98807)
--- trunk/Source/WebCore/ChangeLog 2011-10-29 16:18:44 UTC (rev 98806)
+++ trunk/Source/WebCore/ChangeLog 2011-10-29 16:52:23 UTC (rev 98807)
@@ -1,3 +1,24 @@
+2011-10-29 Anna Cavender <ann...@chromium.org>
+
+ Make sure TextTracks are destructed if HTMLMediaElement goes away.
+ https://bugs.webkit.org/show_bug.cgi?id=71148
+
+ Reviewed by Eric Carlson.
+
+ Test: media/track/track-text-track-destructor-crash.html
+
+ * html/HTMLMediaElement.cpp:
+ (WebCore::HTMLMediaElement::~HTMLMediaElement):
+ Destroy the client (this) on TextTracks.
+ (WebCore::HTMLMediaElement::loadTextTracks):
+ Move TextTrack creation to loadNextTextTrack.
+ (WebCore::HTMLMediaElement::loadNextTextTrack):
+ Keep track of new TextTrack in a list.
+ (WebCore::HTMLMediaElement::addTrack):
+ Keep track of new TextTrack in a list.
+ * html/HTMLMediaElement.h:
+ Add m_textTracks and loadNextTextTrack().
+
2011-10-29 Jochen Eisinger <joc...@chromium.org>
Implement IDBFactory.deleteDatabase
Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (98806 => 98807)
--- trunk/Source/WebCore/html/HTMLMediaElement.cpp 2011-10-29 16:18:44 UTC (rev 98806)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp 2011-10-29 16:52:23 UTC (rev 98807)
@@ -224,6 +224,10 @@
document()->unregisterForDocumentActivationCallbacks(this);
document()->unregisterForMediaVolumeCallbacks(this);
document()->unregisterForPrivateBrowsingStateChangedCallbacks(this);
+#if ENABLE(VIDEO_TRACK)
+ for (unsigned i = 0; i < m_textTracks.size(); ++i)
+ m_textTracks[i]->setClient(0);
+#endif
}
void HTMLMediaElement::willMoveToNewOwnerDocument()
@@ -839,13 +843,22 @@
return;
for (Node* node = firstChild(); node; node = node->nextSibling()) {
- if (node->hasTagName(trackTag)) {
- HTMLTrackElement* track = static_cast<HTMLTrackElement*>(node);
- track->load(ActiveDOMObject::scriptExecutionContext(), this);
- }
+ if (node->hasTagName(trackTag))
+ loadNextTextTrack(static_cast<HTMLTrackElement*>(node));
}
}
+void HTMLMediaElement::loadNextTextTrack(HTMLTrackElement* track)
+{
+ // FIXME(71124): This should schedule an *asynchronous* load.
+ track->load(ActiveDOMObject::scriptExecutionContext(), this);
+ RefPtr<TextTrack> textTrack = track->track();
+ if (textTrack)
+ m_textTracks.append(textTrack.release());
+
+ // FIXME(71123): Set the text track mode accordingly.
+}
+
void HTMLMediaElement::textTrackReadyStateChanged(TextTrack*)
{
// FIXME(62885): Implement.
@@ -1976,7 +1989,9 @@
#if ENABLE(VIDEO_TRACK)
PassRefPtr<TextTrack> HTMLMediaElement::addTrack(const String& kind, const String& label, const String& language)
{
- return TextTrack::create(this, kind, label, language);
+ RefPtr<TextTrack> textTrack = TextTrack::create(this, kind, label, language);
+ m_textTracks.append(textTrack);
+ return textTrack.release();
}
#endif
Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (98806 => 98807)
--- trunk/Source/WebCore/html/HTMLMediaElement.h 2011-10-29 16:18:44 UTC (rev 98806)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h 2011-10-29 16:52:23 UTC (rev 98807)
@@ -49,6 +49,7 @@
#endif
class Event;
class HTMLSourceElement;
+class HTMLTrackElement;
class MediaControls;
class MediaError;
class KURL;
@@ -352,6 +353,7 @@
#if ENABLE(VIDEO_TRACK)
void loadTextTracks();
+ void loadNextTextTrack(HTMLTrackElement*);
// TextTrackClient
virtual void textTrackReadyStateChanged(TextTrack*);
@@ -507,6 +509,10 @@
// The value is cleared in MediaElementAudioSourceNode::~MediaElementAudioSourceNode().
MediaElementAudioSourceNode* m_audioSourceNode;
#endif
+
+#if ENABLE(VIDEO_TRACK)
+ Vector<RefPtr<TextTrack> > m_textTracks;
+#endif
};
} //namespace