1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// This file has been auto-generated by {{code_generator}}. DO NOT MODIFY!
6
7#ifndef {{v8_class}}_h
8#define {{v8_class}}_h
9
10{% filter conditional(conditional_string) %}
11{% for filename in header_includes %}
12#include "{{filename}}"
13{% endfor %}
14
15namespace WebCore {
16
17{% if has_event_constructor %}
18class Dictionary;
19{% endif %}
20{% if named_constructor %}
21class {{v8_class}}Constructor {
22public:
23    static v8::Handle<v8::FunctionTemplate> domTemplate(v8::Isolate*);
24    static const WrapperTypeInfo wrapperTypeInfo;
25};
26
27{% endif %}
28class {{v8_class}} {
29public:
30    static bool hasInstance(v8::Handle<v8::Value>, v8::Isolate*);
31    static v8::Handle<v8::Object> findInstanceInPrototypeChain(v8::Handle<v8::Value>, v8::Isolate*);
32    static v8::Handle<v8::FunctionTemplate> domTemplate(v8::Isolate*);
33    static {{cpp_class}}* toNative(v8::Handle<v8::Object> object)
34    {
35        return fromInternalPointer(object->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex));
36    }
37    static {{cpp_class}}* toNativeWithTypeCheck(v8::Isolate*, v8::Handle<v8::Value>);
38    static const WrapperTypeInfo wrapperTypeInfo;
39    static void derefObject(void*);
40    {% if has_visit_dom_wrapper %}
41    static void visitDOMWrapper(void*, const v8::Persistent<v8::Object>&, v8::Isolate*);
42    {% endif %}
43    {% if is_active_dom_object %}
44    static ActiveDOMObject* toActiveDOMObject(v8::Handle<v8::Object>);
45    {% endif %}
46    {% if is_event_target %}
47    static EventTarget* toEventTarget(v8::Handle<v8::Object>);
48    {% endif %}
49    {% if interface_name == 'Window' %}
50    static v8::Handle<v8::ObjectTemplate> getShadowObjectTemplate(v8::Isolate*);
51    {% endif %}
52    {% for method in methods if method.is_custom %}
53    {% filter conditional(method.conditional_string) %}
54    static void {{method.name}}MethodCustom(const v8::FunctionCallbackInfo<v8::Value>&);
55    {% endfilter %}
56    {% endfor %}
57    {% if constructors or has_custom_constructor or has_event_constructor %}
58    static void constructorCallback(const v8::FunctionCallbackInfo<v8::Value>&);
59    {% endif %}
60    {% if has_custom_constructor %}
61    static void constructorCustom(const v8::FunctionCallbackInfo<v8::Value>&);
62    {% endif %}
63    {% for attribute in attributes %}
64    {% if attribute.has_custom_getter %}{# FIXME: and not attribute.implemented_by #}
65    {% filter conditional(attribute.conditional_string) %}
66    static void {{attribute.name}}AttributeGetterCustom(const v8::PropertyCallbackInfo<v8::Value>&);
67    {% endfilter %}
68    {% endif %}
69    {% if attribute.has_custom_setter %}{# FIXME: and not attribute.implemented_by #}
70    {% filter conditional(attribute.conditional_string) %}
71    static void {{attribute.name}}AttributeSetterCustom(v8::Local<v8::Value>, const v8::PropertyCallbackInfo<void>&);
72    {% endfilter %}
73    {% endif %}
74    {% endfor %}
75    {# Custom special operations #}
76    {% if indexed_property_getter and indexed_property_getter.is_custom %}
77    static void indexedPropertyGetterCustom(uint32_t, const v8::PropertyCallbackInfo<v8::Value>&);
78    {% endif %}
79    {% if indexed_property_setter and indexed_property_setter.is_custom %}
80    static void indexedPropertySetterCustom(uint32_t, v8::Local<v8::Value>, const v8::PropertyCallbackInfo<v8::Value>&);
81    {% endif %}
82    {% if indexed_property_deleter and indexed_property_deleter.is_custom %}
83    static void indexedPropertyDeleterCustom(uint32_t, const v8::PropertyCallbackInfo<v8::Boolean>&);
84    {% endif %}
85    {% if named_property_getter and named_property_getter.is_custom %}
86    static void namedPropertyGetterCustom(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>&);
87    {% endif %}
88    {% if named_property_setter and named_property_setter.is_custom %}
89    static void namedPropertySetterCustom(v8::Local<v8::String>, v8::Local<v8::Value>, const v8::PropertyCallbackInfo<v8::Value>&);
90    {% endif %}
91    {% if named_property_getter and
92          named_property_getter.is_custom_property_query %}
93    static void namedPropertyQueryCustom(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Integer>&);
94    {% endif %}
95    {% if named_property_deleter and named_property_deleter.is_custom %}
96    static void namedPropertyDeleterCustom(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Boolean>&);
97    {% endif %}
98    {% if named_property_getter and
99          named_property_getter.is_custom_property_enumerator %}
100    static void namedPropertyEnumeratorCustom(const v8::PropertyCallbackInfo<v8::Array>&);
101    {% endif %}
102    {# END custom special operations #}
103    {% if has_custom_legacy_call_as_function %}
104    static void legacyCallCustom(const v8::FunctionCallbackInfo<v8::Value>&);
105    {% endif %}
106    {# Custom internal fields #}
107    {% set custom_internal_field_counter = 0 %}
108    {% if is_event_target and not is_node %}
109    {# Event listeners on DOM nodes are explicitly supported in the GC controller. #}
110    static const int eventListenerCacheIndex = v8DefaultWrapperInternalFieldCount + {{custom_internal_field_counter}};
111    {% set custom_internal_field_counter = custom_internal_field_counter + 1 %}
112    {% endif %}
113    {# persistentHandleIndex must be the last field, if it is present.
114       Detailed explanation: https://codereview.chromium.org/139173012
115       FIXME: Remove this internal field, and share one field for either:
116       * a persistent handle (if the object is in oilpan) or
117       * a C++ pointer to the DOM object (if the object is not in oilpan) #}
118    {% if gc_type == 'GarbageCollectedObject' %}
119    static const int persistentHandleIndex = v8DefaultWrapperInternalFieldCount + {{custom_internal_field_counter}};
120    static const int internalFieldCount = v8DefaultWrapperInternalFieldCount + {{custom_internal_field_counter}} + 1;
121    {% elif gc_type == 'WillBeGarbageCollectedObject' %}
122#if ENABLE(OILPAN)
123    static const int persistentHandleIndex = v8DefaultWrapperInternalFieldCount + {{custom_internal_field_counter}};
124    static const int internalFieldCount = v8DefaultWrapperInternalFieldCount + {{custom_internal_field_counter}} + 1;
125#else
126    static const int internalFieldCount = v8DefaultWrapperInternalFieldCount + {{custom_internal_field_counter}};
127#endif
128    {% else %}
129    static const int internalFieldCount = v8DefaultWrapperInternalFieldCount + {{custom_internal_field_counter}};
130    {% endif %}
131    {# End custom internal fields #}
132    static inline void* toInternalPointer({{cpp_class}}* impl)
133    {
134        {% if parent_interface %}
135        return V8{{parent_interface}}::toInternalPointer(impl);
136        {% else %}
137        return impl;
138        {% endif %}
139    }
140
141    static inline {{cpp_class}}* fromInternalPointer(void* object)
142    {
143        {% if parent_interface %}
144        return static_cast<{{cpp_class}}*>(V8{{parent_interface}}::fromInternalPointer(object));
145        {% else %}
146        return static_cast<{{cpp_class}}*>(object);
147        {% endif %}
148    }
149    {% if interface_name == 'Window' %}
150    static bool namedSecurityCheckCustom(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType, v8::Local<v8::Value> data);
151    static bool indexedSecurityCheckCustom(v8::Local<v8::Object> host, uint32_t index, v8::AccessType, v8::Local<v8::Value> data);
152    {% endif %}
153    static void installPerContextEnabledProperties(v8::Handle<v8::Object>, {{cpp_class}}*, v8::Isolate*){% if has_per_context_enabled_attributes %};
154    {% else %} { }
155    {% endif %}
156    static void installPerContextEnabledMethods(v8::Handle<v8::Object>, v8::Isolate*){% if per_context_enabled_methods %};
157    {% else %} { }
158    {% endif %}
159    {# Element wrappers #}
160    {% if interface_name == 'HTMLElement' %}
161    friend v8::Handle<v8::Object> createV8HTMLWrapper(HTMLElement*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
162    friend v8::Handle<v8::Object> createV8HTMLDirectWrapper(HTMLElement*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
163    {% elif interface_name == 'SVGElement' %}
164    friend v8::Handle<v8::Object> createV8SVGWrapper(SVGElement*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
165    friend v8::Handle<v8::Object> createV8SVGDirectWrapper(SVGElement*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
166    friend v8::Handle<v8::Object> createV8SVGFallbackWrapper(SVGElement*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
167    {% elif interface_name == 'HTMLUnknownElement' %}
168    friend v8::Handle<v8::Object> createV8HTMLFallbackWrapper(HTMLUnknownElement*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
169    {% elif interface_name == 'Element' %}
170    // This is a performance optimization hack. See V8Element::wrap.
171    friend v8::Handle<v8::Object> wrap(Node*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
172    {% endif %}
173
174private:
175    {% if not has_custom_to_v8 %}
176    friend v8::Handle<v8::Object> wrap({{cpp_class}}*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
177    static v8::Handle<v8::Object> createWrapper({{pass_cpp_type}}, v8::Handle<v8::Object> creationContext, v8::Isolate*);
178    {% endif %}
179};
180
181{% if has_custom_to_v8 %}
182class {{cpp_class}};
183v8::Handle<v8::Value> toV8({{cpp_class}}*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
184
185template<class CallbackInfo>
186inline void v8SetReturnValue(const CallbackInfo& callbackInfo, {{cpp_class}}* impl)
187{
188    v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInfo.GetIsolate()));
189}
190
191template<class CallbackInfo>
192inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, {{cpp_class}}* impl)
193{
194     v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInfo.GetIsolate()));
195}
196
197template<class CallbackInfo, class Wrappable>
198inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, {{cpp_class}}* impl, Wrappable*)
199{
200     v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInfo.GetIsolate()));
201}
202{% else %}{# has_custom_to_v8 #}
203v8::Handle<v8::Object> wrap({{cpp_class}}* impl, v8::Handle<v8::Object> creationContext, v8::Isolate*);
204
205inline v8::Handle<v8::Value> toV8({{cpp_class}}* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
206{
207    if (UNLIKELY(!impl))
208        return v8::Null(isolate);
209    v8::Handle<v8::Value> wrapper = DOMDataStore::getWrapper<{{v8_class}}>(impl, isolate);
210    if (!wrapper.IsEmpty())
211        return wrapper;
212    return wrap(impl, creationContext, isolate);
213}
214
215template<typename CallbackInfo>
216inline void v8SetReturnValue(const CallbackInfo& callbackInfo, {{cpp_class}}* impl)
217{
218    if (UNLIKELY(!impl)) {
219        v8SetReturnValueNull(callbackInfo);
220        return;
221    }
222    if (DOMDataStore::setReturnValueFromWrapper<{{v8_class}}>(callbackInfo.GetReturnValue(), impl))
223        return;
224    v8::Handle<v8::Object> wrapper = wrap(impl, callbackInfo.Holder(), callbackInfo.GetIsolate());
225    v8SetReturnValue(callbackInfo, wrapper);
226}
227
228template<typename CallbackInfo>
229inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, {{cpp_class}}* impl)
230{
231    ASSERT(DOMWrapperWorld::current(callbackInfo.GetIsolate()).isMainWorld());
232    if (UNLIKELY(!impl)) {
233        v8SetReturnValueNull(callbackInfo);
234        return;
235    }
236    if (DOMDataStore::setReturnValueFromWrapperForMainWorld<{{v8_class}}>(callbackInfo.GetReturnValue(), impl))
237        return;
238    v8::Handle<v8::Value> wrapper = wrap(impl, callbackInfo.Holder(), callbackInfo.GetIsolate());
239    v8SetReturnValue(callbackInfo, wrapper);
240}
241
242template<class CallbackInfo, class Wrappable>
243inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, {{cpp_class}}* impl, Wrappable* wrappable)
244{
245    if (UNLIKELY(!impl)) {
246        v8SetReturnValueNull(callbackInfo);
247        return;
248    }
249    if (DOMDataStore::setReturnValueFromWrapperFast<{{v8_class}}>(callbackInfo.GetReturnValue(), impl, callbackInfo.Holder(), wrappable))
250        return;
251    v8::Handle<v8::Object> wrapper = wrap(impl, callbackInfo.Holder(), callbackInfo.GetIsolate());
252    v8SetReturnValue(callbackInfo, wrapper);
253}
254{% endif %}{# has_custom_to_v8 #}
255
256inline v8::Handle<v8::Value> toV8({{pass_cpp_type}} impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
257{
258    return toV8(impl.get(), creationContext, isolate);
259}
260
261template<class CallbackInfo>
262inline void v8SetReturnValue(const CallbackInfo& callbackInfo, {{pass_cpp_type}} impl)
263{
264    v8SetReturnValue(callbackInfo, impl.get());
265}
266
267template<class CallbackInfo>
268inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, {{pass_cpp_type}} impl)
269{
270    v8SetReturnValueForMainWorld(callbackInfo, impl.get());
271}
272
273template<class CallbackInfo, class Wrappable>
274inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, {{pass_cpp_type}} impl, Wrappable* wrappable)
275{
276    v8SetReturnValueFast(callbackInfo, impl.get(), wrappable);
277}
278
279{% if has_event_constructor %}
280bool initialize{{cpp_class}}({{cpp_class}}Init&, const Dictionary&, ExceptionState&, const v8::FunctionCallbackInfo<v8::Value>& info, const String& = "");
281
282{% endif %}
283}
284{% endfilter %}
285#endif // {{v8_class}}_h
286