<!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>[210349] branches/safari-603-branch/Source/WebCore</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/210349">210349</a></dd>
<dt>Author</dt> <dd>matthew_hanson@apple.com</dd>
<dt>Date</dt> <dd>2017-01-05 09:09:20 -0800 (Thu, 05 Jan 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/210104">r210104</a>. rdar://problem/29139619</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari603branchSourceWebCoreChangeLog">branches/safari-603-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari603branchSourceWebCoreplatformaudioPlatformMediaSessionManagercpp">branches/safari-603-branch/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp</a></li>
<li><a href="#branchessafari603branchSourceWebCoreplatformaudioPlatformMediaSessionManagerh">branches/safari-603-branch/Source/WebCore/platform/audio/PlatformMediaSessionManager.h</a></li>
<li><a href="#branchessafari603branchSourceWebCoreplatformaudioiosMediaSessionManagerIOSmm">branches/safari-603-branch/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari603branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/ChangeLog (210348 => 210349)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/ChangeLog        2017-01-05 17:09:18 UTC (rev 210348)
+++ branches/safari-603-branch/Source/WebCore/ChangeLog        2017-01-05 17:09:20 UTC (rev 210349)
</span><span class="lines">@@ -1,5 +1,35 @@
</span><span class="cx"> 2017-01-05  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r210104. rdar://problem/29139619
+
+    2016-12-22  Jer Noble  &lt;jer.noble@apple.com&gt;
+
+            NULL-deref CRASH in WebCore::PlatformMediaSession::mediaType
+            https://bugs.webkit.org/show_bug.cgi?id=166407
+
+            Reviewed by Darin Adler.
+
+            In r207688, we added a facility in PlatformMediaSessionManager for safely walking through a
+            list of PlatformMediaSessions by replacing entries of deleted sessions with nullptr. We now
+            need to use those new iteration falicities in MediaSessionManageriOS.
+
+            In addition to the existing iterators, add one which takes a predicate, and returns the first
+            session which matches the predicate, or nullptr, if none do.
+
+            * platform/audio/PlatformMediaSessionManager.cpp:
+            (WebCore::PlatformMediaSessionManager::findSession):
+            (WebCore::PlatformMediaSessionManager::anyOfSessions):
+            * platform/audio/PlatformMediaSessionManager.h:
+            (WebCore::PlatformMediaSessionManager::sessions): Deleted.
+            * platform/audio/ios/MediaSessionManagerIOS.mm:
+            (WebCore::MediaSessionManageriOS::configureWireLessTargetMonitoring):
+            (WebCore::MediaSessionManageriOS::nowPlayingEligibleSession):
+            (WebCore::MediaSessionManageriOS::externalOutputDeviceAvailableDidChange):
+            (WebCore::MediaSessionManageriOS::applicationDidEnterBackground):
+            (WebCore::MediaSessionManageriOS::applicationWillEnterForeground):
+
+2017-01-05  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
+
</ins><span class="cx">         Merge r210100. rdar://problem/28388000
</span><span class="cx"> 
</span><span class="cx">     2016-12-22  Jer Noble  &lt;jer.noble@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari603branchSourceWebCoreplatformaudioPlatformMediaSessionManagercpp"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp (210348 => 210349)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp        2017-01-05 17:09:18 UTC (rev 210348)
+++ branches/safari-603-branch/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp        2017-01-05 17:09:20 UTC (rev 210349)
</span><span class="lines">@@ -401,7 +401,7 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void PlatformMediaSessionManager::forEachSession(std::function&lt;void(PlatformMediaSession&amp;, size_t)&gt; func) const
</del><ins>+void PlatformMediaSessionManager::forEachSession(const Function&lt;void(PlatformMediaSession&amp;, size_t)&gt;&amp; predicate) const
</ins><span class="cx"> {
</span><span class="cx">     ++m_iteratingOverSessions;
</span><span class="cx"> 
</span><span class="lines">@@ -409,7 +409,7 @@
</span><span class="cx">         auto session = m_sessions[i];
</span><span class="cx">         if (!session)
</span><span class="cx">             continue;
</span><del>-        func(*session, i);
</del><ins>+        predicate(*session, i);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     --m_iteratingOverSessions;
</span><span class="lines">@@ -417,20 +417,20 @@
</span><span class="cx">         m_sessions.removeAll(nullptr);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool PlatformMediaSessionManager::anyOfSessions(std::function&lt;bool(PlatformMediaSession&amp;, size_t)&gt; func) const
</del><ins>+PlatformMediaSession* PlatformMediaSessionManager::findSession(const Function&lt;bool(PlatformMediaSession&amp;, size_t)&gt;&amp; predicate) const
</ins><span class="cx"> {
</span><span class="cx">     ++m_iteratingOverSessions;
</span><span class="cx"> 
</span><del>-    bool found = false;
</del><ins>+    PlatformMediaSession* foundSession = nullptr;
</ins><span class="cx">     for (size_t i = 0, size = m_sessions.size(); i &lt; size; ++i) {
</span><span class="cx">         auto session = m_sessions[i];
</span><span class="cx">         if (!session)
</span><span class="cx">             continue;
</span><span class="cx"> 
</span><del>-        if (!func(*session, i))
</del><ins>+        if (!predicate(*session, i))
</ins><span class="cx">             continue;
</span><span class="cx"> 
</span><del>-        found = true;
</del><ins>+        foundSession = session;
</ins><span class="cx">         break;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -438,7 +438,7 @@
</span><span class="cx">     if (!m_iteratingOverSessions)
</span><span class="cx">         m_sessions.removeAll(nullptr);
</span><span class="cx"> 
</span><del>-    return found;
</del><ins>+    return foundSession;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(VIDEO) || ENABLE(WEB_AUDIO)
</span></span></pre></div>
<a id="branchessafari603branchSourceWebCoreplatformaudioPlatformMediaSessionManagerh"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/platform/audio/PlatformMediaSessionManager.h (210348 => 210349)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/platform/audio/PlatformMediaSessionManager.h        2017-01-05 17:09:18 UTC (rev 210348)
+++ branches/safari-603-branch/Source/WebCore/platform/audio/PlatformMediaSessionManager.h        2017-01-05 17:09:20 UTC (rev 210349)
</span><span class="lines">@@ -114,14 +114,14 @@
</span><span class="cx">     void addSession(PlatformMediaSession&amp;);
</span><span class="cx">     virtual void removeSession(PlatformMediaSession&amp;);
</span><span class="cx"> 
</span><del>-    Vector&lt;PlatformMediaSession*&gt; sessions() { return m_sessions; }
</del><ins>+    void forEachSession(const Function&lt;void(PlatformMediaSession&amp;, size_t)&gt;&amp;) const;
+    PlatformMediaSession* findSession(const Function&lt;bool(PlatformMediaSession&amp;, size_t)&gt;&amp;) const;
+    bool anyOfSessions(const Function&lt;bool(PlatformMediaSession&amp;, size_t)&gt;&amp; predicate) const { return findSession(predicate); }
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     friend class Internals;
</span><span class="cx"> 
</span><span class="cx">     void updateSessionState();
</span><del>-    void forEachSession(std::function&lt;void(PlatformMediaSession&amp;, size_t)&gt;) const;
-    bool anyOfSessions(std::function&lt;bool(PlatformMediaSession&amp;, size_t)&gt;) const;
</del><span class="cx"> 
</span><span class="cx">     // RemoteCommandListenerClient
</span><span class="cx">     WEBCORE_EXPORT void didReceiveRemoteControlCommand(PlatformMediaSession::RemoteControlCommandType, const PlatformMediaSession::RemoteCommandArgument*) override;
</span></span></pre></div>
<a id="branchessafari603branchSourceWebCoreplatformaudioiosMediaSessionManagerIOSmm"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm (210348 => 210349)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm        2017-01-05 17:09:18 UTC (rev 210348)
+++ branches/safari-603-branch/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm        2017-01-05 17:09:20 UTC (rev 210349)
</span><span class="lines">@@ -173,16 +173,10 @@
</span><span class="cx"> 
</span><span class="cx"> void MediaSessionManageriOS::configureWireLessTargetMonitoring()
</span><span class="cx"> {
</span><del>-    Vector&lt;PlatformMediaSession*&gt; sessions = this-&gt;sessions();
-    bool requiresMonitoring = false;
</del><ins>+    bool requiresMonitoring = anyOfSessions([] (PlatformMediaSession&amp; session, size_t) {
+        return session.requiresPlaybackTargetRouteMonitoring();
+    });
</ins><span class="cx"> 
</span><del>-    for (auto* session : sessions) {
-        if (session-&gt;requiresPlaybackTargetRouteMonitoring()) {
-            requiresMonitoring = true;
-            break;
-        }
-    }
-
</del><span class="cx">     LOG(Media, &quot;MediaSessionManageriOS::configureWireLessTargetMonitoring - requiresMonitoring = %s&quot;, requiresMonitoring ? &quot;true&quot; : &quot;false&quot;);
</span><span class="cx"> 
</span><span class="cx">     if (requiresMonitoring)
</span><span class="lines">@@ -223,16 +217,16 @@
</span><span class="cx"> 
</span><span class="cx"> PlatformMediaSession* MediaSessionManageriOS::nowPlayingEligibleSession()
</span><span class="cx"> {
</span><del>-    for (auto session : sessions()) {
-        PlatformMediaSession::MediaType type = session-&gt;mediaType();
</del><ins>+    return findSession([] (PlatformMediaSession&amp; session, size_t) {
+        PlatformMediaSession::MediaType type = session.mediaType();
</ins><span class="cx">         if (type != PlatformMediaSession::Video &amp;&amp; type != PlatformMediaSession::Audio)
</span><del>-            continue;
</del><ins>+            return false;
</ins><span class="cx"> 
</span><del>-        if (session-&gt;characteristics() &amp; PlatformMediaSession::HasAudio)
-            return session;
-    }
</del><ins>+        if (session.characteristics() &amp; PlatformMediaSession::HasAudio)
+            return true;
</ins><span class="cx"> 
</span><del>-    return nullptr;
</del><ins>+        return false;
+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void MediaSessionManageriOS::updateNowPlayingInfo()
</span><span class="lines">@@ -292,10 +286,9 @@
</span><span class="cx"> 
</span><span class="cx"> void MediaSessionManageriOS::externalOutputDeviceAvailableDidChange()
</span><span class="cx"> {
</span><del>-    Vector&lt;PlatformMediaSession*&gt; sessionList = sessions();
-    bool haveTargets = [m_objcObserver hasWirelessTargetsAvailable];
-    for (auto* session : sessionList)
-        session-&gt;externalOutputDeviceAvailableDidChange(haveTargets);
</del><ins>+    forEachSession([haveTargets = [m_objcObserver hasWirelessTargetsAvailable]] (PlatformMediaSession&amp; session, size_t) {
+        session.externalOutputDeviceAvailableDidChange(haveTargets);
+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void MediaSessionManageriOS::applicationDidEnterBackground(bool isSuspendedUnderLock)
</span><span class="lines">@@ -309,11 +302,10 @@
</span><span class="cx">     if (!isSuspendedUnderLock)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    Vector&lt;PlatformMediaSession*&gt; sessions = this-&gt;sessions();
-    for (auto* session : sessions) {
-        if (restrictions(session-&gt;mediaType()) &amp; BackgroundProcessPlaybackRestricted)
-            session-&gt;beginInterruption(PlatformMediaSession::SuspendedUnderLock);
-    }
</del><ins>+    forEachSession([this] (PlatformMediaSession&amp; session, size_t) {
+        if (restrictions(session.mediaType()) &amp; BackgroundProcessPlaybackRestricted)
+            session.beginInterruption(PlatformMediaSession::SuspendedUnderLock);
+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void MediaSessionManageriOS::applicationWillEnterForeground(bool isSuspendedUnderLock)
</span><span class="lines">@@ -327,11 +319,10 @@
</span><span class="cx">     if (!isSuspendedUnderLock)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    Vector&lt;PlatformMediaSession*&gt; sessions = this-&gt;sessions();
-    for (auto* session : sessions) {
-        if (restrictions(session-&gt;mediaType()) &amp; BackgroundProcessPlaybackRestricted)
-            session-&gt;endInterruption(PlatformMediaSession::MayResumePlaying);
-    }
</del><ins>+    forEachSession([this] (PlatformMediaSession&amp; session, size_t) {
+        if (restrictions(session.mediaType()) &amp; BackgroundProcessPlaybackRestricted)
+            session.endInterruption(PlatformMediaSession::MayResumePlaying);
+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre>
</div>
</div>

</body>
</html>