<!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>[211511] branches/safari-603-branch</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/211511">211511</a></dd>
<dt>Author</dt> <dd>matthew_hanson@apple.com</dd>
<dt>Date</dt> <dd>2017-02-01 13:26:17 -0800 (Wed, 01 Feb 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/211240">r211240</a>. rdar://problem/30247467b</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari603branchSourceWebCoreChangeLog">branches/safari-603-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari603branchSourceWebCoreModuleswebaudioAudioContextcpp">branches/safari-603-branch/Source/WebCore/Modules/webaudio/AudioContext.cpp</a></li>
<li><a href="#branchessafari603branchSourceWebCoreModuleswebaudioAudioContexth">branches/safari-603-branch/Source/WebCore/Modules/webaudio/AudioContext.h</a></li>
<li><a href="#branchessafari603branchSourceWebCorehtmlHTMLMediaElementcpp">branches/safari-603-branch/Source/WebCore/html/HTMLMediaElement.cpp</a></li>
<li><a href="#branchessafari603branchSourceWebCorehtmlHTMLMediaElementh">branches/safari-603-branch/Source/WebCore/html/HTMLMediaElement.h</a></li>
<li><a href="#branchessafari603branchSourceWebCoreplatformaudioPlatformMediaSessioncpp">branches/safari-603-branch/Source/WebCore/platform/audio/PlatformMediaSession.cpp</a></li>
<li><a href="#branchessafari603branchSourceWebCoreplatformaudioPlatformMediaSessionh">branches/safari-603-branch/Source/WebCore/platform/audio/PlatformMediaSession.h</a></li>
<li><a href="#branchessafari603branchSourceWebCoreplatformaudiococoaMediaSessionManagerCocoacpp">branches/safari-603-branch/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.cpp</a></li>
<li><a href="#branchessafari603branchToolsChangeLog">branches/safari-603-branch/Tools/ChangeLog</a></li>
<li><a href="#branchessafari603branchToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj">branches/safari-603-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj</a></li>
<li><a href="#branchessafari603branchToolsTestWebKitAPITestsWebKitiosAudioSessionCategoryIOSmm">branches/safari-603-branch/Tools/TestWebKitAPI/Tests/WebKit/ios/AudioSessionCategoryIOS.mm</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#branchessafari603branchToolsTestWebKitAPITestsWebKitiosvideowithmutedaudioandwebaudiohtml">branches/safari-603-branch/Tools/TestWebKitAPI/Tests/WebKit/ios/video-with-muted-audio-and-webaudio.html</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 (211510 => 211511)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/ChangeLog        2017-02-01 21:26:11 UTC (rev 211510)
+++ branches/safari-603-branch/Source/WebCore/ChangeLog        2017-02-01 21:26:17 UTC (rev 211511)
</span><span class="lines">@@ -1,5 +1,57 @@
</span><span class="cx"> 2017-01-31  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r211240. rdar://problem/30247467b
+
+    2017-01-26  Jer Noble  &lt;jer.noble@apple.com&gt;
+
+            Autoplay muted videos stop playback of any streaming app in the background
+            https://bugs.webkit.org/show_bug.cgi?id=163993
+            &lt;rdar://problem/29020431&gt;
+
+            Reviewed by Eric Carlson.
+
+            Added test in TestWebKitAPI, WebKit1.AudioSessionCategoryIOS.
+
+            Previously, we would set the audio session category to &quot;playback&quot; if there was a media-
+            element-type media session, and if there was a session capable of playing audio. But because
+            this was an &quot;or&quot; operation, we would incorrectly set the category to &quot;playback&quot; if there was
+            a video element incapable of rendering audio (due to being muted, without an audio track,
+            etc.), and also a session capable of producing audio, such as WebAudio.
+
+            With this change, this turns into an &quot;and&quot; operation; there must be a media element capable
+            of rendering audio in order to switch the audio session category to &quot;playback&quot;.
+
+            Additionally, we no longer cache the value of &quot;canProduceAudio()&quot;; it's queried directly
+            whenever updateSessionState() is called.
+
+            * Modules/webaudio/AudioContext.cpp:
+            (WebCore::AudioContext::constructCommon):
+            * Modules/webaudio/AudioContext.h:
+            * html/HTMLMediaElement.cpp:
+            (WebCore::HTMLMediaElement::insertedInto):
+            (WebCore::HTMLMediaElement::loadResource):
+            (WebCore::HTMLMediaElement::setMuted):
+            (WebCore::HTMLMediaElement::mediaPlayerCurrentPlaybackTargetIsWirelessChanged):
+            (WebCore::HTMLMediaElement::mediaPlayerCharacteristicChanged):
+            (WebCore::HTMLMediaElement::clearMediaPlayer):
+            (WebCore::HTMLMediaElement::mediaPlayerCurrentPlaybackTargetIsWirelessChanged):
+            (WebCore::HTMLMediaElement::presentationType):
+            (WebCore::HTMLMediaElement::characteristics):
+            (WebCore::HTMLMediaElement::canProduceAudio):
+            * html/HTMLMediaElement.h:
+            * platform/audio/PlatformMediaSession.cpp:
+            (WebCore::PlatformMediaSession::activeAudioSessionRequired):
+            (WebCore::PlatformMediaSession::canProduceAudio):
+            (WebCore::PlatformMediaSession::canProduceAudioChanged):
+            (WebCore::PlatformMediaSession::setCanProduceAudio): Deleted.
+            * platform/audio/PlatformMediaSession.h:
+            (WebCore::PlatformMediaSessionClient::canProduceAudio):
+            (WebCore::PlatformMediaSession::canProduceAudio): Deleted.
+            * platform/audio/cocoa/MediaSessionManagerCocoa.cpp:
+            (PlatformMediaSessionManager::updateSessionState):
+
+2017-01-31  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
+
</ins><span class="cx">         Merge r210217. rdar://problem/30260068
</span><span class="cx"> 
</span><span class="cx">         Committed on behalf of Chris Dumez.
</span></span></pre></div>
<a id="branchessafari603branchSourceWebCoreModuleswebaudioAudioContextcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/Modules/webaudio/AudioContext.cpp (211510 => 211511)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/Modules/webaudio/AudioContext.cpp        2017-02-01 21:26:11 UTC (rev 211510)
+++ branches/safari-603-branch/Source/WebCore/Modules/webaudio/AudioContext.cpp        2017-02-01 21:26:17 UTC (rev 211511)
</span><span class="lines">@@ -181,8 +181,6 @@
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx">     addBehaviorRestriction(RequirePageConsentForAudioStartRestriction);
</span><span class="cx"> #endif
</span><del>-
-    m_mediaSession-&gt;setCanProduceAudio(true);
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> AudioContext::~AudioContext()
</span></span></pre></div>
<a id="branchessafari603branchSourceWebCoreModuleswebaudioAudioContexth"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/Modules/webaudio/AudioContext.h (211510 => 211511)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/Modules/webaudio/AudioContext.h        2017-02-01 21:26:11 UTC (rev 211510)
+++ branches/safari-603-branch/Source/WebCore/Modules/webaudio/AudioContext.h        2017-02-01 21:26:17 UTC (rev 211511)
</span><span class="lines">@@ -317,6 +317,7 @@
</span><span class="cx">     bool supportsSeeking() const override { return false; }
</span><span class="cx">     bool shouldOverrideBackgroundPlaybackRestriction(PlatformMediaSession::InterruptionType) const override { return false; }
</span><span class="cx">     String sourceApplicationIdentifier() const override;
</span><ins>+    bool canProduceAudio() const final { return true; }
</ins><span class="cx"> 
</span><span class="cx">     // EventTarget
</span><span class="cx">     void refEventTarget() override { ref(); }
</span></span></pre></div>
<a id="branchessafari603branchSourceWebCorehtmlHTMLMediaElementcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/html/HTMLMediaElement.cpp (211510 => 211511)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/html/HTMLMediaElement.cpp        2017-02-01 21:26:11 UTC (rev 211510)
+++ branches/safari-603-branch/Source/WebCore/html/HTMLMediaElement.cpp        2017-02-01 21:26:17 UTC (rev 211511)
</span><span class="lines">@@ -829,6 +829,7 @@
</span><span class="cx">     if (!m_explicitlyMuted) {
</span><span class="cx">         m_explicitlyMuted = true;
</span><span class="cx">         m_muted = hasAttributeWithoutSynchronization(mutedAttr);
</span><ins>+        m_mediaSession-&gt;canProduceAudioChanged();
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     return InsertionShouldCallFinishedInsertingSubtree;
</span><span class="lines">@@ -1487,6 +1488,7 @@
</span><span class="cx">     if (!m_explicitlyMuted) {
</span><span class="cx">         m_explicitlyMuted = true;
</span><span class="cx">         m_muted = hasAttributeWithoutSynchronization(mutedAttr);
</span><ins>+        m_mediaSession-&gt;canProduceAudioChanged();
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     updateVolume();
</span><span class="lines">@@ -3317,6 +3319,7 @@
</span><span class="cx"> #if ENABLE(WIRELESS_PLAYBACK_TARGET)
</span><span class="cx">         updateMediaState(UpdateState::Asynchronously);
</span><span class="cx"> #endif
</span><ins>+        m_mediaSession-&gt;canProduceAudioChanged();
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     scheduleUpdatePlaybackControlsManager();
</span><span class="lines">@@ -4650,8 +4653,6 @@
</span><span class="cx">     if (!paused() &amp;&amp; !m_mediaSession-&gt;playbackPermitted(*this))
</span><span class="cx">         pauseInternal();
</span><span class="cx"> 
</span><del>-    m_mediaSession-&gt;setCanProduceAudio(m_player &amp;&amp; m_readyState &gt;= HAVE_METADATA &amp;&amp; hasAudio());
-
</del><span class="cx"> #if ENABLE(MEDIA_SESSION)
</span><span class="cx">     document().updateIsPlayingMedia(m_elementID);
</span><span class="cx"> #else
</span><span class="lines">@@ -5069,8 +5070,8 @@
</span><span class="cx">         configureTextTrackDisplay();
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    m_mediaSession-&gt;setCanProduceAudio(false);
</del><span class="cx">     m_mediaSession-&gt;clientCharacteristicsChanged();
</span><ins>+    m_mediaSession-&gt;canProduceAudioChanged();
</ins><span class="cx"> 
</span><span class="cx">     updateSleepDisabling();
</span><span class="cx"> }
</span><span class="lines">@@ -5261,8 +5262,7 @@
</span><span class="cx">     configureMediaControls();
</span><span class="cx">     scheduleEvent(eventNames().webkitcurrentplaybacktargetiswirelesschangedEvent);
</span><span class="cx">     m_mediaSession-&gt;isPlayingToWirelessPlaybackTargetChanged(m_isPlayingToWirelessTarget);
</span><del>-    if (m_isPlayingToWirelessTarget)
-        m_mediaSession-&gt;setCanProduceAudio(true);
</del><ins>+    m_mediaSession-&gt;canProduceAudioChanged();
</ins><span class="cx">     updateMediaState(UpdateState::Asynchronously);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -6797,7 +6797,7 @@
</span><span class="cx"> PlatformMediaSession::MediaType HTMLMediaElement::presentationType() const
</span><span class="cx"> {
</span><span class="cx">     if (hasTagName(HTMLNames::videoTag))
</span><del>-        return PlatformMediaSession::VideoAudio;
</del><ins>+        return muted() ? PlatformMediaSession::Video : PlatformMediaSession::VideoAudio;
</ins><span class="cx"> 
</span><span class="cx">     return PlatformMediaSession::Audio;
</span><span class="cx"> }
</span><span class="lines">@@ -6829,6 +6829,21 @@
</span><span class="cx">     return state;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool HTMLMediaElement::canProduceAudio() const
+{
+#if ENABLE(WIRELESS_PLAYBACK_TARGET)
+    // Because the remote target could unmute playback without notifying us, we must assume
+    // that we may be playing audio.
+    if (m_isPlayingToWirelessTarget)
+        return true;
+#endif
+
+    if (muted())
+        return false;
+
+    return m_player &amp;&amp; m_readyState &gt;= HAVE_METADATA &amp;&amp; hasAudio();
+}
+
</ins><span class="cx"> #if ENABLE(MEDIA_SOURCE)
</span><span class="cx"> size_t HTMLMediaElement::maximumSourceBufferSize(const SourceBuffer&amp; buffer) const
</span><span class="cx"> {
</span></span></pre></div>
<a id="branchessafari603branchSourceWebCorehtmlHTMLMediaElementh"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/html/HTMLMediaElement.h (211510 => 211511)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/html/HTMLMediaElement.h        2017-02-01 21:26:11 UTC (rev 211510)
+++ branches/safari-603-branch/Source/WebCore/html/HTMLMediaElement.h        2017-02-01 21:26:17 UTC (rev 211511)
</span><span class="lines">@@ -776,6 +776,7 @@
</span><span class="cx">     bool supportsSeeking() const override;
</span><span class="cx">     bool shouldOverrideBackgroundPlaybackRestriction(PlatformMediaSession::InterruptionType) const override;
</span><span class="cx">     bool shouldOverrideBackgroundLoadingRestriction() const override;
</span><ins>+    bool canProduceAudio() const final;
</ins><span class="cx"> 
</span><span class="cx">     void pageMutedStateDidChange() override;
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari603branchSourceWebCoreplatformaudioPlatformMediaSessioncpp"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/platform/audio/PlatformMediaSession.cpp (211510 => 211511)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/platform/audio/PlatformMediaSession.cpp        2017-02-01 21:26:11 UTC (rev 211510)
+++ branches/safari-603-branch/Source/WebCore/platform/audio/PlatformMediaSession.cpp        2017-02-01 21:26:17 UTC (rev 211511)
</span><span class="lines">@@ -329,15 +329,16 @@
</span><span class="cx">         return false;
</span><span class="cx">     if (state() != PlatformMediaSession::State::Playing)
</span><span class="cx">         return false;
</span><del>-    return m_canProduceAudio;
</del><ins>+    return canProduceAudio();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void PlatformMediaSession::setCanProduceAudio(bool canProduceAudio)
</del><ins>+bool PlatformMediaSession::canProduceAudio() const
</ins><span class="cx"> {
</span><del>-    if (m_canProduceAudio == canProduceAudio)
-        return;
-    m_canProduceAudio = canProduceAudio;
</del><ins>+    return m_client.canProduceAudio();
+}
</ins><span class="cx"> 
</span><ins>+void PlatformMediaSession::canProduceAudioChanged()
+{
</ins><span class="cx">     PlatformMediaSessionManager::sharedManager().sessionCanProduceAudioChanged(*this);
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari603branchSourceWebCoreplatformaudioPlatformMediaSessionh"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/platform/audio/PlatformMediaSession.h (211510 => 211511)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/platform/audio/PlatformMediaSession.h        2017-02-01 21:26:11 UTC (rev 211510)
+++ branches/safari-603-branch/Source/WebCore/platform/audio/PlatformMediaSession.h        2017-02-01 21:26:17 UTC (rev 211511)
</span><span class="lines">@@ -162,8 +162,8 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     bool activeAudioSessionRequired();
</span><del>-    bool canProduceAudio() const { return m_canProduceAudio; }
-    void setCanProduceAudio(bool);
</del><ins>+    bool canProduceAudio() const;
+    void canProduceAudioChanged();
</ins><span class="cx"> 
</span><span class="cx">     void scheduleClientDataBufferingCheck();
</span><span class="cx">     virtual void resetPlaybackSessionState() { }
</span><span class="lines">@@ -186,7 +186,6 @@
</span><span class="cx">     int m_interruptionCount { 0 };
</span><span class="cx">     bool m_notifyingClient;
</span><span class="cx">     bool m_isPlayingToWirelessPlaybackTarget { false };
</span><del>-    bool m_canProduceAudio { false };
</del><span class="cx"> 
</span><span class="cx">     friend class PlatformMediaSessionManager;
</span><span class="cx"> };
</span><span class="lines">@@ -217,6 +216,7 @@
</span><span class="cx"> 
</span><span class="cx">     virtual void setShouldBufferData(bool) { }
</span><span class="cx">     virtual bool elementIsHidden() const { return false; }
</span><ins>+    virtual bool canProduceAudio() const { return false; }
</ins><span class="cx"> 
</span><span class="cx">     virtual bool shouldOverrideBackgroundPlaybackRestriction(PlatformMediaSession::InterruptionType) const = 0;
</span><span class="cx">     virtual bool shouldOverrideBackgroundLoadingRestriction() const { return false; }
</span></span></pre></div>
<a id="branchessafari603branchSourceWebCoreplatformaudiococoaMediaSessionManagerCocoacpp"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.cpp (211510 => 211511)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.cpp        2017-02-01 21:26:11 UTC (rev 211510)
+++ branches/safari-603-branch/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.cpp        2017-02-01 21:26:17 UTC (rev 211511)
</span><span class="lines">@@ -31,6 +31,7 @@
</span><span class="cx"> #include &quot;AudioSession.h&quot;
</span><span class="cx"> #include &quot;Logging.h&quot;
</span><span class="cx"> #include &quot;Settings.h&quot;
</span><ins>+#include &lt;wtf/Function.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> using namespace WebCore;
</span><span class="cx"> 
</span><span class="lines">@@ -60,13 +61,20 @@
</span><span class="cx">     if (!Settings::shouldManageAudioSessionCategory())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    if (has(PlatformMediaSession::VideoAudio) || has(PlatformMediaSession::Audio)) {
-        if (canProduceAudio())
-            AudioSession::sharedSession().setCategory(AudioSession::MediaPlayback);
-        else
-            AudioSession::sharedSession().setCategory(AudioSession::AmbientSound);
-    } else if (has(PlatformMediaSession::WebAudio))
</del><ins>+    bool hasAudioMediaType = false;
+    bool hasAudibleAudioOrVideoMediaType = anyOfSessions([this, hasAudioMediaType] (PlatformMediaSession&amp; session, size_t) mutable {
+        auto type = session.mediaType();
+        if (type == PlatformMediaSession::VideoAudio || type == PlatformMediaSession::Audio || type == PlatformMediaSession::WebAudio)
+            hasAudioMediaType = true;
+        return (type == PlatformMediaSession::VideoAudio || type == PlatformMediaSession::Audio) &amp;&amp; session.canProduceAudio();
+    });
+
+    if (hasAudibleAudioOrVideoMediaType)
+        AudioSession::sharedSession().setCategory(AudioSession::MediaPlayback);
+    else if (hasAudioMediaType)
</ins><span class="cx">         AudioSession::sharedSession().setCategory(AudioSession::AmbientSound);
</span><ins>+    else
+        AudioSession::sharedSession().setCategory(AudioSession::None);
</ins><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari603branchToolsChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Tools/ChangeLog (211510 => 211511)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Tools/ChangeLog        2017-02-01 21:26:11 UTC (rev 211510)
+++ branches/safari-603-branch/Tools/ChangeLog        2017-02-01 21:26:17 UTC (rev 211511)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2017-01-31  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
+
+        Merge r211240. rdar://problem/30247467b
+
+    2017-01-26  Jer Noble  &lt;jer.noble@apple.com&gt;
+
+            Autoplay muted videos stop playback of any streaming app in the background
+            https://bugs.webkit.org/show_bug.cgi?id=163993
+            &lt;rdar://problem/29020431&gt;
+
+            Reviewed by Eric Carlson.
+
+            * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+            * TestWebKitAPI/Tests/WebKit/ios/AudioSessionCategoryIOS.mm:
+            (TestWebKitAPI::TEST):
+            * TestWebKitAPI/Tests/WebKit/ios/video-with-muted-audio-and-webaudio.html: Added.
+
</ins><span class="cx"> 2017-01-25  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Merge r211137. rdar://problem/29896656
</span></span></pre></div>
<a id="branchessafari603branchToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (211510 => 211511)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2017-02-01 21:26:11 UTC (rev 211510)
+++ branches/safari-603-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2017-02-01 21:26:17 UTC (rev 211511)
</span><span class="lines">@@ -502,6 +502,7 @@
</span><span class="cx">                 C540F784152E5A9A00A40C8C /* verboseMarkup.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C540F783152E5A7800A40C8C /* verboseMarkup.html */; };
</span><span class="cx">                 C54237F116B8957D00E638FC /* PasteboardNotifications_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C54237ED16B8955800E638FC /* PasteboardNotifications_Bundle.cpp */; };
</span><span class="cx">                 C5E1AFFE16B221F1006CC1F2 /* execCopy.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C5E1AFFD16B22179006CC1F2 /* execCopy.html */; };
</span><ins>+                CD321B041E3A85FA00EB21C8 /* video-with-muted-audio-and-webaudio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD321B031E3A84B700EB21C8 /* video-with-muted-audio-and-webaudio.html */; };
</ins><span class="cx">                 CD59F53419E9110D00CF1835 /* file-with-mse.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD59F53219E910AA00CF1835 /* file-with-mse.html */; };
</span><span class="cx">                 CD59F53519E9110D00CF1835 /* test-mse.mp4 in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD59F53319E910BC00CF1835 /* test-mse.mp4 */; };
</span><span class="cx">                 CD78E11D1DB7EA660014A2DE /* FullscreenDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD78E11A1DB7EA360014A2DE /* FullscreenDelegate.mm */; };
</span><span class="lines">@@ -599,6 +600,7 @@
</span><span class="cx">                         dstPath = TestWebKitAPI.resources;
</span><span class="cx">                         dstSubfolderSpec = 7;
</span><span class="cx">                         files = (
</span><ins>+                                CD321B041E3A85FA00EB21C8 /* video-with-muted-audio-and-webaudio.html in Copy Resources */,
</ins><span class="cx">                                 7AEAD4811E20122700416EFE /* CrossPartitionFileSchemeAccess.html in Copy Resources */,
</span><span class="cx">                                 CDB4115A1E0B00DB00EAD352 /* video-with-muted-audio.html in Copy Resources */,
</span><span class="cx">                                 9BD4239C1E04C01C00200395 /* chinese-character-with-image.html in Copy Resources */,
</span><span class="lines">@@ -1256,6 +1258,7 @@
</span><span class="cx">                 C5E1AFFD16B22179006CC1F2 /* execCopy.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = execCopy.html; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 C95501BE19AD2FAF0049BE3E /* Preferences.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Preferences.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 CD225C071C45A69200140761 /* ParsedContentRange.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParsedContentRange.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                CD321B031E3A84B700EB21C8 /* video-with-muted-audio-and-webaudio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = &quot;video-with-muted-audio-and-webaudio.html&quot;; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 CD5393C71757BA9700C07123 /* MD5.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MD5.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 CD5393C91757BAC400C07123 /* SHA1.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SHA1.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 CD5451E919E41F9D0016936F /* CSSParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSParser.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -2194,6 +2197,7 @@
</span><span class="cx">                                 CDC8E48B1BC5C96200594FEC /* video-without-audio.html */,
</span><span class="cx">                                 CDC8E48C1BC5C96200594FEC /* video-without-audio.mp4 */,
</span><span class="cx">                                 CDB411591E09DA8E00EAD352 /* video-with-muted-audio.html */,
</span><ins>+                                CD321B031E3A84B700EB21C8 /* video-with-muted-audio-and-webaudio.html */,
</ins><span class="cx">                         );
</span><span class="cx">                         name = Resources;
</span><span class="cx">                         sourceTree = &quot;&lt;group&gt;&quot;;
</span></span></pre></div>
<a id="branchessafari603branchToolsTestWebKitAPITestsWebKitiosAudioSessionCategoryIOSmm"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Tools/TestWebKitAPI/Tests/WebKit/ios/AudioSessionCategoryIOS.mm (211510 => 211511)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Tools/TestWebKitAPI/Tests/WebKit/ios/AudioSessionCategoryIOS.mm        2017-02-01 21:26:11 UTC (rev 211510)
+++ branches/safari-603-branch/Tools/TestWebKitAPI/Tests/WebKit/ios/AudioSessionCategoryIOS.mm        2017-02-01 21:26:17 UTC (rev 211511)
</span><span class="lines">@@ -97,6 +97,14 @@
</span><span class="cx">     Util::run(&amp;didBeginPlaying);
</span><span class="cx"> 
</span><span class="cx">     EXPECT_WK_STREQ(getAVAudioSessionCategoryAmbient(), [[getAVAudioSessionClass() sharedInstance] category]);
</span><ins>+
+    didBeginPlaying = false;
+
+    [uiWebView loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@&quot;video-with-muted-audio-and-webaudio&quot; withExtension:@&quot;html&quot; subdirectory:@&quot;TestWebKitAPI.resources&quot;]]];
+
+    Util::run(&amp;didBeginPlaying);
+
+    EXPECT_WK_STREQ(getAVAudioSessionCategoryAmbient(), [[getAVAudioSessionClass() sharedInstance] category]);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="branchessafari603branchToolsTestWebKitAPITestsWebKitiosvideowithmutedaudioandwebaudiohtml"></a>
<div class="addfile"><h4>Added: branches/safari-603-branch/Tools/TestWebKitAPI/Tests/WebKit/ios/video-with-muted-audio-and-webaudio.html (0 => 211511)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Tools/TestWebKitAPI/Tests/WebKit/ios/video-with-muted-audio-and-webaudio.html                                (rev 0)
+++ branches/safari-603-branch/Tools/TestWebKitAPI/Tests/WebKit/ios/video-with-muted-audio-and-webaudio.html        2017-02-01 21:26:17 UTC (rev 211511)
</span><span class="lines">@@ -0,0 +1,31 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+    &lt;head&gt;
+        &lt;script&gt;
+        function go() {
+            var audioContext = new webkitAudioContext();
+            audioContext.resume();
+
+            var video = document.getElementsByTagName('video')[0];
+            video.play().then(playing).catch(notPlaying);
+        }
+
+        function playing() {
+            try {
+                window.webkit.messageHandlers.testHandler.postMessage('playing');
+            } catch(e) {
+                window.location = 'callback:playing';
+            }
+        }
+
+        function notPlaying() {
+            try {
+                window.webkit.messageHandlers.testHandler.postMessage('not playing');
+            } catch(e) { }
+        }
+        &lt;/script&gt;
+    &lt;/head&gt;
+    &lt;body onload=&quot;go()&quot;&gt;
+        &lt;video src=&quot;video-with-audio.mp4&quot; muted webkit-playsinline&gt;&lt;/video&gt;
+    &lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre>
</div>
</div>

</body>
</html>