Chromium Code Reviews| 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/compositorworker/AnimationWorkletGlobalScope.h" | 5 #include "modules/compositorworker/AnimationWorkletGlobalScope.h" |
| 6 | 6 |
| 7 #include "platform/weborigin/SecurityOrigin.h" | 7 #include "platform/weborigin/SecurityOrigin.h" |
| 8 | 8 |
| 9 #include "bindings/core/v8/ExceptionState.h" | 9 #include "bindings/core/v8/ExceptionState.h" |
| 10 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" | 10 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 WorkerThread* thread) | 34 WorkerThread* thread) |
| 35 : ThreadedWorkletGlobalScope(url, | 35 : ThreadedWorkletGlobalScope(url, |
| 36 user_agent, | 36 user_agent, |
| 37 std::move(security_origin), | 37 std::move(security_origin), |
| 38 isolate, | 38 isolate, |
| 39 thread) {} | 39 thread) {} |
| 40 | 40 |
| 41 AnimationWorkletGlobalScope::~AnimationWorkletGlobalScope() {} | 41 AnimationWorkletGlobalScope::~AnimationWorkletGlobalScope() {} |
| 42 | 42 |
| 43 DEFINE_TRACE(AnimationWorkletGlobalScope) { | 43 DEFINE_TRACE(AnimationWorkletGlobalScope) { |
| 44 visitor->Trace(m_animatorDefinitions); | 44 visitor->Trace(animator_definitions_); |
| 45 visitor->Trace(m_animators); | 45 visitor->Trace(animators_); |
| 46 ThreadedWorkletGlobalScope::Trace(visitor); | 46 ThreadedWorkletGlobalScope::Trace(visitor); |
| 47 } | 47 } |
| 48 | 48 |
| 49 DEFINE_TRACE_WRAPPERS(AnimationWorkletGlobalScope) { | |
| 50 for (auto animator : animators_) | |
| 51 visitor->TraceWrappers(animator); | |
| 52 | |
| 53 for (auto definition : animator_definitions_) | |
| 54 visitor->TraceWrappers(definition.value); | |
|
Michael Lippautz
2017/05/24 14:42:43
Missing dispatch to parent:
ThreadedWorkletGloba
majidvp
2017/05/25 20:16:57
Done.
| |
| 55 } | |
| 56 | |
| 49 void AnimationWorkletGlobalScope::Dispose() { | 57 void AnimationWorkletGlobalScope::Dispose() { |
| 50 DCHECK(IsContextThread()); | 58 DCHECK(IsContextThread()); |
| 51 // Clear animators and definitions to avoid reference cycle. | |
| 52 m_animatorDefinitions.clear(); | |
| 53 m_animators.clear(); | |
| 54 ThreadedWorkletGlobalScope::Dispose(); | 59 ThreadedWorkletGlobalScope::Dispose(); |
| 55 } | 60 } |
| 56 | 61 |
| 57 void AnimationWorkletGlobalScope::registerAnimator( | 62 void AnimationWorkletGlobalScope::registerAnimator( |
| 58 const String& name, | 63 const String& name, |
| 59 const ScriptValue& ctorValue, | 64 const ScriptValue& ctorValue, |
| 60 ExceptionState& exceptionState) { | 65 ExceptionState& exceptionState) { |
| 61 DCHECK(IsContextThread()); | 66 DCHECK(IsContextThread()); |
| 62 if (m_animatorDefinitions.Contains(name)) { | 67 if (animator_definitions_.Contains(name)) { |
| 63 exceptionState.ThrowDOMException( | 68 exceptionState.ThrowDOMException( |
| 64 kNotSupportedError, | 69 kNotSupportedError, |
| 65 "A class with name:'" + name + "' is already registered."); | 70 "A class with name:'" + name + "' is already registered."); |
| 66 return; | 71 return; |
| 67 } | 72 } |
| 68 | 73 |
| 69 if (name.IsEmpty()) { | 74 if (name.IsEmpty()) { |
| 70 exceptionState.ThrowTypeError("The empty string is not a valid name."); | 75 exceptionState.ThrowTypeError("The empty string is not a valid name."); |
| 71 return; | 76 return; |
| 72 } | 77 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 if (!animateValue->IsFunction()) { | 116 if (!animateValue->IsFunction()) { |
| 112 exceptionState.ThrowTypeError( | 117 exceptionState.ThrowTypeError( |
| 113 "The 'animate' property on the prototype is not a function."); | 118 "The 'animate' property on the prototype is not a function."); |
| 114 return; | 119 return; |
| 115 } | 120 } |
| 116 | 121 |
| 117 v8::Local<v8::Function> animate = v8::Local<v8::Function>::Cast(animateValue); | 122 v8::Local<v8::Function> animate = v8::Local<v8::Function>::Cast(animateValue); |
| 118 | 123 |
| 119 AnimatorDefinition* definition = | 124 AnimatorDefinition* definition = |
| 120 new AnimatorDefinition(isolate, constructor, animate); | 125 new AnimatorDefinition(isolate, constructor, animate); |
| 121 m_animatorDefinitions.Set(name, definition); | 126 animator_definitions_.Set( |
| 127 name, TraceWrapperMember<AnimatorDefinition>(this, definition)); | |
| 122 | 128 |
| 123 // Immediately instantiate an animator for the registered definition. | 129 // Immediately instantiate an animator for the registered definition. |
| 124 // TODO(majidvp): Remove this once you add alternative way to instantiate | 130 // TODO(majidvp): Remove this once you add alternative way to instantiate |
| 125 m_animators.push_back(CreateInstance(name)); | 131 Animator* animator = CreateInstance(name); |
| 132 animators_.push_back(TraceWrapperMember<Animator>(this, animator)); | |
| 126 } | 133 } |
| 127 | 134 |
| 128 Animator* AnimationWorkletGlobalScope::CreateInstance(const String& name) { | 135 Animator* AnimationWorkletGlobalScope::CreateInstance(const String& name) { |
| 129 DCHECK(IsContextThread()); | 136 DCHECK(IsContextThread()); |
| 130 AnimatorDefinition* definition = m_animatorDefinitions.at(name); | 137 AnimatorDefinition* definition = animator_definitions_.at(name); |
| 131 if (!definition) | 138 if (!definition) |
| 132 return nullptr; | 139 return nullptr; |
| 133 | 140 |
| 134 v8::Isolate* isolate = ScriptController()->GetScriptState()->GetIsolate(); | 141 v8::Isolate* isolate = ScriptController()->GetScriptState()->GetIsolate(); |
| 135 v8::Local<v8::Function> constructor = definition->ConstructorLocal(isolate); | 142 v8::Local<v8::Function> constructor = definition->ConstructorLocal(isolate); |
| 136 DCHECK(!IsUndefinedOrNull(constructor)); | 143 DCHECK(!IsUndefinedOrNull(constructor)); |
| 137 | 144 |
| 138 v8::Local<v8::Object> instance; | 145 v8::Local<v8::Object> instance; |
| 139 if (!V8ObjectConstructor::NewInstance(isolate, constructor) | 146 if (!V8ObjectConstructor::NewInstance(isolate, constructor) |
| 140 .ToLocal(&instance)) | 147 .ToLocal(&instance)) |
| 141 return nullptr; | 148 return nullptr; |
| 142 | 149 |
| 143 return new Animator(isolate, definition, instance); | 150 return new Animator(isolate, definition, instance); |
| 144 } | 151 } |
| 145 | 152 |
| 146 } // namespace blink | 153 } // namespace blink |
| OLD | NEW |