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

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: fix win build. 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"
7 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" 8 #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
9 #include "core/dom/ExceptionCode.h"
8 #include "core/inspector/MainThreadDebugger.h" 10 #include "core/inspector/MainThreadDebugger.h"
11 #include "modules/csspaint/CSSPaintDefinition.h"
9 12
10 namespace blink { 13 namespace blink {
11 14
12 // static 15 // static
13 PassRefPtrWillBeRawPtr<PaintWorkletGlobalScope> PaintWorkletGlobalScope::create( LocalFrame* frame, const KURL& url, const String& userAgent, PassRefPtr<Security Origin> securityOrigin, v8::Isolate* isolate) 16 PassRefPtrWillBeRawPtr<PaintWorkletGlobalScope> PaintWorkletGlobalScope::create( LocalFrame* frame, const KURL& url, const String& userAgent, PassRefPtr<Security Origin> securityOrigin, v8::Isolate* isolate)
14 { 17 {
15 RefPtrWillBeRawPtr<PaintWorkletGlobalScope> paintWorkletGlobalScope = adoptR efWillBeNoop(new PaintWorkletGlobalScope(frame, url, userAgent, securityOrigin, isolate)); 18 RefPtrWillBeRawPtr<PaintWorkletGlobalScope> paintWorkletGlobalScope = adoptR efWillBeNoop(new PaintWorkletGlobalScope(frame, url, userAgent, securityOrigin, isolate));
16 paintWorkletGlobalScope->scriptController()->initializeContextIfNeeded(); 19 paintWorkletGlobalScope->scriptController()->initializeContextIfNeeded();
17 MainThreadDebugger::instance()->contextCreated(paintWorkletGlobalScope->scri ptController()->getScriptState(), paintWorkletGlobalScope->frame(), paintWorklet GlobalScope->getSecurityOrigin()); 20 MainThreadDebugger::instance()->contextCreated(paintWorkletGlobalScope->scri ptController()->getScriptState(), paintWorkletGlobalScope->frame(), paintWorklet GlobalScope->getSecurityOrigin());
18 return paintWorkletGlobalScope.release(); 21 return paintWorkletGlobalScope.release();
19 } 22 }
20 23
21 PaintWorkletGlobalScope::PaintWorkletGlobalScope(LocalFrame* frame, const KURL& url, const String& userAgent, PassRefPtr<SecurityOrigin> securityOrigin, v8::Iso late* isolate) 24 PaintWorkletGlobalScope::PaintWorkletGlobalScope(LocalFrame* frame, const KURL& url, const String& userAgent, PassRefPtr<SecurityOrigin> securityOrigin, v8::Iso late* isolate)
22 : WorkletGlobalScope(frame, url, userAgent, securityOrigin, isolate) 25 : WorkletGlobalScope(frame, url, userAgent, securityOrigin, isolate)
23 { 26 {
24 } 27 }
25 28
26 PaintWorkletGlobalScope::~PaintWorkletGlobalScope() 29 PaintWorkletGlobalScope::~PaintWorkletGlobalScope()
27 { 30 {
28 } 31 }
29 32
33 void PaintWorkletGlobalScope::dispose()
34 {
35 // Explicitly clear the paint defininitions to break a reference cycle
36 // between them and this global scope.
37 m_paintDefinitions.clear();
38
39 WorkletGlobalScope::dispose();
40 }
41
42 void PaintWorkletGlobalScope::registerPaint(const String& name, const ScriptValu e& ctorValue, ExceptionState& exceptionState)
43 {
44 if (m_paintDefinitions.contains(name)) {
45 exceptionState.throwDOMException(NotSupportedError, "A class with name:' " + name + "' is already registered.");
46 return;
47 }
48
49 if (name.isEmpty()) {
50 exceptionState.throwTypeError("The empty string is not a valid name.");
51 return;
52 }
53
54 v8::Isolate* isolate = scriptController()->getScriptState()->isolate();
55
56 v8::TryCatch block(isolate);
haraken 2016/04/01 00:16:06 I don't think you need this TryCatch block.
ikilpatrick 2016/04/01 03:08:43 Done.
57 v8::Local<v8::Context> context = scriptController()->context();
58
59 ASSERT(ctorValue.v8Value()->IsFunction());
60 v8::Local<v8::Function> constructor = v8::Local<v8::Function>::Cast(ctorValu e.v8Value());
61
62 v8::Local<v8::Value> inputPropertiesValue;
63 if (!constructor->Get(context, v8String(isolate, "inputProperties")).ToLocal (&inputPropertiesValue)) {
haraken 2016/04/01 00:16:06 Would you use v8Call macros in V8BindingMacros.h?
ikilpatrick 2016/04/01 03:08:43 Get can also fail if the developer does something
64 exceptionState.rethrowV8Exception(block.Exception());
65 return;
66 }
67
68 if (!isUndefinedOrNull(inputPropertiesValue)) {
69 toImplArray<Vector<String>>(inputPropertiesValue, 0, isolate, exceptionS tate);
70
71 if (exceptionState.hadException())
72 return;
73
74 // TODO(ikilpatrick): Hook up invalidation based on these inputPropertie s.
75 }
76
77 v8::Local<v8::Value> prototypeValue;
78 if (!constructor->Get(context, v8String(isolate, "prototype")).ToLocal(&prot otypeValue)) {
79 exceptionState.rethrowV8Exception(block.Exception());
80 return;
81 }
82
83 if (isUndefinedOrNull(prototypeValue)) {
84 exceptionState.throwTypeError("The 'prototype' object on the class does not exist.");
85 return;
86 }
87
88 if (!prototypeValue->IsObject()) {
89 exceptionState.throwTypeError("The 'prototype' property on the class is not an object.");
90 return;
91 }
92
93 v8::Local<v8::Object> prototype = v8::Local<v8::Object>::Cast(prototypeValue );
94
95 v8::Local<v8::Value> paintValue;
96 if (!prototype->Get(context, v8String(isolate, "paint")).ToLocal(&paintValue )) {
97 exceptionState.rethrowV8Exception(block.Exception());
98 return;
99 }
100
101 if (isUndefinedOrNull(paintValue)) {
102 exceptionState.throwTypeError("The 'paint' function on the prototype doe s not exist.");
103 return;
104 }
105
106 if (!paintValue->IsFunction()) {
107 exceptionState.throwTypeError("The 'paint' property on the prototype is not a function.");
108 return;
109 }
110
111 v8::Local<v8::Function> paint = v8::Local<v8::Function>::Cast(paintValue);
112
113 RefPtrWillBeRawPtr<CSSPaintDefinition> definition = CSSPaintDefinition::crea te(scriptController()->getScriptState(), constructor, paint);
114 m_paintDefinitions.set(name, definition);
115 }
116
117 CSSPaintDefinition* PaintWorkletGlobalScope::findDefinition(const String& name)
118 {
119 return m_paintDefinitions.get(name);
120 }
121
122 DEFINE_TRACE(PaintWorkletGlobalScope)
123 {
124 #if ENABLE(OILPAN)
125 visitor->trace(m_paintDefinitions);
126 #endif
127 WorkletGlobalScope::trace(visitor);
128 }
129
30 } // namespace blink 130 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698