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

Unified Diff: third_party/WebKit/Source/modules/webaudio/MediaElementAudioSourceNode.cpp

Issue 1952793002: Move the exception logic to the AudioNode creator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 4 years, 7 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
Index: third_party/WebKit/Source/modules/webaudio/MediaElementAudioSourceNode.cpp
diff --git a/third_party/WebKit/Source/modules/webaudio/MediaElementAudioSourceNode.cpp b/third_party/WebKit/Source/modules/webaudio/MediaElementAudioSourceNode.cpp
index a4691864b6752551a083b820a90743a265ff9348..0e5cf9e42c7402560900956bf657a5c9a2cca689 100644
--- a/third_party/WebKit/Source/modules/webaudio/MediaElementAudioSourceNode.cpp
+++ b/third_party/WebKit/Source/modules/webaudio/MediaElementAudioSourceNode.cpp
@@ -206,9 +206,32 @@ MediaElementAudioSourceNode::MediaElementAudioSourceNode(AbstractAudioContext& c
setHandler(MediaElementAudioSourceHandler::create(*this, mediaElement));
}
-MediaElementAudioSourceNode* MediaElementAudioSourceNode::create(AbstractAudioContext& context, HTMLMediaElement& mediaElement)
+MediaElementAudioSourceNode* MediaElementAudioSourceNode::create(AbstractAudioContext& context, HTMLMediaElement& mediaElement, ExceptionState& exceptionState)
{
- return new MediaElementAudioSourceNode(context, mediaElement);
+ DCHECK(isMainThread());
+
+ if (context.isContextClosed()) {
+ context.throwExceptionForClosedState(exceptionState);
+ return nullptr;
+ }
+
+ // First check if this media element already has a source node.
+ if (mediaElement.audioSourceNode()) {
+ exceptionState.throwDOMException(
+ InvalidStateError,
+ "HTMLMediaElement already connected previously to a different MediaElementSourceNode.");
+ return nullptr;
+ }
+
+ MediaElementAudioSourceNode* node = new MediaElementAudioSourceNode(context, mediaElement);
+
+ if (node) {
+ mediaElement.setAudioSourceNode(node);
+ // context keeps reference until node is disconnected
+ context.notifySourceNodeStartedProcessing(node);
+ }
+
+ return node;
}
DEFINE_TRACE(MediaElementAudioSourceNode)

Powered by Google App Engine
This is Rietveld 408576698