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" | |
| 10 #include "bindings/core/v8/V8BindingMacros.h" | |
| 11 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" | |
| 12 #include "core/dom/ExceptionCode.h" | |
| 13 | |
| 9 namespace blink { | 14 namespace blink { |
| 10 | 15 |
| 11 AnimationWorkletGlobalScope* AnimationWorkletGlobalScope::create( | 16 AnimationWorkletGlobalScope* AnimationWorkletGlobalScope::create( |
| 12 const KURL& url, | 17 const KURL& url, |
| 13 const String& userAgent, | 18 const String& userAgent, |
| 14 PassRefPtr<SecurityOrigin> securityOrigin, | 19 PassRefPtr<SecurityOrigin> securityOrigin, |
| 15 v8::Isolate* isolate, | 20 v8::Isolate* isolate, |
| 16 WorkerThread* thread) { | 21 WorkerThread* thread) { |
| 17 return new AnimationWorkletGlobalScope( | 22 return new AnimationWorkletGlobalScope( |
| 18 url, userAgent, std::move(securityOrigin), isolate, thread); | 23 url, userAgent, std::move(securityOrigin), isolate, thread); |
| 19 } | 24 } |
| 20 | 25 |
| 21 AnimationWorkletGlobalScope::AnimationWorkletGlobalScope( | 26 AnimationWorkletGlobalScope::AnimationWorkletGlobalScope( |
| 22 const KURL& url, | 27 const KURL& url, |
| 23 const String& userAgent, | 28 const String& userAgent, |
| 24 PassRefPtr<SecurityOrigin> securityOrigin, | 29 PassRefPtr<SecurityOrigin> securityOrigin, |
| 25 v8::Isolate* isolate, | 30 v8::Isolate* isolate, |
| 26 WorkerThread* thread) | 31 WorkerThread* thread) |
| 27 : ThreadedWorkletGlobalScope(url, | 32 : ThreadedWorkletGlobalScope(url, |
| 28 userAgent, | 33 userAgent, |
| 29 std::move(securityOrigin), | 34 std::move(securityOrigin), |
| 30 isolate, | 35 isolate, |
| 31 thread) {} | 36 thread) {} |
| 32 | 37 |
| 33 AnimationWorkletGlobalScope::~AnimationWorkletGlobalScope() {} | 38 AnimationWorkletGlobalScope::~AnimationWorkletGlobalScope() {} |
| 34 | 39 |
| 40 DEFINE_TRACE(AnimationWorkletGlobalScope) { | |
| 41 visitor->trace(m_animatorDefinitions); | |
| 42 visitor->trace(m_animators); | |
| 43 ThreadedWorkletGlobalScope::trace(visitor); | |
| 44 } | |
| 45 | |
| 46 void AnimationWorkletGlobalScope::dispose() { | |
| 47 // Clear animators and definitions to avoid reference cycle. | |
| 48 m_animatorDefinitions.clear(); | |
| 49 m_animators.clear(); | |
| 50 ThreadedWorkletGlobalScope::dispose(); | |
| 51 } | |
| 52 | |
| 53 void AnimationWorkletGlobalScope::registerAnimator( | |
| 54 const String& name, | |
| 55 const ScriptValue& ctorValue, | |
| 56 ExceptionState& exceptionState) { | |
| 57 if (m_animatorDefinitions.contains(name)) { | |
| 58 exceptionState.throwDOMException( | |
| 59 NotSupportedError, | |
| 60 "A class with name:'" + name + "' is already registered."); | |
| 61 return; | |
| 62 } | |
| 63 | |
| 64 if (name.isEmpty()) { | |
| 65 exceptionState.throwTypeError("The empty string is not a valid name."); | |
| 66 return; | |
| 67 } | |
| 68 | |
| 69 v8::Isolate* isolate = scriptController()->getScriptState()->isolate(); | |
| 70 v8::Local<v8::Context> context = scriptController()->context(); | |
| 71 | |
| 72 DCHECK(ctorValue.v8Value()->IsFunction()); | |
| 73 v8::Local<v8::Function> constructor = | |
| 74 v8::Local<v8::Function>::Cast(ctorValue.v8Value()); | |
|
flackr
2017/03/13 19:04:51
Shouldn't this be another exception state? What ha
majidvp
2017/03/13 22:07:53
there is a test for this. The IDL defines is as a
flackr
2017/03/14 18:30:29
Acknowledged. Thanks.
| |
| 75 | |
| 76 v8::Local<v8::Value> prototypeValue; | |
| 77 if (!v8Call(constructor->Get(context, v8String(isolate, "prototype")), | |
| 78 prototypeValue)) | |
| 79 return; | |
| 80 | |
| 81 if (isUndefinedOrNull(prototypeValue)) { | |
| 82 exceptionState.throwTypeError( | |
| 83 "The 'prototype' object on the class does not exist."); | |
| 84 return; | |
| 85 } | |
| 86 | |
| 87 if (!prototypeValue->IsObject()) { | |
| 88 exceptionState.throwTypeError( | |
| 89 "The 'prototype' property on the class is not an object."); | |
| 90 return; | |
| 91 } | |
| 92 | |
| 93 v8::Local<v8::Object> prototype = v8::Local<v8::Object>::Cast(prototypeValue); | |
| 94 | |
| 95 v8::Local<v8::Value> animateValue; | |
| 96 if (!v8Call(prototype->Get(context, v8String(isolate, "animate")), | |
| 97 animateValue)) | |
| 98 return; | |
| 99 | |
| 100 if (isUndefinedOrNull(animateValue)) { | |
|
flackr
2017/03/13 19:04:51
Does it make sense to check the animate at registr
majidvp
2017/03/13 22:07:53
Hmmm, you suggestion makes sense. Though this is t
ikilpatrick
2017/03/13 22:20:34
We should do this here - firstly consistency with
| |
| 101 exceptionState.throwTypeError( | |
| 102 "The 'animate' function on the prototype does not exist."); | |
| 103 return; | |
| 104 } | |
| 105 | |
| 106 if (!animateValue->IsFunction()) { | |
| 107 exceptionState.throwTypeError( | |
| 108 "The 'animate' property on the prototype is not a function."); | |
| 109 return; | |
| 110 } | |
| 111 | |
| 112 v8::Local<v8::Function> animate = v8::Local<v8::Function>::Cast(animateValue); | |
| 113 | |
| 114 AnimatorDefinition* definition = AnimatorDefinition::create( | |
| 115 scriptController()->getScriptState(), constructor, animate); | |
| 116 m_animatorDefinitions.set(name, definition); | |
| 117 | |
| 118 // Immediately instantiate and animator for the registered definition. | |
|
flackr
2017/03/13 19:04:51
s/and animator/an animator
majidvp
2017/03/13 22:07:53
Done.
| |
| 119 // TODO(majidvp): Remove this once you add alternative way to instantiate | |
| 120 m_animators.push_back(definition->createInstance()); | |
| 121 } | |
| 122 | |
| 35 } // namespace blink | 123 } // namespace blink |
| OLD | NEW |