<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[206127] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/206127">206127</a></dd>
<dt>Author</dt> <dd>jer.noble@apple.com</dd>
<dt>Date</dt> <dd>2016-09-19 16:24:15 -0700 (Mon, 19 Sep 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>[media-source] Fix imported/w3c/web-platform-tests/media-source/mediasource-avtracks.html
https://bugs.webkit.org/show_bug.cgi?id=162104

Reviewed by Eric Carlson.

Source/WebCore:

Fixes test: imported/w3c/web-platform-tests/media-source/mediasource-avtracks.html

Multiple overlapping issues are causing this test to fail:

- When a MediaSource object is not attached from a HTMLMediaElement, it's SourceBuffer
  objects will return `null` from .videoTracks and .audioTracks, foiling the tests ability
  to assert that sourceBuffer.videoTracks.length == 0.

- When a MediaSource object is detached from a HTMLMediaElement, it's tracks are removed
  but do not generate 'removedtrack' events.

When these bugs were fixed, a few more popped up:

- The HTMLMediaElement removes its tracks before it closes the MediaSource, which causes an
  assertion when the MediaSource tells the HTMLMediaElement to remove its copy of the
  source's tracks (which have already been removed).

- When the HTMLMediaElement is stop()-ed due to its ScriptExecutionContext being destroyed,
  it tries to close its MediaSource, which has itself already been stop()-ed and thus asserts.

To eliminate all these bugs and make the code more self explanatory, we will rename the
HTMLMediaElement's closeMediaSource() method to detachMediaSource(), and the MediaSource's
close() method to detachFromElement(). The only way to close a MediaSource is now by calling
detachMediaSource() from the HTMLMediaElement.  The parts of the &quot;Detaching from a media
element&quot; algorithm which were previously spread across setReadyState() and onReadyStateChange()
are now unified in the newly renamed detachFromElement() method. The HTMLMediaElement will
first detach its MediaSource, and only after that remove all its tracks.

* Modules/mediasource/MediaSource.cpp:
(WebCore::MediaSource::setReadyState): Move steps into detachFromElement().
(WebCore::MediaSource::onReadyStateChange): Ditto.
(WebCore::MediaSource::detachFromElement): Perform the steps as specified.
(WebCore::MediaSource::attachToElement): Takes a reference rather than a bare pointer.
(WebCore::MediaSource::stop): Ask the media elemnet to detach.
(WebCore::MediaSource::close): Renamed to detachFromElement().
* Modules/mediasource/MediaSource.h:
* Modules/mediasource/SourceBuffer.cpp:
(WebCore::SourceBuffer::videoTracks): Always return a valid TrackList object.
(WebCore::SourceBuffer::audioTracks): Ditto.
(WebCore::SourceBuffer::textTracks): Ditto.
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::~HTMLMediaElement): Renamed closeMediaSource() -&gt; detachMediaSource().
(WebCore::HTMLMediaElement::prepareForLoad): Ditto.
(WebCore::HTMLMediaElement::loadResource): Ditto.
(WebCore::HTMLMediaElement::noneSupported): Ditto.
(WebCore::HTMLMediaElement::mediaLoadingFailedFatally): Ditto.
(WebCore::HTMLMediaElement::detachMediaSource): Ditto.
(WebCore::HTMLMediaElement::userCancelledLoad): Ditto.
(WebCore::HTMLMediaElement::createMediaPlayer): Ditto.
(WebCore::HTMLMediaElement::clearMediaPlayer): Ditto. Also, detach from the MediaSource before
    removing tracks.
(WebCore::HTMLMediaElement::closeMediaSource): Deleted.
* html/HTMLMediaElement.h:
* html/track/TrackListBase.cpp:
(TrackListBase::remove): Only try to clear the media element from Tracks that have one.

LayoutTests:

