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

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

Issue 2439013002: Implement cross-origin attributes using access check interceptors. (Closed)
Patch Set: . Created 4 years 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 {% extends 'interface_base.cpp.tmpl' %} 1 {% extends 'interface_base.cpp.tmpl' %}
2 2
3 {% set has_prepare_prototype_and_interface_object = 3 {% set has_prepare_prototype_and_interface_object =
4 unscopables or has_conditional_attributes_on_prototype or 4 unscopables or has_conditional_attributes_on_prototype or
5 methods | conditionally_exposed(is_partial) %} 5 methods | conditionally_exposed(is_partial) %}
6 {% set prepare_prototype_and_interface_object_func = 6 {% set prepare_prototype_and_interface_object_func =
7 '%s::preparePrototypeAndInterfaceObject' % v8_class 7 '%s::preparePrototypeAndInterfaceObject' % v8_class
8 if has_prepare_prototype_and_interface_object 8 if has_prepare_prototype_and_interface_object
9 else 'nullptr' %} 9 else 'nullptr' %}
10 10
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 {% else %} 481 {% else %}
482 {{cpp_class}}V8Internal::namedPropertyEnumerator(info); 482 {{cpp_class}}V8Internal::namedPropertyEnumerator(info);
483 {% endif %} 483 {% endif %}
484 } 484 }
485 485
486 {% endif %} 486 {% endif %}
487 {% endblock %} 487 {% endblock %}
488 488
489 489
490 {##############################################################################} 490 {##############################################################################}
491 {# TODO(dcheng): Currently, bindings must create a function object for each
492 realm as a hack to support the incumbent realm. Remove this when Blink
493 properly supports the incumbent realm. #}
491 {% block origin_safe_method_setter %} 494 {% block origin_safe_method_setter %}
492 {% if has_origin_safe_method_setter %} 495 {% if has_origin_safe_method_setter %}
493 static void {{cpp_class}}OriginSafeMethodSetter(v8::Local<v8::Name> name, v8::Lo cal<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info) { 496 static void {{cpp_class}}OriginSafeMethodSetter(v8::Local<v8::Name> name, v8::Lo cal<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info) {
494 if (!name->IsString()) 497 if (!name->IsString())
495 return; 498 return;
496 v8::Local<v8::Object> holder = {{v8_class}}::findInstanceInPrototypeChain(info .Holder(), info.GetIsolate()); 499 v8::Local<v8::Object> holder = {{v8_class}}::findInstanceInPrototypeChain(info .Holder(), info.GetIsolate());
497 if (holder.IsEmpty()) 500 if (holder.IsEmpty())
498 return; 501 return;
499 {{cpp_class}}* impl = {{v8_class}}::toImpl(holder); 502 {{cpp_class}}* impl = {{v8_class}}::toImpl(holder);
500 v8::String::Utf8Value attributeName(name); 503 v8::String::Utf8Value attributeName(name);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 {% else %} 652 {% else %}
650 {{cpp_class}}V8Internal::constructor(info); 653 {{cpp_class}}V8Internal::constructor(info);
651 {% endif %} 654 {% endif %}
652 } 655 }
653 656
654 {% endif %} 657 {% endif %}
655 {% endblock %} 658 {% endblock %}
656 659
657 660
658 {##############################################################################} 661 {##############################################################################}
659 {% macro install_do_not_check_security_method(method, world_suffix, instance_tem plate, prototype_template) %} 662 {% macro install_origin_safe_method(method, world_suffix, instance_template, pro totype_template) %}
660 {% from 'utilities.cpp.tmpl' import property_location %} 663 {% from 'utilities.cpp.tmpl' import property_location %}
661 {# Methods that are [DoNotCheckSecurity] are always readable, but if they are 664 {# TODO(dcheng): Currently, bindings must create a function object for each
662 changed and then accessed from a different origin, we do not return the 665 realm as a hack to support the incumbent realm. Clean this up when Blink
663 underlying value, but instead return a new copy of the original function. 666 properly supports the incumbent realm. #}
664 This is achieved by storing the changed value as a hidden property. #}
665 {% set getter_callback = 667 {% set getter_callback =
666 '%sV8Internal::%sOriginSafeMethodGetterCallback%s' % 668 '%sV8Internal::%sOriginSafeMethodGetterCallback%s' %
667 (cpp_class, method.name, world_suffix) %} 669 (cpp_class, method.name, world_suffix) %}
668 {% set setter_callback = 670 {% set setter_callback =
669 '{0}V8Internal::{0}OriginSafeMethodSetterCallback'.format(cpp_class) 671 '{0}V8Internal::{0}OriginSafeMethodSetterCallback'.format(cpp_class)
670 if not method.is_unforgeable else '0' %} 672 if not method.is_unforgeable else '0' %}
671 {% if method.is_per_world_bindings %} 673 {% if method.is_per_world_bindings %}
672 {% set getter_callback_for_main_world = '%sForMainWorld' % getter_callback %} 674 {% set getter_callback_for_main_world = '%sForMainWorld' % getter_callback %}
673 {% set setter_callback_for_main_world = '%sForMainWorld' % setter_callback 675 {% set setter_callback_for_main_world = '%sForMainWorld' % setter_callback
674 if not method.is_unforgeable else '0' %} 676 if not method.is_unforgeable else '0' %}
675 {% else %} 677 {% else %}
676 {% set getter_callback_for_main_world = '0' %} 678 {% set getter_callback_for_main_world = '0' %}
677 {% set setter_callback_for_main_world = '0' %} 679 {% set setter_callback_for_main_world = '0' %}
678 {% endif %} 680 {% endif %}
679 {% set property_attribute = 681 {% set property_attribute =
680 'static_cast<v8::PropertyAttribute>(%s)' % 682 'static_cast<v8::PropertyAttribute>(%s)' %
681 ' | '.join(method.property_attributes or ['v8::None']) %} 683 ' | '.join(method.property_attributes or ['v8::None']) %}
682 {% set only_exposed_to_private_script = 'V8DOMConfiguration::OnlyExposedToPrivat eScript' if method.only_exposed_to_private_script else 'V8DOMConfiguration::Expo sedToAllScripts' %} 684 {% set only_exposed_to_private_script = 'V8DOMConfiguration::OnlyExposedToPrivat eScript' if method.only_exposed_to_private_script else 'V8DOMConfiguration::Expo sedToAllScripts' %}
683 {% set holder_check = 'V8DOMConfiguration::CheckHolder' %} 685 {% set holder_check = 'V8DOMConfiguration::CheckHolder' %}
684 const V8DOMConfiguration::AttributeConfiguration {{method.name}}OriginSafeAttrib uteConfiguration = { 686 const V8DOMConfiguration::AttributeConfiguration {{method.name}}OriginSafeAttrib uteConfiguration = {
685 "{{method.name}}", {{getter_callback}}, {{setter_callback}}, {{getter_callba ck_for_main_world}}, {{setter_callback_for_main_world}}, nullptr, &{{v8_class}}: :wrapperTypeInfo, v8::ALL_CAN_READ, {{property_attribute}}, {{only_exposed_to_pr ivate_script}}, {{property_location(method)}}, {{holder_check}}, 687 "{{method.name}}", {{getter_callback}}, {{setter_callback}}, {{getter_callba ck_for_main_world}}, {{setter_callback_for_main_world}}, nullptr, &{{v8_class}}: :wrapperTypeInfo, v8::DEFAULT, {{property_attribute}}, {{only_exposed_to_private _script}}, {{property_location(method)}}, {{holder_check}},
686 }; 688 };
687 V8DOMConfiguration::installAttribute(isolate, world, {{instance_template}}, {{pr ototype_template}}, {{method.name}}OriginSafeAttributeConfiguration); 689 V8DOMConfiguration::installAttribute(isolate, world, {{instance_template}}, {{pr ototype_template}}, {{method.name}}OriginSafeAttributeConfiguration);
688 {%- endmacro %} 690 {%- endmacro %}
689 691
690 692
691 {##############################################################################} 693 {##############################################################################}
692 {% macro install_indexed_property_handler(target) %} 694 {% macro install_indexed_property_handler(target) %}
693 {% set indexed_property_getter_callback = 695 {% set indexed_property_getter_callback =
694 '%sV8Internal::indexedPropertyGetterCallback' % cpp_class %} 696 '%sV8Internal::indexedPropertyGetterCallback' % cpp_class %}
695 {% set indexed_property_setter_callback = 697 {% set indexed_property_setter_callback =
696 '%sV8Internal::indexedPropertySetterCallback' % cpp_class 698 '%sV8Internal::indexedPropertySetterCallback' % cpp_class
697 if indexed_property_setter or named_property_setter else '0' %} 699 if indexed_property_setter or named_property_setter else '0' %}
698 {% set indexed_property_query_callback = '0' %}{# Unused #} 700 {% set indexed_property_query_callback = '0' %}{# Unused #}
699 {% set indexed_property_deleter_callback = 701 {% set indexed_property_deleter_callback =
700 '%sV8Internal::indexedPropertyDeleterCallback' % cpp_class 702 '%sV8Internal::indexedPropertyDeleterCallback' % cpp_class
701 if indexed_property_deleter or named_property_deleter else '0' %} 703 if indexed_property_deleter or named_property_deleter else '0' %}
702 {% set indexed_property_enumerator_callback = 704 {% set indexed_property_enumerator_callback =
703 'indexedPropertyEnumerator<%s>' % cpp_class 705 'indexedPropertyEnumerator<%s>' % cpp_class
704 if indexed_property_getter.is_enumerable else '0' %} 706 if indexed_property_getter.is_enumerable else '0' %}
705 {% set property_handler_flags = 707 {% set property_handler_flags =
706 'v8::PropertyHandlerFlags::kAllCanRead' 708 'v8::PropertyHandlerFlags::kNone' %}
707 if indexed_property_getter.do_not_check_security
708 else 'v8::PropertyHandlerFlags::kNone' %}
709 v8::IndexedPropertyHandlerConfiguration indexedPropertyHandlerConfig({{indexed_p roperty_getter_callback}}, {{indexed_property_setter_callback}}, {{indexed_prope rty_query_callback}}, {{indexed_property_deleter_callback}}, {{indexed_property_ enumerator_callback}}, v8::Local<v8::Value>(), {{property_handler_flags}}); 709 v8::IndexedPropertyHandlerConfiguration indexedPropertyHandlerConfig({{indexed_p roperty_getter_callback}}, {{indexed_property_setter_callback}}, {{indexed_prope rty_query_callback}}, {{indexed_property_deleter_callback}}, {{indexed_property_ enumerator_callback}}, v8::Local<v8::Value>(), {{property_handler_flags}});
710 {{target}}->SetHandler(indexedPropertyHandlerConfig); 710 {{target}}->SetHandler(indexedPropertyHandlerConfig);
711 {%- endmacro %} 711 {%- endmacro %}
712 712
713 713
714 {##############################################################################} 714 {##############################################################################}
715 {% macro install_named_property_handler(target) %} 715 {% macro install_named_property_handler(target) %}
716 {% set named_property_getter_callback = 716 {% set named_property_getter_callback =
717 '%sV8Internal::namedPropertyGetterCallback' % cpp_class %} 717 '%sV8Internal::namedPropertyGetterCallback' % cpp_class %}
718 {% set named_property_setter_callback = 718 {% set named_property_setter_callback =
719 '%sV8Internal::namedPropertySetterCallback' % cpp_class 719 '%sV8Internal::namedPropertySetterCallback' % cpp_class
720 if named_property_setter else '0' %} 720 if named_property_setter else '0' %}
721 {% set named_property_query_callback = 721 {% set named_property_query_callback =
722 '%sV8Internal::namedPropertyQueryCallback' % cpp_class 722 '%sV8Internal::namedPropertyQueryCallback' % cpp_class
723 if named_property_getter.is_enumerable else '0' %} 723 if named_property_getter.is_enumerable else '0' %}
724 {% set named_property_deleter_callback = 724 {% set named_property_deleter_callback =
725 '%sV8Internal::namedPropertyDeleterCallback' % cpp_class 725 '%sV8Internal::namedPropertyDeleterCallback' % cpp_class
726 if named_property_deleter else '0' %} 726 if named_property_deleter else '0' %}
727 {% set named_property_enumerator_callback = 727 {% set named_property_enumerator_callback =
728 '%sV8Internal::namedPropertyEnumeratorCallback' % cpp_class 728 '%sV8Internal::namedPropertyEnumeratorCallback' % cpp_class
729 if named_property_getter.is_enumerable else '0' %} 729 if named_property_getter.is_enumerable else '0' %}
730 {% set property_handler_flags_list = 730 {% set property_handler_flags_list =
731 ['int(v8::PropertyHandlerFlags::kOnlyInterceptStrings)'] %} 731 ['int(v8::PropertyHandlerFlags::kOnlyInterceptStrings)'] %}
732 {% if named_property_getter.do_not_check_security %}
733 {% set property_handler_flags_list =
734 property_handler_flags_list + ['int(v8::PropertyHandlerFlags::kAllCanRead )'] %}
735 {% endif %}
736 {% if not is_override_builtins %} 732 {% if not is_override_builtins %}
737 {% set property_handler_flags_list = 733 {% set property_handler_flags_list =
738 property_handler_flags_list + ['int(v8::PropertyHandlerFlags::kNonMasking )'] %} 734 property_handler_flags_list + ['int(v8::PropertyHandlerFlags::kNonMasking )'] %}
739 {% endif %} 735 {% endif %}
740 {% set property_handler_flags = 736 {% set property_handler_flags =
741 'static_cast<v8::PropertyHandlerFlags>(%s)' % 737 'static_cast<v8::PropertyHandlerFlags>(%s)' %
742 ' | '.join(property_handler_flags_list) %} 738 ' | '.join(property_handler_flags_list) %}
743 v8::NamedPropertyHandlerConfiguration namedPropertyHandlerConfig({{named_propert y_getter_callback}}, {{named_property_setter_callback}}, {{named_property_query_ callback}}, {{named_property_deleter_callback}}, {{named_property_enumerator_cal lback}}, v8::Local<v8::Value>(), {{property_handler_flags}}); 739 v8::NamedPropertyHandlerConfiguration namedPropertyHandlerConfig({{named_propert y_getter_callback}}, {{named_property_setter_callback}}, {{named_property_query_ callback}}, {{named_property_deleter_callback}}, {{named_property_enumerator_cal lback}}, v8::Local<v8::Value>(), {{property_handler_flags}});
744 {{target}}->SetHandler(namedPropertyHandlerConfig); 740 {{target}}->SetHandler(namedPropertyHandlerConfig);
745 {%- endmacro %} 741 {%- endmacro %}
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 } 957 }
962 958
963 {% for method in methods if method.overloads and method.overloads.has_partial_ov erloads %} 959 {% for method in methods if method.overloads and method.overloads.has_partial_ov erloads %}
964 void {{v8_class}}::register{{method.name | blink_capitalize}}MethodForPartialInt erface(void (*method)(const v8::FunctionCallbackInfo<v8::Value>&)) { 960 void {{v8_class}}::register{{method.name | blink_capitalize}}MethodForPartialInt erface(void (*method)(const v8::FunctionCallbackInfo<v8::Value>&)) {
965 {{cpp_class}}V8Internal::{{method.name}}MethodForPartialInterface = method; 961 {{cpp_class}}V8Internal::{{method.name}}MethodForPartialInterface = method;
966 } 962 }
967 963
968 {% endfor %} 964 {% endfor %}
969 {% endif %} 965 {% endif %}
970 {% endblock %} 966 {% endblock %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698