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

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

Issue 2880713002: Support combination of [OriginTrialEnabled] and [SecureContext] (Closed)
Patch Set: Remove workarounds Created 3 years, 7 months 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 return sorted([member for member in members if member.get(KEY) and not m ember.get('exposed_test')]) 114 return sorted([member for member in members if member.get(KEY) and not m ember.get('exposed_test')])
115 115
116 def member_filter_by_name(members, name): 116 def member_filter_by_name(members, name):
117 return [member for member in members if member[KEY] == name] 117 return [member for member in members if member[KEY] == name]
118 118
119 # Collect all members visible on this interface with a defined origin trial 119 # Collect all members visible on this interface with a defined origin trial
120 origin_trial_constants = member_filter(constants) 120 origin_trial_constants = member_filter(constants)
121 origin_trial_attributes = member_filter(attributes) 121 origin_trial_attributes = member_filter(attributes)
122 origin_trial_methods = member_filter([method for method in methods 122 origin_trial_methods = member_filter([method for method in methods
123 if v8_methods.method_is_visible(method , interface.is_partial) and 123 if v8_methods.method_is_visible(method , interface.is_partial) and
124 not v8_methods.conditionally_exposed(m ethod) and
125 not v8_methods.custom_registration(met hod)]) 124 not v8_methods.custom_registration(met hod)])
126 125
127 feature_names = set([member[KEY] for member in origin_trial_constants + orig in_trial_attributes + origin_trial_methods]) 126 feature_names = set([member[KEY] for member in origin_trial_constants + orig in_trial_attributes + origin_trial_methods])
128 127
129 # Construct the list of dictionaries. 'needs_instance' will be true if any 128 # Construct the list of dictionaries. 'needs_instance' will be true if any
130 # member for the feature has 'on_instance' defined as true. 129 # member for the feature has 'on_instance' defined as true.
131 features = [{'name': name, 130 features = [{'name': name,
132 'constants': member_filter_by_name(origin_trial_constants, name ), 131 'constants': member_filter_by_name(origin_trial_constants, name ),
133 'attributes': member_filter_by_name(origin_trial_attributes, na me), 132 'attributes': member_filter_by_name(origin_trial_attributes, na me),
134 'methods': member_filter_by_name(origin_trial_methods, name)} 133 'methods': member_filter_by_name(origin_trial_methods, name)}
135 for name in feature_names] 134 for name in feature_names]
136 for feature in features: 135 for feature in features:
137 members = feature['constants'] + feature['attributes'] + feature['method s'] 136 members = feature['constants'] + feature['attributes'] + feature['method s']
138 feature['needs_instance'] = reduce(or_, (member.get('on_instance', False ) for member in members)) 137 feature['needs_instance'] = any(member.get('on_instance', False) for mem ber in members)
138 # TODO(chasej): Need to handle method overloads? e.g.
139 # (method['overloads']['secure_context_test_all'] if 'overloads' in meth od else method['secure_context_test'])
140 feature['needs_secure_context'] = any(member.get('secure_context_test', False) for member in members)
139 141
140 if features: 142 if features:
141 includes.add('platform/bindings/ScriptState.h') 143 includes.add('platform/bindings/ScriptState.h')
142 includes.add('core/origin_trials/OriginTrials.h') 144 includes.add('core/origin_trials/OriginTrials.h')
143 return sorted(features) 145 return sorted(features)
144 146
145 147
148 def conditionally_enabled_attributes(attributes):
149 """ Returns a list of attributes that are conditionally enabled on this
150 interface.
151
152 Attributes with both secure context and origin trial are excluded, as they
153 are handled separately under origin trial features.
154 """
155
156 return [attribute for attribute in attributes if
157 attribute['exposed_test'] or
158 (attribute['secure_context_test'] and
159 not attribute['origin_trial_feature_name'])]
haraken 2017/05/12 11:05:53 Can we create a helper function like v8_attributes
chasej 2017/05/16 02:21:39 Done.
160
161
162 def conditionally_enabled_methods(interface, methods):
163 """ Returns a list of methods that are conditionally enabled on this
164 interface.
165
166 Methods with origin trial are excluded, as they are handled separately under
167 origin trial features.
168 """
169
170 return [method for method in
171 v8_methods.filter_conditionally_exposed(methods, interface.is_partia l) if
172 not method['origin_trial_feature_name']]
173
Yuki 2017/05/12 09:10:05 nit: two empty lines
chasej 2017/05/16 02:21:39 Done. Actually removed this function as well. The
146 def interface_context(interface, interfaces): 174 def interface_context(interface, interfaces):
147 """Creates a Jinja template context for an interface. 175 """Creates a Jinja template context for an interface.
148 176
149 Args: 177 Args:
150 interface: An interface to create the context for 178 interface: An interface to create the context for
151 interfaces: A dict which maps an interface name to the definition 179 interfaces: A dict which maps an interface name to the definition
152 which can be referred if needed 180 which can be referred if needed
153 181
154 Returns: 182 Returns:
155 A Jinja template context for |interface| 183 A Jinja template context for |interface|
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 }) 372 })
345 373
346 # Constants 374 # Constants
347 context.update({ 375 context.update({
348 'constants': [constant_context(constant, interface) for constant in inte rface.constants], 376 'constants': [constant_context(constant, interface) for constant in inte rface.constants],
349 'do_not_check_constants': 'DoNotCheckConstants' in extended_attributes, 377 'do_not_check_constants': 'DoNotCheckConstants' in extended_attributes,
350 }) 378 })
351 379
352 # Attributes 380 # Attributes
353 attributes = attributes_context(interface, interfaces) 381 attributes = attributes_context(interface, interfaces)
382
354 context.update({ 383 context.update({
355 'attributes': attributes, 384 'attributes': attributes,
356 # Elements in attributes are broken in following members. 385 # Elements in attributes are broken in following members.
357 'accessors': v8_attributes.filter_accessors(attributes), 386 'accessors': v8_attributes.filter_accessors(attributes),
358 'data_attributes': v8_attributes.filter_data_attributes(attributes), 387 'data_attributes': v8_attributes.filter_data_attributes(attributes),
359 'lazy_data_attributes': v8_attributes.filter_lazy_data_attributes(attrib utes), 388 'lazy_data_attributes': v8_attributes.filter_lazy_data_attributes(attrib utes),
360 'origin_trial_attributes': v8_attributes.filter_origin_trial_enabled(att ributes), 389 'origin_trial_attributes': v8_attributes.filter_origin_trial_enabled(att ributes),
361 'runtime_enabled_attributes': v8_attributes.filter_runtime_enabled(attri butes), 390 'runtime_enabled_attributes': v8_attributes.filter_runtime_enabled(attri butes),
362 }) 391 })
363 392
393 # Conditionally enabled attributes
394 conditional_enabled_attributes = conditionally_enabled_attributes(attributes )
395 has_conditional_attributes_on_prototype = any( # pylint: disable=invalid-na me
396 attribute['on_prototype'] for attribute in conditional_enabled_attribute s)
397 context.update({
398 'has_conditional_attributes_on_prototype':
399 has_conditional_attributes_on_prototype,
400 'conditionally_enabled_attributes': conditional_enabled_attributes,
401 })
402
364 # Methods 403 # Methods
365 methods, iterator_method = methods_context(interface) 404 methods, iterator_method = methods_context(interface)
366 context.update({ 405 context.update({
367 'has_origin_safe_method_setter': any(method['is_cross_origin'] and not m ethod['is_unforgeable'] 406 'has_origin_safe_method_setter': any(method['is_cross_origin'] and not m ethod['is_unforgeable']
368 for method in methods), 407 for method in methods),
369 'iterator_method': iterator_method, 408 'iterator_method': iterator_method,
370 'methods': methods, 409 'methods': methods,
371 }) 410 })
372 411
412 # Conditionally enabled methods
413 conditional_enabled_methods = conditionally_enabled_methods(interface, metho ds)
414 has_conditional_methods = any( # pylint: disable=invalid-name
415 method for method in conditional_enabled_methods)
haraken 2017/05/12 11:05:54 Is this equivalent to len(conditional_enabled_meth
Yuki 2017/05/12 14:04:25 Python evaluates [] (empty list) to False, so
iclelland 2017/05/12 15:11:49 The template tags work the same way, so {% if cond
chasej 2017/05/16 02:21:39 I've removed the has_conditional_methods variable
416 context.update({
417 'has_conditional_methods':
418 has_conditional_methods,
419 'conditionally_enabled_methods': conditional_enabled_methods,
420 })
421
373 # Window.idl in Blink has indexed properties, but the spec says Window 422 # Window.idl in Blink has indexed properties, but the spec says Window
374 # interface doesn't have indexed properties, instead the WindowProxy exotic 423 # interface doesn't have indexed properties, instead the WindowProxy exotic
375 # object has indexed properties. Thus, Window interface must not support 424 # object has indexed properties. Thus, Window interface must not support
376 # iterators. 425 # iterators.
377 has_array_iterator = (not interface.is_partial and 426 has_array_iterator = (not interface.is_partial and
378 interface.has_indexed_elements and 427 interface.has_indexed_elements and
379 interface.name != 'Window') 428 interface.name != 'Window')
380 context.update({ 429 context.update({
381 'has_array_iterator': has_array_iterator, 430 'has_array_iterator': has_array_iterator,
382 'iterable': interface.iterable, 431 'iterable': interface.iterable,
383 }) 432 })
384 433
385 # Conditionally enabled members 434 # Conditionally enabled members
386 has_conditional_attributes_on_prototype = any( # pylint: disable=invalid-na me
387 (attribute['exposed_test'] or attribute['secure_context_test']) and attr ibute['on_prototype']
388 for attribute in attributes)
389 context.update({
390 'has_conditional_attributes_on_prototype':
391 has_conditional_attributes_on_prototype,
392 })
393
394 prepare_prototype_and_interface_object_func = None # pylint: disable=invali d-name 435 prepare_prototype_and_interface_object_func = None # pylint: disable=invali d-name
395 if (unscopables or has_conditional_attributes_on_prototype or 436 if (unscopables or has_conditional_attributes_on_prototype or
396 v8_methods.filter_conditionally_exposed(methods, interface.is_partia l)): 437 has_conditional_methods):
397 prepare_prototype_and_interface_object_func = '%s::preparePrototypeAndIn terfaceObject' % v8_class_name_or_partial # pylint: disable=invalid-name 438 prepare_prototype_and_interface_object_func = '%s::preparePrototypeAndIn terfaceObject' % v8_class_name_or_partial # pylint: disable=invalid-name
398 439
399 context.update({ 440 context.update({
400 'prepare_prototype_and_interface_object_func': prepare_prototype_and_int erface_object_func, 441 'prepare_prototype_and_interface_object_func': prepare_prototype_and_int erface_object_func,
401 }) 442 })
402 443
403 context.update({ 444 context.update({
404 'legacy_caller': legacy_caller(interface.legacy_caller, interface), 445 'legacy_caller': legacy_caller(interface.legacy_caller, interface),
405 'indexed_property_getter': property_getter(interface.indexed_property_ge tter, ['index']), 446 'indexed_property_getter': property_getter(interface.indexed_property_ge tter, ['index']),
406 'indexed_property_setter': property_setter(interface.indexed_property_se tter, interface), 447 'indexed_property_setter': property_setter(interface.indexed_property_se tter, interface),
(...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 extended_attributes = deleter.extended_attributes 1450 extended_attributes = deleter.extended_attributes
1410 is_call_with_script_state = v8_utilities.has_extended_attribute_value(delete r, 'CallWith', 'ScriptState') 1451 is_call_with_script_state = v8_utilities.has_extended_attribute_value(delete r, 'CallWith', 'ScriptState')
1411 is_ce_reactions = 'CEReactions' in extended_attributes 1452 is_ce_reactions = 'CEReactions' in extended_attributes
1412 return { 1453 return {
1413 'is_call_with_script_state': is_call_with_script_state, 1454 'is_call_with_script_state': is_call_with_script_state,
1414 'is_ce_reactions': is_ce_reactions, 1455 'is_ce_reactions': is_ce_reactions,
1415 'is_custom': 'Custom' in extended_attributes, 1456 'is_custom': 'Custom' in extended_attributes,
1416 'is_raises_exception': 'RaisesException' in extended_attributes, 1457 'is_raises_exception': 'RaisesException' in extended_attributes,
1417 'name': cpp_name(deleter), 1458 'name': cpp_name(deleter),
1418 } 1459 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698