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

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

Issue 2439013002: Implement cross-origin attributes using access check interceptors. (Closed)
Patch Set: Attributes, sort of Created 4 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 {% filter format_blink_cpp_source_code %} 1 {% filter format_blink_cpp_source_code %}
2 2
3 {% include 'copyright_block.txt' %} 3 {% include 'copyright_block.txt' %}
4 #include "{{v8_class_or_partial}}.h" 4 #include "{{v8_class_or_partial}}.h"
5 5
6 {% for filename in cpp_includes if filename != '%s.h' % cpp_class_or_partial %} 6 {% for filename in cpp_includes if filename != '%s.h' % cpp_class_or_partial %}
7 #include "{{filename}}" 7 #include "{{filename}}"
8 {% endfor %} 8 {% endfor %}
9 9
10 namespace blink { 10 namespace blink {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 {% endif %} 110 {% endif %}
111 {% if attribute.has_setter %} 111 {% if attribute.has_setter %}
112 {% if not attribute.has_custom_setter %} 112 {% if not attribute.has_custom_setter %}
113 {{attribute_setter(attribute, world_suffix)}} 113 {{attribute_setter(attribute, world_suffix)}}
114 {% endif %} 114 {% endif %}
115 {{attribute_setter_callback(attribute, world_suffix)}} 115 {{attribute_setter_callback(attribute, world_suffix)}}
116 {% endif %} 116 {% endif %}
117 {% endfor %} 117 {% endfor %}
118 {% endfor %} 118 {% endfor %}
119 {##############################################################################} 119 {##############################################################################}
120 {% block security_check_functions %}
121 {% if has_access_check_callbacks and not is_partial %}
122 bool securityCheck(v8::Local<v8::Context> accessingContext, v8::Local<v8::Object > accessedObject, v8::Local<v8::Value> data)
123 {
124 {% if interface_name == 'Window' %}
125 v8::Isolate* isolate = v8::Isolate::GetCurrent();
126 v8::Local<v8::Object> window = V8Window::findInstanceInPrototypeChain(access edObject, isolate);
127 if (window.IsEmpty())
128 return false; // the frame is gone.
129
130 const DOMWindow* targetWindow = V8Window::toImpl(window);
131 return BindingSecurity::shouldAllowAccessTo(toLocalDOMWindow(toDOMWindow(acc essingContext)), targetWindow, BindingSecurity::ErrorReportOption::DoNotReport);
132 {% else %}{# if interface_name == 'Window' #}
133 {# Not 'Window' means it\'s Location. #}
134 {{cpp_class}}* impl = {{v8_class}}::toImpl(accessedObject);
135 return BindingSecurity::shouldAllowAccessTo(toLocalDOMWindow(toDOMWindow(acc essingContext)), impl, BindingSecurity::ErrorReportOption::DoNotReport);
136 {% endif %}{# if interface_name == 'Window' #}
137 }
138
139 {% endif %}
140 {% endblock %}
141 {##############################################################################}
142 {# Methods #} 120 {# Methods #}
143 {% from 'methods.cpp.tmpl' import generate_method, overload_resolution_method, 121 {% from 'methods.cpp.tmpl' import generate_method, overload_resolution_method,
144 method_callback, origin_safe_method_getter, generate_constructor, 122 method_callback, origin_safe_method_getter, generate_constructor,
145 method_implemented_in_private_script, generate_post_message_impl, 123 method_implemented_in_private_script, generate_post_message_impl,
146 runtime_determined_length_method, runtime_determined_maxarg_method 124 runtime_determined_length_method, runtime_determined_maxarg_method
147 with context %} 125 with context %}
148 {% for method in methods if method.should_be_exposed_to_script %} 126 {% for method in methods if method.should_be_exposed_to_script %}
149 {% for world_suffix in method.world_suffixes %} 127 {% for world_suffix in method.world_suffixes %}
150 {% if not method.is_custom and not method.is_post_message and method.visible %} 128 {% if not method.is_custom and not method.is_post_message and method.visible %}
151 {{generate_method(method, world_suffix)}} 129 {{generate_method(method, world_suffix)}}
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 {% block named_property_query %}{% endblock %} 177 {% block named_property_query %}{% endblock %}
200 {% block named_property_query_callback %}{% endblock %} 178 {% block named_property_query_callback %}{% endblock %}
201 {% block named_property_enumerator %}{% endblock %} 179 {% block named_property_enumerator %}{% endblock %}
202 {% block named_property_enumerator_callback %}{% endblock %} 180 {% block named_property_enumerator_callback %}{% endblock %}
203 {% block indexed_property_getter %}{% endblock %} 181 {% block indexed_property_getter %}{% endblock %}
204 {% block indexed_property_getter_callback %}{% endblock %} 182 {% block indexed_property_getter_callback %}{% endblock %}
205 {% block indexed_property_setter %}{% endblock %} 183 {% block indexed_property_setter %}{% endblock %}
206 {% block indexed_property_setter_callback %}{% endblock %} 184 {% block indexed_property_setter_callback %}{% endblock %}
207 {% block indexed_property_deleter %}{% endblock %} 185 {% block indexed_property_deleter %}{% endblock %}
208 {% block indexed_property_deleter_callback %}{% endblock %} 186 {% block indexed_property_deleter_callback %}{% endblock %}
187 {##############################################################################}
188 {% block security_check_functions %}
189 {% if has_access_check_callbacks and not is_partial %}
190 bool securityCheck(v8::Local<v8::Context> accessingContext, v8::Local<v8::Object > accessedObject, v8::Local<v8::Value> data)
191 {
192 {% if interface_name == 'Window' %}
193 v8::Isolate* isolate = v8::Isolate::GetCurrent();
194 v8::Local<v8::Object> window = V8Window::findInstanceInPrototypeChain(access edObject, isolate);
195 if (window.IsEmpty())
196 return false; // the frame is gone.
197
198 const DOMWindow* targetWindow = V8Window::toImpl(window);
199 return BindingSecurity::shouldAllowAccessTo(toLocalDOMWindow(toDOMWindow(acc essingContext)), targetWindow, BindingSecurity::ErrorReportOption::DoNotReport);
200 {% else %}{# if interface_name == 'Window' #}
201 {# Not 'Window' means it\'s Location. #}
202 {{cpp_class}}* impl = {{v8_class}}::toImpl(accessedObject);
203 return BindingSecurity::shouldAllowAccessTo(toLocalDOMWindow(toDOMWindow(acc essingContext)), impl, BindingSecurity::ErrorReportOption::DoNotReport);
204 {% endif %}{# if interface_name == 'Window' #}
205 }
206
207 void crossOriginNamedGetter(v8::Local<v8::Name> name, const v8::PropertyCallback Info<v8::Value>& info)
208 {
209 {# TODO(dcheng): This needs to dispatch to methods / properties, not just the na med getter. #}
210 {% if named_property_getter and named_property_getter.is_cross_origin %}
211 if (!name->IsString())
212 return;
213 const AtomicString& propertyName = toCoreAtomicString(name.As<v8::String>()) ;
214
215 // TODO(dcheng): Can we / should we use AtomicString here? That means using DEFINE_STATIC_LOCAL here.
dcheng 2016/10/24 07:56:38 This is a easy change, but there's no precedent fo
216 static const struct AttributeInfo {
217 const char* const m_name;
218 using GetterCallback = void(*)(const v8::PropertyCallbackInfo<v8::Value> &);
219 const GetterCallback m_getter;
220 } kAttributeInfoList[] = {
221 {% for attribute in attributes if attribute.should_be_exposed_to_script and attribute.is_cross_origin %}
222 {##### TODO(dcheng): raise an exception somewhere? Don't allow world suf fixes for CrossOrigin attributes #####}
223 {% for world_suffix in attribute.world_suffixes %}
dcheng 2016/10/24 07:56:38 There's a lot of different variations here. I thin
224 {##### TODO(dcheng): error out on attribute.has_custom_getter? Not neede d. Or just support it? #####}
225 {% if not attribute.constructor_type %}
226 {"{{attribute.name}}", &{{cpp_class}}V8Internal::{{attribute.name}}Attri buteGetter},
227 {% elif attribute.needs_constructor_getter_callback %}
228 {##### TODO(dcheng): Raise an exception here too? #####}
229 {{constructor_getter_callback(attribute, world_suffix)}}
230 {% endif %}
231 {% endfor %}
232 {% endfor %}
233 };
234
235 for (const auto& attribute: kAttributeInfoList) {
236 if (propertyName == attribute.m_name) {
237 attribute.m_getter(info);
238 return;
239 }
240 }
241
242 {% if named_property_getter.is_custom %}
243 {{v8_class}}::namedPropertyGetterCustom(propertyName, info);
244 {% else %}
245 {{cpp_class}}V8Internal::namedPropertyGetter(propertyName, info);
246 {% endif %}
247 {% endif %}
248 }
249
250 void crossOriginNamedSetter(v8::Local<v8::Name> name, v8::Local<v8::Value> value , const v8::PropertyCallbackInfo<v8::Value>& info)
251 {
252 {# TODO(dcheng): This needs to dispatch to methods / properties, not just the na med setter. #}
253 {% if named_property_setter and named_property_setter.is_cross_origin %}
254 if (!name->IsString())
255 return;
256 const AtomicString& propertyName = toCoreAtomicString(name.As<v8::String>()) ;
257
258 {% if named_property_setter.is_custom %}
259 {{v8_class}}::namedPropertySetterCustom(propertyName, v8Value, info);
260 {% else %}
261 {{cpp_class}}V8Internal::namedPropertySetter(propertyName, v8Value, info);
262 {% endif %}
263 {% endif %}
264 }
265
266 void crossOriginIndexedGetter(uint32_t index, const v8::PropertyCallbackInfo<v8: :Value>& info)
267 {
268 {% if indexed_property_getter and indexed_property_getter.is_cross_origin %}
269 {% if indexed_property_getter.is_custom %}
270 {{v8_class}}::indexedPropertyGetterCustom(index, info);
271 {% else %}
272 {{cpp_class}}V8Internal::indexedPropertyGetter(index, info);
273 {% endif %}
274 {% endif %}
275 }
276
277 {% endif %}
278 {% endblock %}
279 {##############################################################################}
209 } // namespace {{cpp_class_or_partial}}V8Internal 280 } // namespace {{cpp_class_or_partial}}V8Internal
210 281
211 {% block visit_dom_wrapper %}{% endblock %} 282 {% block visit_dom_wrapper %}{% endblock %}
212 {##############################################################################} 283 {##############################################################################}
213 {% block install_attributes %} 284 {% block install_attributes %}
214 {% from 'attributes.cpp.tmpl' import attribute_configuration with context %} 285 {% from 'attributes.cpp.tmpl' import attribute_configuration with context %}
215 {% if attributes | has_attribute_configuration %} 286 {% if attributes | has_attribute_configuration %}
216 // Suppress warning: global constructors, because AttributeConfiguration is triv ial 287 // Suppress warning: global constructors, because AttributeConfiguration is triv ial
217 // and does not depend on another global objects. 288 // and does not depend on another global objects.
218 #if defined(COMPONENT_BUILD) && defined(WIN32) && COMPILER(CLANG) 289 #if defined(COMPONENT_BUILD) && defined(WIN32) && COMPILER(CLANG)
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 {% endif %} 380 {% endif %}
310 {% if attributes | has_accessor_configuration %} 381 {% if attributes | has_accessor_configuration %}
311 V8DOMConfiguration::installAccessors(isolate, world, instanceTemplate, proto typeTemplate, interfaceTemplate, signature, {{'%sAccessors' % v8_class}}, {{'WTF _ARRAY_LENGTH(%sAccessors)' % v8_class}}); 382 V8DOMConfiguration::installAccessors(isolate, world, instanceTemplate, proto typeTemplate, interfaceTemplate, signature, {{'%sAccessors' % v8_class}}, {{'WTF _ARRAY_LENGTH(%sAccessors)' % v8_class}});
312 {% endif %} 383 {% endif %}
313 {% if methods | has_method_configuration(is_partial) %} 384 {% if methods | has_method_configuration(is_partial) %}
314 V8DOMConfiguration::installMethods(isolate, world, instanceTemplate, prototy peTemplate, interfaceTemplate, signature, {{'%sMethods' % v8_class}}, {{'WTF_ARR AY_LENGTH(%sMethods)' % v8_class}}); 385 V8DOMConfiguration::installMethods(isolate, world, instanceTemplate, prototy peTemplate, interfaceTemplate, signature, {{'%sMethods' % v8_class}}, {{'WTF_ARR AY_LENGTH(%sMethods)' % v8_class}});
315 {% endif %} 386 {% endif %}
316 {% endfilter %} 387 {% endfilter %}
317 {%- if has_access_check_callbacks and not is_partial %}{{newline}} 388 {%- if has_access_check_callbacks and not is_partial %}{{newline}}
318 // Cross-origin access check 389 // Cross-origin access check
319 instanceTemplate->SetAccessCheckCallback({{cpp_class}}V8Internal::securityCh eck, v8::External::New(isolate, const_cast<WrapperTypeInfo*>(&{{v8_class}}::wrap perTypeInfo))); 390 instanceTemplate->SetAccessCheckCallbackAndHandler({{cpp_class}}V8Internal:: securityCheck, v8::NamedPropertyHandlerConfiguration({{cpp_class}}V8Internal::cr ossOriginNamedGetter, {{cpp_class}}V8Internal::crossOriginNamedSetter), v8::Inde xedPropertyHandlerConfiguration({{cpp_class}}V8Internal::crossOriginIndexedGette r), v8::External::New(isolate, const_cast<WrapperTypeInfo*>(&{{v8_class}}::wrapp erTypeInfo)));
320 {% endif %} 391 {% endif %}
321 392
322 {%- for group in attributes | purely_runtime_enabled_attributes | groupby('r untime_feature_name') %}{{newline}} 393 {%- for group in attributes | purely_runtime_enabled_attributes | groupby('r untime_feature_name') %}{{newline}}
323 if ({{group.list[0].runtime_enabled_function}}()) { 394 if ({{group.list[0].runtime_enabled_function}}()) {
324 {% for attribute in group.list | unique_by('name') | sort %} 395 {% for attribute in group.list | unique_by('name') | sort %}
325 {% if attribute.is_data_type_property %} 396 {% if attribute.is_data_type_property %}
326 const V8DOMConfiguration::AttributeConfiguration attribute{{attribute.na me}}Configuration = \ 397 const V8DOMConfiguration::AttributeConfiguration attribute{{attribute.na me}}Configuration = \
327 {{attribute_configuration(attribute)}}; 398 {{attribute_configuration(attribute)}};
328 V8DOMConfiguration::installAttribute(isolate, world, instanceTemplate, p rototypeTemplate, attribute{{attribute.name}}Configuration); 399 V8DOMConfiguration::installAttribute(isolate, world, instanceTemplate, p rototypeTemplate, attribute{{attribute.name}}Configuration);
329 {% else %} 400 {% else %}
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 {% for attribute in attributes if attribute.is_implemented_in_private_script %} 533 {% for attribute in attributes if attribute.is_implemented_in_private_script %}
463 {{attribute_getter_implemented_in_private_script(attribute)}} 534 {{attribute_getter_implemented_in_private_script(attribute)}}
464 {% if attribute.has_setter %} 535 {% if attribute.has_setter %}
465 {{attribute_setter_implemented_in_private_script(attribute)}} 536 {{attribute_setter_implemented_in_private_script(attribute)}}
466 {% endif %} 537 {% endif %}
467 {% endfor %} 538 {% endfor %}
468 {% block partial_interface %}{% endblock %} 539 {% block partial_interface %}{% endblock %}
469 } // namespace blink 540 } // namespace blink
470 541
471 {% endfilter %}{# format_blink_cpp_source_code #} 542 {% endfilter %}{# format_blink_cpp_source_code #}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698