Chromium Code Reviews| Index: Source/modules/webaudio/AudioScheduledSourceNode.cpp |
| diff --git a/Source/modules/webaudio/AudioScheduledSourceNode.cpp b/Source/modules/webaudio/AudioScheduledSourceNode.cpp |
| index c467527aff906266be38459d2e21b6b55404f3ec..bb5236f273ec7113032233a414430cdcf1447add 100644 |
| --- a/Source/modules/webaudio/AudioScheduledSourceNode.cpp |
| +++ b/Source/modules/webaudio/AudioScheduledSourceNode.cpp |
| @@ -42,6 +42,7 @@ const double AudioScheduledSourceNode::UnknownTime = -1; |
| AudioScheduledSourceNode::AudioScheduledSourceNode(AudioContext* context, float sampleRate) |
| : AudioSourceNode(context, sampleRate) |
| + , ActiveDOMObject(context->scriptExecutionContext()) |
| , m_playbackState(UNSCHEDULED_STATE) |
| , m_startTime(0) |
| , m_endTime(UnknownTime) |
| @@ -144,7 +145,7 @@ void AudioScheduledSourceNode::start(double when) |
| m_playbackState = SCHEDULED_STATE; |
| } |
| -void AudioScheduledSourceNode::stop(double when) |
| +void AudioScheduledSourceNode::stopNote(double when) |
| { |
| ASSERT(isMainThread()); |
| if (!(m_playbackState == SCHEDULED_STATE || m_playbackState == PLAYING_STATE)) |
| @@ -161,7 +162,7 @@ void AudioScheduledSourceNode::noteOn(double when) |
| void AudioScheduledSourceNode::noteOff(double when) |
| { |
| - stop(when); |
| + stopNote(when); |
| } |
| void AudioScheduledSourceNode::setOnended(PassRefPtr<EventListener> listener, DOMWrapperWorld* isolatedWorld) |
| @@ -179,8 +180,10 @@ void AudioScheduledSourceNode::finish() |
| context()->decrementActiveSourceCount(); |
| } |
| - if (m_hasEndedListener) |
| + if (m_hasEndedListener) { |
| + setPendingActivity(this); |
|
Ken Russell (switch to Gerrit)
2013/09/09 21:30:05
Sorry, I failed to realize this before. This can't
Ken Russell (switch to Gerrit)
2013/09/09 21:34:31
Apologies, I think I'm wrong. AudioNode::ref is sp
|
| callOnMainThread(&AudioScheduledSourceNode::notifyEndedDispatch, this); |
| + } |
| } |
| void AudioScheduledSourceNode::notifyEndedDispatch(void* userData) |
| @@ -190,9 +193,24 @@ void AudioScheduledSourceNode::notifyEndedDispatch(void* userData) |
| void AudioScheduledSourceNode::notifyEnded() |
| { |
| - RefPtr<Event> event = Event::create(eventNames().endedEvent); |
| - event->setTarget(this); |
| - dispatchEvent(event.get()); |
| + // Avoid firing the event if the document has already gone away. |
| + if (context()->scriptExecutionContext()) { |
| + RefPtr<Event> event = Event::create(eventNames().endedEvent); |
| + event->setTarget(this); |
| + dispatchEvent(event.get()); |
| + } |
| + unsetPendingActivity(this); |
|
Ken Russell (switch to Gerrit)
2013/09/09 19:45:47
This looks wrong now. What happens if we navigate
|
| +} |
| + |
| +ScriptExecutionContext* AudioScheduledSourceNode::scriptExecutionContext() const |
| +{ |
| + return context()->scriptExecutionContext(); |
| +} |
| + |
| +void AudioScheduledSourceNode::stop() |
| +{ |
| + if (hasPendingActivity()) |
| + unsetPendingActivity(this); |
| } |
| } // namespace WebCore |