Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / bindings / templates / interface.h
1 {# http://www.chromium.org/blink/coding-style#TOC-License #}
2 /*
3  * Copyright (C) 2013 Google Inc. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  *     * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *     * Redistributions in binary form must reproduce the above
12  * copyright notice, this list of conditions and the following disclaimer
13  * in the documentation and/or other materials provided with the
14  * distribution.
15  *     * Neither the name of Google Inc. nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31
32 {# FIXME: Rename to Python when switch #}
33 // This file has been auto-generated by code_generator_v8.pm. DO NOT MODIFY!
34
35 #ifndef {{v8_class}}_h
36 #define {{v8_class}}_h
37
38 {% filter conditional(conditional_string) %}
39 {% for filename in header_includes %}
40 #include "{{filename}}"
41 {% endfor %}
42
43 namespace WebCore {
44
45 {% if has_event_constructor %}
46 class Dictionary;
47 {% endif %}
48 {% if named_constructor %}
49 class {{v8_class}}Constructor {
50 public:
51     static v8::Handle<v8::FunctionTemplate> domTemplate(v8::Isolate*, WrapperWorldType);
52     static const WrapperTypeInfo wrapperTypeInfo;
53 };
54
55 {% endif %}
56 class {{v8_class}} {
57 public:
58     static bool hasInstance(v8::Handle<v8::Value>, v8::Isolate*);
59     static v8::Handle<v8::FunctionTemplate> domTemplate(v8::Isolate*, WrapperWorldType);
60     static {{cpp_class}}* toNative(v8::Handle<v8::Object> object)
61     {
62         return fromInternalPointer(object->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex));
63     }
64     static const WrapperTypeInfo wrapperTypeInfo;
65     static void derefObject(void*);
66     {% if has_visit_dom_wrapper %}
67     static void visitDOMWrapper(void*, const v8::Persistent<v8::Object>&, v8::Isolate*);
68     {% endif %}
69     {% if is_active_dom_object %}
70     static ActiveDOMObject* toActiveDOMObject(v8::Handle<v8::Object>);
71     {% endif %}
72     {% if is_event_target %}
73     static EventTarget* toEventTarget(v8::Handle<v8::Object>);
74     {% endif %}
75     {% if interface_name == 'Window' %}
76     static v8::Handle<v8::ObjectTemplate> getShadowObjectTemplate(v8::Isolate*, WrapperWorldType);
77     {% endif %}
78     {% for method in methods if method.is_custom %}
79     {% filter conditional(method.conditional_string) %}
80     static void {{method.name}}MethodCustom(const v8::FunctionCallbackInfo<v8::Value>&);
81     {% endfilter %}
82     {% endfor %}
83     {% if constructors or has_custom_constructor or has_event_constructor %}
84     static void constructorCallback(const v8::FunctionCallbackInfo<v8::Value>&);
85     {% endif %}
86     {% if has_custom_constructor %}
87     static void constructorCustom(const v8::FunctionCallbackInfo<v8::Value>&);
88     {% endif %}
89     {% for attribute in attributes %}
90     {% if attribute.has_custom_getter %}{# FIXME: and not attribute.implemented_by #}
91     {% filter conditional(attribute.conditional_string) %}
92     static void {{attribute.name}}AttributeGetterCustom(const v8::PropertyCallbackInfo<v8::Value>&);
93     {% endfilter %}
94     {% endif %}
95     {% if attribute.has_custom_setter %}{# FIXME: and not attribute.implemented_by #}
96     {% filter conditional(attribute.conditional_string) %}
97     static void {{attribute.name}}AttributeSetterCustom(v8::Local<v8::Value>, const v8::PropertyCallbackInfo<void>&);
98     {% endfilter %}
99     {% endif %}
100     {% endfor %}
101     {# Custom special operations #}
102     {% if indexed_property_getter and indexed_property_getter.is_custom %}
103     static void indexedPropertyGetterCustom(uint32_t, const v8::PropertyCallbackInfo<v8::Value>&);
104     {% endif %}
105     {% if indexed_property_setter and indexed_property_setter.is_custom %}
106     static void indexedPropertySetterCustom(uint32_t, v8::Local<v8::Value>, const v8::PropertyCallbackInfo<v8::Value>&);
107     {% endif %}
108     {% if indexed_property_deleter and indexed_property_deleter.is_custom %}
109     static void indexedPropertyDeleterCustom(uint32_t, const v8::PropertyCallbackInfo<v8::Boolean>&);
110     {% endif %}
111     {% if named_property_getter and named_property_getter.is_custom %}
112     static void namedPropertyGetterCustom(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>&);
113     {% endif %}
114     {% if named_property_setter and named_property_setter.is_custom %}
115     static void namedPropertySetterCustom(v8::Local<v8::String>, v8::Local<v8::Value>, const v8::PropertyCallbackInfo<v8::Value>&);
116     {% endif %}
117     {% if named_property_getter and
118           named_property_getter.is_custom_property_query %}
119     static void namedPropertyQueryCustom(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Integer>&);
120     {% endif %}
121     {% if named_property_deleter and named_property_deleter.is_custom %}
122     static void namedPropertyDeleterCustom(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Boolean>&);
123     {% endif %}
124     {% if named_property_getter and
125           named_property_getter.is_custom_property_enumerator %}
126     static void namedPropertyEnumeratorCustom(const v8::PropertyCallbackInfo<v8::Array>&);
127     {% endif %}
128     {# END custom special operations #}
129     {% if has_custom_legacy_call_as_function %}
130     static void legacyCallCustom(const v8::FunctionCallbackInfo<v8::Value>&);
131     {% endif %}
132     {# Custom internal fields #}
133     {% set custom_internal_field_counter = 0 %}
134     {% if is_event_target and not is_node %}
135     {# Event listeners on DOM nodes are explicitly supported in the GC controller. #}
136     static const int eventListenerCacheIndex = v8DefaultWrapperInternalFieldCount + {{custom_internal_field_counter}};
137     {% set custom_internal_field_counter = custom_internal_field_counter + 1 %}
138     {% endif %}
139     {# persistentHandleIndex must be the last field, if it is present.
140        Detailed explanation: https://codereview.chromium.org/139173012
141        FIXME: Remove this internal field, and share one field for either:
142        * a persistent handle (if the object is in oilpan) or
143        * a C++ pointer to the DOM object (if the object is not in oilpan) #}
144     {% if is_will_be_garbage_collected %}
145     static const int persistentHandleIndex = v8DefaultWrapperInternalFieldCount + {{custom_internal_field_counter}};
146     {% set custom_internal_field_counter = custom_internal_field_counter + 1 %}
147     {% endif %}
148     static const int internalFieldCount = v8DefaultWrapperInternalFieldCount + {{custom_internal_field_counter}};
149     {# End custom internal fields #}
150     static inline void* toInternalPointer({{cpp_class}}* impl)
151     {
152         {% if parent_interface %}
153         return V8{{parent_interface}}::toInternalPointer(impl);
154         {% else %}
155         return impl;
156         {% endif %}
157     }
158
159     static inline {{cpp_class}}* fromInternalPointer(void* object)
160     {
161         {% if parent_interface %}
162         return static_cast<{{cpp_class}}*>(V8{{parent_interface}}::fromInternalPointer(object));
163         {% else %}
164         return static_cast<{{cpp_class}}*>(object);
165         {% endif %}
166     }
167     {% if interface_name == 'Window' %}
168     static bool namedSecurityCheckCustom(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType, v8::Local<v8::Value> data);
169     static bool indexedSecurityCheckCustom(v8::Local<v8::Object> host, uint32_t index, v8::AccessType, v8::Local<v8::Value> data);
170     {% endif %}
171     static void installPerContextEnabledProperties(v8::Handle<v8::Object>, {{cpp_class}}*, v8::Isolate*){% if has_per_context_enabled_attributes %};
172     {% else %} { }
173     {% endif %}
174     static void installPerContextEnabledMethods(v8::Handle<v8::Object>, v8::Isolate*){% if has_per_context_enabled_methods %};
175     {% else %} { }
176     {% endif %}
177     {# Element wrappers #}
178     {% if interface_name == 'HTMLElement' %}
179     friend v8::Handle<v8::Object> createV8HTMLWrapper(HTMLElement*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
180     friend v8::Handle<v8::Object> createV8HTMLDirectWrapper(HTMLElement*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
181     {% elif interface_name == 'HTMLUnknownElement' %}
182     friend v8::Handle<v8::Object> createV8HTMLFallbackWrapper(HTMLUnknownElement*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
183     {% elif interface_name == 'Element' %}
184     // This is a performance optimization hack. See V8Element::wrap.
185     friend v8::Handle<v8::Object> wrap(Node*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
186     {% endif %}
187
188 private:
189     {% if not has_custom_to_v8 %}
190     friend v8::Handle<v8::Object> wrap({{cpp_class}}*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
191     static v8::Handle<v8::Object> createWrapper({{pass_ref_ptr}}<{{cpp_class}}>, v8::Handle<v8::Object> creationContext, v8::Isolate*);
192     {% endif %}
193 };
194
195 template<>
196 class WrapperTypeTraits<{{cpp_class}} > {
197 public:
198     static const WrapperTypeInfo* wrapperTypeInfo() { return &{{v8_class}}::wrapperTypeInfo; }
199 };
200
201 {% if has_custom_to_v8 %}
202 class {{cpp_class}};
203 v8::Handle<v8::Value> toV8({{cpp_class}}*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
204
205 template<class CallbackInfo>
206 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, {{cpp_class}}* impl)
207 {
208     v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInfo.GetIsolate()));
209 }
210
211 template<class CallbackInfo>
212 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, {{cpp_class}}* impl)
213 {
214      v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInfo.GetIsolate()));
215 }
216
217 template<class CallbackInfo, class Wrappable>
218 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, {{cpp_class}}* impl, Wrappable*)
219 {
220      v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInfo.GetIsolate()));
221 }
222 {% else %}{# has_custom_to_v8 #}
223 {% if has_custom_wrap or special_wrap_for or is_document %}
224 v8::Handle<v8::Object> wrap({{cpp_class}}* impl, v8::Handle<v8::Object> creationContext, v8::Isolate*);
225 {% else %}
226 inline v8::Handle<v8::Object> wrap({{cpp_class}}* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
227 {
228     ASSERT(impl);
229     ASSERT(!DOMDataStore::containsWrapper<{{v8_class}}>(impl, isolate));
230     return {{v8_class}}::createWrapper(impl, creationContext, isolate);
231 }
232 {% endif %}
233
234 inline v8::Handle<v8::Value> toV8({{cpp_class}}* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
235 {
236     if (UNLIKELY(!impl))
237         return v8::Null(isolate);
238     v8::Handle<v8::Value> wrapper = DOMDataStore::getWrapper<{{v8_class}}>(impl, isolate);
239     if (!wrapper.IsEmpty())
240         return wrapper;
241     return wrap(impl, creationContext, isolate);
242 }
243
244 template<typename CallbackInfo>
245 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, {{cpp_class}}* impl)
246 {
247     if (UNLIKELY(!impl)) {
248         v8SetReturnValueNull(callbackInfo);
249         return;
250     }
251     if (DOMDataStore::setReturnValueFromWrapper<{{v8_class}}>(callbackInfo.GetReturnValue(), impl))
252         return;
253     v8::Handle<v8::Object> wrapper = wrap(impl, callbackInfo.Holder(), callbackInfo.GetIsolate());
254     v8SetReturnValue(callbackInfo, wrapper);
255 }
256
257 template<typename CallbackInfo>
258 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, {{cpp_class}}* impl)
259 {
260     ASSERT(worldType(callbackInfo.GetIsolate()) == MainWorld);
261     if (UNLIKELY(!impl)) {
262         v8SetReturnValueNull(callbackInfo);
263         return;
264     }
265     if (DOMDataStore::setReturnValueFromWrapperForMainWorld<{{v8_class}}>(callbackInfo.GetReturnValue(), impl))
266         return;
267     v8::Handle<v8::Value> wrapper = wrap(impl, callbackInfo.Holder(), callbackInfo.GetIsolate());
268     v8SetReturnValue(callbackInfo, wrapper);
269 }
270
271 template<class CallbackInfo, class Wrappable>
272 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, {{cpp_class}}* impl, Wrappable* wrappable)
273 {
274     if (UNLIKELY(!impl)) {
275         v8SetReturnValueNull(callbackInfo);
276         return;
277     }
278     if (DOMDataStore::setReturnValueFromWrapperFast<{{v8_class}}>(callbackInfo.GetReturnValue(), impl, callbackInfo.Holder(), wrappable))
279         return;
280     v8::Handle<v8::Object> wrapper = wrap(impl, callbackInfo.Holder(), callbackInfo.GetIsolate());
281     v8SetReturnValue(callbackInfo, wrapper);
282 }
283 {% endif %}{# has_custom_to_v8 #}
284
285 inline v8::Handle<v8::Value> toV8({{pass_ref_ptr}}<{{cpp_class}}> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
286 {
287     return toV8(impl.get(), creationContext, isolate);
288 }
289
290 template<class CallbackInfo>
291 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, {{pass_ref_ptr}}<{{cpp_class}}> impl)
292 {
293     v8SetReturnValue(callbackInfo, impl.get());
294 }
295
296 template<class CallbackInfo>
297 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, {{pass_ref_ptr}}<{{cpp_class}}> impl)
298 {
299     v8SetReturnValueForMainWorld(callbackInfo, impl.get());
300 }
301
302 template<class CallbackInfo, class Wrappable>
303 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, {{pass_ref_ptr}}<{{cpp_class}}> impl, Wrappable* wrappable)
304 {
305     v8SetReturnValueFast(callbackInfo, impl.get(), wrappable);
306 }
307
308 {% if has_event_constructor %}
309 bool initialize{{cpp_class}}({{cpp_class}}Init&, const Dictionary&, ExceptionState&, const v8::FunctionCallbackInfo<v8::Value>& info, const String& = "");
310
311 {% endif %}
312 }
313 {% endfilter %}
314 #endif // {{v8_class}}_h