Skip to content

Commit

Permalink
Add CreateEventEnabled for make_event_factory to use in IDL file.
Browse files Browse the repository at this point in the history
This allows an IDL file to specify whether CreateEvent is enabled
without using the blanket RuntimeEnabled definition hack.

This also removes need for strange and error-prone entry override
in EventAliases.in

BUG=332588

Review-Url: https://codereview.chromium.org/2633383005
Cr-Commit-Position: refs/heads/master@{#444662}
  • Loading branch information
ktyliu authored and Commit bot committed Jan 19, 2017
1 parent e65b92f commit 0243cf7
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
14 changes: 14 additions & 0 deletions third_party/WebKit/Source/bindings/IDLExtendedAttributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,20 @@ When`[Custom]` is specified on a callback function, the code generator doesn't
generate bindings for the callback function. The binding layer uses a
`ScriptValue` instead.

### [CreateEventEnabled] _(i, m, a, c)_

Summary: Like `[RuntimeEnabled]`, it controls at runtime whether bindings are exposed, but only affects createEvent support. See crbug.com/392584#c22.

Usage: `[CreateEventEnabled=FeatureName]`. FeatureName must be included in [RuntimeEnabledFeatures.in](https://code.google.com/p/chromium/codesearch#chromium/src/third_party/WebKit/Source/platform/RuntimeEnabledFeatures.in) like RuntimeEnabled.

```webidl
[
CreateEventEnabled=TouchEventFeatureDetection
] interface TouchEvent : UIEvent { ... };
```

The feature is enabled at runtime and the createEvent operation will throw exception on the web if disabled. It's worth noting the event constructor (modern way of creating events) still works, so this is used only for very special case legacy compat issues (probably nothing ever other than TouchEvent).

#### [Custom=PropertyQuery|PropertyEnumerator] _(s)_

Summary: `[Custom=PropertyEnumerator]` allows you to write custom bindings for the case where properties of a given interface are enumerated; a custom named enumerator. There is currently only one use, and in that case it is used with `[Custom=PropertyQuery]`, since the query is also custom.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Constructor
# FIXME: remove [ConstructorCallWith=Document], as can instead use
# [ConstructorCallWith=ExecutionContext] + toDocument(executionContext)
ConstructorCallWith=ExecutionContext|ScriptState|Document
CreateEventEnabled=*
CrossOrigin=|Getter|Setter
Custom=|Getter|Setter|LegacyCallAsFunction|VisitDOMWrapper|PropertyGetter|PropertyEnumerator|PropertyQuery|CallPrologue|CallEpilogue
CustomConstructor
Expand Down
20 changes: 5 additions & 15 deletions third_party/WebKit/Source/build/scripts/make_event_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def measure_name(name):

class EventFactoryWriter(in_generator.Writer):
defaults = {
'CreateEventEnabled': None,
'ImplementedAs': None,
'RuntimeEnabled': None,
}
Expand All @@ -125,25 +126,14 @@ def __init__(self, in_file_path):
super(EventFactoryWriter, self).__init__(in_file_path)
self.namespace = self.in_file.parameters['namespace'].strip('"')
self.suffix = self.in_file.parameters['suffix'].strip('"')
self._validate_entries()
# Set CreateEventEnabled if feature is RuntimeEnabled (see crbug.com/332588).
for entry in self.in_file.name_dictionaries:
if 'RuntimeEnabled' in entry and 'CreateEventEnabled' not in entry:
entry['CreateEventEnabled'] = entry['RuntimeEnabled']
self._outputs = {(self.namespace + self.suffix + "Headers.h"): self.generate_headers_header,
(self.namespace + self.suffix + ".cpp"): self.generate_implementation,
}

def _validate_entries(self):
# If there is more than one entry with the same script name, only the first one will ever
# be hit in practice, and so we'll silently ignore any properties requested for the second
# (like RuntimeEnabled - see crbug.com/332588).
entries_by_script_name = dict()
for entry in self.in_file.name_dictionaries:
script_name = name_utilities.script_name(entry)
if script_name in entries_by_script_name:
self._fatal('Multiple entries with script_name=%(script_name)s: %(name1)s %(name2)s' % {
'script_name': script_name,
'name1': entry['name'],
'name2': entries_by_script_name[script_name]['name']})
entries_by_script_name[script_name] = entry

def _fatal(self, message):
print 'FATAL ERROR: ' + message
exit(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ namespace blink {
{{namespace}}* {{namespace}}{{suffix}}Factory::create(ExecutionContext* executionContext, const String& type) {
{% for event in events if event|script_name|create_event_whitelist or event|script_name|create_event_legacy_whitelist %}
{% if event|script_name|create_event_whitelist %}
if (equalIgnoringCase(type, "{{event|script_name}}"){% if event.RuntimeEnabled %} && RuntimeEnabledFeatures::{{event.RuntimeEnabled|lower_first}}(){% endif %}) {
if (equalIgnoringCase(type, "{{event|script_name}}"){% if event.CreateEventEnabled %} && RuntimeEnabledFeatures::{{event.CreateEventEnabled|lower_first}}(){% endif %}) {
{% else %}
if (type == "{{event|script_name}}"{% if event.RuntimeEnabled %} && RuntimeEnabledFeatures::{{event.RuntimeEnabled|lower_first}}(){% endif %}) {
if (type == "{{event|script_name}}"{% if event.CreateEventEnabled %} && RuntimeEnabledFeatures::{{event.CreateEventEnabled|lower_first}}(){% endif %}) {
{% endif %}
{% if not event|script_name|create_event_whitelist %}
UseCounter::count(executionContext, UseCounter::{{event|script_name|measure_name}});
Expand Down
2 changes: 0 additions & 2 deletions third_party/WebKit/Source/core/events/EventAliases.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ MutationEvents ImplementedAs=MutationEvent
SVGEvents ImplementedAs=Event
UIEvents ImplementedAs=UIEvent
WebKitTransitionEvent ImplementedAs=TransitionEvent

core/events/TouchEvent RuntimeEnabled=touchEventFeatureDetectionEnabled
1 change: 1 addition & 0 deletions third_party/WebKit/Source/core/events/TouchEvent.idl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

[
Constructor(DOMString type, optional TouchEventInit eventInitDict),
CreateEventEnabled=TouchEventFeatureDetection,
] interface TouchEvent : UIEvent {
readonly attribute TouchList touches;
readonly attribute TouchList targetTouches;
Expand Down

0 comments on commit 0243cf7

Please sign in to comment.