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

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/AudioWorkletGlobalScope.cpp

Issue 2727733002: Implement AudioWorkletProcessor interface (Closed)
Patch Set: Addressing feedback Created 3 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/webaudio/AudioWorkletGlobalScope.h" 5 #include "modules/webaudio/AudioWorkletGlobalScope.h"
6 6
7 #include "bindings/core/v8/V8BindingMacros.h"
8 #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
9 #include "core/dom/ExceptionCode.h"
10 #include "modules/webaudio/AudioWorkletProcessorDefinition.h"
7 #include "platform/weborigin/SecurityOrigin.h" 11 #include "platform/weborigin/SecurityOrigin.h"
8 12
9 namespace blink { 13 namespace blink {
10 14
11 AudioWorkletGlobalScope* AudioWorkletGlobalScope::create( 15 AudioWorkletGlobalScope* AudioWorkletGlobalScope::create(
12 const KURL& url, 16 const KURL& url,
13 const String& userAgent, 17 const String& userAgent,
14 PassRefPtr<SecurityOrigin> securityOrigin, 18 PassRefPtr<SecurityOrigin> securityOrigin,
15 v8::Isolate* isolate, 19 v8::Isolate* isolate,
16 WorkerThread* thread) { 20 WorkerThread* thread) {
17 return new AudioWorkletGlobalScope(url, userAgent, std::move(securityOrigin), 21 return new AudioWorkletGlobalScope(url, userAgent, std::move(securityOrigin),
18 isolate, thread); 22 isolate, thread);
19 } 23 }
20 24
21 AudioWorkletGlobalScope::AudioWorkletGlobalScope( 25 AudioWorkletGlobalScope::AudioWorkletGlobalScope(
22 const KURL& url, 26 const KURL& url,
23 const String& userAgent, 27 const String& userAgent,
24 PassRefPtr<SecurityOrigin> securityOrigin, 28 PassRefPtr<SecurityOrigin> securityOrigin,
25 v8::Isolate* isolate, 29 v8::Isolate* isolate,
26 WorkerThread* thread) 30 WorkerThread* thread)
27 : ThreadedWorkletGlobalScope(url, 31 : ThreadedWorkletGlobalScope(url,
28 userAgent, 32 userAgent,
29 std::move(securityOrigin), 33 std::move(securityOrigin),
30 isolate, 34 isolate,
31 thread) {} 35 thread) {}
32 36
33 AudioWorkletGlobalScope::~AudioWorkletGlobalScope() {} 37 AudioWorkletGlobalScope::~AudioWorkletGlobalScope() {}
34 38
39 void AudioWorkletGlobalScope::dispose() {
40 m_processorDefinitionMap.clear();
41 ThreadedWorkletGlobalScope::dispose();
42 }
43
44 void AudioWorkletGlobalScope::registerProcessor(
45 ScriptState* scriptState,
46 const String& name,
47 const ScriptValue& constructor,
48 ExceptionState& exceptionState) {
49 DCHECK(isContextThread());
50
51 if (m_processorDefinitionMap.contains(name)) {
52 exceptionState.throwDOMException(
53 NotSupportedError,
54 "A class with name:'" + name + "' is already registered.");
55 return;
56 }
57
58 if (name.isEmpty()) {
59 exceptionState.throwTypeError("The empty string is not a valid name.");
60 return;
61 }
62
63 v8::Isolate* isolate = scriptState->isolate();
64 v8::Local<v8::Context> context = scriptState->context();
65
66 DCHECK(constructor.v8Value()->IsFunction());
67
68 v8::Local<v8::Function> constructorLocal =
69 v8::Local<v8::Function>::Cast(constructor.v8Value());
70
71 v8::Local<v8::Value> prototypeValue;
72 if (!v8Call(constructorLocal->Get(context, v8String(isolate, "prototype")),
73 prototypeValue))
74 return;
75
76 if (isUndefinedOrNull(prototypeValue)) {
77 exceptionState.throwTypeError(
78 "The 'prototype' object on the class does not exist.");
79 return;
80 }
81
82 if (!prototypeValue->IsObject()) {
83 exceptionState.throwTypeError(
84 "The 'prototype' property on the class is not an object.");
85 return;
86 }
87
88 v8::Local<v8::Object> prototype = v8::Local<v8::Object>::Cast(prototypeValue);
89
90 v8::Local<v8::Value> processValue;
91 if (!v8Call(prototype->Get(context, v8String(isolate, "process")),
haraken 2017/03/08 09:57:19 It looks a bit nasty to look up a prototype object
hongchan 2017/03/08 19:38:46 Yes, this is how it is specced.
92 processValue))
93 return;
94
95 if (isUndefinedOrNull(processValue)) {
96 exceptionState.throwTypeError(
97 "The 'process' function on the prototype does not exist.");
98 return;
99 }
100
101 if (!processValue->IsFunction()) {
102 exceptionState.throwTypeError(
103 "The 'process' property on the prototype is not a function.");
104 return;
105 }
106
107 v8::Local<v8::Function> processLocal =
108 v8::Local<v8::Function>::Cast(processValue);
109
110 AudioWorkletProcessorDefinition* definition =
111 AudioWorkletProcessorDefinition::create(scriptState, constructorLocal,
112 processLocal);
113
114 m_processorDefinitionMap.set(name, definition);
115 }
116
117 AudioWorkletProcessorDefinition* AudioWorkletGlobalScope::findDefinition(
118 const String& name) {
119 return m_processorDefinitionMap.at(name);
120 }
121
122 DEFINE_TRACE(AudioWorkletGlobalScope) {
123 visitor->trace(m_processorDefinitionMap);
124 ThreadedWorkletGlobalScope::trace(visitor);
125 }
126
35 } // namespace blink 127 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698