• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1{% from "macros.tmpl" import license %}
2{{ license() }}
3
4#include "config.h"
5#include "V8{{namespace}}ElementWrapperFactory.h"
6
7#include "{{namespace}}Names.h"
8#include "bindings/v8/CustomElementWrapper.h"
9{% for tag in tags|sort if tag.has_js_interface %}
10#include "V8{{tag.interface}}.h"
11{% endfor %}
12{% for tag in tags|sort if tag.has_js_interface %}
13#include "core/{{namespace|lower}}/{{tag.js_interface}}.h"
14{% endfor %}
15#include "core/{{namespace|lower}}/{{fallback_js_interface}}.h"
16#include "core/dom/ContextFeatures.h"
17#include "core/dom/Document.h"
18#include "core/frame/Settings.h"
19#include "platform/RuntimeEnabledFeatures.h"
20#include "wtf/StdLibExtras.h"
21
22namespace WebCore {
23
24using namespace {{namespace}}Names;
25
26typedef v8::Handle<v8::Object> (*Create{{namespace}}ElementWrapperFunction)({{namespace}}Element*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
27
28static v8::Handle<v8::Object> create{{namespace}}ElementWrapper({{namespace}}Element*, v8::Handle<v8::Object>, v8::Isolate*)
29{
30    ASSERT_NOT_REACHED();
31    return v8::Handle<v8::Object>();
32}
33{% for js_interface, list in tags|sort|selectattr('has_js_interface')|groupby('js_interface') %}
34{% filter enable_conditional(list[0].Conditional) %}
35static v8::Handle<v8::Object> create{{js_interface}}Wrapper({{namespace}}Element* element, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
36{
37    {% if list[0].contextConditional %}
38    if (!ContextFeatures::{{list[0].contextConditional}}Enabled(&element->document()))
39        return createV8{{namespace}}FallbackWrapper(to{{fallback_js_interface}}(element), creationContext, isolate);
40    {% endif %}
41    {% if list[0].runtimeEnabled %}
42    if (!RuntimeEnabledFeatures::{{list[0].runtimeEnabled}}Enabled())
43        return createV8{{namespace}}FallbackWrapper(to{{fallback_js_interface}}(element), creationContext, isolate);
44    {% endif %}
45    return wrap(static_cast<{{js_interface}}*>(element), creationContext, isolate);
46}
47{% endfilter %}
48{% endfor %}
49
50v8::Handle<v8::Object> createV8{{namespace}}Wrapper({{namespace}}Element* element, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
51{
52    typedef HashMap<StringImpl*, Create{{namespace}}ElementWrapperFunction> FunctionMap;
53    DEFINE_STATIC_LOCAL(FunctionMap, map, ());
54    if (map.isEmpty()) {
55    {% for tag in tags|sort %}
56    {% filter enable_conditional(tag.Conditional) %}
57        map.set({{tag|symbol}}Tag.localName().impl(), create{{tag.js_interface}}Wrapper);
58    {% endfilter %}
59    {% endfor %}
60    }
61
62    Create{{namespace}}ElementWrapperFunction createWrapperFunction = map.get(element->localName().impl());
63    if (createWrapperFunction == create{{namespace}}ElementWrapper)
64        createWrapperFunction = createV8{{namespace}}DirectWrapper;
65    if (element->isCustomElement())
66        return CustomElementWrapper<{{namespace}}Element, V8{{namespace}}Element>::wrap(element, creationContext, isolate, createWrapperFunction);
67
68    if (createWrapperFunction)
69        return createWrapperFunction(element, creationContext, isolate);
70    {% if fallback_js_interface == namespace + 'Element' %}
71    return V8{{fallback_js_interface}}::createWrapper(element, creationContext, isolate);
72    {% else %}
73    return wrap(to{{fallback_js_interface}}(element), creationContext, isolate);
74    {% endif %}
75}
76
77const WrapperTypeInfo* findWrapperTypeFor{{namespace}}TagName(const AtomicString& name)
78{
79    typedef HashMap<StringImpl*, const WrapperTypeInfo*> NameTypeMap;
80    DEFINE_STATIC_LOCAL(NameTypeMap, map, ());
81    if (map.isEmpty()) {
82        // FIXME: This seems wrong. We should list every interface here, not
83        // just the ones that have specialized JavaScript interfaces.
84        {% for tag in tags|sort if tag.has_js_interface %}
85        {% filter enable_conditional(tag.Conditional) %}
86        map.set({{tag|symbol}}Tag.localName().impl(), &V8{{tag.js_interface}}::wrapperTypeInfo);
87        {% endfilter %}
88        {% endfor %}
89    }
90
91    if (const WrapperTypeInfo* result = map.get(name.impl()))
92        return result;
93
94    return &V8{{fallback_js_interface}}::wrapperTypeInfo;
95}
96
97}
98