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/ScopedPersistent.h" | |
8 #include "bindings/core/v8/V8BindingMacros.h" | 7 #include "bindings/core/v8/V8BindingMacros.h" |
9 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" | 8 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" |
10 #include "core/dom/ExceptionCode.h" | 9 #include "core/dom/ExceptionCode.h" |
11 #include "core/inspector/MainThreadDebugger.h" | 10 #include "core/inspector/MainThreadDebugger.h" |
12 #include "modules/csspaint/CSSPaintDefinition.h" | 11 #include "modules/csspaint/CSSPaintDefinition.h" |
| 12 #include "modules/csspaint/CSSPaintImageGeneratorImpl.h" |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 // static | 16 // static |
17 PaintWorkletGlobalScope* PaintWorkletGlobalScope::create(LocalFrame* frame, cons
t KURL& url, const String& userAgent, PassRefPtr<SecurityOrigin> securityOrigin,
v8::Isolate* isolate) | 17 PaintWorkletGlobalScope* PaintWorkletGlobalScope::create(LocalFrame* frame, cons
t KURL& url, const String& userAgent, PassRefPtr<SecurityOrigin> securityOrigin,
v8::Isolate* isolate) |
18 { | 18 { |
19 PaintWorkletGlobalScope* paintWorkletGlobalScope = new PaintWorkletGlobalSco
pe(frame, url, userAgent, securityOrigin, isolate); | 19 PaintWorkletGlobalScope* paintWorkletGlobalScope = new PaintWorkletGlobalSco
pe(frame, url, userAgent, securityOrigin, isolate); |
20 paintWorkletGlobalScope->scriptController()->initializeContextIfNeeded(); | 20 paintWorkletGlobalScope->scriptController()->initializeContextIfNeeded(); |
21 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()); |
22 return paintWorkletGlobalScope; | 22 return paintWorkletGlobalScope; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 98 |
99 if (!paintValue->IsFunction()) { | 99 if (!paintValue->IsFunction()) { |
100 exceptionState.throwTypeError("The 'paint' property on the prototype is
not a function."); | 100 exceptionState.throwTypeError("The 'paint' property on the prototype is
not a function."); |
101 return; | 101 return; |
102 } | 102 } |
103 | 103 |
104 v8::Local<v8::Function> paint = v8::Local<v8::Function>::Cast(paintValue); | 104 v8::Local<v8::Function> paint = v8::Local<v8::Function>::Cast(paintValue); |
105 | 105 |
106 CSSPaintDefinition* definition = CSSPaintDefinition::create(scriptController
()->getScriptState(), constructor, paint); | 106 CSSPaintDefinition* definition = CSSPaintDefinition::create(scriptController
()->getScriptState(), constructor, paint); |
107 m_paintDefinitions.set(name, definition); | 107 m_paintDefinitions.set(name, definition); |
| 108 |
| 109 // Set the definition on any pending generators. |
| 110 GeneratorHashSet* set = m_pendingGenerators.get(name); |
| 111 if (set) { |
| 112 for (const auto& generator : *set) { |
| 113 if (generator) { |
| 114 generator->setDefinition(definition); |
| 115 } |
| 116 } |
| 117 } |
| 118 m_pendingGenerators.remove(name); |
108 } | 119 } |
109 | 120 |
110 CSSPaintDefinition* PaintWorkletGlobalScope::findDefinition(const String& name) | 121 CSSPaintDefinition* PaintWorkletGlobalScope::findDefinition(const String& name) |
111 { | 122 { |
112 return m_paintDefinitions.get(name); | 123 return m_paintDefinitions.get(name); |
113 } | 124 } |
114 | 125 |
| 126 void PaintWorkletGlobalScope::addPendingGenerator(const String& name, CSSPaintIm
ageGeneratorImpl* generator) |
| 127 { |
| 128 Member<GeneratorHashSet>& set = m_pendingGenerators.add(name, nullptr).store
dValue->value; |
| 129 if (!set) |
| 130 set = new GeneratorHashSet; |
| 131 set->add(generator); |
| 132 } |
| 133 |
115 DEFINE_TRACE(PaintWorkletGlobalScope) | 134 DEFINE_TRACE(PaintWorkletGlobalScope) |
116 { | 135 { |
117 visitor->trace(m_paintDefinitions); | 136 visitor->trace(m_paintDefinitions); |
| 137 visitor->trace(m_pendingGenerators); |
118 WorkletGlobalScope::trace(visitor); | 138 WorkletGlobalScope::trace(visitor); |
119 } | 139 } |
120 | 140 |
121 } // namespace blink | 141 } // namespace blink |
OLD | NEW |