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

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 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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 if has_conditional_attributes and interface.is_partial: 369 if has_conditional_attributes and interface.is_partial:
370 raise Exception('Conditional attributes between partial interfaces in mo dules and the original interfaces(%s) in core are not allowed.' % interface.name ) 370 raise Exception('Conditional attributes between partial interfaces in mo dules and the original interfaces(%s) in core are not allowed.' % interface.name )
371 371
372 context.update({ 372 context.update({
373 'attributes': attributes, 373 'attributes': attributes,
374 }) 374 })
375 375
376 # Methods 376 # Methods
377 methods, iterator_method = methods_context(interface) 377 methods, iterator_method = methods_context(interface)
378 context.update({ 378 context.update({
379 'has_origin_safe_method_setter': is_global and any( 379 'has_origin_safe_method_setter': any(method['is_cross_origin'] and not m ethod['is_unforgeable']
380 method['is_check_security_for_receiver'] and not method['is_unforgea ble']
381 for method in methods), 380 for method in methods),
382 'has_private_script': (any(attribute['is_implemented_in_private_script'] for attribute in attributes) or 381 'has_private_script': (any(attribute['is_implemented_in_private_script'] for attribute in attributes) or
383 any(method['is_implemented_in_private_script'] fo r method in methods)), 382 any(method['is_implemented_in_private_script'] fo r method in methods)),
384 'iterator_method': iterator_method, 383 'iterator_method': iterator_method,
385 'methods': methods, 384 'methods': methods,
386 }) 385 })
387 386
388 # Window.idl in Blink has indexed properties, but the spec says Window 387 # Window.idl in Blink has indexed properties, but the spec says Window
389 # interface doesn't have indexed properties, instead the WindowProxy exotic 388 # interface doesn't have indexed properties, instead the WindowProxy exotic
390 # object has indexed properties. Thus, Window interface must not support 389 # object has indexed properties. Thus, Window interface must not support
(...skipping 25 matching lines...) Expand all
416 'named_property_deleter': property_deleter(interface.named_property_dele ter), 415 'named_property_deleter': property_deleter(interface.named_property_dele ter),
417 }) 416 })
418 context.update({ 417 context.update({
419 'has_named_properties_object': is_global and context['named_property_get ter'], 418 'has_named_properties_object': is_global and context['named_property_get ter'],
420 }) 419 })
421 420
422 # Origin Trials 421 # Origin Trials
423 context.update({ 422 context.update({
424 'origin_trial_features': origin_trial_features(interface, context['const ants'], context['attributes'], context['methods']), 423 'origin_trial_features': origin_trial_features(interface, context['const ants'], context['attributes'], context['methods']),
425 }) 424 })
425
426 # Cross-origin interceptors
427 has_cross_origin_named_getter = False
428 has_cross_origin_named_setter = False
429 has_cross_origin_indexed_getter = False
430
431 for attribute in attributes:
432 if attribute['has_cross_origin_getter']:
433 has_cross_origin_named_getter = True
434 if attribute['has_cross_origin_setter']:
435 has_cross_origin_named_setter = True
436
437 # Methods are exposed as getter attributes on the interface: e.g.
438 # window.location gets the location attribute on the Window interface. For
439 # the cross-origin case, this attribute getter is guaranteed to only return
440 # a Function object, which the actual call is dispatched against.
441 for method in methods:
442 if method['is_cross_origin']:
443 has_cross_origin_named_getter = True
444
445 has_cross_origin_named_enumerator = has_cross_origin_named_getter or has_cro ss_origin_named_setter # pylint: disable=invalid-name
446
447 if context['named_property_getter'] and context['named_property_getter']['is _cross_origin']:
448 has_cross_origin_named_getter = True
449
450 if context['indexed_property_getter'] and context['indexed_property_getter'] ['is_cross_origin']:
451 has_cross_origin_indexed_getter = True
452
453 context.update({
454 'has_cross_origin_named_getter': has_cross_origin_named_getter,
455 'has_cross_origin_named_setter': has_cross_origin_named_setter,
456 'has_cross_origin_named_enumerator': has_cross_origin_named_enumerator,
457 'has_cross_origin_indexed_getter': has_cross_origin_indexed_getter,
458 })
459
426 return context 460 return context
427 461
428 462
429 def methods_context(interface): 463 def methods_context(interface):
430 """Creates a list of Jinja template contexts for methods of an interface. 464 """Creates a list of Jinja template contexts for methods of an interface.
431 465
432 Args: 466 Args:
433 interface: An interface to create contexts for 467 interface: An interface to create contexts for
434 468
435 Returns: 469 Returns:
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 if method.get('runtime_enabled_function')) 825 if method.get('runtime_enabled_function'))
792 if not runtime_enabled_functions: 826 if not runtime_enabled_functions:
793 # This "length" is unconditionally enabled, so stop here. 827 # This "length" is unconditionally enabled, so stop here.
794 runtime_determined_maxargs.append((length, [None])) 828 runtime_determined_maxargs.append((length, [None]))
795 break 829 break
796 runtime_determined_maxargs.append( 830 runtime_determined_maxargs.append(
797 (length, sorted(runtime_enabled_functions))) 831 (length, sorted(runtime_enabled_functions)))
798 maxarg = ('%sV8Internal::%sMethodMaxArg()' 832 maxarg = ('%sV8Internal::%sMethodMaxArg()'
799 % (cpp_name_or_partial(interface), name)) 833 % (cpp_name_or_partial(interface), name))
800 834
801 # Check and fail if overloads disagree on any of the extended attributes
802 # that affect how the method should be registered.
803 # Skip the check for overloaded constructors, since they don't support any
804 # of the extended attributes in question.
805 if not overloads[0].get('is_constructor'):
806 overload_extended_attributes = [
807 method['custom_registration_extended_attributes']
808 for method in overloads]
809 for extended_attribute in v8_methods.CUSTOM_REGISTRATION_EXTENDED_ATTRIB UTES:
810 if common_key(overload_extended_attributes, extended_attribute) is N one:
811 raise ValueError('Overloads of %s have conflicting extended attr ibute %s'
812 % (name, extended_attribute))
813
814 # Check and fail if overloads disagree about whether the return type 835 # Check and fail if overloads disagree about whether the return type
815 # is a Promise or not. 836 # is a Promise or not.
816 promise_overload_count = sum(1 for method in overloads if method.get('return s_promise')) 837 promise_overload_count = sum(1 for method in overloads if method.get('return s_promise'))
817 if promise_overload_count not in (0, len(overloads)): 838 if promise_overload_count not in (0, len(overloads)):
818 raise ValueError('Overloads of %s have conflicting Promise/non-Promise t ypes' 839 raise ValueError('Overloads of %s have conflicting Promise/non-Promise t ypes'
819 % (name)) 840 % (name))
820 841
821 has_overload_visible = False 842 has_overload_visible = False
822 has_overload_not_visible = False 843 has_overload_not_visible = False
823 for overload in overloads: 844 for overload in overloads:
824 if overload.get('visible', True): 845 if overload.get('visible', True):
825 # If there exists an overload which is visible, need to generate 846 # If there exists an overload which is visible, need to generate
826 # overload_resolution, i.e. overlods_visible should be True. 847 # overload_resolution, i.e. overlods_visible should be True.
827 has_overload_visible = True 848 has_overload_visible = True
828 else: 849 else:
829 has_overload_not_visible = True 850 has_overload_not_visible = True
830 851
831 # If some overloads are not visible and others are visible, 852 # If some overloads are not visible and others are visible,
832 # the method is overloaded between core and modules. 853 # the method is overloaded between core and modules.
833 has_partial_overloads = has_overload_visible and has_overload_not_visible 854 has_partial_overloads = has_overload_visible and has_overload_not_visible
834 855
835 return { 856 return {
836 'deprecate_all_as': common_value(overloads, 'deprecate_as'), # [Depreca teAs] 857 'deprecate_all_as': common_value(overloads, 'deprecate_as'), # [Depreca teAs]
837 'exposed_test_all': common_value(overloads, 'exposed_test'), # [Exposed ] 858 'exposed_test_all': common_value(overloads, 'exposed_test'), # [Exposed ]
838 'has_custom_registration_all': common_value(overloads, 'has_custom_regis tration'),
839 'length': function_length, 859 'length': function_length,
840 'length_tests_methods': length_tests_methods(effective_overloads_by_leng th), 860 'length_tests_methods': length_tests_methods(effective_overloads_by_leng th),
841 # 1. Let maxarg be the length of the longest type list of the 861 # 1. Let maxarg be the length of the longest type list of the
842 # entries in S. 862 # entries in S.
843 'maxarg': maxarg, 863 'maxarg': maxarg,
844 'measure_all_as': common_value(overloads, 'measure_as'), # [MeasureAs] 864 'measure_all_as': common_value(overloads, 'measure_as'), # [MeasureAs]
845 'returns_promise_all': promise_overload_count > 0, 865 'returns_promise_all': promise_overload_count > 0,
846 'runtime_determined_lengths': runtime_determined_lengths, 866 'runtime_determined_lengths': runtime_determined_lengths,
847 'runtime_determined_maxargs': runtime_determined_maxargs, 867 'runtime_determined_maxargs': runtime_determined_maxargs,
848 'runtime_enabled_function_all': common_value(overloads, 'runtime_enabled _function'), # [RuntimeEnabled] 868 'runtime_enabled_function_all': common_value(overloads, 'runtime_enabled _function'), # [RuntimeEnabled]
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
1398 if is_raises_exception: 1418 if is_raises_exception:
1399 cpp_arguments.append('exceptionState') 1419 cpp_arguments.append('exceptionState')
1400 if use_output_parameter_for_result: 1420 if use_output_parameter_for_result:
1401 cpp_arguments.append('result') 1421 cpp_arguments.append('result')
1402 1422
1403 cpp_value = '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments)) 1423 cpp_value = '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments))
1404 1424
1405 return { 1425 return {
1406 'cpp_type': idl_type.cpp_type, 1426 'cpp_type': idl_type.cpp_type,
1407 'cpp_value': cpp_value, 1427 'cpp_value': cpp_value,
1408 'do_not_check_security': 'DoNotCheckSecurity' in extended_attributes,
1409 'is_call_with_script_state': is_call_with_script_state, 1428 'is_call_with_script_state': is_call_with_script_state,
1429 'is_cross_origin': 'CrossOrigin' in extended_attributes,
1410 'is_custom': 1430 'is_custom':
1411 'Custom' in extended_attributes and 1431 'Custom' in extended_attributes and
1412 (not extended_attributes['Custom'] or 1432 (not extended_attributes['Custom'] or
1413 has_extended_attribute_value(getter, 'Custom', 'PropertyGetter')), 1433 has_extended_attribute_value(getter, 'Custom', 'PropertyGetter')),
1414 'is_custom_property_enumerator': has_extended_attribute_value( 1434 'is_custom_property_enumerator': has_extended_attribute_value(
1415 getter, 'Custom', 'PropertyEnumerator'), 1435 getter, 'Custom', 'PropertyEnumerator'),
1416 'is_custom_property_query': has_extended_attribute_value( 1436 'is_custom_property_query': has_extended_attribute_value(
1417 getter, 'Custom', 'PropertyQuery'), 1437 getter, 'Custom', 'PropertyQuery'),
1418 'is_enumerable': 'NotEnumerable' not in extended_attributes, 1438 'is_enumerable': 'NotEnumerable' not in extended_attributes,
1419 'is_null_expression': is_null_expression(idl_type), 1439 'is_null_expression': is_null_expression(idl_type),
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1463 extended_attributes = deleter.extended_attributes 1483 extended_attributes = deleter.extended_attributes
1464 is_call_with_script_state = v8_utilities.has_extended_attribute_value(delete r, 'CallWith', 'ScriptState') 1484 is_call_with_script_state = v8_utilities.has_extended_attribute_value(delete r, 'CallWith', 'ScriptState')
1465 is_ce_reactions = 'CEReactions' in extended_attributes 1485 is_ce_reactions = 'CEReactions' in extended_attributes
1466 return { 1486 return {
1467 'is_call_with_script_state': is_call_with_script_state, 1487 'is_call_with_script_state': is_call_with_script_state,
1468 'is_ce_reactions': is_ce_reactions, 1488 'is_ce_reactions': is_ce_reactions,
1469 'is_custom': 'Custom' in extended_attributes, 1489 'is_custom': 'Custom' in extended_attributes,
1470 'is_raises_exception': 'RaisesException' in extended_attributes, 1490 'is_raises_exception': 'RaisesException' in extended_attributes,
1471 'name': cpp_name(deleter), 1491 'name': cpp_name(deleter),
1472 } 1492 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/bindings/scripts/v8_attributes.py ('k') | third_party/WebKit/Source/bindings/scripts/v8_methods.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698