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

Side by Side Diff: third_party/WebKit/Source/build/scripts/make_event_factory.py

Issue 2210253002: Limit document.createEvent to existing events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/build/scripts/templates/EventFactory.cpp.tmpl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (C) 2013 Google Inc. All rights reserved. 2 # Copyright (C) 2013 Google Inc. All rights reserved.
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 %(base_header_for_suffix)s 43 %(base_header_for_suffix)s
44 %(includes)s 44 %(includes)s
45 45
46 #endif // %(namespace)s%(suffix)sHeaders_h 46 #endif // %(namespace)s%(suffix)sHeaders_h
47 """ 47 """
48 48
49 49
50 # All events on the following whitelist are matched case-insensitively 50 # All events on the following whitelist are matched case-insensitively
51 # in createEvent. 51 # in createEvent.
52 # 52 #
53 # All events not on the list are being measured (except for already
54 # deprecated ones). The plan is to limit createEvent to just a few
55 # selected events necessary for legacy content in accordance with the
56 # specification:
57 #
58 # https://dom.spec.whatwg.org/#dom-document-createevent 53 # https://dom.spec.whatwg.org/#dom-document-createevent
59 def create_event_whitelist(name): 54 def create_event_whitelist(name):
60 return (name == ('HTMLEvents') 55 return (name == 'HTMLEvents'
61 or name == 'Event' 56 or name == 'Event'
62 or name == 'Events' 57 or name == 'Events'
63 or name.startswith('UIEvent') 58 or name.startswith('UIEvent')
64 or name.startswith('CustomEvent') 59 or name.startswith('CustomEvent')
65 or name == 'KeyboardEvent' 60 or name == 'KeyboardEvent'
66 or name == 'MessageEvent' 61 or name == 'MessageEvent'
67 or name.startswith('MouseEvent') 62 or name.startswith('MouseEvent')
68 or name == 'TouchEvent') 63 or name == 'TouchEvent')
69 64
70 65
66 # All events on the following whitelist are matched case-sensitively
67 # in createEvent and are measured using UseCounter.
68 #
69 # TODO(foolip): All events on this list should either be added to the spec and
70 # moved to the above whitelist (causing them to be matched case-insensitively)
71 # or be deprecated/removed. https://crbug.com/569690
72 def create_event_legacy_whitelist(name):
73 return (name == 'AnimationEvent'
74 or name == 'AnimationPlayerEvent'
75 or name == 'ApplicationCacheErrorEvent'
76 or name == 'AudioProcessingEvent'
77 or name == 'BeforeInstallPromptEvent'
78 or name == 'BeforeUnloadEvent'
79 or name == 'BlobEvent'
80 or name == 'ClipboardEvent'
81 or name == 'CloseEvent'
82 or name == 'CompositionEvent'
83 or name == 'DeviceLightEvent'
84 or name == 'DeviceMotionEvent'
85 or name == 'DeviceOrientationEvent'
86 or name == 'DragEvent'
87 or name == 'ErrorEvent'
88 or name == 'ExtendableEvent'
89 or name == 'ExtendableMessageEvent'
90 or name == 'FetchEvent'
91 or name == 'FocusEvent'
92 or name == 'FontFaceSetLoadEvent'
93 or name == 'ForeignFetchEvent'
94 or name == 'GamepadEvent'
95 or name == 'HashChangeEvent'
96 or name == 'IDBVersionChangeEvent'
97 or name == 'InputEvent'
98 or name == 'InstallEvent'
99 or name == 'KeyboardEvents'
100 or name == 'MediaEncryptedEvent'
101 or name == 'MediaKeyMessageEvent'
102 or name == 'MediaQueryListEvent'
103 or name == 'MediaStreamEvent'
104 or name == 'MediaStreamTrackEvent'
105 or name == 'MIDIConnectionEvent'
106 or name == 'MIDIMessageEvent'
107 or name == 'MutationEvent'
108 or name == 'MutationEvents'
109 or name == 'NotificationEvent'
110 or name == 'OfflineAudioCompletionEvent'
111 or name == 'OrientationEvent'
112 or name == 'PageTransitionEvent'
113 or name == 'PaymentRequestUpdateEvent'
114 or name == 'PointerEvent'
115 or name == 'PopStateEvent'
116 or name == 'PresentationConnectionAvailableEvent'
117 or name == 'PresentationConnectionCloseEvent'
118 or name == 'ProgressEvent'
119 or name == 'PromiseRejectionEvent'
120 or name == 'PushEvent'
121 or name == 'RelatedEvent'
122 or name == 'ResourceProgressEvent'
123 or name == 'RTCDataChannelEvent'
124 or name == 'RTCDTMFToneChangeEvent'
125 or name == 'RTCIceCandidateEvent'
126 or name == 'SecurityPolicyViolationEvent'
127 or name == 'SensorErrorEvent'
128 or name == 'SensorReadingEvent'
129 or name == 'ServiceWorkerMessageEvent'
130 or name == 'SpeechRecognitionError'
131 or name == 'SpeechRecognitionEvent'
132 or name == 'SpeechSynthesisEvent'
133 or name == 'StorageEvent'
134 or name == 'SVGEvents'
135 or name == 'SyncEvent'
136 or name == 'TextEvent'
137 or name == 'TrackEvent'
138 or name == 'TransitionEvent'
139 or name == 'WebGLContextEvent'
140 or name == 'WebKitAnimationEvent'
141 or name == 'WebKitTransitionEvent'
142 or name == 'WheelEvent')
143
144
71 def measure_name(name): 145 def measure_name(name):
72 return 'DocumentCreateEvent' + name 146 return 'DocumentCreateEvent' + name
73 147
74 148
75 class EventFactoryWriter(in_generator.Writer): 149 class EventFactoryWriter(in_generator.Writer):
76 defaults = { 150 defaults = {
77 'ImplementedAs': None, 151 'ImplementedAs': None,
78 'RuntimeEnabled': None, 152 'RuntimeEnabled': None,
79 } 153 }
80 default_parameters = { 154 default_parameters = {
81 'export': '', 155 'export': '',
82 'namespace': '', 156 'namespace': '',
83 'suffix': '', 157 'suffix': '',
84 } 158 }
85 filters = { 159 filters = {
86 'cpp_name': name_utilities.cpp_name, 160 'cpp_name': name_utilities.cpp_name,
87 'lower_first': name_utilities.lower_first, 161 'lower_first': name_utilities.lower_first,
88 'script_name': name_utilities.script_name, 162 'script_name': name_utilities.script_name,
89 'create_event_whitelist': create_event_whitelist, 163 'create_event_whitelist': create_event_whitelist,
164 'create_event_legacy_whitelist': create_event_legacy_whitelist,
90 'measure_name': measure_name, 165 'measure_name': measure_name,
91 } 166 }
92 167
93 def __init__(self, in_file_path): 168 def __init__(self, in_file_path):
94 super(EventFactoryWriter, self).__init__(in_file_path) 169 super(EventFactoryWriter, self).__init__(in_file_path)
95 self.namespace = self.in_file.parameters['namespace'].strip('"') 170 self.namespace = self.in_file.parameters['namespace'].strip('"')
96 self.suffix = self.in_file.parameters['suffix'].strip('"') 171 self.suffix = self.in_file.parameters['suffix'].strip('"')
97 self._validate_entries() 172 self._validate_entries()
98 self._outputs = {(self.namespace + self.suffix + "Headers.h"): self.gene rate_headers_header, 173 self._outputs = {(self.namespace + self.suffix + "Headers.h"): self.gene rate_headers_header,
99 (self.namespace + self.suffix + ".cpp"): self.generate_ implementation, 174 (self.namespace + self.suffix + ".cpp"): self.generate_ implementation,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 def generate_implementation(self): 236 def generate_implementation(self):
162 return { 237 return {
163 'namespace': self.namespace, 238 'namespace': self.namespace,
164 'suffix': self.suffix, 239 'suffix': self.suffix,
165 'events': self.in_file.name_dictionaries, 240 'events': self.in_file.name_dictionaries,
166 } 241 }
167 242
168 243
169 if __name__ == "__main__": 244 if __name__ == "__main__":
170 in_generator.Maker(EventFactoryWriter).main(sys.argv) 245 in_generator.Maker(EventFactoryWriter).main(sys.argv)
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/build/scripts/templates/EventFactory.cpp.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698