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

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

Issue 1960533003: [DO NOT SUBMIT] AudioWorklet FS1: importing scripts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "modules/webaudio/AudioWorkletGlobalScope.h"
6
7 #include "bindings/core/v8/V8BindingMacros.h"
8 #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
9 #include "core/dom/ExceptionCode.h"
10 #include "core/inspector/MainThreadDebugger.h"
11 #include "modules/webaudio/AudioWorkletProcessorDefinition.h"
12
13 namespace blink {
14
15 // static
16 AudioWorkletGlobalScope* AudioWorkletGlobalScope::create(LocalFrame* frame, cons t KURL& url, const String& userAgent, PassRefPtr<SecurityOrigin> securityOrigin, v8::Isolate* isolate)
17 {
18 AudioWorkletGlobalScope* audioWorkletGlobalScope = new AudioWorkletGlobalSco pe(frame, url, userAgent, securityOrigin, isolate);
19 audioWorkletGlobalScope->scriptController()->initializeContextIfNeeded();
20 MainThreadDebugger::instance()->contextCreated(audioWorkletGlobalScope->scri ptController()->getScriptState(), audioWorkletGlobalScope->frame(), audioWorklet GlobalScope->getSecurityOrigin());
21 return audioWorkletGlobalScope;
22 }
23
24 AudioWorkletGlobalScope::AudioWorkletGlobalScope(LocalFrame* frame, const KURL& url, const String& userAgent, PassRefPtr<SecurityOrigin> securityOrigin, v8::Iso late* isolate)
25 : WorkletGlobalScope(frame, url, userAgent, securityOrigin, isolate)
26 {
27 }
28
29 AudioWorkletGlobalScope::~AudioWorkletGlobalScope()
30 {
31 }
32
33 void AudioWorkletGlobalScope::dispose()
34 {
35 // Explicitly clear the processor definitions to break a reference cycle
36 // between them and this global scope.
37 m_processorDefinitions.clear();
38
39 WorkletGlobalScope::dispose();
40 }
41
42 void AudioWorkletGlobalScope::registerAudioWorkletProcessor(const String& name, const ScriptValue& ctorValue, ExceptionState& exceptionState)
43 {
44 if (m_processorDefinitions.contains(name)) {
45 exceptionState.throwDOMException(NotSupportedError, "A class with name:' " + name + "' is already registered.");
46 return;
47 }
48
49 if (name.isEmpty()) {
50 exceptionState.throwTypeError("The empty string is not a valid name.");
51 return;
52 }
53
54 v8::Isolate* isolate = scriptController()->getScriptState()->isolate();
55 v8::Local<v8::Context> context = scriptController()->context();
56
57 ASSERT(ctorValue.v8Value()->IsFunction());
58 v8::Local<v8::Function> constructor = v8::Local<v8::Function>::Cast(ctorValu e.v8Value());
59
60 v8::Local<v8::Value> prototypeValue;
61 if (!v8Call(constructor->Get(context, v8String(isolate, "prototype")), proto typeValue))
62 return;
63
64 if (isUndefinedOrNull(prototypeValue)) {
65 exceptionState.throwTypeError("The 'prototype' object on the class does not exist.");
66 return;
67 }
68
69 if (!prototypeValue->IsObject()) {
70 exceptionState.throwTypeError("The 'prototype' property on the class is not an object.");
71 return;
72 }
73
74 v8::Local<v8::Object> prototype = v8::Local<v8::Object>::Cast(prototypeValue );
75
76 v8::Local<v8::Value> processValue;
77 if (!v8Call(prototype->Get(context, v8String(isolate, "process")), processVa lue))
78 return;
79
80 if (isUndefinedOrNull(processValue)) {
81 exceptionState.throwTypeError("The 'process' function on the prototype d oes not exist.");
82 return;
83 }
84
85 if (!processValue->IsFunction()) {
86 exceptionState.throwTypeError("The 'process' property on the prototype i s not a function.");
87 return;
88 }
89
90 v8::Local<v8::Function> process = v8::Local<v8::Function>::Cast(processValue );
91
92 AudioWorkletProcessorDefinition* definition = AudioWorkletProcessorDefinitio n::create(scriptController()->getScriptState(), constructor, process);
93 m_processorDefinitions.set(name, definition);
94 }
95
96 AudioWorkletProcessorDefinition* AudioWorkletGlobalScope::findDefinition(const S tring& name)
97 {
98 return m_processorDefinitions.get(name);
99 }
100
101 DEFINE_TRACE(AudioWorkletGlobalScope)
102 {
103 visitor->trace(m_processorDefinitions);
104 WorkletGlobalScope::trace(visitor);
105 }
106
107 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698