Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: third_party/WebKit/Source/modules/csspaint/PaintWorkletGlobalScope.cpp

Issue 1839913002: Implement PaintWorkletGlobalScope#registerPaint() for the CSS Paint API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase + remove WillBe types. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/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 RawPtr<PaintWorkletGlobalScope> PaintWorkletGlobalScope::create(LocalFrame* fram e, const KURL& url, const String& userAgent, PassRefPtr<SecurityOrigin> security Origin, v8::Isolate* isolate) 17 RawPtr<PaintWorkletGlobalScope> PaintWorkletGlobalScope::create(LocalFrame* fram e, const KURL& url, const String& userAgent, PassRefPtr<SecurityOrigin> security Origin, v8::Isolate* isolate)
14 { 18 {
15 RawPtr<PaintWorkletGlobalScope> paintWorkletGlobalScope = new PaintWorkletGl obalScope(frame, url, userAgent, securityOrigin, isolate); 19 RawPtr<PaintWorkletGlobalScope> paintWorkletGlobalScope = new PaintWorkletGl obalScope(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::dispose()
35 {
36 // Explicitly clear the paint defininitions to break a reference cycle
37 // between them and this global scope.
38 m_paintDefinitions.clear();
39
40 WorkletGlobalScope::dispose();
41 }
42
43 void PaintWorkletGlobalScope::registerPaint(const String& name, const ScriptValu e& ctorValue, ExceptionState& exceptionState)
44 {
45 if (m_paintDefinitions.contains(name)) {
46 exceptionState.throwDOMException(NotSupportedError, "A class with name:' " + name + "' is already registered.");
47 return;
48 }
49
50 if (name.isEmpty()) {
51 exceptionState.throwTypeError("The empty string is not a valid name.");
52 return;
53 }
54
55 v8::Isolate* isolate = scriptController()->getScriptState()->isolate();
56 v8::Local<v8::Context> context = scriptController()->context();
57
58 ASSERT(ctorValue.v8Value()->IsFunction());
59 v8::Local<v8::Function> constructor = v8::Local<v8::Function>::Cast(ctorValu e.v8Value());
60
61 v8::Local<v8::Value> inputPropertiesValue;
62 if (!v8Call(constructor->Get(context, v8String(isolate, "inputProperties")), inputPropertiesValue))
63 return;
64
65 if (!isUndefinedOrNull(inputPropertiesValue)) {
66 toImplArray<Vector<String>>(inputPropertiesValue, 0, isolate, exceptionS tate);
67
68 if (exceptionState.hadException())
69 return;
70
71 // TODO(ikilpatrick): Hook up invalidation based on these inputPropertie s.
72 }
73
74 v8::Local<v8::Value> prototypeValue;
75 if (!v8Call(constructor->Get(context, v8String(isolate, "prototype")), proto typeValue))
76 return;
77
78 if (isUndefinedOrNull(prototypeValue)) {
79 exceptionState.throwTypeError("The 'prototype' object on the class does not exist.");
80 return;
81 }
82
83 if (!prototypeValue->IsObject()) {
84 exceptionState.throwTypeError("The 'prototype' property on the class is not an object.");
85 return;
86 }
87
88 v8::Local<v8::Object> prototype = v8::Local<v8::Object>::Cast(prototypeValue );
89
90 v8::Local<v8::Value> paintValue;
91 if (!v8Call(prototype->Get(context, v8String(isolate, "paint")), paintValue) )
92 return;
93
94 if (isUndefinedOrNull(paintValue)) {
95 exceptionState.throwTypeError("The 'paint' function on the prototype doe s not exist.");
96 return;
97 }
98
99 if (!paintValue->IsFunction()) {
100 exceptionState.throwTypeError("The 'paint' property on the prototype is not a function.");
101 return;
102 }
103
104 v8::Local<v8::Function> paint = v8::Local<v8::Function>::Cast(paintValue);
105
106 RawPtr<CSSPaintDefinition> definition = CSSPaintDefinition::create(scriptCon troller()->getScriptState(), constructor, paint);
107 m_paintDefinitions.set(name, definition);
108 }
109
110 CSSPaintDefinition* PaintWorkletGlobalScope::findDefinition(const String& name)
111 {
112 return m_paintDefinitions.get(name);
113 }
114
115 DEFINE_TRACE(PaintWorkletGlobalScope)
116 {
117 visitor->trace(m_paintDefinitions);
118 WorkletGlobalScope::trace(visitor);
119 }
120
30 } // namespace blink 121 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698