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

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: . 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 #}
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
dcheng 2017/02/27 05:34:19 I think this shouldn't be needed anymore, as the c
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 %} 42 {% if method.is_check_security_for_return_value %}
74 {{define_exception_state}} 43 {{define_exception_state}}
75 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()), {{method.cpp_value}}, exceptionState)) { 44 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()), {{method.cpp_value}}, exceptionState)) {
76 v8SetReturnValueNull(info); 45 v8SetReturnValueNull(info);
77 return; 46 return;
78 } 47 }
79 {% endif %} 48 {% endif %}
80 49
81 {% set log_activity = world_suffix in method.activity_logging_world_list %} 50 {% if 'scriptState' in function_call %}
82 {% if 'scriptState' in function_call or log_activity %}
83 {% if method.is_static %} 51 {% if method.is_static %}
84 ScriptState* scriptState = ScriptState::forFunctionObject(info); 52 ScriptState* scriptState = ScriptState::forFunctionObject(info);
85 {% else %} 53 {% else %}
86 ScriptState* scriptState = ScriptState::forReceiverObject(info); 54 ScriptState* scriptState = ScriptState::forReceiverObject(info);
87 {% endif %} 55 {% endif %}
88 {% endif %} 56 {% endif %}
89 57
90 {% if log_activity %}
91 V8PerContextData* contextData = scriptState->perContextData();
92 if (contextData && contextData->activityLogger()) {
93 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ExecutionCo ntext, "{{interface_name}}", "{{method.name}}");
94 Vector<v8::Local<v8::Value>> loggerArgs = toImplArguments<Vector<v8::Local<v 8::Value>>>(info, 0, exceptionState);
95 contextData->activityLogger()->logMethod("{{interface_name}}.{{method.name}} ", info.Length(), loggerArgs.data());
96 }
97 {% endif %}
98
99 {% if method.is_custom_element_callbacks %} 58 {% if method.is_custom_element_callbacks %}
100 V0CustomElementProcessingStack::CallbackDeliveryScope deliveryScope; 59 V0CustomElementProcessingStack::CallbackDeliveryScope deliveryScope;
101 {% endif %} 60 {% endif %}
102 61
103 {{function_call | indent(2)}} 62 {{function_call | indent(2)}}
104 } 63 }
105 {% endfilter %} 64 {% endfilter %}
106 {% endmacro %} 65 {% endmacro %}
107 66
108 67
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 {% macro method_callback(method, world_suffix) %} 473 {% macro method_callback(method, world_suffix) %}
515 void {{v8_class_or_partial}}::{{method.name}}MethodCallback{{world_suffix}}(cons t v8::FunctionCallbackInfo<v8::Value>& info) { 474 void {{v8_class_or_partial}}::{{method.name}}MethodCallback{{world_suffix}}(cons t v8::FunctionCallbackInfo<v8::Value>& info) {
516 {% if not method.overloads %}{# Overloaded methods are measured in overload_re solution_method() #} 475 {% if not method.overloads %}{# Overloaded methods are measured in overload_re solution_method() #}
517 {% if method.measure_as %} 476 {% if method.measure_as %}
518 UseCounter::count(currentExecutionContext(info.GetIsolate()), UseCounter::{{me thod.measure_as('Method')}}); 477 UseCounter::count(currentExecutionContext(info.GetIsolate()), UseCounter::{{me thod.measure_as('Method')}});
519 {% endif %} 478 {% endif %}
520 {% if method.deprecate_as %} 479 {% if method.deprecate_as %}
521 Deprecation::countDeprecation(currentExecutionContext(info.GetIsolate()), UseC ounter::{{method.deprecate_as}}); 480 Deprecation::countDeprecation(currentExecutionContext(info.GetIsolate()), UseC ounter::{{method.deprecate_as}});
522 {% endif %} 481 {% endif %}
523 {% endif %}{# not method.overloads #} 482 {% endif %}{# not method.overloads #}
483 {% if world_suffix in method.activity_logging_world_list %}
dcheng 2017/02/27 05:34:19 Restoring the activity logger back to the original
484 {% if method.is_static %}
485 ScriptState* scriptState = ScriptState::forFunctionObject(info);
486 {% else %}
487 ScriptState* scriptState = ScriptState::forReceiverObject(info);
488 {% endif %}
489 V8PerContextData* contextData = scriptState->perContextData();
490 if (contextData && contextData->activityLogger()) {
491 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ExecutionCo ntext, "{{interface_name}}", "{{method.name}}");
492 Vector<v8::Local<v8::Value>> loggerArgs = toImplArguments<Vector<v8::Local<v 8::Value>>>(info, 0, exceptionState);
493 contextData->activityLogger()->logMethod("{{interface_name}}.{{method.name}} ", info.Length(), loggerArgs.data());
494 }
495 {% endif %}
524 {% if method.is_ce_reactions %} 496 {% if method.is_ce_reactions %}
525 CEReactionsScope ceReactionsScope; 497 CEReactionsScope ceReactionsScope;
526 {% endif %} 498 {% endif %}
527 {% if method.is_custom %} 499 {% if method.is_custom %}
528 {{v8_class}}::{{method.name}}MethodCustom(info); 500 {{v8_class}}::{{method.name}}MethodCustom(info);
529 {% elif method.is_post_message %} 501 {% elif method.is_post_message %}
530 {{cpp_class_or_partial}}V8Internal::postMessageImpl("{{interface_name}}", {{v8 _class}}::toImpl(info.Holder()), info); 502 {{cpp_class_or_partial}}V8Internal::postMessageImpl("{{interface_name}}", {{v8 _class}}::toImpl(info.Holder()), info);
531 {% else %} 503 {% else %}
532 {{cpp_class_or_partial}}V8Internal::{{method.name}}Method{{world_suffix}}(info ); 504 {{cpp_class_or_partial}}V8Internal::{{method.name}}Method{{world_suffix}}(info );
533 {% endif %} 505 {% endif %}
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 {% set method_callback = 591 {% set method_callback =
620 '%s::%sMethodCallback' % (v8_class_or_partial, method.name) %} 592 '%s::%sMethodCallback' % (v8_class_or_partial, method.name) %}
621 {% set method_callback_for_main_world = 593 {% set method_callback_for_main_world =
622 '%s::%sMethodCallbackForMainWorld' % (v8_class_or_partial, method.name) 594 '%s::%sMethodCallbackForMainWorld' % (v8_class_or_partial, method.name)
623 if method.is_per_world_bindings else 'nullptr' %} 595 if method.is_per_world_bindings else 'nullptr' %}
624 {% set property_attribute = 596 {% set property_attribute =
625 'static_cast<v8::PropertyAttribute>(%s)' % ' | '.join(method.property_att ributes) 597 'static_cast<v8::PropertyAttribute>(%s)' % ' | '.join(method.property_att ributes)
626 if method.property_attributes else 'v8::None' %} 598 if method.property_attributes else 'v8::None' %}
627 {% set holder_check = 'V8DOMConfiguration::DoNotCheckHolder' 599 {% set holder_check = 'V8DOMConfiguration::DoNotCheckHolder'
628 if method.returns_promise else 'V8DOMConfiguration::CheckHolder' %} 600 if method.returns_promise else 'V8DOMConfiguration::CheckHolder' %}
629 {"{{method.name}}", {{method_callback}}, {{method_callback_for_main_world}}, {{m ethod.length}}, {{property_attribute}}, {{property_location(method)}}, {{holder_ check}}} 601 {% set access_check = 'V8DOMConfiguration::CheckAccess'
602 if method.is_check_security_for_receiver else 'V8DOMConfiguration::DoNotC heckAccess' %}
603 {"{{method.name}}", {{method_callback}}, {{method_callback_for_main_world}}, {{m ethod.length}}, {{property_attribute}}, {{property_location(method)}}, {{holder_ check}}, {{access_check}}}
630 {%- endmacro %} 604 {%- endmacro %}
631 605
632 606
633 {######################################} 607 {######################################}
634 {% macro install_custom_signature(method, instance_template, prototype_template, interface_template, signature) %} 608 {% macro install_custom_signature(method, instance_template, prototype_template, interface_template, signature) %}
635 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}}; 609 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}};
636 V8DOMConfiguration::installMethod(isolate, world, {{instance_template}}, {{proto type_template}}, {{interface_template}}, {{signature}}, {{method.name}}MethodCon figuration); 610 V8DOMConfiguration::installMethod(isolate, world, {{instance_template}}, {{proto type_template}}, {{interface_template}}, {{signature}}, {{method.name}}MethodCon figuration);
637 {%- endmacro %} 611 {%- endmacro %}
638 612
639 613
(...skipping 11 matching lines...) Expand all
651 if method.overloads else 625 if method.overloads else
652 method.runtime_enabled_feature_name) %} 626 method.runtime_enabled_feature_name) %}
653 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}}; 627 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}};
654 V8DOMConfiguration::installMethod(isolate, world, v8::Local<v8::Object>(), proto typeObject, interfaceObject, signature, {{method.name}}MethodConfiguration); 628 V8DOMConfiguration::installMethod(isolate, world, v8::Local<v8::Object>(), proto typeObject, interfaceObject, signature, {{method.name}}MethodConfiguration);
655 {% endfilter %}{# runtime_enabled() #} 629 {% endfilter %}{# runtime_enabled() #}
656 {% endfilter %}{# exposed() #} 630 {% endfilter %}{# exposed() #}
657 {% endfilter %}{# secure_context() #} 631 {% endfilter %}{# secure_context() #}
658 {% endfor %} 632 {% endfor %}
659 {% endif %} 633 {% endif %}
660 {%- endmacro %} 634 {%- endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698