Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: third_party/WebKit/Source/bindings/templates/methods.cpp.tmpl

Issue 2713413002: Blink bindings: use v8 to enforce method call access checks (Closed)
Patch Set: Restore comment Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 {% from 'utilities.cpp.tmpl' import declare_enum_validation_variable, v8_value_t o_local_cpp_value %} 1 {% from 'utilities.cpp.tmpl' import declare_enum_validation_variable, v8_value_t o_local_cpp_value %}
2 2
3 {##############################################################################} 3 {##############################################################################}
4 {% macro generate_method(method, world_suffix) %} 4 {% macro generate_method(method, world_suffix) %}
5 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const v8::FunctionCallbackInfo<v8::Value>& info) { 5 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const v8::FunctionCallbackInfo<v8::Value>& info) {
6 {% filter format_remove_duplicates([ 6 {% filter format_remove_duplicates([
7 'ExceptionState exceptionState', 7 'ExceptionState exceptionState',
8 'ScriptState* scriptState = ']) %} 8 'ScriptState* scriptState = ']) %}
9 {% set define_exception_state -%} 9 {% set define_exception_state -%}
10 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ExecutionCont ext, "{{interface_name}}", "{{method.name}}"); 10 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ExecutionCont ext, "{{interface_name}}", "{{method.name}}");
(...skipping 11 matching lines...) Expand all
22 22
23 {% if not method.is_static %} 23 {% if not method.is_static %}
24 {% if method.returns_promise %} 24 {% if method.returns_promise %}
25 // V8DOMConfiguration::DoNotCheckHolder 25 // V8DOMConfiguration::DoNotCheckHolder
26 // Make sure that info.Holder() really points to an instance of the type. 26 // Make sure that info.Holder() really points to an instance of the type.
27 if (!{{v8_class}}::hasInstance(info.Holder(), info.GetIsolate())) { 27 if (!{{v8_class}}::hasInstance(info.Holder(), info.GetIsolate())) {
28 {{throw_type_error(method, '"Illegal invocation"')}} 28 {{throw_type_error(method, '"Illegal invocation"')}}
29 return; 29 return;
30 } 30 }
31 {% endif %} 31 {% endif %}
32 {% set local_dom_window_only = interface_name == 'Window' and not method.is_cr oss_origin %} 32 {% if interface_name == 'Window' and not method.is_cross_origin %}
33 {% if local_dom_window_only %}
34 {% if method.is_check_security_for_receiver %}
35 {{cpp_class}}* uncheckedImpl = {{v8_class}}::toImpl(info.Holder());
36 {% else %}
37 // Same-origin methods are never exposed via the cross-origin interceptors. 33 // Same-origin methods are never exposed via the cross-origin interceptors.
38 // Since same-origin access requires a LocalDOMWindow, it is safe to downcast 34 // Since same-origin access requires a LocalDOMWindow, it is safe to downcast
39 // here. 35 // here.
40 LocalDOMWindow* impl = toLocalDOMWindow({{v8_class}}::toImpl(info.Holder())); 36 LocalDOMWindow* impl = toLocalDOMWindow({{v8_class}}::toImpl(info.Holder()));
41 {% endif %}{# method.is_check_security_for_receiver #}
42 {% else %} 37 {% else %}
43 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder()); 38 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder());
44 {% endif %}{# local_dom_window_only #} 39 {% endif %}{# interface_name == 'Window' and not method.is_cross_origin #}
45 {% endif %}{# not method.is_static #} 40 {% endif %}{# not method.is_static #}
46 41
47 {# Security checks #} 42 {# Security checks #}
48 {% if method.is_check_security_for_receiver %}
49 {{define_exception_state}}
50 {% if interface_name == 'EventTarget' %}
51 // Performance hack for EventTarget. Checking whether it's a Window or not
52 // prior to the call to BindingSecurity::shouldAllowAccessTo increases 30%
53 // of speed performance on Android Nexus 7 as of Dec 2015. ALWAYS_INLINE
54 // didn't work in this case.
55 if (const DOMWindow* window = impl->toDOMWindow()) {
56 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate() ), window, exceptionState)) {
57 return;
58 }
59 }
60 {% else %}{# interface_name == 'EventTarget' #}
61 {% if local_dom_window_only %}
62 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()), uncheckedImpl, exceptionState)) {
63 {% else %}
64 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()), impl, exceptionState)) {
65 {% endif %}{# local_dom_window_only #}
66 return;
67 }
68 {% if local_dom_window_only %}
69 LocalDOMWindow* impl = toLocalDOMWindow(uncheckedImpl);
70 {% endif %}{# local_dom_window_only #}
71 {% endif %}{# interface_name == 'EventTarget' #}
72 {% endif %}{# method.is_check_security_for_receiver #}
73 {% if method.is_check_security_for_return_value %} 43 {% if method.is_check_security_for_return_value %}
74 {{define_exception_state}} 44 {{define_exception_state}}
75 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()), {{method.cpp_value}}, exceptionState)) { 45 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()), {{method.cpp_value}}, exceptionState)) {
76 v8SetReturnValueNull(info); 46 v8SetReturnValueNull(info);
77 return; 47 return;
78 } 48 }
79 {% endif %} 49 {% endif %}
80 50
81 {% if 'scriptState' in function_call %} 51 {% if 'scriptState' in function_call %}
82 {% if method.is_static %} 52 {% if method.is_static %}
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 {% set method_callback = 592 {% set method_callback =
623 '%s::%sMethodCallback' % (v8_class_or_partial, method.name) %} 593 '%s::%sMethodCallback' % (v8_class_or_partial, method.name) %}
624 {% set method_callback_for_main_world = 594 {% set method_callback_for_main_world =
625 '%s::%sMethodCallbackForMainWorld' % (v8_class_or_partial, method.name) 595 '%s::%sMethodCallbackForMainWorld' % (v8_class_or_partial, method.name)
626 if method.is_per_world_bindings else 'nullptr' %} 596 if method.is_per_world_bindings else 'nullptr' %}
627 {% set property_attribute = 597 {% set property_attribute =
628 'static_cast<v8::PropertyAttribute>(%s)' % ' | '.join(method.property_att ributes) 598 'static_cast<v8::PropertyAttribute>(%s)' % ' | '.join(method.property_att ributes)
629 if method.property_attributes else 'v8::None' %} 599 if method.property_attributes else 'v8::None' %}
630 {% set holder_check = 'V8DOMConfiguration::DoNotCheckHolder' 600 {% set holder_check = 'V8DOMConfiguration::DoNotCheckHolder'
631 if method.returns_promise else 'V8DOMConfiguration::CheckHolder' %} 601 if method.returns_promise else 'V8DOMConfiguration::CheckHolder' %}
632 {"{{method.name}}", {{method_callback}}, {{method_callback_for_main_world}}, {{m ethod.length}}, {{property_attribute}}, {{property_location(method)}}, {{holder_ check}}} 602 {% set access_check = 'V8DOMConfiguration::CheckAccess'
603 if method.is_check_security_for_receiver else 'V8DOMConfiguration::DoNotC heckAccess' %}
604 {"{{method.name}}", {{method_callback}}, {{method_callback_for_main_world}}, {{m ethod.length}}, {{property_attribute}}, {{property_location(method)}}, {{holder_ check}}, {{access_check}}}
633 {%- endmacro %} 605 {%- endmacro %}
634 606
635 607
636 {######################################} 608 {######################################}
637 {% macro install_custom_signature(method, instance_template, prototype_template, interface_template, signature) %} 609 {% macro install_custom_signature(method, instance_template, prototype_template, interface_template, signature) %}
638 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}}; 610 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}};
639 V8DOMConfiguration::installMethod(isolate, world, {{instance_template}}, {{proto type_template}}, {{interface_template}}, {{signature}}, {{method.name}}MethodCon figuration); 611 V8DOMConfiguration::installMethod(isolate, world, {{instance_template}}, {{proto type_template}}, {{interface_template}}, {{signature}}, {{method.name}}MethodCon figuration);
640 {%- endmacro %} 612 {%- endmacro %}
641 613
642 614
(...skipping 11 matching lines...) Expand all
654 if method.overloads else 626 if method.overloads else
655 method.runtime_enabled_feature_name) %} 627 method.runtime_enabled_feature_name) %}
656 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}}; 628 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}};
657 V8DOMConfiguration::installMethod(isolate, world, v8::Local<v8::Object>(), proto typeObject, interfaceObject, signature, {{method.name}}MethodConfiguration); 629 V8DOMConfiguration::installMethod(isolate, world, v8::Local<v8::Object>(), proto typeObject, interfaceObject, signature, {{method.name}}MethodConfiguration);
658 {% endfilter %}{# runtime_enabled() #} 630 {% endfilter %}{# runtime_enabled() #}
659 {% endfilter %}{# exposed() #} 631 {% endfilter %}{# exposed() #}
660 {% endfilter %}{# secure_context() #} 632 {% endfilter %}{# secure_context() #}
661 {% endfor %} 633 {% endfor %}
662 {% endif %} 634 {% endif %}
663 {%- endmacro %} 635 {%- endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698