| Index: third_party/WebKit/Source/modules/csspaint/PaintWorkletGlobalScope.cpp
|
| diff --git a/third_party/WebKit/Source/modules/csspaint/PaintWorkletGlobalScope.cpp b/third_party/WebKit/Source/modules/csspaint/PaintWorkletGlobalScope.cpp
|
| index 627f2ac06ea18f938577cb5e789c95ae5453d689..44bad6e2d9e0b77b4ad38857b2a41aaab6030a82 100644
|
| --- a/third_party/WebKit/Source/modules/csspaint/PaintWorkletGlobalScope.cpp
|
| +++ b/third_party/WebKit/Source/modules/csspaint/PaintWorkletGlobalScope.cpp
|
| @@ -4,8 +4,15 @@
|
|
|
| #include "modules/csspaint/PaintWorkletGlobalScope.h"
|
|
|
| +#include "bindings/core/v8/ScopedPersistent.h"
|
| #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
|
| +#include "core/dom/ExceptionCode.h"
|
| #include "core/inspector/MainThreadDebugger.h"
|
| +#include "modules/csspaint/CSSPaintDefinition.h"
|
| +#include "modules/csspaint/CSSPaintImageGeneratorImpl.h"
|
| +#include "platform/graphics/ImageBuffer.h"
|
| +#include "platform/graphics/ImageBufferSurface.h"
|
| +#include "platform/graphics/RecordingImageBufferSurface.h"
|
|
|
| namespace blink {
|
|
|
| @@ -27,4 +34,108 @@ PaintWorkletGlobalScope::~PaintWorkletGlobalScope()
|
| {
|
| }
|
|
|
| +void PaintWorkletGlobalScope::registerPaint(const String& name, const ScriptValue& ctorValue, ExceptionState& exceptionState)
|
| +{
|
| + if (m_paintDefinitions.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::TryCatch block(isolate());
|
| + v8::Local<v8::Context> context = scriptController()->context();
|
| +
|
| + ASSERT(ctorValue.v8Value()->IsFunction());
|
| + v8::Local<v8::Function> ctor = v8::Local<v8::Function>::Cast(ctorValue.v8Value());
|
| +
|
| + v8::Local<v8::Value> inputPropertiesValue;
|
| + if (!ctor->Get(context, v8String(isolate(), "inputProperties")).ToLocal(&inputPropertiesValue)) {
|
| + exceptionState.rethrowV8Exception(block.Exception());
|
| + return;
|
| + }
|
| +
|
| + if (!isUndefinedOrNull(inputPropertiesValue)) {
|
| + toImplArray<Vector<String>>(inputPropertiesValue, 0, isolate(), exceptionState);
|
| +
|
| + if (exceptionState.hadException())
|
| + return;
|
| +
|
| + // TODO(ikilpatrick): Hook up invalidation based on these inputProperties.
|
| + }
|
| +
|
| + v8::Local<v8::Value> prototypeValue;
|
| + if (!ctor->Get(context, v8String(isolate(), "prototype")).ToLocal(&prototypeValue)) {
|
| + exceptionState.rethrowV8Exception(block.Exception());
|
| + 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> paintValue;
|
| + if (!prototype->Get(context, v8String(isolate(), "paint")).ToLocal(&paintValue)) {
|
| + exceptionState.rethrowV8Exception(block.Exception());
|
| + return;
|
| + }
|
| +
|
| + if (isUndefinedOrNull(paintValue)) {
|
| + exceptionState.throwTypeError("The 'paint' function on the prototype does not exist.");
|
| + return;
|
| + }
|
| +
|
| + if (!paintValue->IsFunction()) {
|
| + exceptionState.throwTypeError("The 'paint' property on the prototype is not a function.");
|
| + return;
|
| + }
|
| +
|
| + v8::Local<v8::Function> paint = v8::Local<v8::Function>::Cast(paintValue);
|
| +
|
| + RefPtrWillBeRawPtr<CSSPaintDefinition> definition = CSSPaintDefinition::create(scriptController()->getScriptState(), ctor, paint);
|
| + m_paintDefinitions.set(name, definition);
|
| +
|
| + auto set = m_pendingGenerators.get(name);
|
| + if (set) {
|
| + for (const auto& generator : *set) {
|
| + if (generator) {
|
| + generator->setDefinition(definition);
|
| + }
|
| + }
|
| + }
|
| +
|
| + m_pendingGenerators.remove(name);
|
| +}
|
| +
|
| +CSSPaintDefinition* PaintWorkletGlobalScope::findDefinition(const String& name)
|
| +{
|
| + return m_paintDefinitions.get(name);
|
| +}
|
| +
|
| +void PaintWorkletGlobalScope::addPendingGenerator(const String& name, PassRefPtrWillBeRawPtr<CSSPaintImageGeneratorImpl> generator)
|
| +{
|
| + OwnPtrWillBeMember<GeneratorHashSet>& set = m_pendingGenerators.add(name, nullptr).storedValue->value;
|
| + if (!set)
|
| + set = adoptPtrWillBeNoop(new GeneratorHashSet);
|
| + set->add(generator);
|
| +}
|
| +
|
| +DEFINE_TRACE(PaintWorkletGlobalScope)
|
| +{
|
| + visitor->trace(m_paintDefinitions);
|
| + visitor->trace(m_pendingGenerators);
|
| + WorkletGlobalScope::trace(visitor);
|
| +}
|
| +
|
| } // namespace blink
|
|
|