Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / modules / webaudio / AudioScheduledSourceNode.cpp
index 56a5426..5d22c8d 100644 (file)
 
 #include "modules/webaudio/AudioScheduledSourceNode.h"
 
-#include "bindings/v8/ExceptionState.h"
+#include "bindings/core/v8/ExceptionState.h"
+#include "core/dom/CrossThreadTask.h"
 #include "core/dom/ExceptionCode.h"
-#include "core/events/Event.h"
-#include "platform/audio/AudioUtilities.h"
+#include "modules/EventModules.h"
 #include "modules/webaudio/AudioContext.h"
-#include <algorithm>
+#include "platform/audio/AudioUtilities.h"
 #include "wtf/MathExtras.h"
+#include <algorithm>
 
-using namespace std;
-
-namespace WebCore {
+namespace blink {
 
 const double AudioScheduledSourceNode::UnknownTime = -1;
 
@@ -90,11 +89,10 @@ void AudioScheduledSourceNode::updateSchedulingInfo(size_t quantumFrameSize,
     if (m_playbackState == SCHEDULED_STATE) {
         // Increment the active source count only if we're transitioning from SCHEDULED_STATE to PLAYING_STATE.
         m_playbackState = PLAYING_STATE;
-        context()->incrementActiveSourceCount();
     }
 
     quantumFrameOffset = startFrame > quantumStartFrame ? startFrame - quantumStartFrame : 0;
-    quantumFrameOffset = min(quantumFrameOffset, quantumFrameSize); // clamp to valid range
+    quantumFrameOffset = std::min(quantumFrameOffset, quantumFrameSize); // clamp to valid range
     nonSilentFramesToProcess = quantumFrameSize - quantumFrameOffset;
 
     if (!nonSilentFramesToProcess) {
@@ -136,7 +134,6 @@ void AudioScheduledSourceNode::updateSchedulingInfo(size_t quantumFrameSize,
     return;
 }
 
-
 void AudioScheduledSourceNode::start(double when, ExceptionState& exceptionState)
 {
     ASSERT(isMainThread());
@@ -148,6 +145,13 @@ void AudioScheduledSourceNode::start(double when, ExceptionState& exceptionState
         return;
     }
 
+    if (!std::isfinite(when) || (when < 0)) {
+        exceptionState.throwDOMException(
+            InvalidAccessError,
+            "Start time must be a finite non-negative number: " + String::number(when));
+        return;
+    }
+
     m_startTime = when;
     m_playbackState = SCHEDULED_STATE;
 }
@@ -160,19 +164,27 @@ void AudioScheduledSourceNode::stop(double when, ExceptionState& exceptionState)
         exceptionState.throwDOMException(
             InvalidStateError,
             "cannot call stop without calling start first.");
-    } else {
-        // stop() can be called more than once, with the last call to stop taking effect, unless the
-        // source has already stopped due to earlier calls to stop. No exceptions are thrown in any
-        // case.
-        when = max(0.0, when);
-        m_endTime = when;
+        return;
     }
+
+    if (!std::isfinite(when) || (when < 0)) {
+        exceptionState.throwDOMException(
+            InvalidAccessError,
+            "Stop time must be a finite non-negative number: " + String::number(when));
+        return;
+    }
+
+    // stop() can be called more than once, with the last call to stop taking effect, unless the
+    // source has already stopped due to earlier calls to stop. No exceptions are thrown in any
+    // case.
+    when = std::max(0.0, when);
+    m_endTime = when;
 }
 
-void AudioScheduledSourceNode::setOnended(PassRefPtr<EventListener> listener, DOMWrapperWorld* isolatedWorld)
+void AudioScheduledSourceNode::setOnended(PassRefPtr<EventListener> listener)
 {
     m_hasEndedListener = listener;
-    setAttributeEventListener(EventTypeNames::ended, listener, isolatedWorld);
+    setAttributeEventListener(EventTypeNames::ended, listener);
 }
 
 void AudioScheduledSourceNode::finish()
@@ -181,35 +193,18 @@ void AudioScheduledSourceNode::finish()
         // Let the context dereference this AudioNode.
         context()->notifyNodeFinishedProcessing(this);
         m_playbackState = FINISHED_STATE;
-        context()->decrementActiveSourceCount();
     }
 
-    if (m_hasEndedListener) {
-        // |task| will keep the AudioScheduledSourceNode alive until the listener has been handled.
-        OwnPtr<NotifyEndedTask> task = adoptPtr(new NotifyEndedTask(this));
-        callOnMainThread(&AudioScheduledSourceNode::notifyEndedDispatch, task.leakPtr());
+    if (m_hasEndedListener && context()->executionContext()) {
+        context()->executionContext()->postTask(createCrossThreadTask(&AudioScheduledSourceNode::notifyEnded, this));
     }
 }
 
-void AudioScheduledSourceNode::notifyEndedDispatch(void* userData)
-{
-    OwnPtr<NotifyEndedTask> task = adoptPtr(static_cast<NotifyEndedTask*>(userData));
-
-    task->notifyEnded();
-}
-
-AudioScheduledSourceNode::NotifyEndedTask::NotifyEndedTask(PassRefPtr<AudioScheduledSourceNode> sourceNode)
-    : m_scheduledNode(sourceNode)
-{
-}
-
-void AudioScheduledSourceNode::NotifyEndedTask::notifyEnded()
+void AudioScheduledSourceNode::notifyEnded()
 {
-    RefPtr<Event> event = Event::create(EventTypeNames::ended);
-    event->setTarget(m_scheduledNode);
-    m_scheduledNode->dispatchEvent(event.get());
+    dispatchEvent(Event::create(EventTypeNames::ended));
 }
 
-} // namespace WebCore
+} // namespace blink
 
 #endif // ENABLE(WEB_AUDIO)