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/csspaint/PaintWorkletGlobalScope.h" | 5 #include "modules/csspaint/PaintWorkletGlobalScope.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/CSSPaintBinding.h" | |
| 8 #include "bindings/core/v8/ScopedPersistent.h" | |
| 7 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" | 9 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" |
| 10 #include "core/dom/ExceptionCode.h" | |
| 8 #include "core/inspector/MainThreadDebugger.h" | 11 #include "core/inspector/MainThreadDebugger.h" |
| 12 #include "modules/csspaint/CSSPaintDefinition.h" | |
| 9 | 13 |
| 10 namespace blink { | 14 namespace blink { |
| 11 | 15 |
| 12 // static | 16 // static |
| 13 PassRefPtrWillBeRawPtr<PaintWorkletGlobalScope> PaintWorkletGlobalScope::create( LocalFrame* frame, const KURL& url, const String& userAgent, PassRefPtr<Security Origin> securityOrigin, v8::Isolate* isolate) | 17 PassRefPtrWillBeRawPtr<PaintWorkletGlobalScope> PaintWorkletGlobalScope::create( LocalFrame* frame, const KURL& url, const String& userAgent, PassRefPtr<Security Origin> securityOrigin, v8::Isolate* isolate) |
| 14 { | 18 { |
| 15 RefPtrWillBeRawPtr<PaintWorkletGlobalScope> paintWorkletGlobalScope = adoptR efWillBeNoop(new PaintWorkletGlobalScope(frame, url, userAgent, securityOrigin, isolate)); | 19 RefPtrWillBeRawPtr<PaintWorkletGlobalScope> paintWorkletGlobalScope = adoptR efWillBeNoop(new PaintWorkletGlobalScope(frame, url, userAgent, securityOrigin, isolate)); |
| 16 paintWorkletGlobalScope->scriptController()->initializeContextIfNeeded(); | 20 paintWorkletGlobalScope->scriptController()->initializeContextIfNeeded(); |
| 17 MainThreadDebugger::instance()->contextCreated(paintWorkletGlobalScope->scri ptController()->getScriptState(), paintWorkletGlobalScope->frame(), paintWorklet GlobalScope->getSecurityOrigin()); | 21 MainThreadDebugger::instance()->contextCreated(paintWorkletGlobalScope->scri ptController()->getScriptState(), paintWorkletGlobalScope->frame(), paintWorklet GlobalScope->getSecurityOrigin()); |
| 18 return paintWorkletGlobalScope.release(); | 22 return paintWorkletGlobalScope.release(); |
| 19 } | 23 } |
| 20 | 24 |
| 21 PaintWorkletGlobalScope::PaintWorkletGlobalScope(LocalFrame* frame, const KURL& url, const String& userAgent, PassRefPtr<SecurityOrigin> securityOrigin, v8::Iso late* isolate) | 25 PaintWorkletGlobalScope::PaintWorkletGlobalScope(LocalFrame* frame, const KURL& url, const String& userAgent, PassRefPtr<SecurityOrigin> securityOrigin, v8::Iso late* isolate) |
| 22 : WorkletGlobalScope(frame, url, userAgent, securityOrigin, isolate) | 26 : WorkletGlobalScope(frame, url, userAgent, securityOrigin, isolate) |
| 23 { | 27 { |
| 24 } | 28 } |
| 25 | 29 |
| 26 PaintWorkletGlobalScope::~PaintWorkletGlobalScope() | 30 PaintWorkletGlobalScope::~PaintWorkletGlobalScope() |
| 27 { | 31 { |
| 28 } | 32 } |
| 29 | 33 |
| 34 void PaintWorkletGlobalScope::registerPaint(const String& name, const ScriptValu e& ctorValue, ExceptionState& exceptionState) | |
| 35 { | |
| 36 if (m_paintDefinitions.contains(name)) { | |
| 37 exceptionState.throwDOMException(NotSupportedError, "A class with name:' " + name + "' is already registered."); | |
| 38 return; | |
| 39 } | |
| 40 | |
| 41 if (name.isEmpty()) { | |
| 42 exceptionState.throwTypeError("The empty string is not a valid name."); | |
| 43 return; | |
| 44 } | |
| 45 | |
| 46 v8::Isolate* isolate = scriptController()->getScriptState()->isolate(); | |
| 47 | |
| 48 v8::TryCatch block(isolate); | |
| 49 v8::Local<v8::Context> context = scriptController()->context(); | |
| 50 | |
| 51 ASSERT(ctorValue.v8Value()->IsFunction()); | |
| 52 v8::Local<v8::Function> constructor = v8::Local<v8::Function>::Cast(ctorValu e.v8Value()); | |
| 53 | |
| 54 v8::Local<v8::Value> inputPropertiesValue; | |
| 55 if (!constructor->Get(context, v8String(isolate, "inputProperties")).ToLocal (&inputPropertiesValue)) { | |
| 56 exceptionState.rethrowV8Exception(block.Exception()); | |
| 57 return; | |
| 58 } | |
| 59 | |
| 60 if (!isUndefinedOrNull(inputPropertiesValue)) { | |
| 61 toImplArray<Vector<String>>(inputPropertiesValue, 0, isolate, exceptionS tate); | |
| 62 | |
| 63 if (exceptionState.hadException()) | |
| 64 return; | |
| 65 | |
| 66 // TODO(ikilpatrick): Hook up invalidation based on these inputPropertie s. | |
| 67 } | |
| 68 | |
| 69 v8::Local<v8::Value> prototypeValue; | |
| 70 if (!constructor->Get(context, v8String(isolate, "prototype")).ToLocal(&prot otypeValue)) { | |
| 71 exceptionState.rethrowV8Exception(block.Exception()); | |
| 72 return; | |
| 73 } | |
| 74 | |
| 75 if (isUndefinedOrNull(prototypeValue)) { | |
| 76 exceptionState.throwTypeError("The 'prototype' object on the class does not exist."); | |
| 77 return; | |
| 78 } | |
| 79 | |
| 80 if (!prototypeValue->IsObject()) { | |
| 81 exceptionState.throwTypeError("The 'prototype' property on the class is not an object."); | |
| 82 return; | |
| 83 } | |
| 84 | |
| 85 v8::Local<v8::Object> prototype = v8::Local<v8::Object>::Cast(prototypeValue ); | |
| 86 | |
| 87 v8::Local<v8::Value> paintValue; | |
| 88 if (!prototype->Get(context, v8String(isolate, "paint")).ToLocal(&paintValue )) { | |
| 89 exceptionState.rethrowV8Exception(block.Exception()); | |
| 90 return; | |
| 91 } | |
| 92 | |
| 93 if (isUndefinedOrNull(paintValue)) { | |
| 94 exceptionState.throwTypeError("The 'paint' function on the prototype doe s not exist."); | |
| 95 return; | |
| 96 } | |
| 97 | |
| 98 if (!paintValue->IsFunction()) { | |
| 99 exceptionState.throwTypeError("The 'paint' property on the prototype is not a function."); | |
| 100 return; | |
| 101 } | |
| 102 | |
| 103 v8::Local<v8::Function> paint = v8::Local<v8::Function>::Cast(paintValue); | |
| 104 | |
| 105 RefPtrWillBeRawPtr<CSSPaintDefinition> definition = CSSPaintDefinition::crea te(scriptController()->getScriptState(), constructor, paint); | |
|
haraken
2016/03/31 02:01:59
Just to confirm: Once registerPaint is called, you
ikilpatrick
2016/03/31 21:59:05
Yes that's correct. Sounds good. Done.
| |
| 106 m_paintDefinitions.set(name, definition); | |
| 107 | |
| 108 setBindingOnPerContextData(CSSPaintBinding::create(isolate, constructor, pai nt)); | |
| 109 } | |
| 110 | |
| 111 CSSPaintDefinition* PaintWorkletGlobalScope::findDefinition(const String& name) | |
| 112 { | |
| 113 return m_paintDefinitions.get(name); | |
| 114 } | |
| 115 | |
| 116 void PaintWorkletGlobalScope::setBindingOnPerContextData(PassOwnPtr<CSSPaintBind ing> binding) | |
| 117 { | |
| 118 v8::Local<v8::Context> context = scriptController()->getScriptState()->conte xt(); | |
| 119 ASSERT(!context.IsEmpty()); | |
| 120 | |
| 121 V8PerContextData* perContextData = V8PerContextData::from(context); | |
| 122 ASSERT(perContextData); | |
| 123 | |
| 124 // The context is responsible for keeping the constructor and paint | |
| 125 // functions alive. | |
| 126 perContextData->addCSSPaintBinding(std::move(binding)); | |
| 127 } | |
| 128 | |
| 129 DEFINE_TRACE(PaintWorkletGlobalScope) | |
| 130 { | |
| 131 #if ENABLE(OILPAN) | |
| 132 visitor->trace(m_paintDefinitions); | |
| 133 #endif | |
| 134 WorkletGlobalScope::trace(visitor); | |
| 135 } | |
| 136 | |
| 30 } // namespace blink | 137 } // namespace blink |
| OLD | NEW |