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