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

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

Issue 2727733002: Implement AudioWorkletProcessor interface (Closed)
Patch Set: Added AudioWorkletProcessor and AudioWorkletProcessorDefinition classes 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 const String& name,
46 const ScriptValue& ctor,
47 ExceptionState& exceptionState) {
nhiroki 2017/03/06 10:08:44 I'd recommend that threaded objects have thread ch
hongchan 2017/03/06 20:06:11 Good point. I do not have the thread for this code
48 if (m_processorDefinitionMap.contains(name)) {
49 exceptionState.throwDOMException(
50 NotSupportedError,
51 "A class with name:'" + name + "' is already registered.");
52 return;
53 }
54
55 if (name.isEmpty()) {
56 exceptionState.throwTypeError("The empty string is not a valid name.");
57 return;
58 }
59
60 v8::Isolate* isolate = scriptController()->getScriptState()->isolate();
61 v8::Local<v8::Context> context = scriptController()->context();
haraken 2017/03/06 11:51:11 If you pass in [ScriptState] to registerProcessor
hongchan 2017/03/06 20:06:11 Done.
62
63 DCHECK(ctor.v8Value()->IsFunction());
64
65 v8::Local<v8::Function> constructor =
66 v8::Local<v8::Function>::Cast(ctor.v8Value());
67
68 v8::Local<v8::Value> prototypeValue;
69 if (!v8Call(constructor->Get(context, v8String(isolate, "prototype")),
70 prototypeValue))
71 return;
72
73 if (isUndefinedOrNull(prototypeValue)) {
74 exceptionState.throwTypeError(
75 "The 'prototype' object on the class does not exist.");
76 return;
77 }
78
79 if (!prototypeValue->IsObject()) {
80 exceptionState.throwTypeError(
81 "The 'prototype' property on the class is not an object.");
82 return;
83 }
84
85 v8::Local<v8::Object> prototype = v8::Local<v8::Object>::Cast(prototypeValue);
86
87 v8::Local<v8::Value> processValue;
88 if (!v8Call(prototype->Get(context, v8String(isolate, "process")),
89 processValue))
90 return;
91
92 if (isUndefinedOrNull(processValue)) {
93 exceptionState.throwTypeError(
94 "The 'process' function on the prototype does not exist.");
95 return;
96 }
97
98 if (!processValue->IsFunction()) {
99 exceptionState.throwTypeError(
100 "The 'process' property on the prototype is not a function.");
101 return;
102 }
103
104 v8::Local<v8::Function> process = v8::Local<v8::Function>::Cast(processValue);
105
106 AudioWorkletProcessorDefinition* definition =
107 AudioWorkletProcessorDefinition::create(
108 scriptController()->getScriptState(), constructor, process);
109
110 m_processorDefinitionMap.set(name, definition);
111 }
112
113 AudioWorkletProcessorDefinition* AudioWorkletGlobalScope::findDefinition(
114 const String& name) {
115 return m_processorDefinitionMap.at(name);
116 }
117
118 DEFINE_TRACE(AudioWorkletGlobalScope) {
119 visitor->trace(m_processorDefinitionMap);
120 ThreadedWorkletGlobalScope::trace(visitor);
121 }
122
35 } // namespace blink 123 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698