<!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>[176350] 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/176350">176350</a></dd>
<dt>Author</dt> <dd>adachan@apple.com</dd>
<dt>Date</dt> <dd>2014-11-19 14:58:43 -0800 (Wed, 19 Nov 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Take Web Audio into account for the Page::isPlayingAudio() API.
https://bugs.webkit.org/show_bug.cgi?id=137464

Reviewed by Jer Noble.

Source/WebCore:

Make AudioContext a subclass of AudioProducer. It figures out whether there's
audio playing by checking whether its AudioDestinationNode is playing (and not
silent). It calls Document::updateIsPlayingAudio() whenever its audio playing
state has changed.

Test: webaudio/web-audio-is-playing.html

* Modules/webaudio/AudioContext.cpp:
(WebCore::AudioContext::lazyInitialize):
Add itself to the Document's list of AudioProducers if it's not an offline
audio context.
(WebCore::AudioContext::uninitialize):
Remove itself from the Document's list of AudioProducers if it's not an offline
audio context.
(WebCore::AudioContext::stop):
Tell the document to update its audio playing state.
(WebCore::AudioContext::isPlayingAudio):
Return true if the audio context hasn't been stopped and its destination node is
playing audio.
(WebCore::AudioContext::pageMutedStateDidChange):
Add a FIXME for now.
(WebCore::AudioContext::isPlayingAudioDidChange):
Call Document::updateIsPlayingAudio().
* Modules/webaudio/AudioContext.h:

* Modules/webaudio/AudioDestinationNode.cpp:
(WebCore::AudioDestinationNode::AudioDestinationNode):
Initialize m_isSilent and m_isEffectivelyPlayingAudio.
(WebCore::AudioDestinationNode::render):
Call setIsSilent() with the appropriate value after rendering.
(WebCore::AudioDestinationNode::isPlayingDidChange):
Call updateIsEffectivelyPlayingAudio().
(WebCore::AudioDestinationNode::setIsSilent):
If m_isSilent has changed, call updateIsEffectivelyPlayingAudio().
(WebCore::AudioDestinationNode::updateIsEffectivelyPlayingAudio):
If m_isEffectivelyPlayingAudio has changed, call AudioContext::isPlayingAudioDidChange().
* Modules/webaudio/AudioDestinationNode.h:
(WebCore::AudioDestinationNode::isPlaying):
(WebCore::AudioDestinationNode::isPlayingAudio):

* Modules/webaudio/DefaultAudioDestinationNode.cpp:
(WebCore::DefaultAudioDestinationNode::isPlaying):
Return whether the AudioDestination is playing.
* Modules/webaudio/DefaultAudioDestinationNode.h:

* platform/audio/AudioIOCallback.h:
* platform/audio/ios/AudioDestinationIOS.cpp:
(WebCore::AudioDestinationIOS::start):
Call setIsPlaying() instead.
(WebCore::AudioDestinationIOS::stop):
Ditto.
(WebCore::AudioDestinationIOS::setIsPlaying):
If m_isPlaying has changed, call AudioIOCallback::isPlayingDidChange().
* platform/audio/ios/AudioDestinationIOS.h:

* platform/audio/mac/AudioDestinationMac.cpp:
(WebCore::AudioDestinationMac::start):
Call setIsPlaying() instead.
(WebCore::AudioDestinationMac::stop):
Ditto.
(WebCore::AudioDestinationMac::setIsPlaying):
If m_isPlaying has changed, call AudioIOCallback::isPlayingDidChange().
* platform/audio/mac/AudioDestinationMac.h:

* testing/Internals.cpp:
(WebCore::Internals::isPagePlayingAudio):
* testing/Internals.h:
* testing/Internals.idl:
Add internals.isPagePlayingAudio() for testing.

LayoutTests:

This test checks that Page::isPlayingAudio() returns false before an audio context is created
and before the oscillator node makes a sound. It then starts the oscillator node and checks
that Page::isPlayingAudio() later returns true.

* webaudio/web-audio-is-playing-expected.txt: Added.
* webaudio/web-audio-is-playing.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModuleswebaudioAudioContextcpp">trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp</a></li>
<li><a href="#trunkSourceWebCoreModuleswebaudioAudioContexth">trunk/Source/WebCore/Modules/webaudio/AudioContext.h</a></li>
<li><a href="#trunkSourceWebCoreModuleswebaudioAudioDestinationNodecpp">trunk/Source/WebCore/Modules/webaudio/AudioDestinationNode.cpp</a></li>
<li><a href="#trunkSourceWebCoreModuleswebaudioAudioDestinationNodeh">trunk/Source/WebCore/Modules/webaudio/AudioDestinationNode.h</a></li>
<li><a href="#trunkSourceWebCoreModuleswebaudioDefaultAudioDestinationNodecpp">trunk/Source/WebCore/Modules/webaudio/DefaultAudioDestinationNode.cpp</a></li>
<li><a href="#trunkSourceWebCoreModuleswebaudioDefaultAudioDestinationNodeh">trunk/Source/WebCore/Modules/webaudio/DefaultAudioDestinationNode.h</a></li>
<li><a href="#trunkSourceWebCoreplatformaudioAudioIOCallbackh">trunk/Source/WebCore/platform/audio/AudioIOCallback.h</a></li>
<li><a href="#trunkSourceWebCoreplatformaudioiosAudioDestinationIOScpp">trunk/Source/WebCore/platform/audio/ios/AudioDestinationIOS.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformaudioiosAudioDestinationIOSh">trunk/Source/WebCore/platform/audio/ios/AudioDestinationIOS.h</a></li>
<li><a href="#trunkSourceWebCoreplatformaudiomacAudioDestinationMaccpp">trunk/Source/WebCore/platform/audio/mac/AudioDestinationMac.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformaudiomacAudioDestinationMach">trunk/Source/WebCore/platform/audio/mac/AudioDestinationMac.h</a></li>
<li><a href="#trunkSourceWebCoretestingInternalscpp">trunk/Source/WebCore/testing/Internals.cpp</a></li>
<li><a href="#trunkSourceWebCoretestingInternalsh">trunk/Source/WebCore/testing/Internals.h</a></li>
<li><a href="#trunkSourceWebCoretestingInternalsidl">trunk/Source/WebCore/testing/Internals.idl</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestswebaudiowebaudioisplayingexpectedtxt">trunk/LayoutTests/webaudio/web-audio-is-playing-expected.txt</a></li>
<li><a href="#trunkLayoutTestswebaudiowebaudioisplayinghtml">trunk/LayoutTests/webaudio/web-audio-is-playing.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (176349 => 176350)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-11-19 22:51:40 UTC (rev 176349)
+++ trunk/LayoutTests/ChangeLog        2014-11-19 22:58:43 UTC (rev 176350)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2014-11-18  Ada Chan  &lt;adachan@apple.com&gt;
+
+        Take Web Audio into account for the Page::isPlayingAudio() API.
+        https://bugs.webkit.org/show_bug.cgi?id=137464
+
+        Reviewed by Jer Noble.
+
+        This test checks that Page::isPlayingAudio() returns false before an audio context is created
+        and before the oscillator node makes a sound. It then starts the oscillator node and checks
+        that Page::isPlayingAudio() later returns true.
+
+        * webaudio/web-audio-is-playing-expected.txt: Added.
+        * webaudio/web-audio-is-playing.html: Added.
+
</ins><span class="cx"> 2014-11-19  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Add layout test for throttling of DOM timer changing the style of visible and invisible elements
</span></span></pre></div>
<a id="trunkLayoutTestswebaudiowebaudioisplayingexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/webaudio/web-audio-is-playing-expected.txt (0 => 176350)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/webaudio/web-audio-is-playing-expected.txt                                (rev 0)
+++ trunk/LayoutTests/webaudio/web-audio-is-playing-expected.txt        2014-11-19 22:58:43 UTC (rev 176350)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+Testing Page::isPlayingAudio() with web audio
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+PASS window.internals.isPagePlayingAudio() is false
+PASS window.internals.isPagePlayingAudio() is false
+PASS window.internals.isPagePlayingAudio() became true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestswebaudiowebaudioisplayinghtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/webaudio/web-audio-is-playing.html (0 => 176350)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/webaudio/web-audio-is-playing.html                                (rev 0)
+++ trunk/LayoutTests/webaudio/web-audio-is-playing.html        2014-11-19 22:58:43 UTC (rev 176350)
</span><span class="lines">@@ -0,0 +1,31 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+    &lt;script src=&quot;../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+    &lt;script&gt;
+        description(&quot;Testing Page::isPlayingAudio() with web audio&quot;);
+
+        jsTestIsAsync = true;
+
+        if (window.internals)
+            shouldBeFalse(&quot;window.internals.isPagePlayingAudio()&quot;);
+
+        var context = new webkitAudioContext();
+        var frequency = 300;
+        var oscillator = context.createOscillator();
+
+        if (window.internals)
+            shouldBeFalse(&quot;window.internals.isPagePlayingAudio()&quot;);
+
+        oscillator.frequency.value = frequency;
+        oscillator.type = 0;
+        oscillator.connect(context.destination);
+        oscillator.start(0);
+
+        shouldBecomeEqual(&quot;window.internals.isPagePlayingAudio()&quot;, &quot;true&quot;, finishJSTest);
+    &lt;/script&gt;
+    &lt;script src=&quot;../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (176349 => 176350)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-11-19 22:51:40 UTC (rev 176349)
+++ trunk/Source/WebCore/ChangeLog        2014-11-19 22:58:43 UTC (rev 176350)
</span><span class="lines">@@ -1,3 +1,80 @@
</span><ins>+2014-11-18  Ada Chan  &lt;adachan@apple.com&gt;
+
+        Take Web Audio into account for the Page::isPlayingAudio() API.
+        https://bugs.webkit.org/show_bug.cgi?id=137464
+
+        Reviewed by Jer Noble.
+
+        Make AudioContext a subclass of AudioProducer. It figures out whether there's
+        audio playing by checking whether its AudioDestinationNode is playing (and not
+        silent). It calls Document::updateIsPlayingAudio() whenever its audio playing
+        state has changed.
+
+        Test: webaudio/web-audio-is-playing.html
+
+        * Modules/webaudio/AudioContext.cpp:
+        (WebCore::AudioContext::lazyInitialize):
+        Add itself to the Document's list of AudioProducers if it's not an offline
+        audio context.
+        (WebCore::AudioContext::uninitialize):
+        Remove itself from the Document's list of AudioProducers if it's not an offline
+        audio context.
+        (WebCore::AudioContext::stop):
+        Tell the document to update its audio playing state.
+        (WebCore::AudioContext::isPlayingAudio):
+        Return true if the audio context hasn't been stopped and its destination node is
+        playing audio.
+        (WebCore::AudioContext::pageMutedStateDidChange):
+        Add a FIXME for now.
+        (WebCore::AudioContext::isPlayingAudioDidChange):
+        Call Document::updateIsPlayingAudio().
+        * Modules/webaudio/AudioContext.h:
+
+        * Modules/webaudio/AudioDestinationNode.cpp:
+        (WebCore::AudioDestinationNode::AudioDestinationNode):
+        Initialize m_isSilent and m_isEffectivelyPlayingAudio.
+        (WebCore::AudioDestinationNode::render):
+        Call setIsSilent() with the appropriate value after rendering.
+        (WebCore::AudioDestinationNode::isPlayingDidChange):
+        Call updateIsEffectivelyPlayingAudio().
+        (WebCore::AudioDestinationNode::setIsSilent):
+        If m_isSilent has changed, call updateIsEffectivelyPlayingAudio().
+        (WebCore::AudioDestinationNode::updateIsEffectivelyPlayingAudio):
+        If m_isEffectivelyPlayingAudio has changed, call AudioContext::isPlayingAudioDidChange().
+        * Modules/webaudio/AudioDestinationNode.h:
+        (WebCore::AudioDestinationNode::isPlaying):
+        (WebCore::AudioDestinationNode::isPlayingAudio):
+
+        * Modules/webaudio/DefaultAudioDestinationNode.cpp:
+        (WebCore::DefaultAudioDestinationNode::isPlaying):
+        Return whether the AudioDestination is playing.
+        * Modules/webaudio/DefaultAudioDestinationNode.h:
+
+        * platform/audio/AudioIOCallback.h:
+        * platform/audio/ios/AudioDestinationIOS.cpp:
+        (WebCore::AudioDestinationIOS::start):
+        Call setIsPlaying() instead.
+        (WebCore::AudioDestinationIOS::stop):
+        Ditto.
+        (WebCore::AudioDestinationIOS::setIsPlaying):
+        If m_isPlaying has changed, call AudioIOCallback::isPlayingDidChange().
+        * platform/audio/ios/AudioDestinationIOS.h:
+
+        * platform/audio/mac/AudioDestinationMac.cpp:
+        (WebCore::AudioDestinationMac::start):
+        Call setIsPlaying() instead.
+        (WebCore::AudioDestinationMac::stop):
+        Ditto.
+        (WebCore::AudioDestinationMac::setIsPlaying):
+        If m_isPlaying has changed, call AudioIOCallback::isPlayingDidChange().
+        * platform/audio/mac/AudioDestinationMac.h:
+
+        * testing/Internals.cpp:
+        (WebCore::Internals::isPagePlayingAudio):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+        Add internals.isPagePlayingAudio() for testing.
+
</ins><span class="cx"> 2014-11-19  Daniel Bates  &lt;dabates@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Attempt to fix the Apple Internal Mountain Lion build after &lt;https://trac.webkit.org/changeset/176347&gt;
</span></span></pre></div>
<a id="trunkSourceWebCoreModuleswebaudioAudioContextcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp (176349 => 176350)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp        2014-11-19 22:51:40 UTC (rev 176349)
+++ trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp        2014-11-19 22:58:43 UTC (rev 176350)
</span><span class="lines">@@ -219,6 +219,8 @@
</span><span class="cx">                 m_destinationNode-&gt;initialize();
</span><span class="cx"> 
</span><span class="cx">                 if (!isOfflineContext()) {
</span><ins>+                    document()-&gt;addAudioProducer(this);
+
</ins><span class="cx">                     // This starts the audio thread. The destination node's provideInput() method will now be called repeatedly to render audio.
</span><span class="cx">                     // Each time provideInput() is called, a portion of the audio stream is rendered. Let's call this time period a &quot;render quantum&quot;.
</span><span class="cx">                     // NOTE: for now default AudioContext does not need an explicit startRendering() call from JavaScript.
</span><span class="lines">@@ -264,6 +266,8 @@
</span><span class="cx">     m_isAudioThreadFinished = true;
</span><span class="cx"> 
</span><span class="cx">     if (!isOfflineContext()) {
</span><ins>+        document()-&gt;removeAudioProducer(this);
+
</ins><span class="cx">         ASSERT(s_hardwareContextCount);
</span><span class="cx">         --s_hardwareContextCount;
</span><span class="cx">     }
</span><span class="lines">@@ -297,6 +301,8 @@
</span><span class="cx">         return;
</span><span class="cx">     m_isStopScheduled = true;
</span><span class="cx"> 
</span><ins>+    document()-&gt;updateIsPlayingAudio();
+
</ins><span class="cx">     // Don't call uninitialize() immediately here because the ScriptExecutionContext is in the middle
</span><span class="cx">     // of dealing with all of its ActiveDOMObjects at this point. uninitialize() can de-reference other
</span><span class="cx">     // ActiveDOMObjects so let's schedule uninitialize() to be called later.
</span><span class="lines">@@ -962,6 +968,21 @@
</span><span class="cx">     removeBehaviorRestriction(AudioContext::RequirePageConsentForAudioStartRestriction);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool AudioContext::isPlayingAudio()
+{
+    return !m_isStopScheduled &amp;&amp; m_destinationNode &amp;&amp; m_destinationNode-&gt;isPlayingAudio();
+}
+
+void AudioContext::pageMutedStateDidChange()
+{
+    // FIXME https://bugs.webkit.org/show_bug.cgi?id=138104: Handle muting web audio.
+}
+
+void AudioContext::isPlayingAudioDidChange()
+{
+    document()-&gt;updateIsPlayingAudio();
+}
+
</ins><span class="cx"> void AudioContext::fireCompletionEvent()
</span><span class="cx"> {
</span><span class="cx">     ASSERT(isMainThread());
</span></span></pre></div>
<a id="trunkSourceWebCoreModuleswebaudioAudioContexth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/webaudio/AudioContext.h (176349 => 176350)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/webaudio/AudioContext.h        2014-11-19 22:51:40 UTC (rev 176349)
+++ trunk/Source/WebCore/Modules/webaudio/AudioContext.h        2014-11-19 22:58:43 UTC (rev 176350)
</span><span class="lines">@@ -29,6 +29,7 @@
</span><span class="cx"> #include &quot;AsyncAudioDecoder.h&quot;
</span><span class="cx"> #include &quot;AudioBus.h&quot;
</span><span class="cx"> #include &quot;AudioDestinationNode.h&quot;
</span><ins>+#include &quot;AudioProducer.h&quot;
</ins><span class="cx"> #include &quot;EventListener.h&quot;
</span><span class="cx"> #include &quot;EventTarget.h&quot;
</span><span class="cx"> #include &quot;MediaCanStartListener.h&quot;
</span><span class="lines">@@ -73,7 +74,7 @@
</span><span class="cx"> // AudioContext is the cornerstone of the web audio API and all AudioNodes are created from it.
</span><span class="cx"> // For thread safety between the audio thread and the main thread, it has a rendering graph locking mechanism. 
</span><span class="cx"> 
</span><del>-class AudioContext : public ActiveDOMObject, public ThreadSafeRefCounted&lt;AudioContext&gt;, public EventTargetWithInlineData, public MediaCanStartListener {
</del><ins>+class AudioContext : public ActiveDOMObject, public ThreadSafeRefCounted&lt;AudioContext&gt;, public EventTargetWithInlineData, public MediaCanStartListener, public AudioProducer {
</ins><span class="cx"> public:
</span><span class="cx">     // Create an AudioContext for rendering to the audio hardware.
</span><span class="cx">     static PassRefPtr&lt;AudioContext&gt; create(Document&amp;, ExceptionCode&amp;);
</span><span class="lines">@@ -257,6 +258,8 @@
</span><span class="cx">     void addBehaviorRestriction(BehaviorRestrictions restriction) { m_restrictions |= restriction; }
</span><span class="cx">     void removeBehaviorRestriction(BehaviorRestrictions restriction) { m_restrictions &amp;= ~restriction; }
</span><span class="cx"> 
</span><ins>+    void isPlayingAudioDidChange();
+
</ins><span class="cx"> protected:
</span><span class="cx">     explicit AudioContext(Document&amp;);
</span><span class="cx">     AudioContext(Document&amp;, unsigned numberOfChannels, size_t numberOfFrames, float sampleRate);
</span><span class="lines">@@ -280,6 +283,10 @@
</span><span class="cx"> 
</span><span class="cx">     virtual void mediaCanStart() override;
</span><span class="cx"> 
</span><ins>+    // AudioProducer
+    virtual bool isPlayingAudio() override;
+    virtual void pageMutedStateDidChange() override;
+
</ins><span class="cx">     bool m_isInitialized;
</span><span class="cx">     bool m_isAudioThreadFinished;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModuleswebaudioAudioDestinationNodecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/webaudio/AudioDestinationNode.cpp (176349 => 176350)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/webaudio/AudioDestinationNode.cpp        2014-11-19 22:51:40 UTC (rev 176349)
+++ trunk/Source/WebCore/Modules/webaudio/AudioDestinationNode.cpp        2014-11-19 22:58:43 UTC (rev 176350)
</span><span class="lines">@@ -39,6 +39,8 @@
</span><span class="cx"> AudioDestinationNode::AudioDestinationNode(AudioContext* context, float sampleRate)
</span><span class="cx">     : AudioNode(context, sampleRate)
</span><span class="cx">     , m_currentSampleFrame(0)
</span><ins>+    , m_isSilent(true)
+    , m_isEffectivelyPlayingAudio(false)
</ins><span class="cx"> {
</span><span class="cx">     addInput(std::make_unique&lt;AudioNodeInput&gt;(this));
</span><span class="cx">     
</span><span class="lines">@@ -61,16 +63,19 @@
</span><span class="cx">     
</span><span class="cx">     if (!context()-&gt;isInitialized()) {
</span><span class="cx">         destinationBus-&gt;zero();
</span><ins>+        setIsSilent(true);
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if (context()-&gt;userGestureRequiredForAudioStart()) {
</span><span class="cx">         destinationBus-&gt;zero();
</span><ins>+        setIsSilent(true);
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if (context()-&gt;pageConsentRequiredForAudioStart()) {
</span><span class="cx">         destinationBus-&gt;zero();
</span><ins>+        setIsSilent(true);
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -100,8 +105,35 @@
</span><span class="cx">     
</span><span class="cx">     // Advance current sample-frame.
</span><span class="cx">     m_currentSampleFrame += numberOfFrames;
</span><ins>+
+    setIsSilent(destinationBus-&gt;isSilent());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void AudioDestinationNode::isPlayingDidChange()
+{
+    updateIsEffectivelyPlayingAudio();
+}
+
+void AudioDestinationNode::setIsSilent(bool isSilent)
+{
+    if (m_isSilent == isSilent)
+        return;
+
+    m_isSilent = isSilent;
+    updateIsEffectivelyPlayingAudio();
+}
+
+void AudioDestinationNode::updateIsEffectivelyPlayingAudio()
+{
+    bool isEffectivelyPlayingAudio = isPlaying() &amp;&amp; !m_isSilent;
+    if (m_isEffectivelyPlayingAudio == isEffectivelyPlayingAudio)
+        return;
+
+    m_isEffectivelyPlayingAudio = isEffectivelyPlayingAudio;
+    if (context())
+        context()-&gt;isPlayingAudioDidChange();
+}
+
</ins><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(WEB_AUDIO)
</span></span></pre></div>
<a id="trunkSourceWebCoreModuleswebaudioAudioDestinationNodeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/webaudio/AudioDestinationNode.h (176349 => 176350)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/webaudio/AudioDestinationNode.h        2014-11-19 22:51:40 UTC (rev 176349)
+++ trunk/Source/WebCore/Modules/webaudio/AudioDestinationNode.h        2014-11-19 22:58:43 UTC (rev 176350)
</span><span class="lines">@@ -60,7 +60,11 @@
</span><span class="cx">     virtual void startRendering() = 0;
</span><span class="cx"> 
</span><span class="cx">     AudioSourceProvider* localAudioInputProvider() { return &amp;m_localAudioInputProvider; }
</span><del>-    
</del><ins>+
+    virtual bool isPlaying() { return false; }
+    virtual void isPlayingDidChange() override;
+    bool isPlayingAudio() const { return m_isEffectivelyPlayingAudio; }
+
</ins><span class="cx"> protected:
</span><span class="cx">     // LocalAudioInputProvider allows us to expose an AudioSourceProvider for local/live audio input.
</span><span class="cx">     // If there is local/live audio input, we call set() with the audio input data every render quantum.
</span><span class="lines">@@ -93,10 +97,15 @@
</span><span class="cx">     virtual double tailTime() const override { return 0; }
</span><span class="cx">     virtual double latencyTime() const override { return 0; }
</span><span class="cx"> 
</span><ins>+    void setIsSilent(bool);
+    void updateIsEffectivelyPlayingAudio();
+
</ins><span class="cx">     // Counts the number of sample-frames processed by the destination.
</span><span class="cx">     size_t m_currentSampleFrame;
</span><span class="cx"> 
</span><span class="cx">     LocalAudioInputProvider m_localAudioInputProvider;
</span><ins>+    bool m_isSilent;
+    bool m_isEffectivelyPlayingAudio;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreModuleswebaudioDefaultAudioDestinationNodecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/webaudio/DefaultAudioDestinationNode.cpp (176349 => 176350)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/webaudio/DefaultAudioDestinationNode.cpp        2014-11-19 22:51:40 UTC (rev 176349)
+++ trunk/Source/WebCore/Modules/webaudio/DefaultAudioDestinationNode.cpp        2014-11-19 22:58:43 UTC (rev 176350)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx"> 
</span><span class="cx"> #include &quot;DefaultAudioDestinationNode.h&quot;
</span><span class="cx"> 
</span><ins>+#include &quot;AudioContext.h&quot;
</ins><span class="cx"> #include &quot;ExceptionCode.h&quot;
</span><span class="cx"> #include &quot;Logging.h&quot;
</span><span class="cx"> #include &lt;wtf/MainThread.h&gt;
</span><span class="lines">@@ -133,6 +134,11 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool DefaultAudioDestinationNode::isPlaying()
+{
+    return m_destination &amp;&amp; m_destination-&gt;isPlaying();
+}
+
</ins><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(WEB_AUDIO)
</span></span></pre></div>
<a id="trunkSourceWebCoreModuleswebaudioDefaultAudioDestinationNodeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/webaudio/DefaultAudioDestinationNode.h (176349 => 176350)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/webaudio/DefaultAudioDestinationNode.h        2014-11-19 22:51:40 UTC (rev 176349)
+++ trunk/Source/WebCore/Modules/webaudio/DefaultAudioDestinationNode.h        2014-11-19 22:58:43 UTC (rev 176350)
</span><span class="lines">@@ -51,7 +51,8 @@
</span><span class="cx">     virtual void enableInput(const String&amp; inputDeviceId) override;
</span><span class="cx">     virtual void startRendering() override;
</span><span class="cx">     virtual unsigned long maxChannelCount() const override;
</span><del>-    
</del><ins>+    virtual bool isPlaying() override;
+
</ins><span class="cx"> private:
</span><span class="cx">     explicit DefaultAudioDestinationNode(AudioContext*);
</span><span class="cx">     void createDestination();
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudioAudioIOCallbackh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/AudioIOCallback.h (176349 => 176350)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/AudioIOCallback.h        2014-11-19 22:51:40 UTC (rev 176349)
+++ trunk/Source/WebCore/platform/audio/AudioIOCallback.h        2014-11-19 22:58:43 UTC (rev 176350)
</span><span class="lines">@@ -40,6 +40,8 @@
</span><span class="cx">     // Optional audio input is given in sourceBus (if it's not 0).
</span><span class="cx">     virtual void render(AudioBus* sourceBus, AudioBus* destinationBus, size_t framesToProcess) = 0;
</span><span class="cx"> 
</span><ins>+    virtual void isPlayingDidChange() = 0;
+
</ins><span class="cx">     virtual ~AudioIOCallback() { }
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudioiosAudioDestinationIOScpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/ios/AudioDestinationIOS.cpp (176349 => 176350)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/ios/AudioDestinationIOS.cpp        2014-11-19 22:51:40 UTC (rev 176349)
+++ trunk/Source/WebCore/platform/audio/ios/AudioDestinationIOS.cpp        2014-11-19 22:58:43 UTC (rev 176350)
</span><span class="lines">@@ -191,7 +191,7 @@
</span><span class="cx"> 
</span><span class="cx">     OSStatus result = AudioOutputUnitStart(m_outputUnit);
</span><span class="cx">     if (!result)
</span><del>-        m_isPlaying = true;
</del><ins>+        setIsPlaying(true);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void AudioDestinationIOS::stop()
</span><span class="lines">@@ -204,7 +204,7 @@
</span><span class="cx"> 
</span><span class="cx">     OSStatus result = AudioOutputUnitStop(m_outputUnit);
</span><span class="cx">     if (!result)
</span><del>-        m_isPlaying = false;
</del><ins>+        setIsPlaying(false);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // Pulls on our provider to get rendered audio stream.
</span><span class="lines">@@ -225,6 +225,15 @@
</span><span class="cx">     return noErr;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void AudioDestinationIOS::setIsPlaying(bool isPlaying)
+{
+    if (m_isPlaying == isPlaying)
+        return;
+
+    m_isPlaying = isPlaying;
+    m_callback.isPlayingDidChange();
+}
+
</ins><span class="cx"> // DefaultOutputUnit callback
</span><span class="cx"> OSStatus AudioDestinationIOS::inputProc(void* userData, AudioUnitRenderActionFlags*, const AudioTimeStamp*, UInt32 /*busNumber*/, UInt32 numberOfFrames, AudioBufferList* ioData)
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudioiosAudioDestinationIOSh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/ios/AudioDestinationIOS.h (176349 => 176350)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/ios/AudioDestinationIOS.h        2014-11-19 22:51:40 UTC (rev 176349)
+++ trunk/Source/WebCore/platform/audio/ios/AudioDestinationIOS.h        2014-11-19 22:58:43 UTC (rev 176350)
</span><span class="lines">@@ -70,6 +70,7 @@
</span><span class="cx">     friend float AudioDestination::hardwareSampleRate();
</span><span class="cx"> 
</span><span class="cx">     OSStatus render(UInt32 numberOfFrames, AudioBufferList* ioData);
</span><ins>+    void setIsPlaying(bool);
</ins><span class="cx"> 
</span><span class="cx">     AudioUnit m_outputUnit;
</span><span class="cx">     AudioIOCallback&amp; m_callback;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudiomacAudioDestinationMaccpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/mac/AudioDestinationMac.cpp (176349 => 176350)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/mac/AudioDestinationMac.cpp        2014-11-19 22:51:40 UTC (rev 176349)
+++ trunk/Source/WebCore/platform/audio/mac/AudioDestinationMac.cpp        2014-11-19 22:58:43 UTC (rev 176350)
</span><span class="lines">@@ -144,7 +144,7 @@
</span><span class="cx">     OSStatus result = AudioOutputUnitStart(m_outputUnit);
</span><span class="cx"> 
</span><span class="cx">     if (!result)
</span><del>-        m_isPlaying = true;
</del><ins>+        setIsPlaying(true);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void AudioDestinationMac::stop()
</span><span class="lines">@@ -152,7 +152,7 @@
</span><span class="cx">     OSStatus result = AudioOutputUnitStop(m_outputUnit);
</span><span class="cx"> 
</span><span class="cx">     if (!result)
</span><del>-        m_isPlaying = false;
</del><ins>+        setIsPlaying(false);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // Pulls on our provider to get rendered audio stream.
</span><span class="lines">@@ -174,6 +174,15 @@
</span><span class="cx">     return noErr;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void AudioDestinationMac::setIsPlaying(bool isPlaying)
+{
+    if (m_isPlaying == isPlaying)
+        return;
+
+    m_isPlaying = isPlaying;
+    m_callback.isPlayingDidChange();
+}
+
</ins><span class="cx"> // DefaultOutputUnit callback
</span><span class="cx"> OSStatus AudioDestinationMac::inputProc(void* userData, AudioUnitRenderActionFlags*, const AudioTimeStamp*, UInt32 /*busNumber*/, UInt32 numberOfFrames, AudioBufferList* ioData)
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudiomacAudioDestinationMach"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/mac/AudioDestinationMac.h (176349 => 176350)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/mac/AudioDestinationMac.h        2014-11-19 22:51:40 UTC (rev 176349)
+++ trunk/Source/WebCore/platform/audio/mac/AudioDestinationMac.h        2014-11-19 22:58:43 UTC (rev 176350)
</span><span class="lines">@@ -51,6 +51,7 @@
</span><span class="cx">     static OSStatus inputProc(void* userData, AudioUnitRenderActionFlags*, const AudioTimeStamp*, UInt32 busNumber, UInt32 numberOfFrames, AudioBufferList* ioData);
</span><span class="cx"> 
</span><span class="cx">     OSStatus render(UInt32 numberOfFrames, AudioBufferList* ioData);
</span><ins>+    void setIsPlaying(bool);
</ins><span class="cx"> 
</span><span class="cx">     virtual MediaSession::MediaType mediaType() const override { return MediaSession::WebAudio; }
</span><span class="cx">     virtual MediaSession::MediaType presentationType() const { return MediaSession::WebAudio; }
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.cpp (176349 => 176350)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.cpp        2014-11-19 22:51:40 UTC (rev 176349)
+++ trunk/Source/WebCore/testing/Internals.cpp        2014-11-19 22:58:43 UTC (rev 176350)
</span><span class="lines">@@ -2410,4 +2410,13 @@
</span><span class="cx">         page-&gt;setMuted(muted);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool Internals::isPagePlayingAudio()
+{
+    Document* document = contextDocument();
+    if (!document || !document-&gt;page())
+        return false;
+
+    return document-&gt;page()-&gt;isPlayingAudio();
</ins><span class="cx"> }
</span><ins>+
+}
</ins></span></pre></div>
<a id="trunkSourceWebCoretestingInternalsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.h (176349 => 176350)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.h        2014-11-19 22:51:40 UTC (rev 176349)
+++ trunk/Source/WebCore/testing/Internals.h        2014-11-19 22:58:43 UTC (rev 176350)
</span><span class="lines">@@ -349,6 +349,7 @@
</span><span class="cx">     String pageOverlayLayerTreeAsText(ExceptionCode&amp;) const;
</span><span class="cx"> 
</span><span class="cx">     void setPageMuted(bool);
</span><ins>+    bool isPagePlayingAudio();
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     explicit Internals(Document*);
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalsidl"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.idl (176349 => 176350)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.idl        2014-11-19 22:51:40 UTC (rev 176349)
+++ trunk/Source/WebCore/testing/Internals.idl        2014-11-19 22:58:43 UTC (rev 176350)
</span><span class="lines">@@ -304,4 +304,5 @@
</span><span class="cx">     [RaisesException] DOMString pageOverlayLayerTreeAsText();
</span><span class="cx"> 
</span><span class="cx">     void setPageMuted(boolean muted);
</span><ins>+    boolean isPagePlayingAudio();
</ins><span class="cx"> };
</span></span></pre>
</div>
</div>

</body>
</html>