| 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/IDLTypes.h" | 7 #include "bindings/core/v8/IDLTypes.h" |
| 8 #include "bindings/core/v8/NativeValueTraitsImpl.h" | 8 #include "bindings/core/v8/NativeValueTraitsImpl.h" |
| 9 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" | 9 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" |
| 10 #include "core/CSSPropertyNames.h" | 10 #include "core/CSSPropertyNames.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 std::move(security_origin), | 50 std::move(security_origin), |
| 51 isolate), | 51 isolate), |
| 52 pending_generator_registry_(pending_generator_registry) {} | 52 pending_generator_registry_(pending_generator_registry) {} |
| 53 | 53 |
| 54 PaintWorkletGlobalScope::~PaintWorkletGlobalScope() {} | 54 PaintWorkletGlobalScope::~PaintWorkletGlobalScope() {} |
| 55 | 55 |
| 56 void PaintWorkletGlobalScope::Dispose() { | 56 void PaintWorkletGlobalScope::Dispose() { |
| 57 MainThreadDebugger::Instance()->ContextWillBeDestroyed( | 57 MainThreadDebugger::Instance()->ContextWillBeDestroyed( |
| 58 ScriptController()->GetScriptState()); | 58 ScriptController()->GetScriptState()); |
| 59 | 59 |
| 60 // Explicitly clear the paint defininitions to break a reference cycle | |
| 61 // between them and this global scope. | |
| 62 paint_definitions_.clear(); | |
| 63 | |
| 64 pending_generator_registry_ = nullptr; | 60 pending_generator_registry_ = nullptr; |
| 65 WorkletGlobalScope::Dispose(); | 61 WorkletGlobalScope::Dispose(); |
| 66 } | 62 } |
| 67 | 63 |
| 68 void PaintWorkletGlobalScope::registerPaint(const String& name, | 64 void PaintWorkletGlobalScope::registerPaint(const String& name, |
| 69 const ScriptValue& ctor_value, | 65 const ScriptValue& ctor_value, |
| 70 ExceptionState& exception_state) { | 66 ExceptionState& exception_state) { |
| 71 if (paint_definitions_.Contains(name)) { | 67 if (paint_definitions_.Contains(name)) { |
| 72 exception_state.ThrowDOMException( | 68 exception_state.ThrowDOMException( |
| 73 kNotSupportedError, | 69 kNotSupportedError, |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 "The 'paint' property on the prototype is not a function."); | 187 "The 'paint' property on the prototype is not a function."); |
| 192 return; | 188 return; |
| 193 } | 189 } |
| 194 | 190 |
| 195 v8::Local<v8::Function> paint = v8::Local<v8::Function>::Cast(paint_value); | 191 v8::Local<v8::Function> paint = v8::Local<v8::Function>::Cast(paint_value); |
| 196 | 192 |
| 197 CSSPaintDefinition* definition = CSSPaintDefinition::Create( | 193 CSSPaintDefinition* definition = CSSPaintDefinition::Create( |
| 198 ScriptController()->GetScriptState(), constructor, paint, | 194 ScriptController()->GetScriptState(), constructor, paint, |
| 199 native_invalidation_properties, custom_invalidation_properties, | 195 native_invalidation_properties, custom_invalidation_properties, |
| 200 input_argument_types, has_alpha); | 196 input_argument_types, has_alpha); |
| 201 paint_definitions_.Set(name, definition); | 197 paint_definitions_.Set( |
| 198 name, TraceWrapperMember<CSSPaintDefinition>(this, definition)); |
| 202 pending_generator_registry_->SetDefinition(name, definition); | 199 pending_generator_registry_->SetDefinition(name, definition); |
| 203 } | 200 } |
| 204 | 201 |
| 205 CSSPaintDefinition* PaintWorkletGlobalScope::FindDefinition( | 202 CSSPaintDefinition* PaintWorkletGlobalScope::FindDefinition( |
| 206 const String& name) { | 203 const String& name) { |
| 207 return paint_definitions_.at(name); | 204 return paint_definitions_.at(name); |
| 208 } | 205 } |
| 209 | 206 |
| 210 DEFINE_TRACE(PaintWorkletGlobalScope) { | 207 DEFINE_TRACE(PaintWorkletGlobalScope) { |
| 211 visitor->Trace(paint_definitions_); | 208 visitor->Trace(paint_definitions_); |
| 212 visitor->Trace(pending_generator_registry_); | 209 visitor->Trace(pending_generator_registry_); |
| 213 MainThreadWorkletGlobalScope::Trace(visitor); | 210 MainThreadWorkletGlobalScope::Trace(visitor); |
| 214 } | 211 } |
| 215 | 212 |
| 213 DEFINE_TRACE_WRAPPERS(PaintWorkletGlobalScope) { |
| 214 for (auto definition : paint_definitions_) |
| 215 visitor->TraceWrappers(definition.value); |
| 216 MainThreadWorkletGlobalScope::TraceWrappers(visitor); |
| 217 } |
| 218 |
| 216 } // namespace blink | 219 } // namespace blink |
| OLD | NEW |