| OLD | NEW |
| 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/ToV8ForCore.h" | 7 #include "bindings/core/v8/ToV8ForCore.h" |
| 8 #include "bindings/core/v8/V8BindingForCore.h" | 8 #include "bindings/core/v8/V8BindingForCore.h" |
| 9 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" | 9 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" |
| 10 #include "core/dom/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 v8::Isolate* isolate, | 34 v8::Isolate* isolate, |
| 35 WorkerThread* thread) | 35 WorkerThread* thread) |
| 36 : ThreadedWorkletGlobalScope(url, | 36 : ThreadedWorkletGlobalScope(url, |
| 37 user_agent, | 37 user_agent, |
| 38 std::move(security_origin), | 38 std::move(security_origin), |
| 39 isolate, | 39 isolate, |
| 40 thread) {} | 40 thread) {} |
| 41 | 41 |
| 42 AudioWorkletGlobalScope::~AudioWorkletGlobalScope() {} | 42 AudioWorkletGlobalScope::~AudioWorkletGlobalScope() {} |
| 43 | 43 |
| 44 void AudioWorkletGlobalScope::Dispose() { | |
| 45 DCHECK(IsContextThread()); | |
| 46 processor_definition_map_.clear(); | |
| 47 processor_instances_.clear(); | |
| 48 ThreadedWorkletGlobalScope::Dispose(); | |
| 49 } | |
| 50 | |
| 51 void AudioWorkletGlobalScope::registerProcessor( | 44 void AudioWorkletGlobalScope::registerProcessor( |
| 52 const String& name, | 45 const String& name, |
| 53 const ScriptValue& class_definition, | 46 const ScriptValue& class_definition, |
| 54 ExceptionState& exception_state) { | 47 ExceptionState& exception_state) { |
| 55 DCHECK(IsContextThread()); | 48 DCHECK(IsContextThread()); |
| 56 | 49 |
| 57 if (processor_definition_map_.Contains(name)) { | 50 if (processor_definition_map_.Contains(name)) { |
| 58 exception_state.ThrowDOMException( | 51 exception_state.ThrowDOMException( |
| 59 kNotSupportedError, | 52 kNotSupportedError, |
| 60 "A class with name:'" + name + "' is already registered."); | 53 "A class with name:'" + name + "' is already registered."); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 } | 102 } |
| 110 | 103 |
| 111 v8::Local<v8::Function> process_function_local = | 104 v8::Local<v8::Function> process_function_local = |
| 112 process_value_local.As<v8::Function>(); | 105 process_value_local.As<v8::Function>(); |
| 113 | 106 |
| 114 AudioWorkletProcessorDefinition* definition = | 107 AudioWorkletProcessorDefinition* definition = |
| 115 AudioWorkletProcessorDefinition::Create( | 108 AudioWorkletProcessorDefinition::Create( |
| 116 isolate, name, class_definition_local, process_function_local); | 109 isolate, name, class_definition_local, process_function_local); |
| 117 DCHECK(definition); | 110 DCHECK(definition); |
| 118 | 111 |
| 119 processor_definition_map_.Set(name, definition); | 112 processor_definition_map_.Set( |
| 113 name, |
| 114 TraceWrapperMember<AudioWorkletProcessorDefinition>(this, definition)); |
| 120 } | 115 } |
| 121 | 116 |
| 122 AudioWorkletProcessor* AudioWorkletGlobalScope::CreateInstance( | 117 AudioWorkletProcessor* AudioWorkletGlobalScope::CreateInstance( |
| 123 const String& name) { | 118 const String& name) { |
| 124 DCHECK(IsContextThread()); | 119 DCHECK(IsContextThread()); |
| 125 | 120 |
| 126 AudioWorkletProcessorDefinition* definition = FindDefinition(name); | 121 AudioWorkletProcessorDefinition* definition = FindDefinition(name); |
| 127 if (!definition) | 122 if (!definition) |
| 128 return nullptr; | 123 return nullptr; |
| 129 | 124 |
| 130 // V8 object instance construction: this construction process is here to make | 125 // V8 object instance construction: this construction process is here to make |
| 131 // the AudioWorkletProcessor class a thin wrapper of V8::Object instance. | 126 // the AudioWorkletProcessor class a thin wrapper of V8::Object instance. |
| 132 v8::Isolate* isolate = ScriptController()->GetScriptState()->GetIsolate(); | 127 v8::Isolate* isolate = ScriptController()->GetScriptState()->GetIsolate(); |
| 133 v8::Local<v8::Object> instance_local; | 128 v8::Local<v8::Object> instance_local; |
| 134 if (!V8ObjectConstructor::NewInstance(isolate, | 129 if (!V8ObjectConstructor::NewInstance(isolate, |
| 135 definition->ConstructorLocal(isolate)) | 130 definition->ConstructorLocal(isolate)) |
| 136 .ToLocal(&instance_local)) { | 131 .ToLocal(&instance_local)) { |
| 137 return nullptr; | 132 return nullptr; |
| 138 } | 133 } |
| 139 | 134 |
| 140 AudioWorkletProcessor* processor = AudioWorkletProcessor::Create(this, name); | 135 AudioWorkletProcessor* processor = AudioWorkletProcessor::Create(this, name); |
| 141 DCHECK(processor); | 136 DCHECK(processor); |
| 142 | 137 |
| 143 processor->SetInstance(isolate, instance_local); | 138 processor->SetInstance(isolate, instance_local); |
| 144 processor_instances_.push_back(processor); | 139 processor_instances_.push_back( |
| 140 TraceWrapperMember<AudioWorkletProcessor>(this, processor)); |
| 145 | 141 |
| 146 return processor; | 142 return processor; |
| 147 } | 143 } |
| 148 | 144 |
| 149 bool AudioWorkletGlobalScope::Process(AudioWorkletProcessor* processor, | 145 bool AudioWorkletGlobalScope::Process(AudioWorkletProcessor* processor, |
| 150 AudioBuffer* input_buffer, | 146 AudioBuffer* input_buffer, |
| 151 AudioBuffer* output_buffer) { | 147 AudioBuffer* output_buffer) { |
| 152 CHECK(input_buffer); | 148 CHECK(input_buffer); |
| 153 CHECK(output_buffer); | 149 CHECK(output_buffer); |
| 154 | 150 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 184 const String& name) { | 180 const String& name) { |
| 185 return processor_definition_map_.at(name); | 181 return processor_definition_map_.at(name); |
| 186 } | 182 } |
| 187 | 183 |
| 188 DEFINE_TRACE(AudioWorkletGlobalScope) { | 184 DEFINE_TRACE(AudioWorkletGlobalScope) { |
| 189 visitor->Trace(processor_definition_map_); | 185 visitor->Trace(processor_definition_map_); |
| 190 visitor->Trace(processor_instances_); | 186 visitor->Trace(processor_instances_); |
| 191 ThreadedWorkletGlobalScope::Trace(visitor); | 187 ThreadedWorkletGlobalScope::Trace(visitor); |
| 192 } | 188 } |
| 193 | 189 |
| 190 DEFINE_TRACE_WRAPPERS(AudioWorkletGlobalScope) { |
| 191 for (auto definition : processor_definition_map_) |
| 192 visitor->TraceWrappers(definition.value); |
| 193 |
| 194 for (auto processor : processor_instances_) |
| 195 visitor->TraceWrappers(processor); |
| 196 |
| 197 ThreadedWorkletGlobalScope::TraceWrappers(visitor); |
| 198 } |
| 199 |
| 194 } // namespace blink | 200 } // namespace blink |
| OLD | NEW |