Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / bindings / templates / interface_base.cpp
index 34520c6..9a6b9d9 100644 (file)
@@ -6,12 +6,13 @@
 
 #include "config.h"
 {% filter conditional(conditional_string) %}
-#include "{{v8_class}}.h"
+#include "{{v8_class_or_partial}}.h"
 
-{% for filename in cpp_includes if filename != '%s.h' % v8_class %}
+{% for filename in cpp_includes if filename != '%s.h' % cpp_class_or_partial %}
 #include "{{filename}}"
 {% endfor %}
 
+{% block initialize_script_wrappable %}{% endblock %}
 namespace blink {
 {% set to_active_dom_object = '%s::toActiveDOMObject' % v8_class
                               if is_active_dom_object else '0' %}
@@ -23,19 +24,30 @@ namespace blink {
                                   if parent_interface else '0' %}
 {% set wrapper_type_prototype = 'WrapperTypeExceptionPrototype' if is_exception else
                                 'WrapperTypeObjectPrototype' %}
+{% set dom_template = '%s::domTemplate' % v8_class if not is_array_buffer_or_view else '0' %}
 
-const WrapperTypeInfo {{v8_class}}::wrapperTypeInfo = { gin::kEmbedderBlink, {{v8_class}}::domTemplate, {{v8_class}}::refObject, {{v8_class}}::derefObject, {{v8_class}}::createPersistentHandle, {{to_active_dom_object}}, {{to_event_target}}, {{visit_dom_wrapper}}, {{v8_class}}::installConditionallyEnabledMethods, {{v8_class}}::installConditionallyEnabledProperties, {{parent_wrapper_type_info}}, WrapperTypeInfo::{{wrapper_type_prototype}}, WrapperTypeInfo::{{wrapper_class_id}}, WrapperTypeInfo::{{lifetime}}, WrapperTypeInfo::{{gc_type}} };
+{% set wrapper_type_info_const = '' if has_partial_interface else 'const ' %}
+{% if not is_partial %}
+{{wrapper_type_info_const}}WrapperTypeInfo {{v8_class}}::wrapperTypeInfo = { gin::kEmbedderBlink, {{dom_template}}, {{v8_class}}::refObject, {{v8_class}}::derefObject, {{v8_class}}::trace, {{to_active_dom_object}}, {{to_event_target}}, {{visit_dom_wrapper}}, {{v8_class}}::installConditionallyEnabledMethods, {{v8_class}}::installConditionallyEnabledProperties, {{parent_wrapper_type_info}}, WrapperTypeInfo::{{wrapper_type_prototype}}, WrapperTypeInfo::{{wrapper_class_id}}, WrapperTypeInfo::{{lifetime}}, WrapperTypeInfo::{{gc_type}} };
 
 {% if is_script_wrappable %}
 // This static member must be declared by DEFINE_WRAPPERTYPEINFO in {{cpp_class}}.h.
 // For details, see the comment of DEFINE_WRAPPERTYPEINFO in
 // bindings/core/v8/ScriptWrappable.h.
+{% if is_typed_array_type %}
+template<>
+{% endif %}
 const WrapperTypeInfo& {{cpp_class}}::s_wrapperTypeInfo = {{v8_class}}::wrapperTypeInfo;
 
 {% endif %}
-namespace {{cpp_class}}V8Internal {
-
-template <typename T> void V8_USE(T) { }
+{% endif %}
+{% if not is_array_buffer_or_view %}
+namespace {{cpp_class_or_partial}}V8Internal {
+{% if has_partial_interface %}
+{% for method in methods if method.overloads and method.overloads.has_partial_overloads %}
+static void (*{{method.name}}MethodForPartialInterface)(const v8::FunctionCallbackInfo<v8::Value>&) = 0;
+{% endfor %}
+{% endif %}
 
 {# Constants #}
 {% from 'constants.cpp' import constant_getter_callback
@@ -66,14 +78,70 @@ template <typename T> void V8_USE(T) { }
 {% endfor %}
 {% endif %}
 {% endfor %}
-{% block constructor_getter %}{% endblock %}
+{##############################################################################}
+{% block constructor_getter %}
+{% if has_constructor_attributes %}
+static void {{cpp_class}}ConstructorGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
+{
+    v8::Handle<v8::Value> data = info.Data();
+    ASSERT(data->IsExternal());
+    V8PerContextData* perContextData = V8PerContextData::from(info.Holder()->CreationContext());
+    if (!perContextData)
+        return;
+    v8SetReturnValue(info, perContextData->constructorForType(WrapperTypeInfo::unwrap(data)));
+}
+
+{% endif %}
+{% endblock %}
+{##############################################################################}
 {% for attribute in attributes if attribute.needs_constructor_getter_callback %}
 {% for world_suffix in attribute.world_suffixes %}
 {{constructor_getter_callback(attribute, world_suffix)}}
 {% endfor %}
 {% endfor %}
-{% block replaceable_attribute_setter_and_callback %}{% endblock %}
-{% block security_check_functions %}{% endblock %}
+{##############################################################################}
+{% block replaceable_attribute_setter_and_callback %}
+{% if has_replaceable_attributes or has_constructor_attributes %}
+static void {{cpp_class}}ForceSetAttributeOnThis(v8::Local<v8::String> name, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
+{
+    {% if is_check_security %}
+    {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder());
+    v8::String::Utf8Value attributeName(name);
+    ExceptionState exceptionState(ExceptionState::SetterContext, *attributeName, "{{interface_name}}", info.Holder(), info.GetIsolate());
+    if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->frame(), exceptionState)) {
+        exceptionState.throwIfNeeded();
+        return;
+    }
+    {% endif %}
+    if (info.This()->IsObject())
+        v8::Handle<v8::Object>::Cast(info.This())->ForceSet(name, v8Value);
+}
+
+static void {{cpp_class}}ForceSetAttributeOnThisCallback(v8::Local<v8::String> name, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
+{
+    {{cpp_class_or_partial}}V8Internal::{{cpp_class}}ForceSetAttributeOnThis(name, v8Value, info);
+}
+
+{% endif %}
+{% endblock %}
+{##############################################################################}
+{% block security_check_functions %}
+{% if has_access_check_callbacks %}
+bool indexedSecurityCheck(v8::Local<v8::Object> host, uint32_t index, v8::AccessType type, v8::Local<v8::Value>)
+{
+    {{cpp_class}}* impl = {{v8_class}}::toImpl(host);
+    return BindingSecurity::shouldAllowAccessToFrame(v8::Isolate::GetCurrent(), impl->frame(), DoNotReportSecurityError);
+}
+
+bool namedSecurityCheck(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType type, v8::Local<v8::Value>)
+{
+    {{cpp_class}}* impl = {{v8_class}}::toImpl(host);
+    return BindingSecurity::shouldAllowAccessToFrame(v8::Isolate::GetCurrent(), impl->frame(), DoNotReportSecurityError);
+}
+
+{% endif %}
+{% endblock %}
+{##############################################################################}
 {# Methods #}
 {% from 'methods.cpp' import generate_method, overload_resolution_method,
        method_callback, origin_safe_method_getter, generate_constructor,
@@ -82,17 +150,24 @@ template <typename T> void V8_USE(T) { }
 {% for method in methods %}
 {% if method.should_be_exposed_to_script %}
 {% for world_suffix in method.world_suffixes %}
-{% if not method.is_custom %}
+{% if not method.is_custom and method.visible %}
 {{generate_method(method, world_suffix)}}
 {% endif %}
-{% if method.overloads %}
+{% if method.overloads and method.overloads.visible %}
 {{overload_resolution_method(method.overloads, world_suffix)}}
 {% endif %}
 {% if not method.overload_index or method.overloads %}
+{# Document about the following condition: #}
+{# https://docs.google.com/document/d/1qBC7Therp437Jbt_QYAtNYMZs6zQ_7_tnMkNUG_ACqs/edit?usp=sharing #}
+{% if (method.overloads and method.overloads.visible and
+        (not method.overloads.has_partial_overloads or not is_partial)) or
+      (not method.overloads and method.visible) %}
 {# A single callback is generated for overloaded methods #}
+{# with considering partial overloads #}
 {{method_callback(method, world_suffix)}}
 {% endif %}
-{% if method.is_do_not_check_security %}
+{% endif %}
+{% if method.is_do_not_check_security and method.visible %}
 {{origin_safe_method_getter(method, world_suffix)}}
 {% endif %}
 {% endfor %}
@@ -126,28 +201,262 @@ template <typename T> void V8_USE(T) { }
 {% block named_property_deleter_callback %}{% endblock %}
 {% block named_property_enumerator %}{% endblock %}
 {% block named_property_enumerator_callback %}{% endblock %}
-} // namespace {{cpp_class}}V8Internal
+} // namespace {{cpp_class_or_partial}}V8Internal
 
 {% block visit_dom_wrapper %}{% endblock %}
 {% block shadow_attributes %}{% endblock %}
-{% block install_attributes %}{% endblock %}
-{% block install_accessors %}{% endblock %}
-{% block install_methods %}{% endblock %}
+{##############################################################################}
+{% block install_attributes %}
+{% from 'attributes.cpp' import attribute_configuration with context %}
+{% if has_attribute_configuration %}
+static const V8DOMConfiguration::AttributeConfiguration {{v8_class}}Attributes[] = {
+    {% for attribute in attributes
+       if not (attribute.is_expose_js_accessors or
+               attribute.is_static or
+               attribute.runtime_enabled_function or
+               attribute.per_context_enabled_function or
+               attribute.exposed_test or
+               (interface_name == 'Window' and attribute.is_unforgeable))
+           and attribute.should_be_exposed_to_script %}
+    {% filter conditional(attribute.conditional_string) %}
+    {{attribute_configuration(attribute)}},
+    {% endfilter %}
+    {% endfor %}
+};
+
+{% endif %}
+{% endblock %}
+{##############################################################################}
+{% block install_accessors %}
+{% from 'attributes.cpp' import attribute_configuration with context %}
+{% if has_accessors %}
+static const V8DOMConfiguration::AccessorConfiguration {{v8_class}}Accessors[] = {
+    {% for attribute in attributes if attribute.is_expose_js_accessors and attribute.should_be_exposed_to_script %}
+    {{attribute_configuration(attribute)}},
+    {% endfor %}
+};
+
+{% endif %}
+{% endblock %}
+{##############################################################################}
+{% block install_methods %}
+{% from 'methods.cpp' import method_configuration with context %}
+{% if method_configuration_methods %}
+static const V8DOMConfiguration::MethodConfiguration {{v8_class}}Methods[] = {
+    {% for method in method_configuration_methods %}
+    {% filter conditional(method.conditional_string) %}
+    {{method_configuration(method)}},
+    {% endfilter %}
+    {% endfor %}
+};
+
+{% endif %}
+{% endblock %}
+{% endif %}{# not is_array_buffer_or_view #}
+{##############################################################################}
 {% block named_constructor %}{% endblock %}
 {% block initialize_event %}{% endblock %}
 {% block constructor_callback %}{% endblock %}
 {% block configure_shadow_object_template %}{% endblock %}
-{% block install_dom_template %}{% endblock %}
+{##############################################################################}
+{% block install_dom_template %}
+{% if not is_array_buffer_or_view %}
+{% from 'methods.cpp' import install_custom_signature with context %}
+{% from 'attributes.cpp' import attribute_configuration with context %}
+{% from 'constants.cpp' import install_constants with context %}
+{% if has_partial_interface or is_partial %}
+void {{v8_class_or_partial}}::install{{v8_class}}Template(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate)
+{% else %}
+static void install{{v8_class}}Template(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate)
+{% endif %}
+{
+    {% if is_partial %}
+    {{v8_class}}::install{{v8_class}}Template(functionTemplate, isolate);
+    {% else %}
+    functionTemplate->ReadOnlyPrototype();
+    {% endif %}
+
+    v8::Local<v8::Signature> defaultSignature;
+    {% set parent_template =
+           'V8%s::domTemplate(isolate)' % parent_interface
+           if parent_interface else 'v8::Local<v8::FunctionTemplate>()' %}
+    {% if runtime_enabled_function %}
+    if (!{{runtime_enabled_function}}())
+        defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "", {{parent_template}}, {{v8_class}}::internalFieldCount, 0, 0, 0, 0, 0, 0, isolate);
+    else
+    {% endif %}
+    {% set runtime_enabled_indent = 4 if runtime_enabled_function else 0 %}
+    {% filter indent(runtime_enabled_indent, true) %}
+    defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "{{interface_name}}", {{parent_template}}, {{v8_class}}::internalFieldCount,
+        {# Test needed as size 0 arrays definitions are not allowed per standard
+           (so objects have distinct addresses), which is enforced by MSVC.
+           8.5.1 Aggregates [dcl.init.aggr]
+           An array of unknown size initialized with a brace-enclosed
+           initializer-list containing n initializer-clauses, where n shall be
+           greater than zero, is defined as having n elements (8.3.4). #}
+        {% set attributes_name, attributes_length =
+               ('%sAttributes' % v8_class,
+                'WTF_ARRAY_LENGTH(%sAttributes)' % v8_class)
+           if has_attribute_configuration else (0, 0) %}
+        {% set accessors_name, accessors_length =
+               ('%sAccessors' % v8_class,
+                'WTF_ARRAY_LENGTH(%sAccessors)' % v8_class)
+           if has_accessors else (0, 0) %}
+        {% set methods_name, methods_length =
+               ('%sMethods' % v8_class,
+                'WTF_ARRAY_LENGTH(%sMethods)' % v8_class)
+           if method_configuration_methods else (0, 0) %}
+        {{attributes_name}}, {{attributes_length}},
+        {{accessors_name}}, {{accessors_length}},
+        {{methods_name}}, {{methods_length}},
+        isolate);
+    {% endfilter %}
+
+    {% if constructors or has_custom_constructor or has_event_constructor %}
+    functionTemplate->SetCallHandler({{v8_class}}::constructorCallback);
+    functionTemplate->SetLength({{interface_length}});
+    {% endif %}
+    v8::Local<v8::ObjectTemplate> instanceTemplate = functionTemplate->InstanceTemplate();
+    ALLOW_UNUSED_LOCAL(instanceTemplate);
+    v8::Local<v8::ObjectTemplate> prototypeTemplate = functionTemplate->PrototypeTemplate();
+    ALLOW_UNUSED_LOCAL(prototypeTemplate);
+    {% if has_access_check_callbacks %}
+    instanceTemplate->SetAccessCheckCallbacks({{cpp_class}}V8Internal::namedSecurityCheck, {{cpp_class}}V8Internal::indexedSecurityCheck, v8::External::New(isolate, const_cast<WrapperTypeInfo*>(&{{v8_class}}::wrapperTypeInfo)));
+    {% endif %}
+    {% for attribute in attributes
+       if attribute.runtime_enabled_function and
+          not attribute.per_context_enabled_function and
+          not attribute.exposed_test and
+          not attribute.is_static %}
+    {% filter conditional(attribute.conditional_string) %}
+    if ({{attribute.runtime_enabled_function}}()) {
+        static const V8DOMConfiguration::AttributeConfiguration attributeConfiguration =\
+        {{attribute_configuration(attribute)}};
+        V8DOMConfiguration::installAttribute(instanceTemplate, prototypeTemplate, attributeConfiguration, isolate);
+    }
+    {% endfilter %}
+    {% endfor %}
+    {% if constants %}
+    {{install_constants() | indent}}
+    {% endif %}
+    {# Special operations #}
+    {# V8 has access-check callback API and it\'s used on Window instead of
+       deleters or enumerators; see ObjectTemplate::SetAccessCheckCallbacks.
+       In addition, the getter should be set on the prototype template, to get
+       the implementation straight out of the Window prototype, regardless of
+       what prototype is actually set on the object. #}
+    {% set set_on_template = 'PrototypeTemplate' if interface_name == 'Window'
+                        else 'InstanceTemplate' %}
+    {% if indexed_property_getter %}
+    {# if have indexed properties, MUST have an indexed property getter #}
+    {% set indexed_property_getter_callback =
+           '%sV8Internal::indexedPropertyGetterCallback' % cpp_class %}
+    {% set indexed_property_setter_callback =
+           '%sV8Internal::indexedPropertySetterCallback' % cpp_class
+           if indexed_property_setter else '0' %}
+    {% set indexed_property_query_callback = '0' %}{# Unused #}
+    {% set indexed_property_deleter_callback =
+           '%sV8Internal::indexedPropertyDeleterCallback' % cpp_class
+           if indexed_property_deleter else '0' %}
+    {% set indexed_property_enumerator_callback =
+           'indexedPropertyEnumerator<%s>' % cpp_class
+           if indexed_property_getter.is_enumerable else '0' %}
+    functionTemplate->{{set_on_template}}()->SetIndexedPropertyHandler({{indexed_property_getter_callback}}, {{indexed_property_setter_callback}}, {{indexed_property_query_callback}}, {{indexed_property_deleter_callback}}, {{indexed_property_enumerator_callback}});
+    {% endif %}
+    {% if named_property_getter %}
+    {# if have named properties, MUST have a named property getter #}
+    {% set named_property_getter_callback =
+           '%sV8Internal::namedPropertyGetterCallback' % cpp_class %}
+    {% set named_property_setter_callback =
+           '%sV8Internal::namedPropertySetterCallback' % cpp_class
+           if named_property_setter else '0' %}
+    {% set named_property_query_callback =
+           '%sV8Internal::namedPropertyQueryCallback' % cpp_class
+           if named_property_getter.is_enumerable else '0' %}
+    {% set named_property_deleter_callback =
+           '%sV8Internal::namedPropertyDeleterCallback' % cpp_class
+           if named_property_deleter else '0' %}
+    {% set named_property_enumerator_callback =
+           '%sV8Internal::namedPropertyEnumeratorCallback' % cpp_class
+           if named_property_getter.is_enumerable else '0' %}
+    functionTemplate->{{set_on_template}}()->SetNamedPropertyHandler({{named_property_getter_callback}}, {{named_property_setter_callback}}, {{named_property_query_callback}}, {{named_property_deleter_callback}}, {{named_property_enumerator_callback}});
+    {% endif %}
+    {% if iterator_method %}
+    static const V8DOMConfiguration::SymbolKeyedMethodConfiguration symbolKeyedIteratorConfiguration = { v8::Symbol::GetIterator, {{cpp_class_or_partial}}V8Internal::iteratorMethodCallback, 0, V8DOMConfiguration::ExposedToAllScripts };
+    V8DOMConfiguration::installMethod(prototypeTemplate, defaultSignature, v8::DontDelete, symbolKeyedIteratorConfiguration, isolate);
+    {% endif %}
+    {# End special operations #}
+    {% if has_custom_legacy_call_as_function %}
+    functionTemplate->InstanceTemplate()->SetCallAsFunctionHandler({{v8_class}}::legacyCallCustom);
+    {% endif %}
+    {% if interface_name == 'HTMLAllCollection' %}
+    {# Needed for legacy support of document.all #}
+    functionTemplate->InstanceTemplate()->MarkAsUndetectable();
+    {% endif %}
+    {% for method in custom_registration_methods %}
+    {# install_custom_signature #}
+    {% filter conditional(method.conditional_string) %}
+    {% filter runtime_enabled(method.overloads.runtime_enabled_function_all
+                              if method.overloads else
+                              method.runtime_enabled_function) %}
+    {% if method.is_do_not_check_security %}
+    {{install_do_not_check_security_signature(method) | indent}}
+    {% else %}{# is_do_not_check_security #}
+    {{install_custom_signature(method) | indent}}
+    {% endif %}{# is_do_not_check_security #}
+    {% endfilter %}{# runtime_enabled() #}
+    {% endfilter %}{# conditional() #}
+    {% endfor %}
+    {% for attribute in attributes if attribute.is_static %}
+    {% set getter_callback = '%sV8Internal::%sAttributeGetterCallback' %
+           (cpp_class, attribute.name) %}
+    {% filter conditional(attribute.conditional_string) %}
+    functionTemplate->SetNativeDataProperty(v8AtomicString(isolate, "{{attribute.name}}"), {{getter_callback}}, {{attribute.setter_callback}}, v8::External::New(isolate, 0), static_cast<v8::PropertyAttribute>(v8::None), v8::Handle<v8::AccessorSignature>(), static_cast<v8::AccessControl>(v8::DEFAULT));
+    {% endfilter %}
+    {% endfor %}
+    {# Special interfaces #}
+    {% if not is_partial %}
+    {% if interface_name == 'Window' %}
+
+    prototypeTemplate->SetInternalFieldCount(V8Window::internalFieldCount);
+    functionTemplate->SetHiddenPrototype(true);
+    instanceTemplate->SetInternalFieldCount(V8Window::internalFieldCount);
+    // Set access check callbacks, but turned off initially.
+    // When a context is detached from a frame, turn on the access check.
+    // Turning on checks also invalidates inline caches of the object.
+    instanceTemplate->SetAccessCheckCallbacks(V8Window::namedSecurityCheckCustom, V8Window::indexedSecurityCheckCustom, v8::External::New(isolate, const_cast<WrapperTypeInfo*>(&V8Window::wrapperTypeInfo)), false);
+    {% elif interface_name in [
+           'HTMLDocument', 'DedicatedWorkerGlobalScope',
+           'SharedWorkerGlobalScope', 'ServiceWorkerGlobalScope'] %}
+    functionTemplate->SetHiddenPrototype(true);
+    {% endif %}
+
+    // Custom toString template
+    functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate());
+    {% endif %}
+}
+
+{% endif %}{# not is_array_buffer_or_view #}
+{% endblock %}
+{##############################################################################}
 {% block get_dom_template %}{% endblock %}
 {% block has_instance %}{% endblock %}
-{% block to_native_with_type_check %}{% endblock %}
+{% block to_impl %}{% endblock %}
+{% block to_impl_with_type_check %}{% endblock %}
 {% block install_conditional_attributes %}{% endblock %}
-{% block install_conditional_methods %}{% endblock %}
+{##############################################################################}
+{% block install_conditional_methods %}
+{% from 'methods.cpp' import install_conditionally_enabled_methods
+        with context %}
+{% if is_partial or conditionally_enabled_methods %}
+{{install_conditionally_enabled_methods()}}
+
+{% endif %}
+{% endblock %}
+{##############################################################################}
 {% block to_active_dom_object %}{% endblock %}
 {% block to_event_target %}{% endblock %}
 {% block get_shadow_object_template %}{% endblock %}
-{% block wrap %}{% endblock %}
-{% block create_wrapper %}{% endblock %}
 {% block deref_object_and_to_v8_no_inline %}{% endblock %}
 {% for method in methods if method.is_implemented_in_private_script %}
 {{method_implemented_in_private_script(method)}}
@@ -158,5 +467,6 @@ template <typename T> void V8_USE(T) { }
 {{attribute_setter_implemented_in_private_script(attribute)}}
 {% endif %}
 {% endfor %}
+{% block partial_interface %}{% endblock %}
 } // namespace blink
 {% endfilter %}