Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2242)

Unified Diff: Source/modules/webaudio/AudioScheduledSourceNode.cpp

Issue 23596014: Keep AudioScheduledSourceNode alive until onended is called. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/webaudio/AudioScheduledSourceNode.cpp
diff --git a/Source/modules/webaudio/AudioScheduledSourceNode.cpp b/Source/modules/webaudio/AudioScheduledSourceNode.cpp
index c467527aff906266be38459d2e21b6b55404f3ec..39e06e752610f0a599276debad244fa76455983c 100644
--- a/Source/modules/webaudio/AudioScheduledSourceNode.cpp
+++ b/Source/modules/webaudio/AudioScheduledSourceNode.cpp
@@ -179,8 +179,11 @@ void AudioScheduledSourceNode::finish()
context()->decrementActiveSourceCount();
}
- if (m_hasEndedListener)
+ if (m_hasEndedListener) {
+ // Reference ourself so we don't accidentally get deleted before notifyEnded gets called.
+ ref();
haraken 2013/09/05 23:42:44 You can just set m_playing to true, and...
callOnMainThread(&AudioScheduledSourceNode::notifyEndedDispatch, this);
+ }
}
void AudioScheduledSourceNode::notifyEndedDispatch(void* userData)
@@ -190,9 +193,15 @@ 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());
+ }
+
+ // Deref to match the ref() call in finish();
+ deref();
haraken 2013/09/05 23:42:44 ... set m_playing to false here. Then you can imp
}
} // namespace WebCore
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698