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

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

Issue 1417023006: bindings: Refactors BindingSecurity::shouldAllowAccessToXXX. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Synced. Created 5 years, 1 month 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 'conversions.cpp' import declare_enum_validation_variable, v8_value_to_l ocal_cpp_value %} 1 {% from 'conversions.cpp' import declare_enum_validation_variable, v8_value_to_l ocal_cpp_value %}
2 2
3 3
4 {##############################################################################} 4 {##############################################################################}
5 {% macro generate_method(method, world_suffix) %} 5 {% macro generate_method(method, world_suffix) %}
6 {% filter conditional(method.conditional_string) %} 6 {% filter conditional(method.conditional_string) %}
7 {% if method.returns_promise and method.has_exception_state %} 7 {% if method.returns_promise and method.has_exception_state %}
8 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}Promis e(const v8::FunctionCallbackInfo<v8::Value>& info, ExceptionState& exceptionStat e) 8 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}Promis e(const v8::FunctionCallbackInfo<v8::Value>& info, ExceptionState& exceptionStat e)
9 {% else %} 9 {% else %}
10 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const v8::FunctionCallbackInfo<v8::Value>& info) 10 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const v8::FunctionCallbackInfo<v8::Value>& info)
11 {% endif %} 11 {% endif %}
12 { 12 {
13 {# Local variables #} 13 {# Local variables #}
14 {% if method.has_exception_state and not method.returns_promise %} 14 {% if method.has_exception_state and not method.returns_promise %}
15 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); 15 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na me}}", "{{interface_name}}", info.Holder(), info.GetIsolate());
16 {% endif %} 16 {% endif %}
17 {# Overloaded methods have length checked during overload resolution #} 17 {# Overloaded methods have length checked during overload resolution #}
18 {% if method.number_of_required_arguments and not method.overload_index %} 18 {% if method.number_of_required_arguments and not method.overload_index %}
19 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { 19 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) {
20 {{throw_minimum_arity_type_error(method, method.number_of_required_argum ents) | indent(8)}} 20 {{throw_minimum_arity_type_error(method, method.number_of_required_argum ents) | indent(8)}}
21 } 21 }
22 {% endif %} 22 {% endif %}
23 {% if not method.is_static %} 23 {% if not method.is_static %}
24 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder()); 24 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder());
25 {% endif %} 25 {% endif %}
26 {% if method.is_custom_element_callbacks %} 26 {% if method.is_custom_element_callbacks %}
27 CustomElementProcessingStack::CallbackDeliveryScope deliveryScope; 27 CustomElementProcessingStack::CallbackDeliveryScope deliveryScope;
28 {% endif %} 28 {% endif %}
29 {# Security checks #} 29 {# Security checks #}
30 {% if method.is_check_security_for_window %} 30 {% if method.is_check_security_for_window or
31 if (LocalDOMWindow* window = impl->toDOMWindow()) { 31 method.is_check_security_for_frame or
32 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), callin gDOMWindow(info.GetIsolate()), window->frame(), exceptionState)) { 32 method.is_check_security_for_node %}
33 {{propagate_error_with_exception_state(method) | indent(12)}} 33 if (!BindingSecurity::shouldAllowAccessTo(info.GetIsolate(), callingDOMWindo w(info.GetIsolate()), {{method.cpp_value if method.is_check_security_for_node el se 'impl'}}, exceptionState)) {
34 } 34 {% if not method.returns_promise %}
35 if (!window->document()) 35 exceptionState.throwIfNeeded();
haraken 2015/11/16 11:34:21 Ditto.
Yuki 2015/11/20 12:27:52 Ditto.
36 return; 36 {% endif %}
37 } 37 return;
38 {% elif method.is_check_security_for_frame %}
39 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), callingDOM Window(info.GetIsolate()), impl->frame(), exceptionState)) {
40 {{propagate_error_with_exception_state(method) | indent(8)}}
41 }
42 {% endif %}
43 {% if method.is_check_security_for_node %}
44 if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), callingDOMW indow(info.GetIsolate()), impl->{{method.name}}(exceptionState), exceptionState) ) {
45 v8SetReturnValueNull(info);
46 {{propagate_error_with_exception_state(method) | indent(8)}}
47 } 38 }
48 {% endif %} 39 {% endif %}
49 {# Call method #} 40 {# Call method #}
50 {% if method.arguments %} 41 {% if method.arguments %}
51 {{generate_arguments(method, world_suffix) | indent}} 42 {{generate_arguments(method, world_suffix) | indent}}
52 {% endif %} 43 {% endif %}
53 {% if world_suffix %} 44 {% if world_suffix %}
54 {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method. cpp_value) | indent}} 45 {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method. cpp_value) | indent}}
55 {% else %} 46 {% else %}
56 {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | in dent}} 47 {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | in dent}}
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 v8::Local<v8::FunctionTemplate> domTemplate = data->domTemplate(&domTemplate Key, {{cpp_class}}V8Internal::{{method.name}}MethodCallback{{world_suffix}}, v8U ndefined(), {{signature}}, {{method.length}}); 519 v8::Local<v8::FunctionTemplate> domTemplate = data->domTemplate(&domTemplate Key, {{cpp_class}}V8Internal::{{method.name}}MethodCallback{{world_suffix}}, v8U ndefined(), {{signature}}, {{method.length}});
529 520
530 // It is unsafe to use info.Holder() because OriginSafeMethodGetter is calle d 521 // It is unsafe to use info.Holder() because OriginSafeMethodGetter is calle d
531 // back without checking the type of info.Holder(). 522 // back without checking the type of info.Holder().
532 v8::Local<v8::Object> holder = {{v8_class}}::findInstanceInPrototypeChain(in fo.This(), info.GetIsolate()); 523 v8::Local<v8::Object> holder = {{v8_class}}::findInstanceInPrototypeChain(in fo.This(), info.GetIsolate());
533 if (holder.IsEmpty()) { 524 if (holder.IsEmpty()) {
534 v8SetReturnValue(info, domTemplate->GetFunction(info.GetIsolate()->GetCu rrentContext()).ToLocalChecked()); 525 v8SetReturnValue(info, domTemplate->GetFunction(info.GetIsolate()->GetCu rrentContext()).ToLocalChecked());
535 return; 526 return;
536 } 527 }
537 {{cpp_class}}* impl = {{v8_class}}::toImpl(holder); 528 {{cpp_class}}* impl = {{v8_class}}::toImpl(holder);
538 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), callingDOM Window(info.GetIsolate()), impl->frame(), DoNotReportSecurityError)) { 529 if (!BindingSecurity::shouldAllowAccessTo(info.GetIsolate(), callingDOMWindo w(info.GetIsolate()), impl, DoNotReportSecurityError)) {
539 v8SetReturnValue(info, domTemplate->GetFunction(info.GetIsolate()->GetCu rrentContext()).ToLocalChecked()); 530 v8SetReturnValue(info, domTemplate->GetFunction(info.GetIsolate()->GetCu rrentContext()).ToLocalChecked());
540 return; 531 return;
541 } 532 }
542 533
543 {# The findInstanceInPrototypeChain() call above only returns a non-empty ha ndle if info.This() is an Object. #} 534 {# The findInstanceInPrototypeChain() call above only returns a non-empty ha ndle if info.This() is an Object. #}
544 v8::Local<v8::Value> hiddenValue = V8HiddenValue::getHiddenValue(info.GetIso late(), v8::Local<v8::Object>::Cast(info.This()), v8AtomicString(info.GetIsolate (), "{{method.name}}")); 535 v8::Local<v8::Value> hiddenValue = V8HiddenValue::getHiddenValue(info.GetIso late(), v8::Local<v8::Object>::Cast(info.This()), v8AtomicString(info.GetIsolate (), "{{method.name}}"));
545 if (!hiddenValue.IsEmpty()) { 536 if (!hiddenValue.IsEmpty()) {
546 v8SetReturnValue(info, hiddenValue); 537 v8SetReturnValue(info, hiddenValue);
547 return; 538 return;
548 } 539 }
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 {% filter runtime_enabled(method.overloads.runtime_enabled_function_all 675 {% filter runtime_enabled(method.overloads.runtime_enabled_function_all
685 if method.overloads else 676 if method.overloads else
686 method.runtime_enabled_function) %} 677 method.runtime_enabled_function) %}
687 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}}; 678 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration = {{method_configuration(method)}};
688 V8DOMConfiguration::installMethod(isolate, v8::Local<v8::Object>(), prototypeObj ect, interfaceObject, defaultSignature, {{method.name}}MethodConfiguration); 679 V8DOMConfiguration::installMethod(isolate, v8::Local<v8::Object>(), prototypeObj ect, interfaceObject, defaultSignature, {{method.name}}MethodConfiguration);
689 {% endfilter %}{# runtime_enabled() #} 680 {% endfilter %}{# runtime_enabled() #}
690 {% endfilter %}{# exposed() #} 681 {% endfilter %}{# exposed() #}
691 {% endfor %} 682 {% endfor %}
692 {% endif %} 683 {% endif %}
693 {%- endmacro %} 684 {%- endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698