From 0243cf7bee3551dc90e45aabe65a72211a509bbe Mon Sep 17 00:00:00 2001 From: ktyliu Date: Wed, 18 Jan 2017 22:14:19 -0800 Subject: [PATCH] Add CreateEventEnabled for make_event_factory to use in IDL file. 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} --- .../Source/bindings/IDLExtendedAttributes.md | 14 +++++++++++++ .../Source/bindings/IDLExtendedAttributes.txt | 1 + .../build/scripts/make_event_factory.py | 20 +++++-------------- .../scripts/templates/EventFactory.cpp.tmpl | 4 ++-- .../WebKit/Source/core/events/EventAliases.in | 2 -- .../WebKit/Source/core/events/TouchEvent.idl | 1 + 6 files changed, 23 insertions(+), 19 deletions(-) diff --git a/third_party/WebKit/Source/bindings/IDLExtendedAttributes.md b/third_party/WebKit/Source/bindings/IDLExtendedAttributes.md index 9d5dd81304b186..a1de374dd66db0 100644 --- a/third_party/WebKit/Source/bindings/IDLExtendedAttributes.md +++ b/third_party/WebKit/Source/bindings/IDLExtendedAttributes.md @@ -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. diff --git a/third_party/WebKit/Source/bindings/IDLExtendedAttributes.txt b/third_party/WebKit/Source/bindings/IDLExtendedAttributes.txt index faae80fb01de5b..0e46e6f0da1f4f 100644 --- a/third_party/WebKit/Source/bindings/IDLExtendedAttributes.txt +++ b/third_party/WebKit/Source/bindings/IDLExtendedAttributes.txt @@ -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 diff --git a/third_party/WebKit/Source/build/scripts/make_event_factory.py b/third_party/WebKit/Source/build/scripts/make_event_factory.py index 370452aa8ffafe..5d78cf31955d0e 100755 --- a/third_party/WebKit/Source/build/scripts/make_event_factory.py +++ b/third_party/WebKit/Source/build/scripts/make_event_factory.py @@ -104,6 +104,7 @@ def measure_name(name): class EventFactoryWriter(in_generator.Writer): defaults = { + 'CreateEventEnabled': None, 'ImplementedAs': None, 'RuntimeEnabled': None, } @@ -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) diff --git a/third_party/WebKit/Source/build/scripts/templates/EventFactory.cpp.tmpl b/third_party/WebKit/Source/build/scripts/templates/EventFactory.cpp.tmpl index 64d27433fc2029..27606444b06f3d 100644 --- a/third_party/WebKit/Source/build/scripts/templates/EventFactory.cpp.tmpl +++ b/third_party/WebKit/Source/build/scripts/templates/EventFactory.cpp.tmpl @@ -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}}); diff --git a/third_party/WebKit/Source/core/events/EventAliases.in b/third_party/WebKit/Source/core/events/EventAliases.in index f6e30878ecedb1..37ce52a01eb966 100644 --- a/third_party/WebKit/Source/core/events/EventAliases.in +++ b/third_party/WebKit/Source/core/events/EventAliases.in @@ -8,5 +8,3 @@ MutationEvents ImplementedAs=MutationEvent SVGEvents ImplementedAs=Event UIEvents ImplementedAs=UIEvent WebKitTransitionEvent ImplementedAs=TransitionEvent - -core/events/TouchEvent RuntimeEnabled=touchEventFeatureDetectionEnabled diff --git a/third_party/WebKit/Source/core/events/TouchEvent.idl b/third_party/WebKit/Source/core/events/TouchEvent.idl index 539fc2a69fa929..f7875d8fd0997a 100644 --- a/third_party/WebKit/Source/core/events/TouchEvent.idl +++ b/third_party/WebKit/Source/core/events/TouchEvent.idl @@ -27,6 +27,7 @@ [ Constructor(DOMString type, optional TouchEventInit eventInitDict), + CreateEventEnabled=TouchEventFeatureDetection, ] interface TouchEvent : UIEvent { readonly attribute TouchList touches; readonly attribute TouchList targetTouches;