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

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: etc2 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): Custom registration shouldn't be necessary with cross-origin
65 # interceptors, but v8 doesn't support querying the incumbent context. For
66 # now, always use custom registration for these methods.
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 17 matching lines...) Expand all
183 179
184 return { 180 return {
185 'activity_logging_world_list': v8_utilities.activity_logging_world_list( method), # [ActivityLogging] 181 'activity_logging_world_list': v8_utilities.activity_logging_world_list( method), # [ActivityLogging]
186 'arguments': argument_contexts, 182 'arguments': argument_contexts,
187 'argument_declarations_for_private_script': 183 'argument_declarations_for_private_script':
188 argument_declarations_for_private_script(interface, method), 184 argument_declarations_for_private_script(interface, method),
189 'cpp_type': (v8_types.cpp_template_type('Nullable', idl_type.cpp_type) 185 'cpp_type': (v8_types.cpp_template_type('Nullable', idl_type.cpp_type)
190 if idl_type.is_explicit_nullable else idl_type.cpp_type), 186 if idl_type.is_explicit_nullable else idl_type.cpp_type),
191 'cpp_value': this_cpp_value, 187 'cpp_value': this_cpp_value,
192 'cpp_type_initializer': idl_type.cpp_type_initializer, 188 'cpp_type_initializer': idl_type.cpp_type_initializer,
193 'custom_registration_extended_attributes':
194 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES.intersection(
195 extended_attributes.iterkeys()),
196 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs] 189 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs]
197 'do_not_test_new_object': 'DoNotTestNewObject' in extended_attributes, 190 'do_not_test_new_object': 'DoNotTestNewObject' in extended_attributes,
198 'exposed_test': v8_utilities.exposed(method, interface), # [Exposed] 191 'exposed_test': v8_utilities.exposed(method, interface), # [Exposed]
199 # TODO(yukishiino): Retire has_custom_registration flag. Should be
200 # replaced with V8DOMConfiguration::PropertyLocationConfiguration.
201 'has_custom_registration':
202 v8_utilities.has_extended_attribute(
203 method, CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES),
204 'has_exception_state': 192 'has_exception_state':
205 is_raises_exception or 193 is_raises_exception or
206 is_check_security_for_receiver or 194 is_check_security_for_receiver or
207 any(argument for argument in arguments 195 any(argument for argument in arguments
208 if (argument.idl_type.name == 'SerializedScriptValue' or 196 if (argument.idl_type.name == 'SerializedScriptValue' or
209 argument_conversion_needs_exception_state(method, argument)) ), 197 argument_conversion_needs_exception_state(method, argument)) ),
210 'has_optional_argument_without_default_value': 198 'has_optional_argument_without_default_value':
211 any(True for argument_context in argument_contexts 199 any(True for argument_context in argument_contexts
212 if argument_context['is_optional_without_default_value']), 200 if argument_context['is_optional_without_default_value']),
213 'idl_type': idl_type.base_type, 201 'idl_type': idl_type.base_type,
214 'is_call_with_execution_context': has_extended_attribute_value(method, ' CallWith', 'ExecutionContext'), 202 'is_call_with_execution_context': has_extended_attribute_value(method, ' CallWith', 'ExecutionContext'),
215 'is_call_with_script_arguments': is_call_with_script_arguments, 203 'is_call_with_script_arguments': is_call_with_script_arguments,
216 'is_call_with_script_state': is_call_with_script_state, 204 'is_call_with_script_state': is_call_with_script_state,
217 'is_call_with_this_value': is_call_with_this_value, 205 'is_call_with_this_value': is_call_with_this_value,
218 'is_ce_reactions': is_ce_reactions, 206 'is_ce_reactions': is_ce_reactions,
219 'is_check_security_for_receiver': is_check_security_for_receiver, 207 'is_check_security_for_receiver': is_check_security_for_receiver,
220 'is_check_security_for_return_value': is_check_security_for_return_value , 208 'is_check_security_for_return_value': is_check_security_for_return_value ,
209 'is_cross_origin': 'CrossOrigin' in extended_attributes,
221 'is_custom': 'Custom' in extended_attributes and 210 'is_custom': 'Custom' in extended_attributes and
222 not (is_custom_call_prologue or is_custom_call_epilogue), 211 not (is_custom_call_prologue or is_custom_call_epilogue),
223 'is_custom_call_prologue': is_custom_call_prologue, 212 'is_custom_call_prologue': is_custom_call_prologue,
224 'is_custom_call_epilogue': is_custom_call_epilogue, 213 'is_custom_call_epilogue': is_custom_call_epilogue,
225 'is_custom_element_callbacks': is_custom_element_callbacks, 214 'is_custom_element_callbacks': is_custom_element_callbacks,
226 'is_do_not_check_security': is_do_not_check_security,
227 'is_explicit_nullable': idl_type.is_explicit_nullable, 215 'is_explicit_nullable': idl_type.is_explicit_nullable,
228 'is_implemented_in_private_script': is_implemented_in_private_script, 216 'is_implemented_in_private_script': is_implemented_in_private_script,
229 'is_new_object': 'NewObject' in extended_attributes, 217 'is_new_object': 'NewObject' in extended_attributes,
230 'is_partial_interface_member': 218 'is_partial_interface_member':
231 'PartialInterfaceImplementedAs' in extended_attributes, 219 'PartialInterfaceImplementedAs' in extended_attributes,
232 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, 220 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes,
233 'is_post_message': is_post_message, 221 'is_post_message': is_post_message,
234 'is_raises_exception': is_raises_exception, 222 'is_raises_exception': is_raises_exception,
235 'is_static': is_static, 223 'is_static': is_static,
236 'is_unforgeable': is_unforgeable(interface, method), 224 'is_unforgeable': is_unforgeable(interface, method),
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 return method.idl_type and method.idl_type.name == 'Promise' 507 return method.idl_type and method.idl_type.name == 'Promise'
520 508
521 IdlOperation.returns_promise = property(method_returns_promise) 509 IdlOperation.returns_promise = property(method_returns_promise)
522 510
523 511
524 def argument_conversion_needs_exception_state(method, argument): 512 def argument_conversion_needs_exception_state(method, argument):
525 idl_type = argument.idl_type 513 idl_type = argument.idl_type
526 return (idl_type.v8_conversion_needs_exception_state or 514 return (idl_type.v8_conversion_needs_exception_state or
527 argument.is_variadic or 515 argument.is_variadic or
528 (method.returns_promise and idl_type.is_string_type)) 516 (method.returns_promise and idl_type.is_string_type))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698