Removing HTMLTrackElement does not delete TextTrack
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Mar 2012 18:28:48 +0000 (18:28 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Mar 2012 18:28:48 +0000 (18:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=80873

Reviewed by Antti Koivisto.

Source/WebCore:

No new tests, but media/track/track-language-preference.html has been updated
to test this fix.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::didAddTrack): Renamed from trackWasAdded.
(WebCore::HTMLMediaElement::willRemoveTrack): Renamed from trackWasRemoved because it is
called before the track is removed, to allow the TextTrack to be removed.
* html/HTMLMediaElement.h:

* html/HTMLTrackElement.cpp:
(WebCore::HTMLTrackElement::insertedIntoTree): Renamed from insertedIntoDocument
(WebCore::HTMLTrackElement::willRemove): Renamed from removedFromDocument.
* html/HTMLTrackElement.h:

* html/track/LoadableTextTrack.cpp:
(WebCore::LoadableTextTrack::trackElementIndex): Don't include tracks that are not in the
document in the calcualtion.

LayoutTests:

* media/track/track-language-preference-expected.txt:
* media/track/track-language-preference.html:

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

LayoutTests/ChangeLog
LayoutTests/media/track/track-language-preference-expected.txt
LayoutTests/media/track/track-language-preference.html
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/html/HTMLTrackElement.cpp
Source/WebCore/html/HTMLTrackElement.h
Source/WebCore/html/track/LoadableTextTrack.cpp

index 3f6386d..d0e5f16 100644 (file)
@@ -1,3 +1,13 @@
+2012-03-21  Eric Carlson  <eric.carlson@apple.com>
+
+        Removing HTMLTrackElement does not delete TextTrack
+        https://bugs.webkit.org/show_bug.cgi?id=80873
+
+        Reviewed by Antti Koivisto.
+
+        * media/track/track-language-preference-expected.txt:
+        * media/track/track-language-preference.html:
+
 2012-03-21  Mark Hahnenberg  <mhahnenberg@apple.com>
 
         Checking in updated test expectations
index a4eb724..dc5253f 100644 (file)
@@ -28,5 +28,6 @@ EVENT(load)
 EXPECTED (track.readyState == '2') OK
 EXPECTED (track.srclang == 'fa') OK
 
+EXPECTED (video.textTracks.length == '3') OK
 END OF TEST
 
index 1777343..750af15 100644 (file)
@@ -45,6 +45,8 @@
                 consoleWrite("");
                 testList.current++;
                 if (testList.current >= testList.tests.length) {
+                    var tracks = document.querySelectorAll('track');
+                    testExpected("video.textTracks.length", tracks.length);
                     endTest();
                     return;
                 }
index 68f4859..436bba8 100644 (file)
@@ -1,3 +1,28 @@
+2012-03-21  Eric Carlson  <eric.carlson@apple.com>
+
+        Removing HTMLTrackElement does not delete TextTrack
+        https://bugs.webkit.org/show_bug.cgi?id=80873
+
+        Reviewed by Antti Koivisto.
+
+        No new tests, but media/track/track-language-preference.html has been updated
+        to test this fix.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::didAddTrack): Renamed from trackWasAdded.
+        (WebCore::HTMLMediaElement::willRemoveTrack): Renamed from trackWasRemoved because it is
+        called before the track is removed, to allow the TextTrack to be removed.
+        * html/HTMLMediaElement.h:
+
+        * html/HTMLTrackElement.cpp:
+        (WebCore::HTMLTrackElement::insertedIntoTree): Renamed from insertedIntoDocument
+        (WebCore::HTMLTrackElement::willRemove): Renamed from removedFromDocument.
+        * html/HTMLTrackElement.h:
+
+        * html/track/LoadableTextTrack.cpp:
+        (WebCore::LoadableTextTrack::trackElementIndex): Don't include tracks that are not in the
+        document in the calcualtion.
+
 2012-03-21  Zeno Albisser  <zeno@webkit.org>
 
         [Qt][Mac] ranlib segfaults when creating symbol tables for libWebCore.a.
index 0752335..ff4ae30 100644 (file)
@@ -2490,7 +2490,7 @@ HTMLTrackElement* HTMLMediaElement::showingTrackWithSameKind(HTMLTrackElement* t
     return 0;
 }
 
