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

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: . 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 {% if interface_name == 'Window' %}
124 v8::Isolate* isolate = v8::Isolate::GetCurrent();
125 v8::Local<v8::Object> window = V8Window::findInstanceInPrototypeChain(accessed Object, isolate);
126 if (window.IsEmpty())
127 return false; // the frame is gone.
128
129 const DOMWindow* targetWindow = V8Window::toImpl(window);
130 return BindingSecurity::shouldAllowAccessTo(toLocalDOMWindow(toDOMWindow(acces singContext)), targetWindow, BindingSecurity::ErrorReportOption::DoNotReport);
131 {% else %}{# if interface_name == 'Window' #}
132 {# Not 'Window' means it\'s Location. #}
133 {{cpp_class}}* impl = {{v8_class}}::toImpl(accessedObject);
134 return BindingSecurity::shouldAllowAccessTo(toLocalDOMWindow(toDOMWindow(acces singContext)), impl, BindingSecurity::ErrorReportOption::DoNotReport);
135 {% endif %}{# if interface_name == 'Window' #}
136 }
137
138 {% endif %}
139 {% endblock %}
140 {##############################################################################}
141 {# Methods #} 120 {# Methods #}
142 {% from 'methods.cpp.tmpl' import generate_method, overload_resolution_method, 121 {% from 'methods.cpp.tmpl' import generate_method, overload_resolution_method,
143 method_callback, origin_safe_method_getter, generate_constructor, 122 method_callback, cross_origin_method_getter, generate_constructor,
144 method_implemented_in_private_script, generate_post_message_impl, 123 method_implemented_in_private_script, generate_post_message_impl,
145 runtime_determined_length_method, runtime_determined_maxarg_method 124 runtime_determined_length_method, runtime_determined_maxarg_method
146 with context %} 125 with context %}
147 {% for method in methods if method.should_be_exposed_to_script %} 126 {% for method in methods if method.should_be_exposed_to_script %}
148 {% for world_suffix in method.world_suffixes %} 127 {% for world_suffix in method.world_suffixes %}
149 {% 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 %}
150 {{generate_method(method, world_suffix)}} 129 {{generate_method(method, world_suffix)}}
151 {% endif %} 130 {% endif %}
152 {% if method.is_post_message and not is_partial %} 131 {% if method.is_post_message and not is_partial %}
153 {{generate_post_message_impl(method)}} 132 {{generate_post_message_impl(method)}}
(...skipping 11 matching lines...) Expand all
165 {# Document about the following condition: #} 144 {# Document about the following condition: #}
166 {# https://docs.google.com/document/d/1qBC7Therp437Jbt_QYAtNYMZs6zQ_7_tnMkNUG_AC qs/edit?usp=sharing #} 145 {# https://docs.google.com/document/d/1qBC7Therp437Jbt_QYAtNYMZs6zQ_7_tnMkNUG_AC qs/edit?usp=sharing #}
167 {% if (method.overloads and method.overloads.visible and 146 {% if (method.overloads and method.overloads.visible and
168 (not method.overloads.has_partial_overloads or not is_partial)) or 147 (not method.overloads.has_partial_overloads or not is_partial)) or
169 (not method.overloads and method.visible) %} 148 (not method.overloads and method.visible) %}
170 {# A single callback is generated for overloaded methods #} 149 {# A single callback is generated for overloaded methods #}
171 {# with considering partial overloads #} 150 {# with considering partial overloads #}
172 {{method_callback(method, world_suffix)}} 151 {{method_callback(method, world_suffix)}}
173 {% endif %} 152 {% endif %}
174 {% endif %} 153 {% endif %}
175 {% if method.is_do_not_check_security and method.visible %} 154 {% if method.is_cross_origin and method.visible %}
176 {{origin_safe_method_getter(method, world_suffix)}} 155 {{cross_origin_method_getter(method, world_suffix)}}
177 {% endif %} 156 {% endif %}
178 {% endfor %} 157 {% endfor %}
179 {% endfor %} 158 {% endfor %}
180 {% if iterator_method %} 159 {% if iterator_method %}
181 {{generate_method(iterator_method)}} 160 {{generate_method(iterator_method)}}
182 {{method_callback(iterator_method)}} 161 {{method_callback(iterator_method)}}
183 {% endif %} 162 {% endif %}
184 {% block origin_safe_method_setter %}{% endblock %}
185 {# Constructors #} 163 {# Constructors #}
186 {% for constructor in constructors %} 164 {% for constructor in constructors %}
187 {{generate_constructor(constructor)}} 165 {{generate_constructor(constructor)}}
188 {% endfor %} 166 {% endfor %}
189 {% block overloaded_constructor %}{% endblock %} 167 {% block overloaded_constructor %}{% endblock %}
190 {% block event_constructor %}{% endblock %} 168 {% block event_constructor %}{% endblock %}
191 {# Special operations (methods) #} 169 {# Special operations (methods) #}
192 {% block named_property_getter %}{% endblock %} 170 {% block named_property_getter %}{% endblock %}
193 {% block named_property_getter_callback %}{% endblock %} 171 {% block named_property_getter_callback %}{% endblock %}
194 {% block named_property_setter %}{% endblock %} 172 {% block named_property_setter %}{% endblock %}
195 {% block named_property_setter_callback %}{% endblock %} 173 {% block named_property_setter_callback %}{% endblock %}
196 {% block named_property_deleter %}{% endblock %} 174 {% block named_property_deleter %}{% endblock %}
197 {% block named_property_deleter_callback %}{% endblock %} 175 {% block named_property_deleter_callback %}{% endblock %}
198 {% block named_property_query %}{% endblock %} 176 {% block named_property_query %}{% endblock %}
199 {% block named_property_query_callback %}{% endblock %} 177 {% block named_property_query_callback %}{% endblock %}
200 {% block named_property_enumerator %}{% endblock %} 178 {% block named_property_enumerator %}{% endblock %}
201 {% block named_property_enumerator_callback %}{% endblock %} 179 {% block named_property_enumerator_callback %}{% endblock %}
202 {% block indexed_property_getter %}{% endblock %} 180 {% block indexed_property_getter %}{% endblock %}
203 {% block indexed_property_getter_callback %}{% endblock %} 181 {% block indexed_property_getter_callback %}{% endblock %}
204 {% block indexed_property_setter %}{% endblock %} 182 {% block indexed_property_setter %}{% endblock %}
205 {% block indexed_property_setter_callback %}{% endblock %} 183 {% block indexed_property_setter_callback %}{% endblock %}
206 {% block indexed_property_deleter %}{% endblock %} 184 {% block indexed_property_deleter %}{% endblock %}
207 {% block indexed_property_deleter_callback %}{% endblock %} 185 {% block indexed_property_deleter_callback %}{% endblock %}
186 {##############################################################################}
187 {% block security_check_functions %}
dcheng 2016/11/02 01:46:42 This block is moved so it can reference the genera
188 {% if has_access_check_callbacks and not is_partial %}
189 bool securityCheck(v8::Local<v8::Context> accessingContext, v8::Local<v8::Object > accessedObject, v8::Local<v8::Value> data) {
190 {% if interface_name == 'Window' %}
191 v8::Isolate* isolate = v8::Isolate::GetCurrent();
192 v8::Local<v8::Object> window = V8Window::findInstanceInPrototypeChain(accessed Object, isolate);
193 if (window.IsEmpty())
194 return false; // the frame is gone.
195
196 const DOMWindow* targetWindow = V8Window::toImpl(window);
197 return BindingSecurity::shouldAllowAccessTo(toLocalDOMWindow(toDOMWindow(acces singContext)), targetWindow, BindingSecurity::ErrorReportOption::DoNotReport);
198 {% else %}{# if interface_name == 'Window' #}
199 {# Not 'Window' means it\'s Location. #}
200 {{cpp_class}}* impl = {{v8_class}}::toImpl(accessedObject);
201 return BindingSecurity::shouldAllowAccessTo(toLocalDOMWindow(toDOMWindow(acces singContext)), impl, BindingSecurity::ErrorReportOption::DoNotReport);
202 {% endif %}{# if interface_name == 'Window' #}
203 }
204
205 {% if has_cross_origin_named_getter %}
206 void crossOriginNamedGetter(v8::Local<v8::Name> name, const v8::PropertyCallback Info<v8::Value>& info) {
207 if (!name->IsString())
208 return;
209 const AtomicString& propertyName = toCoreAtomicString(name.As<v8::String>());
210
211 // TODO(dcheng): Can we / should we use AtomicString here? That means using DE FINE_STATIC_LOCAL here.
212 static const struct AttributeInfo {
213 const char* const name;
214 using GetterCallback = void(*)(const v8::PropertyCallbackInfo<v8::Value>&);
215 const GetterCallback getter;
216 } kAttributeInfoList[] = {
217 {##### Cross-origin attributes #####}
218 {##### TODO(dcheng): Should another layer assert that should_be_exposed_to_s cript is true and world_suffixes == ['']? #####}
219 {% for attribute in attributes if attribute.has_cross_origin_getter %}
220 {##### TODO(dcheng): error out on attribute.has_custom_getter and attribute. constructor_type? #####}
dcheng 2016/11/02 01:46:42 For all these TODOs, I'm open to the best way to p
221 {"{{attribute.name}}", &{{cpp_class}}V8Internal::{{attribute.name}}Attribute Getter},
222 {% endfor %}
223 {##### Cross-origin methods #####}
224 {##### TODO(dcheng): Should another layer assert that method.visible is true ? #####}
225 {% for method in methods if method.is_cross_origin %}
226 {"{{method.name}}", &{{cpp_class}}V8Internal::{{method.name}}CrossOriginMeth odGetter},
227 {% endfor %}
228 };
229
230 for (const auto& attribute: kAttributeInfoList) {
231 if (propertyName == attribute.name) {
232 attribute.getter(info);
233 return;
234 }
235 }
236
237 {% if named_property_getter and named_property_getter.is_cross_origin %}
238 {% if named_property_getter.is_custom %}
239 {{v8_class}}::namedPropertyGetterCustom(propertyName, info);
240 {% else %}
241 {{cpp_class}}V8Internal::namedPropertyGetter(propertyName, info);
242 {% endif %}
243 {% endif %}
244 }
245 {% endif %}
246
247 {% if has_cross_origin_named_setter %}
248 void crossOriginNamedSetter(v8::Local<v8::Name> name, v8::Local<v8::Value> value , const v8::PropertyCallbackInfo<v8::Value>& info) {
249 if (!name->IsString())
250 return;
251 const AtomicString& propertyName = toCoreAtomicString(name.As<v8::String>());
252
253 // TODO(dcheng): Can we / should we use AtomicString here? That means using DE FINE_STATIC_LOCAL here.
254 static const struct AttributeInfo {
255 const char* const name;
256 using SetterCallback = void(*)(v8::Local<v8::Value>, const V8CrossOriginSett erInfo&);
257 const SetterCallback setter;
258 } kAttributeInfoList[] = {
259 {##### Cross-origin attributes #####}
260 {##### TODO(dcheng): Should another layer assert that should_be_exposed_to_s cript is true and world_suffixes == ['']? #####}
261 {% for attribute in attributes if attribute.has_cross_origin_setter %}
262 {##### TODO(dcheng): error out on attribute.has_custom_setter? #####}
263 {"{{attribute.name}}", &{{cpp_class}}V8Internal::{{attribute.name}}Attribute Setter},
264 {% endfor %}
265 };
266
267 for (const auto& attribute: kAttributeInfoList) {
268 if (propertyName == attribute.name) {
269 attribute.setter(value, V8CrossOriginSetterInfo(info.GetIsolate(), info.Ho lder()));
270 return;
271 }
272 }
273 }
274 {% endif %}
275
276 {% if has_cross_origin_indexed_getter %}
277 void crossOriginIndexedGetter(uint32_t index, const v8::PropertyCallbackInfo<v8: :Value>& info) {
278 {% if indexed_property_getter.is_custom %}
279 {{v8_class}}::indexedPropertyGetterCustom(index, info);
280 {% else %}
281 {{cpp_class}}V8Internal::indexedPropertyGetter(index, info);
282 {% endif %}
283 }
284 {% endif %}
285
286 {% endif %}
287 {% endblock %}
288 {##############################################################################}
208 } // namespace {{cpp_class_or_partial}}V8Internal 289 } // namespace {{cpp_class_or_partial}}V8Internal
209 290
210 {% block visit_dom_wrapper %}{% endblock %} 291 {% block visit_dom_wrapper %}{% endblock %}
211 {##############################################################################} 292 {##############################################################################}
212 {% block install_attributes %} 293 {% block install_attributes %}
213 {% from 'attributes.cpp.tmpl' import attribute_configuration with context %} 294 {% from 'attributes.cpp.tmpl' import attribute_configuration with context %}
214 {% if attributes | has_attribute_configuration %} 295 {% if attributes | has_attribute_configuration %}
215 // Suppress warning: global constructors, because AttributeConfiguration is triv ial 296 // Suppress warning: global constructors, because AttributeConfiguration is triv ial
216 // and does not depend on another global objects. 297 // and does not depend on another global objects.
217 #if defined(COMPONENT_BUILD) && defined(WIN32) && COMPILER(CLANG) 298 #if defined(COMPONENT_BUILD) && defined(WIN32) && COMPILER(CLANG)
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 {% endif %} 388 {% endif %}
308 {% if attributes | has_accessor_configuration %} 389 {% if attributes | has_accessor_configuration %}
309 V8DOMConfiguration::installAccessors(isolate, world, instanceTemplate, prototy peTemplate, interfaceTemplate, signature, {{'%sAccessors' % v8_class}}, {{'WTF_A RRAY_LENGTH(%sAccessors)' % v8_class}}); 390 V8DOMConfiguration::installAccessors(isolate, world, instanceTemplate, prototy peTemplate, interfaceTemplate, signature, {{'%sAccessors' % v8_class}}, {{'WTF_A RRAY_LENGTH(%sAccessors)' % v8_class}});
310 {% endif %} 391 {% endif %}
311 {% if methods | has_method_configuration(is_partial) %} 392 {% if methods | has_method_configuration(is_partial) %}
312 V8DOMConfiguration::installMethods(isolate, world, instanceTemplate, prototype Template, interfaceTemplate, signature, {{'%sMethods' % v8_class}}, {{'WTF_ARRAY _LENGTH(%sMethods)' % v8_class}}); 393 V8DOMConfiguration::installMethods(isolate, world, instanceTemplate, prototype Template, interfaceTemplate, signature, {{'%sMethods' % v8_class}}, {{'WTF_ARRAY _LENGTH(%sMethods)' % v8_class}});
313 {% endif %} 394 {% endif %}
314 {% endfilter %} 395 {% endfilter %}
315 {%- if has_access_check_callbacks and not is_partial %}{{newline}} 396 {%- if has_access_check_callbacks and not is_partial %}{{newline}}
316 // Cross-origin access check 397 // Cross-origin access check
317 instanceTemplate->SetAccessCheckCallback({{cpp_class}}V8Internal::securityChec k, v8::External::New(isolate, const_cast<WrapperTypeInfo*>(&{{v8_class}}::wrappe rTypeInfo))); 398 {% set cross_origin_named_getter = '%sV8Internal::crossOriginNamedGetter' % cp p_class if has_cross_origin_named_getter else 'nullptr' %}
399 {% set cross_origin_named_setter = '%sV8Internal::crossOriginNamedSetter' % cp p_class if has_cross_origin_named_setter else 'nullptr' %}
400 {% set cross_origin_indexed_getter = '%sV8Internal::crossOriginIndexedGetter' % cpp_class if has_cross_origin_indexed_getter else 'nullptr' %}
401 instanceTemplate->SetAccessCheckCallbackAndHandler({{cpp_class}}V8Internal::se curityCheck, v8::NamedPropertyHandlerConfiguration({{cross_origin_named_getter}} , {{cross_origin_named_setter}}), v8::IndexedPropertyHandlerConfiguration({{cros s_origin_indexed_getter}}), v8::External::New(isolate, const_cast<WrapperTypeInf o*>(&{{v8_class}}::wrapperTypeInfo)));
318 {% endif %} 402 {% endif %}
319 403
320 {%- for group in attributes | purely_runtime_enabled_attributes | groupby('run time_feature_name') %}{{newline}} 404 {%- for group in attributes | purely_runtime_enabled_attributes | groupby('run time_feature_name') %}{{newline}}
321 if ({{group.list[0].runtime_enabled_function}}()) { 405 if ({{group.list[0].runtime_enabled_function}}()) {
322 {% for attribute in group.list | unique_by('name') | sort %} 406 {% for attribute in group.list | unique_by('name') | sort %}
323 {% if attribute.is_data_type_property %} 407 {% if attribute.is_data_type_property %}
324 const V8DOMConfiguration::AttributeConfiguration attribute{{attribute.name}} Configuration = {{attribute_configuration(attribute)}}; 408 const V8DOMConfiguration::AttributeConfiguration attribute{{attribute.name}} Configuration = {{attribute_configuration(attribute)}};
325 V8DOMConfiguration::installAttribute(isolate, world, instanceTemplate, proto typeTemplate, attribute{{attribute.name}}Configuration); 409 V8DOMConfiguration::installAttribute(isolate, world, instanceTemplate, proto typeTemplate, attribute{{attribute.name}}Configuration);
326 {% else %} 410 {% else %}
327 const V8DOMConfiguration::AccessorConfiguration accessor{{attribute.name}}Co nfiguration = {{attribute_configuration(attribute)}}; 411 const V8DOMConfiguration::AccessorConfiguration accessor{{attribute.name}}Co nfiguration = {{attribute_configuration(attribute)}};
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 instanceTemplate->MarkAsUndetectable(); 448 instanceTemplate->MarkAsUndetectable();
365 {% endif %} 449 {% endif %}
366 450
367 {%- if methods | custom_registration(is_partial) %}{{newline}} 451 {%- if methods | custom_registration(is_partial) %}{{newline}}
368 {% for method in methods | custom_registration(is_partial) %} 452 {% for method in methods | custom_registration(is_partial) %}
369 {# install_custom_signature #} 453 {# install_custom_signature #}
370 {% filter exposed(method.overloads.exposed_test_all 454 {% filter exposed(method.overloads.exposed_test_all
371 if method.overloads else method.exposed_test) %} 455 if method.overloads else method.exposed_test) %}
372 {% filter runtime_enabled(method.overloads.runtime_enabled_function_all 456 {% filter runtime_enabled(method.overloads.runtime_enabled_function_all
373 if method.overloads else method.runtime_enabled_func tion) %} 457 if method.overloads else method.runtime_enabled_func tion) %}
374 {% if method.is_do_not_check_security %}
375 {{install_do_not_check_security_method(method, '', 'instanceTemplate', 'protot ypeTemplate') | indent(2)}}
376 {% else %}
377 {{install_custom_signature(method, 'instanceTemplate', 'prototypeTemplate', 'i nterfaceTemplate', 'signature') | indent(2)}} 458 {{install_custom_signature(method, 'instanceTemplate', 'prototypeTemplate', 'i nterfaceTemplate', 'signature') | indent(2)}}
378 {% endif %}
379 {% endfilter %} 459 {% endfilter %}
380 {% endfilter %} 460 {% endfilter %}
381 {% endfor %} 461 {% endfor %}
382 {% endif %} 462 {% endif %}
383 } 463 }
384 464
385 {% endif %}{# not is_array_buffer_or_view #} 465 {% endif %}{# not is_array_buffer_or_view #}
386 {% endblock %} 466 {% endblock %}
387 {##############################################################################} 467 {##############################################################################}
388 {% block origin_trials %} 468 {% block origin_trials %}
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 {% for attribute in attributes if attribute.is_implemented_in_private_script %} 531 {% for attribute in attributes if attribute.is_implemented_in_private_script %}
452 {{attribute_getter_implemented_in_private_script(attribute)}} 532 {{attribute_getter_implemented_in_private_script(attribute)}}
453 {% if attribute.has_setter %} 533 {% if attribute.has_setter %}
454 {{attribute_setter_implemented_in_private_script(attribute)}} 534 {{attribute_setter_implemented_in_private_script(attribute)}}
455 {% endif %} 535 {% endif %}
456 {% endfor %} 536 {% endfor %}
457 {% block partial_interface %}{% endblock %} 537 {% block partial_interface %}{% endblock %}
458 } // namespace blink 538 } // namespace blink
459 539
460 {% endfilter %}{# format_blink_cpp_source_code #} 540 {% endfilter %}{# format_blink_cpp_source_code #}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698