* imported/w3c/web-platform-tests/media-source/mediasource-avtracks-expected.txt
* platform/mac/TestExpectations:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsplatformmacTestExpectations">trunk/LayoutTests/platform/mac/TestExpectations</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesmediasourceMediaSourcecpp">trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesmediasourceMediaSourceh">trunk/Source/WebCore/Modules/mediasource/MediaSource.h</a></li>
<li><a href="#trunkSourceWebCoreModulesmediasourceSourceBuffercpp">trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLMediaElementcpp">trunk/Source/WebCore/html/HTMLMediaElement.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLMediaElementh">trunk/Source/WebCore/html/HTMLMediaElement.h</a></li>
<li><a href="#trunkSourceWebCorehtmltrackTrackListBasecpp">trunk/Source/WebCore/html/track/TrackListBase.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsmediasourcemediasourceavtracksexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/media-source/mediasource-avtracks-expected.txt</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (206126 => 206127)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-09-19 23:05:11 UTC (rev 206126)
+++ trunk/LayoutTests/ChangeLog        2016-09-19 23:24:15 UTC (rev 206127)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2016-09-16  Jer Noble  &lt;jer.noble@apple.com&gt;
+
+        [media-source] Fix imported/w3c/web-platform-tests/media-source/mediasource-avtracks.html
+        https://bugs.webkit.org/show_bug.cgi?id=162104
+
+        Reviewed by Eric Carlson.
+
+        * imported/w3c/web-platform-tests/media-source/mediasource-avtracks-expected.txt
+        * platform/mac/TestExpectations:
+
</ins><span class="cx"> 2016-09-19  Daniel Bates  &lt;dabates@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Remove ENABLE(TEXT_AUTOSIZING) automatic text size adjustment code
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsmediasourcemediasourceavtracksexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/imported/w3c/web-platform-tests/media-source/mediasource-avtracks-expected.txt (0 => 206127)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/media-source/mediasource-avtracks-expected.txt                                (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/media-source/mediasource-avtracks-expected.txt        2016-09-19 23:24:15 UTC (rev 206127)
</span><span class="lines">@@ -0,0 +1,6 @@
</span><ins>+
+PASS Check that media tracks and their properties are populated properly 
+PASS Media tracks must be removed when the SourceBuffer is removed from the MediaSource 
+PASS Media tracks must be removed when the HTMLMediaElement.src is changed 
+PASS Media tracks must be removed when HTMLMediaElement.load() is called 
+
</ins></span></pre></div>
<a id="trunkLayoutTestsplatformmacTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/mac/TestExpectations (206126 => 206127)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac/TestExpectations        2016-09-19 23:05:11 UTC (rev 206126)
+++ trunk/LayoutTests/platform/mac/TestExpectations        2016-09-19 23:24:15 UTC (rev 206127)
</span><span class="lines">@@ -1045,6 +1045,7 @@
</span><span class="cx"> [ Yosemite+ ] imported/w3c/web-platform-tests/media-source/URL-createObjectURL.html [ Pass ]
</span><span class="cx"> [ Yosemite+ ] imported/w3c/web-platform-tests/media-source/mediasource-addsourcebuffer-mode.html [ Pass ]
</span><span class="cx"> [ Yosemite+ ] imported/w3c/web-platform-tests/media-source/mediasource-addsourcebuffer.html [ Pass ]
</span><ins>+[ Yosemite+ ] imported/w3c/web-platform-tests/media-source/mediasource-avtracks.html [ Pass ]
</ins><span class="cx"> [ Yosemite+ ] imported/w3c/web-platform-tests/media-source/mediasource-buffered.html [ Pass ]
</span><span class="cx"> [ Yosemite+ ] imported/w3c/web-platform-tests/media-source/mediasource-closed.html [ Pass ]
</span><span class="cx"> [ Yosemite+ ] imported/w3c/web-platform-tests/media-source/mediasource-config-change-mp4-a-bitrate.html [ Pass ]
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (206126 => 206127)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-09-19 23:05:11 UTC (rev 206126)
+++ trunk/Source/WebCore/ChangeLog        2016-09-19 23:24:15 UTC (rev 206127)
</span><span class="lines">@@ -1,3 +1,66 @@
</span><ins>+2016-09-16  Jer Noble  &lt;jer.noble@apple.com&gt;
+
+        [media-source] Fix imported/w3c/web-platform-tests/media-source/mediasource-avtracks.html
+        https://bugs.webkit.org/show_bug.cgi?id=162104
+
+        Reviewed by Eric Carlson.
+
+        Fixes test: imported/w3c/web-platform-tests/media-source/mediasource-avtracks.html
+
+        Multiple overlapping issues are causing this test to fail:
+
+        - When a MediaSource object is not attached from a HTMLMediaElement, it's SourceBuffer
+          objects will return `null` from .videoTracks and .audioTracks, foiling the tests ability
+          to assert that sourceBuffer.videoTracks.length == 0.
+
+        - When a MediaSource object is detached from a HTMLMediaElement, it's tracks are removed
+          but do not generate 'removedtrack' events.
+
+        When these bugs were fixed, a few more popped up:
+
+        - The HTMLMediaElement removes its tracks before it closes the MediaSource, which causes an
+          assertion when the MediaSource tells the HTMLMediaElement to remove its copy of the 
+          source's tracks (which have already been removed).
+
+        - When the HTMLMediaElement is stop()-ed due to its ScriptExecutionContext being destroyed,
+          it tries to close its MediaSource, which has itself already been stop()-ed and thus asserts.
+
+        To eliminate all these bugs and make the code more self explanatory, we will rename the 
+        HTMLMediaElement's closeMediaSource() method to detachMediaSource(), and the MediaSource's
+        close() method to detachFromElement(). The only way to close a MediaSource is now by calling
+        detachMediaSource() from the HTMLMediaElement.  The parts of the &quot;Detaching from a media
+        element&quot; algorithm which were previously spread across setReadyState() and onReadyStateChange()
+        are now unified in the newly renamed detachFromElement() method. The HTMLMediaElement will
+        first detach its MediaSource, and only after that remove all its tracks.
+
+        * Modules/mediasource/MediaSource.cpp:
+        (WebCore::MediaSource::setReadyState): Move steps into detachFromElement().
+        (WebCore::MediaSource::onReadyStateChange): Ditto.
+        (WebCore::MediaSource::detachFromElement): Perform the steps as specified.
+        (WebCore::MediaSource::attachToElement): Takes a reference rather than a bare pointer.
+        (WebCore::MediaSource::stop): Ask the media elemnet to detach.
+        (WebCore::MediaSource::close): Renamed to detachFromElement().
+        * Modules/mediasource/MediaSource.h:
+        * Modules/mediasource/SourceBuffer.cpp:
+        (WebCore::SourceBuffer::videoTracks): Always return a valid TrackList object.
+        (WebCore::SourceBuffer::audioTracks): Ditto.
+        (WebCore::SourceBuffer::textTracks): Ditto.
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::~HTMLMediaElement): Renamed closeMediaSource() -&gt; detachMediaSource().
+        (WebCore::HTMLMediaElement::prepareForLoad): Ditto.
+        (WebCore::HTMLMediaElement::loadResource): Ditto.
+        (WebCore::HTMLMediaElement::noneSupported): Ditto.
+        (WebCore::HTMLMediaElement::mediaLoadingFailedFatally): Ditto.
+        (WebCore::HTMLMediaElement::detachMediaSource): Ditto.
+        (WebCore::HTMLMediaElement::userCancelledLoad): Ditto.
+        (WebCore::HTMLMediaElement::createMediaPlayer): Ditto.
+        (WebCore::HTMLMediaElement::clearMediaPlayer): Ditto. Also, detach from the MediaSource before
+            removing tracks.
+        (WebCore::HTMLMediaElement::closeMediaSource): Deleted.
+        * html/HTMLMediaElement.h:
+        * html/track/TrackListBase.cpp:
+        (TrackListBase::remove): Only try to clear the media element from Tracks that have one.
+
</ins><span class="cx"> 2016-09-19  Alex Christensen  &lt;achristensen@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         URLParser can read memory out of bounds
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediasourceMediaSourcecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp (206126 => 206127)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp        2016-09-19 23:05:11 UTC (rev 206126)
+++ trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp        2016-09-19 23:24:15 UTC (rev 206127)
</span><span class="lines">@@ -466,12 +466,6 @@
</span><span class="cx">     AtomicString oldState = readyState();
</span><span class="cx">     LOG(MediaSource, &quot;MediaSource::setReadyState(%p) : %s -&gt; %s&quot;, this, oldState.string().ascii().data(), state.string().ascii().data());
</span><span class="cx"> 
</span><del>-    if (state == closedKeyword()) {
-        m_private = nullptr;
-        m_mediaElement = nullptr;
-        m_duration = MediaTime::invalidTime();
-    }
-
</del><span class="cx">     if (oldState == state)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="lines">@@ -819,9 +813,33 @@
</span><span class="cx">     return readyState() == endedKeyword();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void MediaSource::close()
</del><ins>+void MediaSource::detachFromElement(HTMLMediaElement&amp; element)
</ins><span class="cx"> {
</span><ins>+    ASSERT_UNUSED(element, m_mediaElement == &amp;element);
+    ASSERT(!isClosed());
+
+    // 2.4.2 Detaching from a media element
+    // https://rawgit.com/w3c/media-source/45627646344eea0170dd1cbc5a3d508ca751abb8/media-source-respec.html#mediasource-detach
+
+    // 1. Set the readyState attribute to &quot;closed&quot;.
+    // 7. Queue a task to fire a simple event named sourceclose at the MediaSource.
</ins><span class="cx">     setReadyState(closedKeyword());
</span><ins>+
+    // 2. Update duration to NaN.
+    m_duration = MediaTime::invalidTime();
+
+    // 3. Remove all the SourceBuffer objects from activeSourceBuffers.
+    // 4. Queue a task to fire a simple event named removesourcebuffer at activeSourceBuffers.
+    while (m_activeSourceBuffers-&gt;length())
+        removeSourceBuffer(*m_activeSourceBuffers-&gt;item(0), IGNORE_EXCEPTION);
+
+    // 5. Remove all the SourceBuffer objects from sourceBuffers.
+    // 6. Queue a task to fire a simple event named removesourcebuffer at sourceBuffers.
+    while (m_sourceBuffers-&gt;length())
+        removeSourceBuffer(*m_sourceBuffers-&gt;item(0), IGNORE_EXCEPTION);
+
+    m_private = nullptr;
+    m_mediaElement = nullptr;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void MediaSource::sourceBufferDidChangeActiveState(SourceBuffer&amp;, bool)
</span><span class="lines">@@ -829,7 +847,7 @@
</span><span class="cx">     regenerateActiveSourceBuffers();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool MediaSource::attachToElement(HTMLMediaElement* element)
</del><ins>+bool MediaSource::attachToElement(HTMLMediaElement&amp; element)
</ins><span class="cx"> {
</span><span class="cx">     if (m_mediaElement)
</span><span class="cx">         return false;
</span><span class="lines">@@ -836,7 +854,7 @@
</span><span class="cx"> 
</span><span class="cx">     ASSERT(isClosed());
</span><span class="cx"> 
</span><del>-    m_mediaElement = element;
</del><ins>+    m_mediaElement = &amp;element;
</ins><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -858,8 +876,8 @@
</span><span class="cx"> void MediaSource::stop()
</span><span class="cx"> {
</span><span class="cx">     m_asyncEventQueue.close();
</span><del>-    if (!isClosed())
-        setReadyState(closedKeyword());
</del><ins>+    if (m_mediaElement)
+        m_mediaElement-&gt;detachMediaSource();
</ins><span class="cx">     m_private = nullptr;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -889,14 +907,6 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     ASSERT(isClosed());
</span><del>-
-    m_activeSourceBuffers-&gt;clear();
-
-    // Clear SourceBuffer references to this object.
-    for (auto&amp; buffer : *m_sourceBuffers)
-        buffer-&gt;removedFromMediaSource();
-    m_sourceBuffers-&gt;clear();
-    
</del><span class="cx">     scheduleEvent(eventNames().sourcecloseEvent);
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediasourceMediaSourceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediasource/MediaSource.h (206126 => 206127)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediasource/MediaSource.h        2016-09-19 23:05:11 UTC (rev 206126)
+++ trunk/Source/WebCore/Modules/mediasource/MediaSource.h        2016-09-19 23:24:15 UTC (rev 206127)
</span><span class="lines">@@ -77,8 +77,8 @@
</span><span class="cx">     std::unique_ptr&lt;PlatformTimeRanges&gt; buffered() const override;
</span><span class="cx">     void seekToTime(const MediaTime&amp;) override;
</span><span class="cx"> 
</span><del>-    bool attachToElement(HTMLMediaElement*);
-    void close();
</del><ins>+    bool attachToElement(HTMLMediaElement&amp;);
+    void detachFromElement(HTMLMediaElement&amp;);
</ins><span class="cx">     void monitorSourceBuffers();
</span><span class="cx">     bool isSeeking() const { return m_pendingSeekTime.isValid(); }
</span><span class="cx">     void completeSeek();
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediasourceSourceBuffercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp (206126 => 206127)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp        2016-09-19 23:05:11 UTC (rev 206126)
+++ trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp        2016-09-19 23:24:15 UTC (rev 206127)
</span><span class="lines">@@ -969,9 +969,6 @@
</span><span class="cx"> 
</span><span class="cx"> VideoTrackList* SourceBuffer::videoTracks()
</span><span class="cx"> {
</span><del>-    if (!m_source || !m_source-&gt;mediaElement())
-        return nullptr;
-
</del><span class="cx">     if (!m_videoTracks)
</span><span class="cx">         m_videoTracks = VideoTrackList::create(m_source-&gt;mediaElement(), ActiveDOMObject::scriptExecutionContext());
</span><span class="cx"> 
</span><span class="lines">@@ -980,9 +977,6 @@
</span><span class="cx"> 
</span><span class="cx"> AudioTrackList* SourceBuffer::audioTracks()
</span><span class="cx"> {
</span><del>-    if (!m_source || !m_source-&gt;mediaElement())
-        return nullptr;
-
</del><span class="cx">     if (!m_audioTracks)
</span><span class="cx">         m_audioTracks = AudioTrackList::create(m_source-&gt;mediaElement(), ActiveDOMObject::scriptExecutionContext());
</span><span class="cx"> 
</span><span class="lines">@@ -991,9 +985,6 @@
</span><span class="cx"> 
</span><span class="cx"> TextTrackList* SourceBuffer::textTracks()
</span><span class="cx"> {
</span><del>-    if (!m_source || !m_source-&gt;mediaElement())
-        return nullptr;
-
</del><span class="cx">     if (!m_textTracks)
</span><span class="cx">         m_textTracks = TextTrackList::create(m_source-&gt;mediaElement(), ActiveDOMObject::scriptExecutionContext());
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLMediaElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (206126 => 206127)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLMediaElement.cpp        2016-09-19 23:05:11 UTC (rev 206126)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp        2016-09-19 23:24:15 UTC (rev 206127)
</span><span class="lines">@@ -610,7 +610,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(MEDIA_SOURCE)
</span><del>-    closeMediaSource();
</del><ins>+    detachMediaSource();
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(ENCRYPTED_MEDIA_V2)
</span><span class="lines">@@ -1206,7 +1206,7 @@
</span><span class="cx">         scheduleEvent(eventNames().abortEvent);
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(MEDIA_SOURCE)
</span><del>-    closeMediaSource();
</del><ins>+    detachMediaSource();
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     createMediaPlayer();
</span><span class="lines">@@ -1522,7 +1522,7 @@
</span><span class="cx">         m_mediaSource = MediaSource::lookup(url.string());
</span><span class="cx"> 
</span><span class="cx">     if (m_mediaSource) {
</span><del>-        if (m_mediaSource-&gt;attachToElement(this))
</del><ins>+        if (m_mediaSource-&gt;attachToElement(*this))
</ins><span class="cx">             m_player-&gt;load(url, contentType, m_mediaSource.get());
</span><span class="cx">         else {
</span><span class="cx">             // Forget our reference to the MediaSource, so we leave it alone
</span><span class="lines">@@ -2067,7 +2067,7 @@
</span><span class="cx">     rejectPendingPlayPromises(DOMError::create(&quot;NotSupportedError&quot;, &quot;The operation is not supported.&quot;));
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(MEDIA_SOURCE)
</span><del>-    closeMediaSource();
</del><ins>+    detachMediaSource();
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     // 8 - Set the element's delaying-the-load-event flag to false. This stops delaying the load event.
</span><span class="lines">@@ -2101,7 +2101,7 @@
</span><span class="cx">     scheduleEvent(eventNames().errorEvent);
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(MEDIA_SOURCE)
</span><del>-    closeMediaSource();
</del><ins>+    detachMediaSource();
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     // 4 - Set the element's networkState attribute to the NETWORK_EMPTY value and queue a
</span><span class="lines">@@ -3286,12 +3286,12 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(MEDIA_SOURCE)
</span><del>-void HTMLMediaElement::closeMediaSource()
</del><ins>+void HTMLMediaElement::detachMediaSource()
</ins><span class="cx"> {
</span><span class="cx">     if (!m_mediaSource)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    m_mediaSource-&gt;close();
</del><ins>+    m_mediaSource-&gt;detachFromElement(*this);
</ins><span class="cx">     m_mediaSource = nullptr;
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="lines">@@ -5110,7 +5110,7 @@
</span><span class="cx">     scheduleEvent(eventNames().abortEvent);
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(MEDIA_SOURCE)
</span><del>-    closeMediaSource();
</del><ins>+    detachMediaSource();
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     // 4 - If the media element's readyState attribute has a value equal to HAVE_NOTHING, set the 
</span><span class="lines">@@ -5142,14 +5142,14 @@
</span><span class="cx"> {
</span><span class="cx">     LOG(Media, &quot;HTMLMediaElement::clearMediaPlayer(%p) - flags = %s&quot;, this, actionName(flags).utf8().data());
</span><span class="cx"> 
</span><ins>+#if ENABLE(MEDIA_SOURCE)
+    detachMediaSource();
+#endif
+
</ins><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><span class="cx">     forgetResourceSpecificTracks();
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-#if ENABLE(MEDIA_SOURCE)
-    closeMediaSource();
-#endif
-
</del><span class="cx"> #if ENABLE(WIRELESS_PLAYBACK_TARGET)
</span><span class="cx">     if (hasEventListeners(eventNames().webkitplaybacktargetavailabilitychangedEvent)) {
</span><span class="cx">         m_hasPlaybackTargetAvailabilityListeners = false;
</span><span class="lines">@@ -6096,7 +6096,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(MEDIA_SOURCE)
</span><span class="cx">     if (m_mediaSource)
</span><del>-        m_mediaSource-&gt;close();
</del><ins>+        m_mediaSource-&gt;detachFromElement(*this);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(MEDIA_STREAM)
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLMediaElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (206126 => 206127)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLMediaElement.h        2016-09-19 23:05:11 UTC (rev 206126)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h        2016-09-19 23:24:15 UTC (rev 206127)
</span><span class="lines">@@ -241,7 +241,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(MEDIA_SOURCE)
</span><span class="cx"> //  Media Source.
</span><del>-    void closeMediaSource();
</del><ins>+    void detachMediaSource();
</ins><span class="cx">     void incrementDroppedFrameCount() { ++m_droppedVideoFrames; }
</span><span class="cx">     size_t maximumSourceBufferSize(const SourceBuffer&amp;) const;
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebCorehtmltrackTrackListBasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/track/TrackListBase.cpp (206126 => 206127)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/track/TrackListBase.cpp        2016-09-19 23:05:11 UTC (rev 206126)
+++ trunk/Source/WebCore/html/track/TrackListBase.cpp        2016-09-19 23:24:15 UTC (rev 206127)
</span><span class="lines">@@ -73,8 +73,10 @@
</span><span class="cx">     size_t index = m_inbandTracks.find(&amp;track);
</span><span class="cx">     ASSERT(index != notFound);
</span><span class="cx"> 
</span><del>-    ASSERT(track.mediaElement() == m_element);
-    track.setMediaElement(nullptr);
</del><ins>+    if (track.mediaElement()) {
+        ASSERT(track.mediaElement() == m_element);
+        track.setMediaElement(nullptr);
+    }
</ins><span class="cx"> 
</span><span class="cx">     Ref&lt;TrackBase&gt; trackRef = *m_inbandTracks[index];
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>