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

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: . 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::contextCreated(paintWorkletGlobalScope->scriptController ()->getScriptState(), paintWorkletGlobalScope->frame(), paintWorkletGlobalScope- >getSecurityOrigin()); 20 MainThreadDebugger::contextCreated(paintWorkletGlobalScope->scriptController ()->getScriptState(), paintWorkletGlobalScope->frame(), paintWorkletGlobalScope- >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::registerPaint(const String& name, const ScriptValu e& ctorValue, ExceptionState& exceptionState)
34 {
35 if (m_paintDefinitions.contains(name)) {
36 exceptionState.throwDOMException(NotSupportedError, "A class with name:' " + name + "' is already registered.");
37 return;
38 }
39
40 if (name.isEmpty()) {
41 exceptionState.throwTypeError("The empty string is not a valid name.");
42 return;
43 }
44
45 v8::Isolate* isolate = scriptController()->getScriptState()->isolate();
46
47 v8::TryCatch block(isolate);
48 v8::Local<v8::Context> context = scriptController()->context();
49
50 ASSERT(ctorValue.v8Value()->IsFunction());
51 v8::Local<v8::Function> ctor = v8::Local<v8::Function>::Cast(ctorValue.v8Val ue());
52
53 v8::Local<v8::Value> inputPropertiesValue;
54 if (!ctor->Get(context, v8String(isolate, "inputProperties")).ToLocal(&input PropertiesValue)) {
55 exceptionState.rethrowV8Exception(block.Exception());
56 return;
57 }
58
59 if (!isUndefinedOrNull(inputPropertiesValue)) {
60 toImplArray<Vector<String>>(inputPropertiesValue, 0, isolate, exceptionS tate);
61
62 if (exceptionState.hadException())
63 return;
64
65 // TODO(ikilpatrick): Hook up invalidation based on these inputPropertie s.
66 }
67
68 v8::Local<v8::Value> prototypeValue;
69 if (!ctor->Get(context, v8String(isolate, "prototype")).ToLocal(&prototypeVa lue)) {
70 exceptionState.rethrowV8Exception(block.Exception());
71 return;
72 }
73
74 if (isUndefinedOrNull(prototypeValue)) {
75 exceptionState.throwTypeError("The 'prototype' object on the class does not exist.");
76 return;
77 }
78
79 if (!prototypeValue->IsObject()) {
80 exceptionState.throwTypeError("The 'prototype' property on the class is not an object.");
81 return;
82 }
83
84 v8::Local<v8::Object> prototype = v8::Local<v8::Object>::Cast(prototypeValue );
85
86 v8::Local<v8::Value> paintValue;
87 if (!prototype->Get(context, v8String(isolate, "paint")).ToLocal(&paintValue )) {
88 exceptionState.rethrowV8Exception(block.Exception());
89 return;
90 }
91
92 if (isUndefinedOrNull(paintValue)) {
93 exceptionState.throwTypeError("The 'paint' function on the prototype doe s not exist.");
94 return;
95 }
96
97 if (!paintValue->IsFunction()) {
98 exceptionState.throwTypeError("The 'paint' property on the prototype is not a function.");
99 return;
100 }
101
102 v8::Local<v8::Function> paint = v8::Local<v8::Function>::Cast(paintValue);
103
104 RefPtrWillBeRawPtr<CSSPaintDefinition> definition = CSSPaintDefinition::crea te(scriptController()->getScriptState(), ctor, paint);
105 m_paintDefinitions.set(name, definition);
106 }
107
108 CSSPaintDefinition* PaintWorkletGlobalScope::findDefinition(const String& name)
109 {
110 return m_paintDefinitions.get(name);
111 }
112
113 DEFINE_TRACE(PaintWorkletGlobalScope)
114 {
115 visitor->trace(m_paintDefinitions);
116 WorkletGlobalScope::trace(visitor);
117 }
118
30 } // namespace blink 119 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698