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

Side by Side Diff: third_party/WebKit/Source/bindings/scripts/v8_methods.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 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 25 matching lines...) Expand all
36 36
37 from idl_definitions import IdlArgument, IdlOperation 37 from idl_definitions import IdlArgument, IdlOperation
38 from idl_types import IdlTypeBase, IdlUnionType, inherits_interface 38 from idl_types import IdlTypeBase, IdlUnionType, inherits_interface
39 from v8_globals import includes 39 from v8_globals import includes
40 import v8_types 40 import v8_types
41 import v8_utilities 41 import v8_utilities
42 from v8_utilities import (has_extended_attribute_value, is_unforgeable, 42 from v8_utilities import (has_extended_attribute_value, is_unforgeable,
43 is_legacy_interface_type_checking) 43 is_legacy_interface_type_checking)
44 44
45 45
46 # Methods with any of these require custom method registration code in the
47 # interface's configure*Template() function.
48 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES = frozenset([
49 'DoNotCheckSecurity',
50 ])
51
52
53 def method_is_visible(method, interface_is_partial): 46 def method_is_visible(method, interface_is_partial):
54 if 'overloads' in method: 47 if 'overloads' in method:
55 return method['overloads']['visible'] and not (method['overloads']['has_ partial_overloads'] and interface_is_partial) 48 return method['overloads']['visible'] and not (method['overloads']['has_ partial_overloads'] and interface_is_partial)
56 return method['visible'] and 'overload_index' not in method 49 return method['visible'] and 'overload_index' not in method
57 50
58 51
59 def conditionally_exposed(method): 52 def conditionally_exposed(method):
60 exposed = method['overloads']['exposed_test_all'] if 'overloads' in method e lse method['exposed_test'] 53 exposed = method['overloads']['exposed_test_all'] if 'overloads' in method e lse method['exposed_test']
61 secure_context = method['overloads']['secure_context_test_all'] if 'overload s' in method else method['secure_context_test'] 54 secure_context = method['overloads']['secure_context_test_all'] if 'overload s' in method else method['secure_context_test']
62 return exposed or secure_context 55 return exposed or secure_context
63 56
64 57
65 def filter_conditionally_exposed(methods, interface_is_partial): 58 def filter_conditionally_exposed(methods, interface_is_partial):
66 return [method for method in methods if ( 59 return [method for method in methods if (
67 method_is_visible(method, interface_is_partial) and conditionally_expose d(method))] 60 method_is_visible(method, interface_is_partial) and conditionally_expose d(method))]
68 61
69 62
70 def custom_registration(method): 63 def custom_registration(method):
64 # TODO(dcheng): Currently, bindings must create a function object for each
65 # realm as a hack to support the incumbent realm. Remove the need for custom
66 # registration when Blink properly supports the incumbent realm.
67 if method['is_cross_origin']:
68 return True
71 if 'overloads' in method: 69 if 'overloads' in method:
72 return (method['overloads']['has_custom_registration_all'] or 70 return (method['overloads']['runtime_determined_lengths'] or
73 method['overloads']['runtime_determined_lengths'] or
74 (method['overloads']['runtime_enabled_function_all'] and not con ditionally_exposed(method))) 71 (method['overloads']['runtime_enabled_function_all'] and not con ditionally_exposed(method)))
75 return (method['has_custom_registration'] or 72 return method['runtime_enabled_function'] and not conditionally_exposed(meth od)
76 (method['runtime_enabled_function'] and not conditionally_exposed(me thod)))
77 73
78 74
79 def filter_custom_registration(methods, interface_is_partial): 75 def filter_custom_registration(methods, interface_is_partial):
80 return [method for method in methods if ( 76 return [method for method in methods if (
81 method_is_visible(method, interface_is_partial) and custom_registration( method))] 77 method_is_visible(method, interface_is_partial) and custom_registration( method))]
82 78
83 79
84 def filter_method_configuration(methods, interface_is_partial): 80 def filter_method_configuration(methods, interface_is_partial):
85 return [method for method in methods if 81 return [method for method in methods if
86 method_is_visible(method, interface_is_partial) and 82 method_is_visible(method, interface_is_partial) and
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 is_call_with_script_arguments = has_extended_attribute_value(method, 'CallWi th', 'ScriptArguments') 138 is_call_with_script_arguments = has_extended_attribute_value(method, 'CallWi th', 'ScriptArguments')
143 if is_call_with_script_arguments: 139 if is_call_with_script_arguments:
144 includes.update(['bindings/core/v8/ScriptCallStack.h', 140 includes.update(['bindings/core/v8/ScriptCallStack.h',
145 'core/inspector/ScriptArguments.h']) 141 'core/inspector/ScriptArguments.h'])
146 is_call_with_script_state = has_extended_attribute_value(method, 'CallWith', 'ScriptState') 142 is_call_with_script_state = has_extended_attribute_value(method, 'CallWith', 'ScriptState')
147 is_call_with_this_value = has_extended_attribute_value(method, 'CallWith', ' ThisValue') 143 is_call_with_this_value = has_extended_attribute_value(method, 'CallWith', ' ThisValue')
148 if is_call_with_script_state or is_call_with_this_value: 144 if is_call_with_script_state or is_call_with_this_value:
149 includes.add('bindings/core/v8/ScriptState.h') 145 includes.add('bindings/core/v8/ScriptState.h')
150 146
151 # [CheckSecurity] 147 # [CheckSecurity]
152 is_do_not_check_security = 'DoNotCheckSecurity' in extended_attributes 148 is_cross_origin = 'CrossOrigin' in extended_attributes
153 is_check_security_for_receiver = ( 149 is_check_security_for_receiver = (
154 has_extended_attribute_value(interface, 'CheckSecurity', 'Receiver') and 150 has_extended_attribute_value(interface, 'CheckSecurity', 'Receiver') and
155 not is_do_not_check_security) 151 not is_cross_origin)
156 is_check_security_for_return_value = ( 152 is_check_security_for_return_value = (
157 has_extended_attribute_value(method, 'CheckSecurity', 'ReturnValue')) 153 has_extended_attribute_value(method, 'CheckSecurity', 'ReturnValue'))
158 if is_check_security_for_receiver or is_check_security_for_return_value: 154 if is_check_security_for_receiver or is_check_security_for_return_value:
159 includes.add('bindings/core/v8/BindingSecurity.h') 155 includes.add('bindings/core/v8/BindingSecurity.h')
160 156
161 is_ce_reactions = 'CEReactions' in extended_attributes 157 is_ce_reactions = 'CEReactions' in extended_attributes
162 if is_ce_reactions: 158 if is_ce_reactions:
163 includes.add('core/dom/custom/CEReactionsScope.h') 159 includes.add('core/dom/custom/CEReactionsScope.h')
164 is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attribute s 160 is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attribute s
165 if is_custom_element_callbacks: 161 if is_custom_element_callbacks:
(...skipping 18 matching lines...) Expand all
184 180
185 return { 181 return {
186 'activity_logging_world_list': v8_utilities.activity_logging_world_list( method), # [ActivityLogging] 182 'activity_logging_world_list': v8_utilities.activity_logging_world_list( method), # [ActivityLogging]
187 'arguments': argument_contexts, 183 'arguments': argument_contexts,
188 'argument_declarations_for_private_script': 184 'argument_declarations_for_private_script':
189 argument_declarations_for_private_script(interface, method), 185 argument_declarations_for_private_script(interface, method),
190 'cpp_type': (v8_types.cpp_template_type('Nullable', idl_type.cpp_type) 186 'cpp_type': (v8_types.cpp_template_type('Nullable', idl_type.cpp_type)
191 if idl_type.is_explicit_nullable else idl_type.cpp_type), 187 if idl_type.is_explicit_nullable else idl_type.cpp_type),
192 'cpp_value': this_cpp_value, 188 'cpp_value': this_cpp_value,
193 'cpp_type_initializer': idl_type.cpp_type_initializer, 189 'cpp_type_initializer': idl_type.cpp_type_initializer,
194 'custom_registration_extended_attributes':
195 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES.intersection(
196 extended_attributes.iterkeys()),
197 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs] 190 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs]
198 'do_not_test_new_object': 'DoNotTestNewObject' in extended_attributes, 191 'do_not_test_new_object': 'DoNotTestNewObject' in extended_attributes,
199 'exposed_test': v8_utilities.exposed(method, interface), # [Exposed] 192 'exposed_test': v8_utilities.exposed(method, interface), # [Exposed]
200 # TODO(yukishiino): Retire has_custom_registration flag. Should be
201 # replaced with V8DOMConfiguration::PropertyLocationConfiguration.
202 'has_custom_registration':
203 v8_utilities.has_extended_attribute(
204 method, CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES),
205 'has_exception_state': 193 'has_exception_state':
206 is_raises_exception or 194 is_raises_exception or
207 is_check_security_for_receiver or 195 is_check_security_for_receiver or
208 any(argument for argument in arguments 196 any(argument for argument in arguments
209 if (argument.idl_type.name == 'SerializedScriptValue' or 197 if (argument.idl_type.name == 'SerializedScriptValue' or
210 argument_conversion_needs_exception_state(method, argument)) ), 198 argument_conversion_needs_exception_state(method, argument)) ),
211 'has_optional_argument_without_default_value': 199 'has_optional_argument_without_default_value':
212 any(True for argument_context in argument_contexts 200 any(True for argument_context in argument_contexts
213 if argument_context['is_optional_without_default_value']), 201 if argument_context['is_optional_without_default_value']),
214 'idl_type': idl_type.base_type, 202 'idl_type': idl_type.base_type,
215 'is_call_with_execution_context': has_extended_attribute_value(method, ' CallWith', 'ExecutionContext'), 203 'is_call_with_execution_context': has_extended_attribute_value(method, ' CallWith', 'ExecutionContext'),
216 'is_call_with_script_arguments': is_call_with_script_arguments, 204 'is_call_with_script_arguments': is_call_with_script_arguments,
217 'is_call_with_script_state': is_call_with_script_state, 205 'is_call_with_script_state': is_call_with_script_state,
218 'is_call_with_this_value': is_call_with_this_value, 206 'is_call_with_this_value': is_call_with_this_value,
219 'is_ce_reactions': is_ce_reactions, 207 'is_ce_reactions': is_ce_reactions,
220 'is_check_security_for_receiver': is_check_security_for_receiver, 208 'is_check_security_for_receiver': is_check_security_for_receiver,
221 'is_check_security_for_return_value': is_check_security_for_return_value , 209 'is_check_security_for_return_value': is_check_security_for_return_value ,
210 'is_cross_origin': 'CrossOrigin' in extended_attributes,
222 'is_custom': 'Custom' in extended_attributes and 211 'is_custom': 'Custom' in extended_attributes and
223 not (is_custom_call_prologue or is_custom_call_epilogue), 212 not (is_custom_call_prologue or is_custom_call_epilogue),
224 'is_custom_call_prologue': is_custom_call_prologue, 213 'is_custom_call_prologue': is_custom_call_prologue,
225 'is_custom_call_epilogue': is_custom_call_epilogue, 214 'is_custom_call_epilogue': is_custom_call_epilogue,
226 'is_custom_element_callbacks': is_custom_element_callbacks, 215 'is_custom_element_callbacks': is_custom_element_callbacks,
227 'is_do_not_check_security': is_do_not_check_security,
228 'is_explicit_nullable': idl_type.is_explicit_nullable, 216 'is_explicit_nullable': idl_type.is_explicit_nullable,
229 'is_implemented_in_private_script': is_implemented_in_private_script, 217 'is_implemented_in_private_script': is_implemented_in_private_script,
230 'is_new_object': 'NewObject' in extended_attributes, 218 'is_new_object': 'NewObject' in extended_attributes,
231 'is_partial_interface_member': 219 'is_partial_interface_member':
232 'PartialInterfaceImplementedAs' in extended_attributes, 220 'PartialInterfaceImplementedAs' in extended_attributes,
233 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, 221 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes,
234 'is_post_message': is_post_message, 222 'is_post_message': is_post_message,
235 'is_raises_exception': is_raises_exception, 223 'is_raises_exception': is_raises_exception,
236 'is_static': is_static, 224 'is_static': is_static,
237 'is_unforgeable': is_unforgeable(interface, method), 225 'is_unforgeable': is_unforgeable(interface, method),
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 return method.idl_type and method.idl_type.name == 'Promise' 508 return method.idl_type and method.idl_type.name == 'Promise'
521 509
522 IdlOperation.returns_promise = property(method_returns_promise) 510 IdlOperation.returns_promise = property(method_returns_promise)
523 511
524 512
525 def argument_conversion_needs_exception_state(method, argument): 513 def argument_conversion_needs_exception_state(method, argument):
526 idl_type = argument.idl_type 514 idl_type = argument.idl_type
527 return (idl_type.v8_conversion_needs_exception_state or 515 return (idl_type.v8_conversion_needs_exception_state or
528 argument.is_variadic or 516 argument.is_variadic or
529 (method.returns_promise and idl_type.is_string_type)) 517 (method.returns_promise and idl_type.is_string_type))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698