| 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/V8BindingMacros.h" | 7 #include "bindings/core/v8/V8BindingMacros.h" |
| 8 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" | 8 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" |
| 9 #include "core/CSSPropertyNames.h" | 9 #include "core/CSSPropertyNames.h" |
| 10 #include "core/css/CSSSyntaxDescriptor.h" |
| 10 #include "core/dom/ExceptionCode.h" | 11 #include "core/dom/ExceptionCode.h" |
| 11 #include "core/inspector/MainThreadDebugger.h" | 12 #include "core/inspector/MainThreadDebugger.h" |
| 12 #include "modules/csspaint/CSSPaintDefinition.h" | 13 #include "modules/csspaint/CSSPaintDefinition.h" |
| 13 #include "modules/csspaint/CSSPaintImageGeneratorImpl.h" | 14 #include "modules/csspaint/CSSPaintImageGeneratorImpl.h" |
| 14 | 15 |
| 15 namespace blink { | 16 namespace blink { |
| 16 | 17 |
| 17 // static | 18 // static |
| 18 PaintWorkletGlobalScope* PaintWorkletGlobalScope::create( | 19 PaintWorkletGlobalScope* PaintWorkletGlobalScope::create( |
| 19 LocalFrame* frame, | 20 LocalFrame* frame, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 for (const auto& property : properties) { | 97 for (const auto& property : properties) { |
| 97 CSSPropertyID propertyID = cssPropertyID(property); | 98 CSSPropertyID propertyID = cssPropertyID(property); |
| 98 if (propertyID == CSSPropertyVariable) { | 99 if (propertyID == CSSPropertyVariable) { |
| 99 customInvalidationProperties.push_back(property); | 100 customInvalidationProperties.push_back(property); |
| 100 } else if (propertyID != CSSPropertyInvalid) { | 101 } else if (propertyID != CSSPropertyInvalid) { |
| 101 nativeInvalidationProperties.push_back(propertyID); | 102 nativeInvalidationProperties.push_back(propertyID); |
| 102 } | 103 } |
| 103 } | 104 } |
| 104 } | 105 } |
| 105 | 106 |
| 107 // Get input argument types. Parse the argument type values only when |
| 108 // cssPaintAPIArguments is enabled. |
| 109 Vector<CSSSyntaxDescriptor> inputArgumentTypes; |
| 110 if (RuntimeEnabledFeatures::cssPaintAPIArgumentsEnabled()) { |
| 111 v8::Local<v8::Value> inputArgumentTypeValues; |
| 112 if (!v8Call(constructor->Get(context, v8String(isolate, "inputArguments")), |
| 113 inputArgumentTypeValues)) |
| 114 return; |
| 115 |
| 116 if (!isUndefinedOrNull(inputArgumentTypeValues)) { |
| 117 Vector<String> argumentTypes = toImplArray<Vector<String>>( |
| 118 inputArgumentTypeValues, 0, isolate, exceptionState); |
| 119 |
| 120 if (exceptionState.hadException()) |
| 121 return; |
| 122 |
| 123 for (const auto& type : argumentTypes) { |
| 124 CSSSyntaxDescriptor syntaxDescriptor(type); |
| 125 if (!syntaxDescriptor.isValid()) { |
| 126 exceptionState.throwTypeError("Invalid argument types."); |
| 127 return; |
| 128 } |
| 129 inputArgumentTypes.append(syntaxDescriptor); |
| 130 } |
| 131 } |
| 132 } |
| 133 |
| 106 // Parse 'alpha' AKA hasAlpha property. | 134 // Parse 'alpha' AKA hasAlpha property. |
| 107 v8::Local<v8::Value> alphaValue; | 135 v8::Local<v8::Value> alphaValue; |
| 108 if (!v8Call(constructor->Get(context, v8String(isolate, "alpha")), | 136 if (!v8Call(constructor->Get(context, v8String(isolate, "alpha")), |
| 109 alphaValue)) | 137 alphaValue)) |
| 110 return; | 138 return; |
| 111 if (!isUndefinedOrNull(alphaValue) && !alphaValue->IsBoolean()) { | 139 if (!isUndefinedOrNull(alphaValue) && !alphaValue->IsBoolean()) { |
| 112 exceptionState.throwTypeError( | 140 exceptionState.throwTypeError( |
| 113 "The 'alpha' property on the class is not a boolean."); | 141 "The 'alpha' property on the class is not a boolean."); |
| 114 return; | 142 return; |
| 115 } | 143 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 if (!paintValue->IsFunction()) { | 177 if (!paintValue->IsFunction()) { |
| 150 exceptionState.throwTypeError( | 178 exceptionState.throwTypeError( |
| 151 "The 'paint' property on the prototype is not a function."); | 179 "The 'paint' property on the prototype is not a function."); |
| 152 return; | 180 return; |
| 153 } | 181 } |
| 154 | 182 |
| 155 v8::Local<v8::Function> paint = v8::Local<v8::Function>::Cast(paintValue); | 183 v8::Local<v8::Function> paint = v8::Local<v8::Function>::Cast(paintValue); |
| 156 | 184 |
| 157 CSSPaintDefinition* definition = CSSPaintDefinition::create( | 185 CSSPaintDefinition* definition = CSSPaintDefinition::create( |
| 158 scriptController()->getScriptState(), constructor, paint, | 186 scriptController()->getScriptState(), constructor, paint, |
| 159 nativeInvalidationProperties, customInvalidationProperties, hasAlpha); | 187 nativeInvalidationProperties, customInvalidationProperties, |
| 188 inputArgumentTypes, hasAlpha); |
| 160 m_paintDefinitions.set(name, definition); | 189 m_paintDefinitions.set(name, definition); |
| 161 | 190 |
| 162 // Set the definition on any pending generators. | 191 // Set the definition on any pending generators. |
| 163 GeneratorHashSet* set = m_pendingGenerators.get(name); | 192 GeneratorHashSet* set = m_pendingGenerators.get(name); |
| 164 if (set) { | 193 if (set) { |
| 165 for (const auto& generator : *set) { | 194 for (const auto& generator : *set) { |
| 166 if (generator) { | 195 if (generator) { |
| 167 generator->setDefinition(definition); | 196 generator->setDefinition(definition); |
| 168 } | 197 } |
| 169 } | 198 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 186 set->add(generator); | 215 set->add(generator); |
| 187 } | 216 } |
| 188 | 217 |
| 189 DEFINE_TRACE(PaintWorkletGlobalScope) { | 218 DEFINE_TRACE(PaintWorkletGlobalScope) { |
| 190 visitor->trace(m_paintDefinitions); | 219 visitor->trace(m_paintDefinitions); |
| 191 visitor->trace(m_pendingGenerators); | 220 visitor->trace(m_pendingGenerators); |
| 192 MainThreadWorkletGlobalScope::trace(visitor); | 221 MainThreadWorkletGlobalScope::trace(visitor); |
| 193 } | 222 } |
| 194 | 223 |
| 195 } // namespace blink | 224 } // namespace blink |
| OLD | NEW |