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

Side by Side Diff: third_party/WebKit/Source/bindings/scripts/v8_interface.py

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 # Copyright (C) 2013 Google Inc. All rights reserved. 1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 # coding=utf-8 2 # coding=utf-8
3 # 3 #
4 # Redistribution and use in source and binary forms, with or without 4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are 5 # modification, are permitted provided that the following conditions are
6 # met: 6 # met:
7 # 7 #
8 # * Redistributions of source code must retain the above copyright 8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer. 9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above 10 # * Redistributions in binary form must reproduce the above
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 if has_conditional_attributes and interface.is_partial: 363 if has_conditional_attributes and interface.is_partial:
364 raise Exception('Conditional attributes between partial interfaces in mo dules and the original interfaces(%s) in core are not allowed.' % interface.name ) 364 raise Exception('Conditional attributes between partial interfaces in mo dules and the original interfaces(%s) in core are not allowed.' % interface.name )
365 365
366 context.update({ 366 context.update({
367 'attributes': attributes, 367 'attributes': attributes,
368 }) 368 })
369 369
370 # Methods 370 # Methods
371 methods, iterator_method = methods_context(interface) 371 methods, iterator_method = methods_context(interface)
372 context.update({ 372 context.update({
373 'has_origin_safe_method_setter': is_global and any(
374 method['is_check_security_for_receiver'] and not method['is_unforgea ble']
375 for method in methods),
376 'has_private_script': (any(attribute['is_implemented_in_private_script'] for attribute in attributes) or 373 'has_private_script': (any(attribute['is_implemented_in_private_script'] for attribute in attributes) or
377 any(method['is_implemented_in_private_script'] fo r method in methods)), 374 any(method['is_implemented_in_private_script'] fo r method in methods)),
378 'iterator_method': iterator_method, 375 'iterator_method': iterator_method,
379 'methods': methods, 376 'methods': methods,
380 }) 377 })
381 378
382 # Window.idl in Blink has indexed properties, but the spec says Window 379 # Window.idl in Blink has indexed properties, but the spec says Window
383 # interface doesn't have indexed properties, instead the WindowProxy exotic 380 # interface doesn't have indexed properties, instead the WindowProxy exotic
384 # object has indexed properties. Thus, Window interface must not support 381 # object has indexed properties. Thus, Window interface must not support
385 # iterators. 382 # iterators.
(...skipping 23 matching lines...) Expand all
409 'named_property_deleter': property_deleter(interface.named_property_dele ter), 406 'named_property_deleter': property_deleter(interface.named_property_dele ter),
410 }) 407 })
411 context.update({ 408 context.update({
412 'has_named_properties_object': is_global and context['named_property_get ter'], 409 'has_named_properties_object': is_global and context['named_property_get ter'],
413 }) 410 })
414 411
415 # Origin Trials 412 # Origin Trials
416 context.update({ 413 context.update({
417 'origin_trial_features': origin_trial_features(interface, context['const ants'], context['attributes'], context['methods']), 414 'origin_trial_features': origin_trial_features(interface, context['const ants'], context['attributes'], context['methods']),
418 }) 415 })
416
417 # Cross-origin interceptors
418 has_cross_origin_named_getter = False
419 has_cross_origin_named_setter = False
420 has_cross_origin_indexed_getter = False
haraken 2016/11/02 04:30:32 What about an indexed setter?
dcheng 2016/11/02 07:45:32 There are no cross-origin indexed setters. We can
Yuki 2016/11/02 08:26:39 I'm happy with raising an exception in the binding
dcheng 2016/11/03 07:44:45 I updated the bindings generator to raise exceptio
421
422 for attribute in attributes:
423 if attribute['has_cross_origin_getter']:
424 has_cross_origin_named_getter = True
425 elif attribute['has_cross_origin_setter']:
426 has_cross_origin_named_setter = True
427
428 for method in methods:
429 if method['is_cross_origin']:
430 has_cross_origin_named_getter = True
haraken 2016/11/02 04:30:32 Why do we treat cross-origin methods as named gett
dcheng 2016/11/02 07:45:32 Added a comment.
431
432 if context['named_property_getter'] and context['named_property_getter']['is _cross_origin']:
433 has_cross_origin_named_getter = True
434
435 if context['indexed_property_getter'] and context['indexed_property_getter'] ['is_cross_origin']:
436 has_cross_origin_indexed_getter = True
437
438 context.update({
439 'has_cross_origin_named_getter': has_cross_origin_named_getter,
440 'has_cross_origin_named_setter': has_cross_origin_named_setter,
441 'has_cross_origin_indexed_getter': has_cross_origin_indexed_getter,
442 })
443
419 return context 444 return context
420 445
421 446
422 def methods_context(interface): 447 def methods_context(interface):
423 """Creates a list of Jinja template contexts for methods of an interface. 448 """Creates a list of Jinja template contexts for methods of an interface.
424 449
425 Args: 450 Args:
426 interface: An interface to create contexts for 451 interface: An interface to create contexts for
427 452
428 Returns: 453 Returns:
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 if method.get('runtime_enabled_function')) 809 if method.get('runtime_enabled_function'))
785 if not runtime_enabled_functions: 810 if not runtime_enabled_functions:
786 # This "length" is unconditionally enabled, so stop here. 811 # This "length" is unconditionally enabled, so stop here.
787 runtime_determined_maxargs.append((length, [None])) 812 runtime_determined_maxargs.append((length, [None]))
788 break 813 break
789 runtime_determined_maxargs.append( 814 runtime_determined_maxargs.append(
790 (length, sorted(runtime_enabled_functions))) 815 (length, sorted(runtime_enabled_functions)))
791 maxarg = ('%sV8Internal::%sMethodMaxArg()' 816 maxarg = ('%sV8Internal::%sMethodMaxArg()'
792 % (cpp_name_or_partial(interface), name)) 817 % (cpp_name_or_partial(interface), name))
793 818
794 # Check and fail if overloads disagree on any of the extended attributes
795 # that affect how the method should be registered.
796 # Skip the check for overloaded constructors, since they don't support any
797 # of the extended attributes in question.
798 if not overloads[0].get('is_constructor'):
799 overload_extended_attributes = [
800 method['custom_registration_extended_attributes']
801 for method in overloads]
802 for extended_attribute in v8_methods.CUSTOM_REGISTRATION_EXTENDED_ATTRIB UTES:
803 if common_key(overload_extended_attributes, extended_attribute) is N one:
804 raise ValueError('Overloads of %s have conflicting extended attr ibute %s'
805 % (name, extended_attribute))
806
807 # Check and fail if overloads disagree about whether the return type 819 # Check and fail if overloads disagree about whether the return type
808 # is a Promise or not. 820 # is a Promise or not.
809 promise_overload_count = sum(1 for method in overloads if method.get('return s_promise')) 821 promise_overload_count = sum(1 for method in overloads if method.get('return s_promise'))
810 if promise_overload_count not in (0, len(overloads)): 822 if promise_overload_count not in (0, len(overloads)):
811 raise ValueError('Overloads of %s have conflicting Promise/non-Promise t ypes' 823 raise ValueError('Overloads of %s have conflicting Promise/non-Promise t ypes'
812 % (name)) 824 % (name))
813 825
814 has_overload_visible = False 826 has_overload_visible = False
815 has_overload_not_visible = False 827 has_overload_not_visible = False
816 for overload in overloads: 828 for overload in overloads:
817 if overload.get('visible', True): 829 if overload.get('visible', True):
818 # If there exists an overload which is visible, need to generate 830 # If there exists an overload which is visible, need to generate
819 # overload_resolution, i.e. overlods_visible should be True. 831 # overload_resolution, i.e. overlods_visible should be True.
820 has_overload_visible = True 832 has_overload_visible = True
821 else: 833 else:
822 has_overload_not_visible = True 834 has_overload_not_visible = True
823 835
824 # If some overloads are not visible and others are visible, 836 # If some overloads are not visible and others are visible,
825 # the method is overloaded between core and modules. 837 # the method is overloaded between core and modules.
826 has_partial_overloads = has_overload_visible and has_overload_not_visible 838 has_partial_overloads = has_overload_visible and has_overload_not_visible
827 839
828 return { 840 return {
829 'deprecate_all_as': common_value(overloads, 'deprecate_as'), # [Depreca teAs] 841 'deprecate_all_as': common_value(overloads, 'deprecate_as'), # [Depreca teAs]
830 'exposed_test_all': common_value(overloads, 'exposed_test'), # [Exposed ] 842 'exposed_test_all': common_value(overloads, 'exposed_test'), # [Exposed ]
831 'has_custom_registration_all': common_value(overloads, 'has_custom_regis tration'),
832 'length': function_length, 843 'length': function_length,
833 'length_tests_methods': length_tests_methods(effective_overloads_by_leng th), 844 'length_tests_methods': length_tests_methods(effective_overloads_by_leng th),
834 # 1. Let maxarg be the length of the longest type list of the 845 # 1. Let maxarg be the length of the longest type list of the
835 # entries in S. 846 # entries in S.
836 'maxarg': maxarg, 847 'maxarg': maxarg,
837 'measure_all_as': common_value(overloads, 'measure_as'), # [MeasureAs] 848 'measure_all_as': common_value(overloads, 'measure_as'), # [MeasureAs]
838 'returns_promise_all': promise_overload_count > 0, 849 'returns_promise_all': promise_overload_count > 0,
839 'runtime_determined_lengths': runtime_determined_lengths, 850 'runtime_determined_lengths': runtime_determined_lengths,
840 'runtime_determined_maxargs': runtime_determined_maxargs, 851 'runtime_determined_maxargs': runtime_determined_maxargs,
841 'runtime_enabled_function_all': common_value(overloads, 'runtime_enabled _function'), # [RuntimeEnabled] 852 'runtime_enabled_function_all': common_value(overloads, 'runtime_enabled _function'), # [RuntimeEnabled]
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 if is_raises_exception: 1396 if is_raises_exception:
1386 cpp_arguments.append('exceptionState') 1397 cpp_arguments.append('exceptionState')
1387 if use_output_parameter_for_result: 1398 if use_output_parameter_for_result:
1388 cpp_arguments.append('result') 1399 cpp_arguments.append('result')
1389 1400
1390 cpp_value = '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments)) 1401 cpp_value = '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments))
1391 1402
1392 return { 1403 return {
1393 'cpp_type': idl_type.cpp_type, 1404 'cpp_type': idl_type.cpp_type,
1394 'cpp_value': cpp_value, 1405 'cpp_value': cpp_value,
1395 'do_not_check_security': 'DoNotCheckSecurity' in extended_attributes,
1396 'is_call_with_script_state': is_call_with_script_state, 1406 'is_call_with_script_state': is_call_with_script_state,
1407 'is_cross_origin': 'CrossOrigin' in extended_attributes,
1397 'is_custom': 1408 'is_custom':
1398 'Custom' in extended_attributes and 1409 'Custom' in extended_attributes and
1399 (not extended_attributes['Custom'] or 1410 (not extended_attributes['Custom'] or
1400 has_extended_attribute_value(getter, 'Custom', 'PropertyGetter')), 1411 has_extended_attribute_value(getter, 'Custom', 'PropertyGetter')),
1401 'is_custom_property_enumerator': has_extended_attribute_value( 1412 'is_custom_property_enumerator': has_extended_attribute_value(
1402 getter, 'Custom', 'PropertyEnumerator'), 1413 getter, 'Custom', 'PropertyEnumerator'),
1403 'is_custom_property_query': has_extended_attribute_value( 1414 'is_custom_property_query': has_extended_attribute_value(
1404 getter, 'Custom', 'PropertyQuery'), 1415 getter, 'Custom', 'PropertyQuery'),
1405 'is_enumerable': 'NotEnumerable' not in extended_attributes, 1416 'is_enumerable': 'NotEnumerable' not in extended_attributes,
1406 'is_null_expression': is_null_expression(idl_type), 1417 'is_null_expression': is_null_expression(idl_type),
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1450 extended_attributes = deleter.extended_attributes 1461 extended_attributes = deleter.extended_attributes
1451 is_call_with_script_state = v8_utilities.has_extended_attribute_value(delete r, 'CallWith', 'ScriptState') 1462 is_call_with_script_state = v8_utilities.has_extended_attribute_value(delete r, 'CallWith', 'ScriptState')
1452 is_ce_reactions = 'CEReactions' in extended_attributes 1463 is_ce_reactions = 'CEReactions' in extended_attributes
1453 return { 1464 return {
1454 'is_call_with_script_state': is_call_with_script_state, 1465 'is_call_with_script_state': is_call_with_script_state,
1455 'is_ce_reactions': is_ce_reactions, 1466 'is_ce_reactions': is_ce_reactions,
1456 'is_custom': 'Custom' in extended_attributes, 1467 'is_custom': 'Custom' in extended_attributes,
1457 'is_raises_exception': 'RaisesException' in extended_attributes, 1468 'is_raises_exception': 'RaisesException' in extended_attributes,
1458 'name': cpp_name(deleter), 1469 'name': cpp_name(deleter),
1459 } 1470 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698