| Index: third_party/WebKit/Source/modules/webaudio/AudioWorkletGlobalScope.cpp
|
| diff --git a/third_party/WebKit/Source/modules/webaudio/AudioWorkletGlobalScope.cpp b/third_party/WebKit/Source/modules/webaudio/AudioWorkletGlobalScope.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..dd7dac60a6db42bd3ca4bb09669e78f5735080d4
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/modules/webaudio/AudioWorkletGlobalScope.cpp
|
| @@ -0,0 +1,107 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "modules/webaudio/AudioWorkletGlobalScope.h"
|
| +
|
| +#include "bindings/core/v8/V8BindingMacros.h"
|
| +#include "bindings/core/v8/WorkerOrWorkletScriptController.h"
|
| +#include "core/dom/ExceptionCode.h"
|
| +#include "core/inspector/MainThreadDebugger.h"
|
| +#include "modules/webaudio/AudioWorkletProcessorDefinition.h"
|
| +
|
| +namespace blink {
|
| +
|
| +// static
|
| +AudioWorkletGlobalScope* AudioWorkletGlobalScope::create(LocalFrame* frame, const KURL& url, const String& userAgent, PassRefPtr<SecurityOrigin> securityOrigin, v8::Isolate* isolate)
|
| +{
|
| + AudioWorkletGlobalScope* audioWorkletGlobalScope = new AudioWorkletGlobalScope(frame, url, userAgent, securityOrigin, isolate);
|
| + audioWorkletGlobalScope->scriptController()->initializeContextIfNeeded();
|
| + MainThreadDebugger::instance()->contextCreated(audioWorkletGlobalScope->scriptController()->getScriptState(), audioWorkletGlobalScope->frame(), audioWorkletGlobalScope->getSecurityOrigin());
|
| + return audioWorkletGlobalScope;
|
| +}
|
| +
|
| +AudioWorkletGlobalScope::AudioWorkletGlobalScope(LocalFrame* frame, const KURL& url, const String& userAgent, PassRefPtr<SecurityOrigin> securityOrigin, v8::Isolate* isolate)
|
| + : WorkletGlobalScope(frame, url, userAgent, securityOrigin, isolate)
|
| +{
|
| +}
|
| +
|
| +AudioWorkletGlobalScope::~AudioWorkletGlobalScope()
|
| +{
|
| +}
|
| +
|
| +void AudioWorkletGlobalScope::dispose()
|
| +{
|
| + // Explicitly clear the processor definitions to break a reference cycle
|
| + // between them and this global scope.
|
| + m_processorDefinitions.clear();
|
| +
|
| + WorkletGlobalScope::dispose();
|
| +}
|
| +
|
| +void AudioWorkletGlobalScope::registerAudioWorkletProcessor(const String& name, const ScriptValue& ctorValue, ExceptionState& exceptionState)
|
| +{
|
| + if (m_processorDefinitions.contains(name)) {
|
| + exceptionState.throwDOMException(NotSupportedError, "A class with name:'" + name + "' is already registered.");
|
| + return;
|
| + }
|
| +
|
| + if (name.isEmpty()) {
|
| + exceptionState.throwTypeError("The empty string is not a valid name.");
|
| + return;
|
| + }
|
| +
|
| + v8::Isolate* isolate = scriptController()->getScriptState()->isolate();
|
| + v8::Local<v8::Context> context = scriptController()->context();
|
| +
|
| + ASSERT(ctorValue.v8Value()->IsFunction());
|
| + v8::Local<v8::Function> constructor = v8::Local<v8::Function>::Cast(ctorValue.v8Value());
|
| +
|
| + v8::Local<v8::Value> prototypeValue;
|
| + if (!v8Call(constructor->Get(context, v8String(isolate, "prototype")), prototypeValue))
|
| + return;
|
| +
|
| + if (isUndefinedOrNull(prototypeValue)) {
|
| + exceptionState.throwTypeError("The 'prototype' object on the class does not exist.");
|
| + return;
|
| + }
|
| +
|
| + if (!prototypeValue->IsObject()) {
|
| + exceptionState.throwTypeError("The 'prototype' property on the class is not an object.");
|
| + return;
|
| + }
|
| +
|
| + v8::Local<v8::Object> prototype = v8::Local<v8::Object>::Cast(prototypeValue);
|
| +
|
| + v8::Local<v8::Value> processValue;
|
| + if (!v8Call(prototype->Get(context, v8String(isolate, "process")), processValue))
|
| + return;
|
| +
|
| + if (isUndefinedOrNull(processValue)) {
|
| + exceptionState.throwTypeError("The 'process' function on the prototype does not exist.");
|
| + return;
|
| + }
|
| +
|
| + if (!processValue->IsFunction()) {
|
| + exceptionState.throwTypeError("The 'process' property on the prototype is not a function.");
|
| + return;
|
| + }
|
| +
|
| + v8::Local<v8::Function> process = v8::Local<v8::Function>::Cast(processValue);
|
| +
|
| + AudioWorkletProcessorDefinition* definition = AudioWorkletProcessorDefinition::create(scriptController()->getScriptState(), constructor, process);
|
| + m_processorDefinitions.set(name, definition);
|
| +}
|
| +
|
| +AudioWorkletProcessorDefinition* AudioWorkletGlobalScope::findDefinition(const String& name)
|
| +{
|
| + return m_processorDefinitions.get(name);
|
| +}
|
| +
|
| +DEFINE_TRACE(AudioWorkletGlobalScope)
|
| +{
|
| + visitor->trace(m_processorDefinitions);
|
| + WorkletGlobalScope::trace(visitor);
|
| +}
|
| +
|
| +} // namespace blink
|
|
|