-void HTMLMediaElement::trackWasAdded(HTMLTrackElement* trackElement)
+void HTMLMediaElement::didAddTrack(HTMLTrackElement* trackElement)
 {
     ASSERT(trackElement->hasTagName(trackTag));
 
@@ -2513,7 +2513,7 @@ void HTMLMediaElement::trackWasAdded(HTMLTrackElement* trackElement)
         scheduleLoad(TextTrackResource);
 }
 
-void HTMLMediaElement::trackWasRemoved(HTMLTrackElement* trackElement)
+void HTMLMediaElement::willRemoveTrack(HTMLTrackElement* trackElement)
 {
     ASSERT(trackElement->hasTagName(trackTag));
 
@@ -2523,7 +2523,7 @@ void HTMLMediaElement::trackWasRemoved(HTMLTrackElement* trackElement)
 #if !LOG_DISABLED
     if (trackElement->hasTagName(trackTag)) {
         KURL url = trackElement->getNonEmptyURLAttribute(srcAttr);
-        LOG(Media, "HTMLMediaElement::trackWasRemoved - 'src' is %s", urlForLogging(url).utf8().data());
+        LOG(Media, "HTMLMediaElement::willRemoveTrack - 'src' is %s", urlForLogging(url).utf8().data());
     }
 #endif
 
index 3f310fb..d14e439 100644 (file)
@@ -204,8 +204,8 @@ public:
     TextTrackList* textTracks();
     CueList currentlyActiveCues() const { return m_currentlyActiveCues; }
 
-    virtual void trackWasAdded(HTMLTrackElement*);
-    virtual void trackWasRemoved(HTMLTrackElement*);
+    virtual void didAddTrack(HTMLTrackElement*);
+    virtual void willRemoveTrack(HTMLTrackElement*);
 
     struct TrackGroup {
         enum GroupKind { CaptionsAndSubtitles, Description, Chapter, Metadata, Other };
index f3578da..6005799 100644 (file)
@@ -72,20 +72,20 @@ PassRefPtr<HTMLTrackElement> HTMLTrackElement::create(const QualifiedName& tagNa
     return adoptRef(new HTMLTrackElement(tagName, document));
 }
 
-void HTMLTrackElement::insertedIntoDocument()
+void HTMLTrackElement::insertedIntoTree(bool deep)
 {
-    HTMLElement::insertedIntoDocument();
+    HTMLElement::insertedIntoTree(deep);
 
     if (HTMLMediaElement* parent = mediaElement())
-        parent->trackWasAdded(this);
+        parent->didAddTrack(this);
 }
 
-void HTMLTrackElement::removedFromDocument()
+void HTMLTrackElement::willRemove()
 {
     if (HTMLMediaElement* parent = mediaElement())
-        parent->trackWasRemoved(this);
+        parent->willRemoveTrack(this);
 
-    HTMLElement::removedFromDocument();
+    HTMLElement::willRemove();
 }
 
 void HTMLTrackElement::parseAttribute(Attribute* attribute)
index ce1247c..e2a55f3 100644 (file)
@@ -77,8 +77,8 @@ private:
 
     virtual void parseAttribute(Attribute*) OVERRIDE;
 
-    virtual void insertedIntoDocument() OVERRIDE;
-    virtual void removedFromDocument() OVERRIDE;
+    virtual void insertedIntoTree(bool) OVERRIDE;
+    virtual void willRemove() OVERRIDE;
     virtual bool isURLAttribute(Attribute*) const;
 
 #if ENABLE(MICRODATA)
index 400b42c..86ac787 100644 (file)
@@ -135,10 +135,11 @@ size_t LoadableTextTrack::trackElementIndex()
 {
     ASSERT(m_trackElement);
     ASSERT(m_trackElement->parentNode());
+    ASSERT(m_trackElement->inDocument());
 
     size_t index = 0;
     for (Node* node = m_trackElement->parentNode()->firstChild(); node; node = node->nextSibling()) {
-        if (!node->hasTagName(trackTag))
+        if (!node->hasTagName(trackTag) || !node->inDocument())
             continue;
         if (node == m_trackElement)
             return index;