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

Side by Side Diff: tools/dom/scripts/systemnative.py

Issue 1720743005: Generation of sdk/lib files from 45 roll (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Merged with TOT Created 4 years, 10 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 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
3 # for details. All rights reserved. Use of this source code is governed by a 3 # for details. All rights reserved. Use of this source code is governed by a
4 # BSD-style license that can be found in the LICENSE file. 4 # BSD-style license that can be found in the LICENSE file.
5 5
6 """This module provides shared functionality for the systems to generate 6 """This module provides shared functionality for the systems to generate
7 native binding from the IDL database.""" 7 native binding from the IDL database."""
8 8
9 import emitter 9 import emitter
10 import os 10 import os
11 from generator import * 11 from generator import *
12 from htmldartgenerator import * 12 from htmldartgenerator import *
13 from idlnode import IDLArgument, IDLAttribute, IDLEnum, IDLMember 13 from idlnode import IDLArgument, IDLAttribute, IDLEnum, IDLMember
14 from systemhtml import js_support_checks, GetCallbackInfo, HTML_LIBRARY_NAMES 14 from systemhtml import js_support_checks, GetCallbackInfo, HTML_LIBRARY_NAMES
15 15
16 # TODO(vsm): This logic needs to pulled from the source IDL. These tables are
17 # an ugly workaround.
18 _cpp_callback_map = {
19 ('DataTransferItem', 'webkitGetAsEntry'): 'DataTransferItemFileSystem',
20 ('Document', 'fonts'): 'DocumentFontFaceSet',
21 ('Document', 'webkitIsFullScreen'): 'DocumentFullscreen',
22 ('Document', 'webkitFullScreenKeyboardInputAllowed'): 'DocumentFullscreen',
23 ('Document', 'webkitCurrentFullScreenElement'): 'DocumentFullscreen',
24 ('Document', 'webkitCancelFullScreen'): 'DocumentFullscreen',
25 ('Document', 'webkitFullscreenEnabled'): 'DocumentFullscreen',
26 ('Document', 'webkitFullscreenElement'): 'DocumentFullscreen',
27 ('Document', 'webkitExitFullscreen'): 'DocumentFullscreen',
28 ('DOMWindow', 'crypto'): 'DOMWindowCrypto',
29 ('DOMWindow', 'indexedDB'): 'DOMWindowIndexedDatabase',
30 ('DOMWindow', 'speechSynthesis'): 'DOMWindowSpeechSynthesis',
31 ('DOMWindow', 'webkitNotifications'): 'DOMWindowNotifications',
32 ('DOMWindow', 'storage'): 'DOMWindowQuota',
33 ('DOMWindow', 'webkitStorageInfo'): 'DOMWindowQuota',
34 ('DOMWindow', 'openDatabase'): 'DOMWindowWebDatabase',
35 ('DOMWindow', 'webkitRequestFileSystem'): 'DOMWindowFileSystem',
36 ('DOMWindow', 'webkitResolveLocalFileSystemURL'): 'DOMWindowFileSystem',
37 ('DOMWindow', 'atob'): 'DOMWindowBase64',
38 ('DOMWindow', 'btoa'): 'DOMWindowBase64',
39 ('DOMWindow', 'clearTimeout'): 'DOMWindowTimers',
40 ('DOMWindow', 'clearInterval'): 'DOMWindowTimers',
41 ('DOMWindow', 'createImageBitmap'): 'ImageBitmapFactories',
42 ('Element', 'animate'): 'ElementAnimation',
43 ('HTMLInputElement', 'webkitEntries'): 'HTMLInputElementFileSystem',
44 ('HTMLVideoElement', 'getVideoPlaybackQuality'): 'HTMLVideoElementMediaSource' ,
45 ('Navigator', 'doNotTrack'): 'NavigatorDoNotTrack',
46 ('Navigator', 'geolocation'): 'NavigatorGeolocation',
47 ('Navigator', 'webkitPersistentStorage'): 'NavigatorStorageQuota',
48 ('Navigator', 'webkitTemporaryStorage'): 'NavigatorStorageQuota',
49 ('Navigator', 'registerProtocolHandler'): 'NavigatorContentUtils',
50 ('Navigator', 'unregisterProtocolHandler'): 'NavigatorContentUtils',
51 ('Navigator', 'webkitGetUserMedia'): 'NavigatorMediaStream',
52 ('Navigator', 'webkitGetGamepads'): 'NavigatorGamepad',
53 ('Navigator', 'requestMIDIAccess'): 'NavigatorWebMIDI',
54 ('Navigator', 'vibrate'): 'NavigatorVibration',
55 ('Navigator', 'appName'): 'NavigatorID',
56 ('Navigator', 'appVersion'): 'NavigatorID',
57 ('Navigator', 'appCodeName'): 'NavigatorID',
58 ('Navigator', 'platform'): 'NavigatorID',
59 ('Navigator', 'product'): 'NavigatorID',
60 ('Navigator', 'userAgent'): 'NavigatorID',
61 ('Navigator', 'onLine'): 'NavigatorOnLine',
62 ('Navigator', 'registerServiceWorker'): 'NavigatorServiceWorker',
63 ('Navigator', 'unregisterServiceWorker'): 'NavigatorServiceWorker',
64 ('Navigator', 'maxTouchPoints'): 'NavigatorEvents',
65 ('WorkerGlobalScope', 'crypto'): 'WorkerGlobalScopeCrypto',
66 ('WorkerGlobalScope', 'indexedDB'): 'WorkerGlobalScopeIndexedDatabase',
67 ('WorkerGlobalScope', 'webkitNotifications'): 'WorkerGlobalScopeNotifications' ,
68 ('WorkerGlobalScope', 'openDatabase'): 'WorkerGlobalScopeWebDatabase',
69 ('WorkerGlobalScope', 'openDatabaseSync'): 'WorkerGlobalScopeWebDatabase',
70 ('WorkerGlobalScope', 'performance'): 'WorkerGlobalScopePerformance',
71 ('WorkerGlobalScope', 'webkitRequestFileSystem'): 'WorkerGlobalScopeFileSystem ',
72 ('WorkerGlobalScope', 'webkitRequestFileSystemSync'): 'WorkerGlobalScopeFileSy stem',
73 ('WorkerGlobalScope', 'webkitResolveLocalFileSystemURL'): 'WorkerGlobalScopeFi leSystem',
74 ('WorkerGlobalScope', 'webkitResolveLocalFileSystemSyncURL'): 'WorkerGlobalSco peFileSystem',
75 ('WorkerGlobalScope', 'atob'): 'DOMWindowBase64',
76 ('WorkerGlobalScope', 'btoa'): 'DOMWindowBase64',
77 ('WorkerGlobalScope', 'clearTimeout'): 'DOMWindowTimers',
78 ('WorkerGlobalScope', 'clearInterval'): 'DOMWindowTimers',
79 ('Document', 'rootElement'): 'SVGDocument',
80 ('Document', 'childElementCount'): 'ParentNode',
81 ('Document', 'firstElementChild'): 'ParentNode',
82 ('Document', 'lastElementChild'): 'ParentNode',
83 ('DocumentFragment', 'childElementCount'): 'ParentNode',
84 ('DocumentFragment', 'firstElementChild'): 'ParentNode',
85 ('DocumentFragment', 'lastElementChild'): 'ParentNode',
86 ('CharacterData', 'nextElementSibling'): 'ChildNode',
87 ('CharacterData', 'previousElementSibling'): 'ChildNode',
88 ('Element', 'childElementCount'): 'ParentNode',
89 ('Element', 'firstElementChild'): 'ParentNode',
90 ('Element', 'lastElementChild'): 'ParentNode',
91 ('Element', 'nextElementSibling'): 'ChildNode',
92 ('Element', 'previousElementSibling'): 'ChildNode',
93 ('SVGAnimationElement', 'requiredExtensions'): 'SVGTests',
94 ('SVGAnimationElement', 'requiredFeatures'): 'SVGTests',
95 ('SVGAnimationElement', 'systemLanguage'): 'SVGTests',
96 ('SVGAnimationElement', 'hasExtension'): 'SVGTests',
97 ('SVGGraphicsElement', 'requiredExtensions'): 'SVGTests',
98 ('SVGGraphicsElement', 'requiredFeatures'): 'SVGTests',
99 ('SVGGraphicsElement', 'systemLanguage'): 'SVGTests',
100 ('SVGGraphicsElement', 'hasExtension'): 'SVGTests',
101 ('SVGPatternElement', 'requiredExtensions'): 'SVGTests',
102 ('SVGPatternElement', 'requiredFeatures'): 'SVGTests',
103 ('SVGPatternElement', 'systemLanguage'): 'SVGTests',
104 ('SVGPatternElement', 'hasExtension'): 'SVGTests',
105 ('SVGUseElement', 'requiredExtensions'): 'SVGTests',
106 ('SVGUseElement', 'requiredFeatures'): 'SVGTests',
107 ('SVGUseElement', 'systemLanguage'): 'SVGTests',
108 ('SVGUseElement', 'hasExtension'): 'SVGTests',
109 ('SVGMaskElement', 'requiredExtensions'): 'SVGTests',
110 ('SVGMaskElement', 'requiredFeatures'): 'SVGTests',
111 ('SVGMaskElement', 'systemLanguage'): 'SVGTests',
112 ('SVGMaskElement', 'hasExtension'): 'SVGTests',
113 ('SVGViewSpec', 'zoomAndPan'): 'SVGZoomAndPan',
114 ('SVGViewSpec', 'setZoomAndPan'): 'SVGZoomAndPan',
115 ('SVGViewElement', 'setZoomAndPan'): 'SVGZoomAndPan',
116 ('SVGSVGElement', 'setZoomAndPan'): 'SVGZoomAndPan',
117 ('Screen', 'orientation'): 'ScreenOrientation',
118 ('Screen', 'lockOrientation'): 'ScreenOrientation',
119 ('Screen', 'unlockOrientation'): 'ScreenOrientation',
120 ('Navigator', 'serviceWorker'): 'NavigatorServiceWorker',
121 ('Navigator', 'storageQuota'): 'NavigatorStorageQuota',
122 ('Navigator', 'isProtocolHandlerRegistered'): 'NavigatorContentUtils',
123 ('SharedWorker', 'workerStart'): 'SharedWorkerPerformance',
124 }
125
126 _cpp_import_map = {
127 'ImageBitmapFactories' : 'modules/imagebitmap/ImageBitmapFactories',
128 'ScreenOrientation' : 'modules/screen_orientation/ScreenOrientation'
129 }
130
131 _cpp_overloaded_callback_map = {
132 ('DOMURL', 'createObjectUrlFromSourceCallback'): 'URLMediaSource',
133 ('DOMURL', 'createObjectUrlFromStreamCallback'): 'URLMediaStream',
134 ('DOMURL', '_createObjectUrlFromWebKitSourceCallback'): 'URLMediaSource',
135 ('DOMURL', '_createObjectURL_2Callback'): 'URLMediaSource',
136 ('DOMURL', '_createObjectURL_3Callback'): 'URLMediaStream',
137 }
138
139 _cpp_partial_map = {}
140
141 _cpp_no_auto_scope_list = set([
142 ('Document', 'body', 'Getter'),
143 ('Document', 'getElementById', 'Callback'),
144 ('Document', 'getElementsByName', 'Callback'),
145 ('Document', 'getElementsByTagName', 'Callback'),
146 ('Element', 'getAttribute', 'Callback'),
147 ('Element', 'getAttributeNS', 'Callback'),
148 ('Element', 'id', 'Getter'),
149 ('Element', 'id', 'Setter'),
150 ('Element', 'setAttribute', 'Callback'),
151 ('Element', 'setAttributeNS', 'Callback'),
152 ('Node', 'firstChild', 'Getter'),
153 ('Node', 'lastChild', 'Getter'),
154 ('Node', 'nextSibling', 'Getter'),
155 ('Node', 'previousSibling', 'Getter'),
156 ('Node', 'childNodes', 'Getter'),
157 ('Node', 'nodeType', 'Getter'),
158 ('NodeList', 'length', 'Getter'),
159 ('NodeList', 'item', 'Callback'),
160 ('WebGLRenderingContext', 'drawingBufferHeight', 'Getter'),
161 ('WebGLRenderingContext', 'drawingBufferWidth', 'Getter'),
162 ('WebGLRenderingContext', 'activeTexture', 'Callback'),
163 ('WebGLRenderingContext', 'attachShader', 'Callback'),
164 ('WebGLRenderingContext', 'bindAttribLocation', 'Callback'),
165 ('WebGLRenderingContext', 'bindBuffer', 'Callback'),
166 ('WebGLRenderingContext', 'bindFramebuffer', 'Callback'),
167 ('WebGLRenderingContext', 'bindRenderbuffer', 'Callback'),
168 ('WebGLRenderingContext', 'bindTexture', 'Callback'),
169 ('WebGLRenderingContext', 'blendColor', 'Callback'),
170 ('WebGLRenderingContext', 'blendEquation', 'Callback'),
171 ('WebGLRenderingContext', 'blendEquationSeparate', 'Callback'),
172 ('WebGLRenderingContext', 'blendFunc', 'Callback'),
173 ('WebGLRenderingContext', 'blendFuncSeparate', 'Callback'),
174 ('WebGLRenderingContext', 'checkFramebufferStatus', 'Callback'),
175 ('WebGLRenderingContext', 'clear', 'Callback'),
176 ('WebGLRenderingContext', 'clearColor', 'Callback'),
177 ('WebGLRenderingContext', 'clearDepth', 'Callback'),
178 ('WebGLRenderingContext', 'clearStencil', 'Callback'),
179 ('WebGLRenderingContext', 'colorMask', 'Callback'),
180 ('WebGLRenderingContext', 'compileShader', 'Callback'),
181 ('WebGLRenderingContext', 'compressedTexImage2D', 'Callback'),
182 ('WebGLRenderingContext', 'compressedTexSubImage2D', 'Callback'),
183 ('WebGLRenderingContext', 'copyTexImage2D', 'Callback'),
184 ('WebGLRenderingContext', 'copyTexSubImage2D', 'Callback'),
185 ('WebGLRenderingContext', 'cullFace', 'Callback'),
186 ('WebGLRenderingContext', 'deleteBuffer', 'Callback'),
187 ('WebGLRenderingContext', 'deleteFramebuffer', 'Callback'),
188 ('WebGLRenderingContext', 'deleteProgram', 'Callback'),
189 ('WebGLRenderingContext', 'deleteRenderbuffer', 'Callback'),
190 ('WebGLRenderingContext', 'deleteShader', 'Callback'),
191 ('WebGLRenderingContext', 'deleteTexture', 'Callback'),
192 ('WebGLRenderingContext', 'depthFunc', 'Callback'),
193 ('WebGLRenderingContext', 'depthMask', 'Callback'),
194 ('WebGLRenderingContext', 'depthRange', 'Callback'),
195 ('WebGLRenderingContext', 'detachShader', 'Callback'),
196 ('WebGLRenderingContext', 'disable', 'Callback'),
197 ('WebGLRenderingContext', 'disableVertexAttribArray', 'Callback'),
198 ('WebGLRenderingContext', 'drawArrays', 'Callback'),
199 ('WebGLRenderingContext', 'drawElements', 'Callback'),
200 ('WebGLRenderingContext', 'enable', 'Callback'),
201 ('WebGLRenderingContext', 'enableVertexAttribArray', 'Callback'),
202 ('WebGLRenderingContext', 'finish', 'Callback'),
203 ('WebGLRenderingContext', 'flush', 'Callback'),
204 ('WebGLRenderingContext', 'framebufferRenderbuffer', 'Callback'),
205 ('WebGLRenderingContext', 'framebufferTexture2D', 'Callback'),
206 ('WebGLRenderingContext', 'frontFace', 'Callback'),
207 ('WebGLRenderingContext', 'generateMipmap', 'Callback'),
208 ('WebGLRenderingContext', 'getActiveAttrib', 'Callback'),
209 ('WebGLRenderingContext', 'getActiveUniform', 'Callback'),
210 ('WebGLRenderingContext', 'getAttachedShaders', 'Callback'),
211 ('WebGLRenderingContext', 'getAttribLocation', 'Callback'),
212 ('WebGLRenderingContext', 'hint', 'Callback'),
213 ('WebGLRenderingContext', 'isBuffer', 'Callback'),
214 ('WebGLRenderingContext', 'isContextLost', 'Callback'),
215 ('WebGLRenderingContext', 'isEnabled', 'Callback'),
216 ('WebGLRenderingContext', 'isFramebuffer', 'Callback'),
217 ('WebGLRenderingContext', 'isProgram', 'Callback'),
218 ('WebGLRenderingContext', 'isRenderbuffer', 'Callback'),
219 ('WebGLRenderingContext', 'isShader', 'Callback'),
220 ('WebGLRenderingContext', 'isTexture', 'Callback'),
221 ('WebGLRenderingContext', 'lineWidth', 'Callback'),
222 ('WebGLRenderingContext', 'linkProgram', 'Callback'),
223 ('WebGLRenderingContext', 'pixelStorei', 'Callback'),
224 ('WebGLRenderingContext', 'polygonOffset', 'Callback'),
225 ('WebGLRenderingContext', 'scissor', 'Callback'),
226 ('WebGLRenderingContext', 'stencilFunc', 'Callback'),
227 ('WebGLRenderingContext', 'stencilFuncSeparate', 'Callback'),
228 ('WebGLRenderingContext', 'stencilMask', 'Callback'),
229 ('WebGLRenderingContext', 'stencilMaskSeparate', 'Callback'),
230 ('WebGLRenderingContext', 'stencilOp', 'Callback'),
231 ('WebGLRenderingContext', 'stencilOpSeparate', 'Callback'),
232 ('WebGLRenderingContext', 'uniform1f', 'Callback'),
233 ('WebGLRenderingContext', 'uniform1fv', 'Callback'),
234 ('WebGLRenderingContext', 'uniform1i', 'Callback'),
235 ('WebGLRenderingContext', 'uniform1iv', 'Callback'),
236 ('WebGLRenderingContext', 'uniform2f', 'Callback'),
237 ('WebGLRenderingContext', 'uniform2fv', 'Callback'),
238 ('WebGLRenderingContext', 'uniform2i', 'Callback'),
239 ('WebGLRenderingContext', 'uniform2iv', 'Callback'),
240 ('WebGLRenderingContext', 'uniform3f', 'Callback'),
241 ('WebGLRenderingContext', 'uniform3fv', 'Callback'),
242 ('WebGLRenderingContext', 'uniform3i', 'Callback'),
243 ('WebGLRenderingContext', 'uniform3iv', 'Callback'),
244 ('WebGLRenderingContext', 'uniform4f', 'Callback'),
245 ('WebGLRenderingContext', 'uniform4fv', 'Callback'),
246 ('WebGLRenderingContext', 'uniform4i', 'Callback'),
247 ('WebGLRenderingContext', 'uniform4iv', 'Callback'),
248 ('WebGLRenderingContext', 'uniformMatrix2fv', 'Callback'),
249 ('WebGLRenderingContext', 'uniformMatrix3fv', 'Callback'),
250 ('WebGLRenderingContext', 'uniformMatrix4fv', 'Callback'),
251 ('WebGLRenderingContext', 'useProgram', 'Callback'),
252 ('WebGLRenderingContext', 'validateProgram', 'Callback'),
253 ('WebGLRenderingContext', 'vertexAttrib1f', 'Callback'),
254 ('WebGLRenderingContext', 'vertexAttrib1fv', 'Callback'),
255 ('WebGLRenderingContext', 'vertexAttrib2f', 'Callback'),
256 ('WebGLRenderingContext', 'vertexAttrib2fv', 'Callback'),
257 ('WebGLRenderingContext', 'vertexAttrib3f', 'Callback'),
258 ('WebGLRenderingContext', 'vertexAttrib3fv', 'Callback'),
259 ('WebGLRenderingContext', 'vertexAttrib4f', 'Callback'),
260 ('WebGLRenderingContext', 'vertexAttrib4fv', 'Callback'),
261 ('WebGLRenderingContext', 'vertexAttribPointer', 'Callback'),
262 ('WebGLRenderingContext', 'viewport', 'Callback'),
263 ])
264 16
265 # TODO(vsm): This should be recoverable from IDL, but we appear to not 17 # TODO(vsm): This should be recoverable from IDL, but we appear to not
266 # track the necessary info. 18 # track the necessary info.
267 _url_utils = ['hash', 'host', 'hostname', 'origin', 19 _url_utils = ['hash', 'host', 'hostname', 'origin',
268 'password', 'pathname', 'port', 'protocol', 20 'password', 'pathname', 'port', 'protocol',
269 'search', 'username'] 21 'search', 'username']
270 _cpp_static_call_map = {
271 'DOMURL': _url_utils + ['href', 'toString'],
272 'HTMLAnchorElement': _url_utils,
273 'HTMLAreaElement': _url_utils,
274 }
275
276 def _GetCPPPartialNames(interface):
277 interface_name = interface.ext_attrs.get('ImplementedAs', interface.id)
278 if not _cpp_partial_map:
279 for (type, member) in _cpp_callback_map.keys():
280 if type not in _cpp_partial_map:
281 _cpp_partial_map[type] = set([])
282
283 name_with_path = _cpp_callback_map[(type, member)]
284 if name_with_path in _cpp_import_map:
285 name_with_path = _cpp_import_map[name_with_path]
286 _cpp_partial_map[type].add(name_with_path)
287
288 for (type, member) in _cpp_overloaded_callback_map.keys():
289 if type not in _cpp_partial_map:
290 _cpp_partial_map[type] = set([])
291 _cpp_partial_map[type].add(_cpp_overloaded_callback_map[(type, member)])
292
293 if interface_name in _cpp_partial_map:
294 return _cpp_partial_map[interface_name]
295 else:
296 return set([])
297 22
298 def array_type(data_type): 23 def array_type(data_type):
299 matched = re.match(r'([\w\d_\s]+)\[\]', data_type) 24 matched = re.match(r'([\w\d_\s]+)\[\]', data_type)
300 if not matched: 25 if not matched:
301 return None 26 return None
302 return matched.group(1) 27 return matched.group(1)
303 28
304 _sequence_matcher = re.compile('sequence\<(.+)\>') 29 _sequence_matcher = re.compile('sequence\<(.+)\>')
305 30
306 def TypeIdToBlinkName(interface_id, database): 31 def TypeIdToBlinkName(interface_id, database):
307 # Maybe should use the type_registry here? 32 # Maybe should use the type_registry here?
308 if database.HasEnum(interface_id): 33 if database.HasEnum(interface_id):
309 return "DOMString" # All enums are strings. 34 return "DOMString" # All enums are strings.
310 35
311 seq_match = _sequence_matcher.match(interface_id) 36 seq_match = _sequence_matcher.match(interface_id)
312 if seq_match is not None: 37 if seq_match is not None:
313 t = TypeIdToBlinkName(seq_match.group(1), database) 38 t = TypeIdToBlinkName(seq_match.group(1), database)
314 return "sequence<%s>" % t 39 return "sequence<%s>" % t
315 40
316 arr_match = array_type(interface_id) 41 arr_match = array_type(interface_id)
317 if arr_match is not None: 42 if arr_match is not None:
318 t = TypeIdToBlinkName(arr_match, database) 43 t = TypeIdToBlinkName(arr_match, database)
319 return "%s[]" % t 44 return "%s[]" % t
320 45
321 return interface_id 46 return interface_id
322 47
323 def _GetCPPTypeName(interface_name, callback_name, cpp_name):
324 # TODO(vsm): We need to track the original IDL file name in order to recover
325 # the proper CPP name.
326
327 cpp_tuple = (interface_name, callback_name)
328 if cpp_tuple in _cpp_callback_map:
329 cpp_type_name = _cpp_callback_map[cpp_tuple]
330 elif (interface_name, cpp_name) in _cpp_overloaded_callback_map:
331 cpp_type_name = _cpp_overloaded_callback_map[(interface_name, cpp_name)]
332 else:
333 cpp_type_name = interface_name
334 return cpp_type_name
335
336 def DeriveQualifiedName(library_name, name): 48 def DeriveQualifiedName(library_name, name):
337 return library_name + "." + name 49 return library_name + "." + name
338 50
339 def DeriveBlinkClassName(name): 51 def DeriveBlinkClassName(name):
340 return "Blink" + name 52 return "Blink" + name
341 53
342 _type_encoding_map = { 54 _type_encoding_map = {
343 'long long': "ll", 55 'long long': "ll",
344 'unsigned long': "ul", 56 'unsigned long': "ul",
345 'unsigned long long': "ull", 57 'unsigned long long': "ull",
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 # generated on merged interface implementation instead. 103 # generated on merged interface implementation instead.
392 return False 104 return False
393 105
394 def CustomJSMembers(self): 106 def CustomJSMembers(self):
395 return {} 107 return {}
396 108
397 def _InputConversion(self, idl_type, member): 109 def _InputConversion(self, idl_type, member):
398 return FindConversion(idl_type, 'set', self._interface.id, member) 110 return FindConversion(idl_type, 'set', self._interface.id, member)
399 111
400 def GenerateCallback(self, info): 112 def GenerateCallback(self, info):
401 if IsPureInterface(self._interface.id) or IsCustomType(self._interface.id): 113 return None
402 return
403
404 interface = self._interface
405 if interface.parents:
406 supertype = '%sClassId' % interface.parents[0].type.id
407 else:
408 supertype = '-1'
409
410 cpp_impl_includes = set(['"' + partial + '.h"'
411 for partial in _GetCPPPartialNames(self._interface) ])
412 cpp_header_handlers_emitter = emitter.Emitter()
413 cpp_impl_handlers_emitter = emitter.Emitter()
414 class_name = 'Dart%s' % self._interface.id
415 for operation in self._interface.operations:
416 function_name = operation.id
417 return_type = self.SecureOutputType(operation.type.id)
418 parameters = []
419 arguments = []
420 if operation.ext_attrs.get('CallWith') == 'ThisValue':
421 parameters.append('ScriptValue scriptValue')
422 conversion_includes = []
423 for argument in operation.arguments:
424 argument_type_info = self._TypeInfo(argument.type.id)
425 parameters.append('%s %s' % (argument_type_info.parameter_type(),
426 argument.id))
427 arguments.append(argument_type_info.to_dart_conversion(argument.id))
428 conversion_includes.extend(argument_type_info.conversion_includes())
429
430 # FIXME(vsm): Handle ThisValue attribute.
431 if (return_type == 'void'):
432 ret = ''
433 else:
434 ret = ' return 0;\n'
435
436 if operation.ext_attrs.get('CallWith') == 'ThisValue':
437 cpp_header_handlers_emitter.Emit(
438 '\n'
439 ' virtual $RETURN_TYPE $FUNCTION($PARAMETERS) {\n'
440 ' DART_UNIMPLEMENTED();\n'
441 '$RET'
442 ' }\n',
443 RETURN_TYPE=return_type,
444 RET=ret,
445 FUNCTION=function_name,
446 PARAMETERS=', '.join(parameters))
447 continue
448
449 cpp_header_handlers_emitter.Emit(
450 '\n'
451 ' virtual $RETURN_TYPE $FUNCTION($PARAMETERS);\n',
452 RETURN_TYPE=return_type,
453 FUNCTION=function_name,
454 PARAMETERS=', '.join(parameters))
455
456 if _IsCustom(operation):
457 continue
458
459 cpp_impl_includes |= set(conversion_includes)
460 arguments_declaration = 'Dart_Handle arguments[] = { %s }' % ', '.join(arg uments)
461 if not len(arguments):
462 arguments_declaration = 'Dart_Handle* arguments = 0'
463 if (return_type == 'void'):
464 ret1 = 'return'
465 ret2 = ''
466 else:
467 ret1 = 'return 0'
468 ret2 = ' return'
469 cpp_impl_handlers_emitter.Emit(
470 '\n'
471 '$RETURN_TYPE $CLASS_NAME::$FUNCTION($PARAMETERS)\n'
472 '{\n'
473 ' if (!m_callback.isIsolateAlive())\n'
474 ' $RET1;\n'
475 ' DartIsolateScope scope(m_callback.isolate());\n'
476 ' DartApiScope apiScope;\n'
477 ' $ARGUMENTS_DECLARATION;\n'
478 ' $RET2 m_callback.handleEvent($ARGUMENT_COUNT, arguments);\n'
479 '}\n',
480 RETURN_TYPE=return_type,
481 RET1=ret1,
482 RET2=ret2,
483 CLASS_NAME=class_name,
484 FUNCTION=function_name,
485 PARAMETERS=', '.join(parameters),
486 ARGUMENTS_DECLARATION=arguments_declaration,
487 ARGUMENT_COUNT=len(arguments))
488
489 cpp_header_emitter = self._cpp_library_emitter.CreateHeaderEmitter(
490 self._interface.id,
491 self._renamer.GetLibraryName(self._interface),
492 True)
493 cpp_header_emitter.Emit(
494 self._template_loader.Load('cpp_callback_header.template'),
495 INTERFACE=self._interface.id,
496 HANDLERS=cpp_header_handlers_emitter.Fragments())
497
498 cpp_impl_emitter = self._cpp_library_emitter.CreateSourceEmitter(self._inter face.id)
499 cpp_impl_emitter.Emit(
500 self._template_loader.Load('cpp_callback_implementation.template'),
501 INCLUDES=self._GenerateCPPIncludes(cpp_impl_includes),
502 INTERFACE=self._interface.id,
503 SUPER_INTERFACE=supertype,
504 HANDLERS=cpp_impl_handlers_emitter.Fragments(),
505 DART_IMPLEMENTATION_CLASS=self._interface_type_info.implementation_name( ),
506 DART_IMPLEMENTATION_LIBRARY_ID='Dart%sLibraryId' % self._renamer.GetLibr aryId(self._interface))
507 114
508 def ImplementationTemplate(self): 115 def ImplementationTemplate(self):
509 template = None 116 template = None
510 interface_name = self._interface.doc_js_name 117 interface_name = self._interface.doc_js_name
511 if interface_name == self._interface.id or not self._database.HasInterface(i nterface_name): 118 if interface_name == self._interface.id or not self._database.HasInterface(i nterface_name):
512 template_file = 'impl_%s.darttemplate' % interface_name 119 template_file = 'impl_%s.darttemplate' % interface_name
513 template = self._template_loader.TryLoad(template_file) 120 template = self._template_loader.TryLoad(template_file)
514 if not template: 121 if not template:
515 template = self._template_loader.Load('dart_implementation.darttemplate') 122 template = self._template_loader.Load('dart_implementation.darttemplate')
516 return template 123 return template
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 self._cpp_library_emitter.CreateSourceEmitter(self._interface.id) 188 self._cpp_library_emitter.CreateSourceEmitter(self._interface.id)
582 else: 189 else:
583 self._cpp_header_emitter = emitter.Emitter() 190 self._cpp_header_emitter = emitter.Emitter()
584 self._cpp_impl_emitter = emitter.Emitter() 191 self._cpp_impl_emitter = emitter.Emitter()
585 192
586 self._interface_type_info = self._TypeInfo(self._interface.id) 193 self._interface_type_info = self._TypeInfo(self._interface.id)
587 self._members_emitter = members_emitter 194 self._members_emitter = members_emitter
588 195
589 self._cpp_declarations_emitter = emitter.Emitter() 196 self._cpp_declarations_emitter = emitter.Emitter()
590 197
591 self._cpp_impl_includes = \
592 set(['"' + partial + '.h"'
593 for partial in _GetCPPPartialNames(self._interface)])
594
595 # This is a hack to work around a strange C++ compile error that we weren't 198 # This is a hack to work around a strange C++ compile error that we weren't
596 # able to track down the true cause of. 199 # able to track down the true cause of.
597 if self._interface.id == 'Timing': 200 if self._interface.id == 'Timing':
598 self._cpp_impl_includes.add('"core/animation/TimedItem.h"') 201 self._cpp_impl_includes.add('"core/animation/TimedItem.h"')
599 202
600 self._cpp_definitions_emitter = emitter.Emitter() 203 self._cpp_definitions_emitter = emitter.Emitter()
601 self._cpp_resolver_emitter = emitter.Emitter() 204 self._cpp_resolver_emitter = emitter.Emitter()
602 205
603 # We need to revisit our treatment of typed arrays, right now 206 # We need to revisit our treatment of typed arrays, right now
604 # it is full of hacks. 207 # it is full of hacks.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 constructor_info, name, 'constructorCallback', name, arguments, 300 constructor_info, name, 'constructorCallback', name, arguments,
698 emit_to_native=True, 301 emit_to_native=True,
699 is_custom=False) 302 is_custom=False)
700 303
701 ext_attrs = self._interface.ext_attrs 304 ext_attrs = self._interface.ext_attrs
702 305
703 create_function = 'create' 306 create_function = 'create'
704 if 'NamedConstructor' in ext_attrs: 307 if 'NamedConstructor' in ext_attrs:
705 create_function = 'createForJSConstructor' 308 create_function = 'createForJSConstructor'
706 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function) 309 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function)
707 self._GenerateNativeCallback(
708 constructor_callback_cpp_name,
709 False,
710 function_expression,
711 self._interface,
712 arguments,
713 self._interface.id,
714 False,
715 'ConstructorRaisesException' in ext_attrs or 'RaisesException' in ext_at trs,
716 True)
717 310
718 def HasSupportCheck(self): 311 def HasSupportCheck(self):
719 # Need to omit a support check if it is conditional in JS. 312 # Need to omit a support check if it is conditional in JS.
720 return self._interface.doc_js_name in js_support_checks 313 return self._interface.doc_js_name in js_support_checks
721 314
722 def GetSupportCheck(self): 315 def GetSupportCheck(self):
723 # Assume that everything is supported on Dartium. 316 # Assume that everything is supported on Dartium.
724 value = js_support_checks.get(self._interface.doc_js_name) 317 value = js_support_checks.get(self._interface.doc_js_name)
725 if type(value) == tuple: 318 if type(value) == tuple:
726 return (value[0], 'true') 319 return (value[0], 'true')
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 TO_EVENT_TARGET=to_event_target_emitter.Fragments(), 492 TO_EVENT_TARGET=to_event_target_emitter.Fragments(),
900 TO_NATIVE=to_native_emitter.Fragments(), 493 TO_NATIVE=to_native_emitter.Fragments(),
901 TO_DART=to_dart_emitter.Fragments()) 494 TO_DART=to_dart_emitter.Fragments())
902 495
903 def EmitAttribute(self, attribute, html_name, read_only): 496 def EmitAttribute(self, attribute, html_name, read_only):
904 self._AddGetter(attribute, html_name, read_only) 497 self._AddGetter(attribute, html_name, read_only)
905 if not read_only: 498 if not read_only:
906 self._AddSetter(attribute, html_name) 499 self._AddSetter(attribute, html_name)
907 500
908 def _GenerateAutoSetupScope(self, idl_name, native_suffix): 501 def _GenerateAutoSetupScope(self, idl_name, native_suffix):
909 return (self._interface.id, idl_name, native_suffix) not in _cpp_no_auto_sco pe_list 502 return None
910 503
911 def _AddGetter(self, attr, html_name, read_only): 504 def _AddGetter(self, attr, html_name, read_only):
912 # Temporary hack to force dart:scalarlist clamped array for ImageData.data. 505 # Temporary hack to force dart:scalarlist clamped array for ImageData.data.
913 # TODO(antonm): solve in principled way. 506 # TODO(antonm): solve in principled way.
914 if self._interface.id == 'ImageData' and html_name == 'data': 507 if self._interface.id == 'ImageData' and html_name == 'data':
915 html_name = '_data' 508 html_name = '_data'
916 type_info = self._TypeInfo(attr.type.id) 509 type_info = self._TypeInfo(attr.type.id)
510
917 return_type = self.SecureOutputType(attr.type.id, False, False if self._dart _use_blink else True) 511 return_type = self.SecureOutputType(attr.type.id, False, False if self._dart _use_blink else True)
512 dictionary_returned = False
513 # Return type for dictionary is any (untyped).
514 if attr.type.id == 'Dictionary':
515 return_type = '';
516 dictionary_returned = True;
517
918 parameters = [] 518 parameters = []
919 dart_declaration = '%s get %s' % (return_type, html_name) 519 dart_declaration = '%s get %s' % (return_type, html_name)
920 is_custom = _IsCustom(attr) and (_IsCustomValue(attr, None) or 520 is_custom = _IsCustom(attr) and (_IsCustomValue(attr, None) or
921 _IsCustomValue(attr, 'Getter')) 521 _IsCustomValue(attr, 'Getter'))
922 522
923 # Operation uses blink? 523 # Operation uses blink?
924 wrap_unwrap_list = []; 524 wrap_unwrap_list = [];
925 return_wrap_jso = False 525 return_wrap_jso = False
926 if self._dart_use_blink: 526 if self._dart_use_blink:
927 # Unwrap the type to get the JsObject if Type is: 527 # Unwrap the type to get the JsObject if Type is:
(...skipping 11 matching lines...) Expand all
939 # This seems to have been replaced with Custom=Getter (see above), but 539 # This seems to have been replaced with Custom=Getter (see above), but
940 # check to be sure we don't see the old syntax 540 # check to be sure we don't see the old syntax
941 assert(not ('CustomGetter' in attr.ext_attrs)) 541 assert(not ('CustomGetter' in attr.ext_attrs))
942 native_suffix = 'Getter' 542 native_suffix = 'Getter'
943 auto_scope_setup = self._GenerateAutoSetupScope(attr.id, native_suffix) 543 auto_scope_setup = self._GenerateAutoSetupScope(attr.id, native_suffix)
944 native_entry = \ 544 native_entry = \
945 self.DeriveNativeEntry(attr.id, 'Getter', None) 545 self.DeriveNativeEntry(attr.id, 'Getter', None)
946 cpp_callback_name = self._GenerateNativeBinding(attr.id, 1, 546 cpp_callback_name = self._GenerateNativeBinding(attr.id, 1,
947 dart_declaration, attr.is_static, return_type, parameters, 547 dart_declaration, attr.is_static, return_type, parameters,
948 native_suffix, is_custom, auto_scope_setup, native_entry=native_entry, 548 native_suffix, is_custom, auto_scope_setup, native_entry=native_entry,
949 wrap_unwrap_list=wrap_unwrap_list) 549 wrap_unwrap_list=wrap_unwrap_list, dictionary_return=dictionary_returned )
950 if is_custom: 550 if is_custom:
951 return 551 return
952 552
953 if 'Reflect' in attr.ext_attrs: 553 if 'Reflect' in attr.ext_attrs:
954 webcore_function_name = self._TypeInfo(attr.type.id).webcore_getter_name() 554 webcore_function_name = self._TypeInfo(attr.type.id).webcore_getter_name()
955 if 'URL' in attr.ext_attrs: 555 if 'URL' in attr.ext_attrs:
956 if 'NonEmpty' in attr.ext_attrs: 556 if 'NonEmpty' in attr.ext_attrs:
957 webcore_function_name = 'getNonEmptyURLAttribute' 557 webcore_function_name = 'getNonEmptyURLAttribute'
958 else: 558 else:
959 webcore_function_name = 'getURLAttribute' 559 webcore_function_name = 'getURLAttribute'
960 elif 'ImplementedAs' in attr.ext_attrs: 560 elif 'ImplementedAs' in attr.ext_attrs:
961 webcore_function_name = attr.ext_attrs['ImplementedAs'] 561 webcore_function_name = attr.ext_attrs['ImplementedAs']
962 else: 562 else:
963 if attr.id == 'operator': 563 if attr.id == 'operator':
964 webcore_function_name = '_operator' 564 webcore_function_name = '_operator'
965 elif attr.id == 'target' and attr.type.id == 'SVGAnimatedString': 565 elif attr.id == 'target' and attr.type.id == 'SVGAnimatedString':
966 webcore_function_name = 'svgTarget' 566 webcore_function_name = 'svgTarget'
967 elif attr.id == 'CSS': 567 elif attr.id == 'CSS':
968 webcore_function_name = 'css' 568 webcore_function_name = 'css'
969 else: 569 else:
970 webcore_function_name = self._ToWebKitName(attr.id) 570 webcore_function_name = self._ToWebKitName(attr.id)
971 571
972 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr) 572 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr)
973 raises = ('RaisesException' in attr.ext_attrs and 573 raises = ('RaisesException' in attr.ext_attrs and
974 attr.ext_attrs['RaisesException'] != 'Setter') 574 attr.ext_attrs['RaisesException'] != 'Setter')
975 self._GenerateNativeCallback(
976 cpp_callback_name,
977 True,
978 function_expression,
979 attr,
980 [],
981 attr.type.id,
982 attr.type.nullable,
983 raises,
984 auto_scope_setup)
985 575
986 def _AddSetter(self, attr, html_name): 576 def _AddSetter(self, attr, html_name):
987 return_type = 'void' 577 return_type = 'void'
988 ptype = self._DartType(attr.type.id) 578 ptype = self._DartType(attr.type.id)
989 579
990 type_info = self._TypeInfo(attr.type.id) 580 type_info = self._TypeInfo(attr.type.id)
991 581
992 # Is the setter value a DartClass (that has a JsObject) or the type is 582 # Is the setter value a DartClass (that has a JsObject) or the type is
993 # None (it's a dynamic/any type) then unwrap_jso before passing to blink. 583 # None (it's a dynamic/any type) then unwrap_jso before passing to blink.
994 parameters = ['unwrap_jso(value)' if (isinstance(type_info, InterfaceIDLType Info) or 584 parameters = ['unwrap_jso(value)' if (isinstance(type_info, InterfaceIDLType Info) or
(...skipping 30 matching lines...) Expand all
1025 else: 615 else:
1026 attr_name = attr.id 616 attr_name = attr.id
1027 webcore_function_name = re.sub(r'^(xml|css|(?=[A-Z])|\w)', 617 webcore_function_name = re.sub(r'^(xml|css|(?=[A-Z])|\w)',
1028 lambda s: s.group(1).upper(), 618 lambda s: s.group(1).upper(),
1029 attr_name) 619 attr_name)
1030 webcore_function_name = 'set%s' % webcore_function_name 620 webcore_function_name = 'set%s' % webcore_function_name
1031 621
1032 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr) 622 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr)
1033 raises = ('RaisesException' in attr.ext_attrs and 623 raises = ('RaisesException' in attr.ext_attrs and
1034 attr.ext_attrs['RaisesException'] != 'Getter') 624 attr.ext_attrs['RaisesException'] != 'Getter')
1035 self._GenerateNativeCallback(
1036 cpp_callback_name,
1037 True,
1038 function_expression,
1039 attr,
1040 [attr],
1041 'void',
1042 False,
1043 raises,
1044 auto_scope_setup,
1045 generate_custom_element_scope_if_needed=True)
1046 625
1047 def AddIndexer(self, element_type): 626 def AddIndexer(self, element_type):
1048 """Adds all the methods required to complete implementation of List.""" 627 """Adds all the methods required to complete implementation of List."""
1049 # We would like to simply inherit the implementation of everything except 628 # We would like to simply inherit the implementation of everything except
1050 # length, [], and maybe []=. It is possible to extend from a base 629 # length, [], and maybe []=. It is possible to extend from a base
1051 # array implementation class only when there is no other implementation 630 # array implementation class only when there is no other implementation
1052 # inheritance. There might be no implementation inheritance other than 631 # inheritance. There might be no implementation inheritance other than
1053 # DOMBaseWrapper for many classes, but there might be some where the 632 # DOMBaseWrapper for many classes, but there might be some where the
1054 # array-ness is introduced by a non-root interface: 633 # array-ness is introduced by a non-root interface:
1055 # 634 #
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 756
1178 def _EmitNativeIndexSetter(self, element_type): 757 def _EmitNativeIndexSetter(self, element_type):
1179 return_type = 'void' 758 return_type = 'void'
1180 formals = ', '.join(['int index', '%s value' % element_type]) 759 formals = ', '.join(['int index', '%s value' % element_type])
1181 parameters = ['index', 'value'] 760 parameters = ['index', 'value']
1182 dart_declaration = 'void operator[]=(%s)' % formals 761 dart_declaration = 'void operator[]=(%s)' % formals
1183 self._GenerateNativeBinding('numericIndexSetter', 3, 762 self._GenerateNativeBinding('numericIndexSetter', 3,
1184 dart_declaration, False, return_type, parameters, 763 dart_declaration, False, return_type, parameters,
1185 'Callback', True, False) 764 'Callback', True, False)
1186 765
766 def _ChangePrivateOpMapArgToAny(self, operations):
767 # TODO(terry): Hack to map any operations marked as private to not
768 # handle converting Map to native (JsObject) the public
769 # members that call the private method will have done
770 # conversions.
771 for operation in operations:
772 for arg in operation.arguments:
773 type = arg.type
774 if type.id == 'Dictionary':
775 type.id = 'any'
776
1187 def EmitOperation(self, info, html_name, dart_js_interop=False): 777 def EmitOperation(self, info, html_name, dart_js_interop=False):
1188 """ 778 """
1189 Arguments: 779 Arguments:
1190 info: An OperationInfo object. 780 info: An OperationInfo object.
1191 """ 781 """
782 if self._renamer.isPrivate(self._interface, info.operations[0].id):
783 # Any private operations with Maps parameters changed to any type.
784 # The public method that delegates to this private operation has already
785 # converted from Map to native (JsObject) e.g., Element.animate.
786 self._ChangePrivateOpMapArgToAny(info.operations)
787
1192 return_type = self.SecureOutputType(info.type_name, False, False if dart_js_ interop else True) 788 return_type = self.SecureOutputType(info.type_name, False, False if dart_js_ interop else True)
1193 789
1194 formals = info.ParametersAsDeclaration(self._DartType) 790 formals = info.ParametersAsDeclaration(self._DartType)
1195 791
1196 parameters = info.ParametersAsListOfVariables(None, 792 parameters = info.ParametersAsListOfVariables(None,
1197 self._type_registry if self._d art_use_blink else None, 793 self._type_registry if self._d art_use_blink else None,
1198 dart_js_interop, 794 dart_js_interop,
1199 self) 795 self)
796
797 operation = info.operations[0]
798
799 dictionary_returned = False
800 # Return type for dictionary is any (untyped).
801 if operation.type.id == 'Dictionary':
802 return_type = '';
803 dictionary_returned = True;
804
1200 dart_declaration = '%s%s %s(%s)' % ( 805 dart_declaration = '%s%s %s(%s)' % (
1201 'static ' if info.IsStatic() else '', 806 'static ' if info.IsStatic() else '',
1202 return_type, 807 return_type,
1203 html_name, 808 html_name,
1204 formals) 809 formals)
1205 810
1206 operation = info.operations[0]
1207
1208 is_custom = _IsCustom(operation) 811 is_custom = _IsCustom(operation)
1209 has_optional_arguments = any(IsOptional(argument) for argument in operation. arguments) 812 has_optional_arguments = any(IsOptional(argument) for argument in operation. arguments)
1210 needs_dispatcher = not is_custom and (len(info.operations) > 1 or has_option al_arguments) 813 needs_dispatcher = not is_custom and (len(info.operations) > 1 or has_option al_arguments)
1211 814
1212 # Operation uses blink? 815 # Operation uses blink?
1213 wrap_unwrap_list = []; 816 wrap_unwrap_list = [];
1214 return_wrap_jso = False 817 return_wrap_jso = False
1215 # return type wrapped? 818 # return type wrapped?
1216 if self._dart_use_blink: 819 if self._dart_use_blink:
1217 # Wrap the type to store the JsObject if Type is: 820 # Wrap the type to store the JsObject if Type is:
(...skipping 21 matching lines...) Expand all
1239 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos) 842 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos)
1240 native_suffix = 'Callback' 843 native_suffix = 'Callback'
1241 auto_scope_setup = self._GenerateAutoSetupScope(info.name, native_suffix) 844 auto_scope_setup = self._GenerateAutoSetupScope(info.name, native_suffix)
1242 native_entry = \ 845 native_entry = \
1243 self.DeriveNativeEntry(operation.id, 'Method', len(info.param_infos)) 846 self.DeriveNativeEntry(operation.id, 'Method', len(info.param_infos))
1244 cpp_callback_name = self._GenerateNativeBinding( 847 cpp_callback_name = self._GenerateNativeBinding(
1245 info.name, argument_count, dart_declaration, 848 info.name, argument_count, dart_declaration,
1246 info.IsStatic(), return_type, parameters, 849 info.IsStatic(), return_type, parameters,
1247 native_suffix, is_custom, auto_scope_setup, 850 native_suffix, is_custom, auto_scope_setup,
1248 native_entry=native_entry, 851 native_entry=native_entry,
1249 wrap_unwrap_list=wrap_unwrap_list) 852 wrap_unwrap_list=wrap_unwrap_list,
853 dictionary_return=dictionary_returned)
1250 if not is_custom: 854 if not is_custom:
1251 self._GenerateOperationNativeCallback(operation, operation.arguments, cp p_callback_name, auto_scope_setup) 855 self._GenerateOperationNativeCallback(operation, operation.arguments, cp p_callback_name, auto_scope_setup)
1252 else: 856 else:
1253 self._GenerateDispatcher(info, info.operations, dart_declaration, html_nam e) 857 self._GenerateDispatcher(info, info.operations, dart_declaration, html_nam e)
1254 858
1255 def _GenerateDispatcher(self, info, operations, dart_declaration, html_name): 859 def _GenerateDispatcher(self, info, operations, dart_declaration, html_name):
1256 860
1257 def GenerateCall( 861 def GenerateCall(
1258 stmts_emitter, call_emitter, version, operation, argument_count): 862 stmts_emitter, call_emitter, version, operation, argument_count):
1259 native_suffix = 'Callback' 863 native_suffix = 'Callback'
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 GenerateCall, 914 GenerateCall,
1311 IsOptional) 915 IsOptional)
1312 916
1313 def SecondaryContext(self, interface): 917 def SecondaryContext(self, interface):
1314 pass 918 pass
1315 919
1316 def _GenerateOperationNativeCallback(self, operation, arguments, cpp_callback_ name, auto_scope_setup=True): 920 def _GenerateOperationNativeCallback(self, operation, arguments, cpp_callback_ name, auto_scope_setup=True):
1317 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i d) 921 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i d)
1318 922
1319 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, operation, cpp_callback_name) 923 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, operation, cpp_callback_name)
1320 self._GenerateNativeCallback(
1321 cpp_callback_name,
1322 not operation.is_static,
1323 function_expression,
1324 operation,
1325 arguments,
1326 operation.type.id,
1327 operation.type.nullable,
1328 'RaisesException' in operation.ext_attrs,
1329 auto_scope_setup,
1330 generate_custom_element_scope_if_needed=True)
1331
1332 def _GenerateNativeCallback(self,
1333 callback_name,
1334 needs_receiver,
1335 function_expression,
1336 node,
1337 arguments,
1338 return_type,
1339 return_type_is_nullable,
1340 raises_dom_exception,
1341 auto_scope_setup=True,
1342 generate_custom_element_scope_if_needed=False):
1343
1344 ext_attrs = node.ext_attrs
1345
1346 if self._IsStatic(node.id):
1347 needs_receiver = True
1348
1349 cpp_arguments = []
1350 runtime_check = None
1351 raises_exceptions = raises_dom_exception or arguments or needs_receiver
1352 needs_custom_element_callbacks = False
1353
1354 # TODO(antonm): unify with ScriptState below.
1355 call_with = ext_attrs.get('CallWith', [])
1356 if not(isinstance(call_with, list)):
1357 call_with = [call_with]
1358 constructor_with = ext_attrs.get('ConstructorCallWith', [])
1359 if not(isinstance(constructor_with, list)):
1360 constructor_with = [constructor_with]
1361 call_with = call_with + constructor_with
1362
1363
1364 requires_stack_info = 'ScriptArguments' in call_with or 'ScriptState' in cal l_with
1365 if requires_stack_info:
1366 raises_exceptions = True
1367 cpp_arguments = ['&state', 'scriptArguments.release()']
1368 # WebKit uses scriptArguments to reconstruct last argument, so
1369 # it's not needed and should be just removed.
1370 arguments = arguments[:-1]
1371
1372 # TODO(antonm): unify with ScriptState below.
1373 requires_script_arguments = (ext_attrs.get('CallWith') == 'ScriptArguments' or
1374 ext_attrs.get('ConstructorCallWith') == 'Script Arguments')
1375 if requires_script_arguments:
1376 raises_exceptions = True
1377 cpp_arguments = ['scriptArguments.release()']
1378 # WebKit uses scriptArguments to reconstruct last argument, so
1379 # it's not needed and should be just removed.
1380 arguments = arguments[:-1]
1381
1382 requires_script_execution_context = (ext_attrs.get('CallWith') == 'Execution Context' or
1383 ext_attrs.get('ConstructorCallWith') == 'ExecutionContext')
1384
1385 # Hack because our parser misses that these IDL members require an execution
1386 # context.
1387
1388 if (self._interface.id == 'FontFace'
1389 and callback_name in ['familySetter', 'featureSettingsSetter', 'stretchS etter',
1390 'styleSetter', 'unicodeRangeSetter', 'variantSette r', 'weightSetter']):
1391 requires_script_execution_context = True
1392
1393 requires_document = ext_attrs.get('ConstructorCallWith') == 'Document'
1394
1395 if requires_script_execution_context:
1396 raises_exceptions = True
1397 cpp_arguments = ['context']
1398
1399 requires_script_state = (ext_attrs.get('CallWith') == 'ScriptState' or
1400 ext_attrs.get('ConstructorCallWith') == 'ScriptStat e')
1401 if requires_script_state:
1402 raises_exceptions = True
1403 cpp_arguments = ['&state']
1404
1405 requires_dom_window = 'NamedConstructor' in ext_attrs
1406 if requires_dom_window or requires_document:
1407 raises_exceptions = True
1408 cpp_arguments = ['document']
1409
1410 if 'ImplementedBy' in ext_attrs:
1411 assert needs_receiver
1412 self._cpp_impl_includes.add('"%s.h"' % ext_attrs['ImplementedBy'])
1413 cpp_arguments.append('receiver')
1414
1415 if 'Reflect' in ext_attrs:
1416 cpp_arguments = [self._GenerateWebCoreReflectionAttributeName(node)]
1417
1418 if generate_custom_element_scope_if_needed and (ext_attrs.get('CustomElement Callbacks', 'None') != 'None' or 'Reflect' in ext_attrs):
1419 self._cpp_impl_includes.add('"core/dom/custom/CustomElementCallbackDispatc her.h"')
1420 needs_custom_element_callbacks = True
1421
1422 if return_type_is_nullable:
1423 cpp_arguments = ['isNull']
1424
1425 v8EnabledPerContext = ext_attrs.get('synthesizedV8EnabledPerContext', ext_at trs.get('V8EnabledPerContext'))
1426 v8EnabledAtRuntime = ext_attrs.get('synthesizedV8EnabledAtRuntime', ext_attr s.get('V8EnabledAtRuntime'))
1427 assert(not (v8EnabledPerContext and v8EnabledAtRuntime))
1428
1429 if v8EnabledPerContext:
1430 raises_exceptions = True
1431 self._cpp_impl_includes.add('"ContextFeatures.h"')
1432 self._cpp_impl_includes.add('"DOMWindow.h"')
1433 runtime_check = emitter.Format(
1434 ' if (!ContextFeatures::$(FEATURE)Enabled(DartUtilities::domWin dowForCurrentIsolate()->document())) {\n'
1435 ' exception = Dart_NewStringFromCString("Feature $FEATURE i s not enabled");\n'
1436 ' goto fail;\n'
1437 ' }',
1438 FEATURE=v8EnabledPerContext)
1439
1440 if v8EnabledAtRuntime:
1441 raises_exceptions = True
1442 self._cpp_impl_includes.add('"RuntimeEnabledFeatures.h"')
1443 runtime_check = emitter.Format(
1444 ' if (!RuntimeEnabledFeatures::$(FEATURE)Enabled()) {\n'
1445 ' exception = Dart_NewStringFromCString("Feature $FEATURE i s not enabled");\n'
1446 ' goto fail;\n'
1447 ' }',
1448 FEATURE=self._ToWebKitName(v8EnabledAtRuntime))
1449
1450 body_emitter = self._cpp_definitions_emitter.Emit(
1451 '\n'
1452 'static void $CALLBACK_NAME(Dart_NativeArguments args)\n'
1453 '{\n'
1454 '$!BODY'
1455 '}\n',
1456 CALLBACK_NAME=callback_name)
1457
1458 if raises_exceptions:
1459 body_emitter = body_emitter.Emit(
1460 ' Dart_Handle exception = 0;\n'
1461 '$!BODY'
1462 '\n'
1463 'fail:\n'
1464 ' Dart_ThrowException(exception);\n'
1465 ' ASSERT_NOT_REACHED();\n')
1466
1467 body_emitter = body_emitter.Emit(
1468 ' {\n'
1469 '$!BODY'
1470 ' return;\n'
1471 ' }\n')
1472
1473 if runtime_check:
1474 body_emitter.Emit(
1475 '$RUNTIME_CHECK\n',
1476 RUNTIME_CHECK=runtime_check)
1477
1478 if requires_script_execution_context:
1479 body_emitter.Emit(
1480 ' ExecutionContext* context = DartUtilities::scriptExecutionCon text();\n'
1481 ' if (!context) {\n'
1482 ' exception = Dart_NewStringFromCString("Failed to retrieve a context");\n'
1483 ' goto fail;\n'
1484 ' }\n\n')
1485
1486 if requires_script_state:
1487 body_emitter.Emit(
1488 ' ScriptState* currentState = DartUtilities::currentScriptState ();\n'
1489 ' if (!currentState) {\n'
1490 ' exception = Dart_NewStringFromCString("Failed to retrieve a script state");\n'
1491 ' goto fail;\n'
1492 ' }\n'
1493 ' ScriptState& state = *currentState;\n\n')
1494
1495 if requires_dom_window or requires_document:
1496 self._cpp_impl_includes.add('"DOMWindow.h"')
1497
1498 body_emitter.Emit(
1499 ' DOMWindow* domWindow = DartUtilities::domWindowForCurrentIsol ate();\n'
1500 ' if (!domWindow) {\n'
1501 ' exception = Dart_NewStringFromCString("Failed to fetch do mWindow");\n'
1502 ' goto fail;\n'
1503 ' }\n'
1504 ' Document& document = *domWindow->document();\n')
1505
1506 if needs_receiver:
1507 body_emitter.Emit(
1508 ' $WEBCORE_CLASS_NAME* receiver = '
1509 'DartDOMWrapper::receiverChecked<Dart$INTERFACE>(args, exception);\n'
1510 ' if (exception)\n'
1511 ' goto fail;\n',
1512 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(),
1513 INTERFACE=self._interface.id)
1514
1515 if requires_stack_info:
1516 self._cpp_impl_includes.add('"ScriptArguments.h"')
1517 body_emitter.Emit(
1518 '\n'
1519 ' ScriptState* currentState = DartUtilities::currentScriptState ();\n'
1520 ' if (!currentState) {\n'
1521 ' exception = Dart_NewStringFromCString("Failed to retrieve a script state");\n'
1522 ' goto fail;\n'
1523 ' }\n'
1524 ' ScriptState& state = *currentState;\n'
1525 '\n'
1526 ' Dart_Handle customArgument = Dart_GetNativeArgument(args, $IN DEX);\n'
1527 ' RefPtr<ScriptArguments> scriptArguments(DartUtilities::create ScriptArguments(customArgument, exception));\n'
1528 ' if (!scriptArguments)\n'
1529 ' goto fail;\n',
1530 INDEX=len(arguments) + 1)
1531
1532 if requires_script_arguments:
1533 self._cpp_impl_includes.add('"ScriptArguments.h"')
1534 body_emitter.Emit(
1535 '\n'
1536 ' Dart_Handle customArgument = Dart_GetNativeArgument(args, $IN DEX);\n'
1537 ' RefPtr<ScriptArguments> scriptArguments(DartUtilities::create ScriptArguments(customArgument, exception));\n'
1538 ' if (!scriptArguments)\n'
1539 ' goto fail;\n',
1540 INDEX=len(arguments) + 1)
1541
1542 if needs_custom_element_callbacks:
1543 body_emitter.Emit(' CustomElementCallbackDispatcher::CallbackDelive ryScope deliveryScope;\n');
1544
1545 # Emit arguments.
1546 start_index = 1 if needs_receiver else 0
1547 for i, argument in enumerate(arguments):
1548 type_info = self._TypeInfo(argument.type.id)
1549 self._cpp_impl_includes |= set(type_info.conversion_includes())
1550 argument_expression_template, type, cls, function = \
1551 type_info.to_native_info(argument, self._interface.id, callback_name)
1552
1553 def AllowsNull():
1554 # TODO(vsm): HTMLSelectElement's indexed setter treats a null as a remov e.
1555 # We need to handle that.
1556 # assert argument.ext_attrs.get('TreatNullAs', 'NullString') == 'NullStr ing'
1557 if argument.ext_attrs.get('TreatNullAs') == 'NullString':
1558 return True
1559
1560 if argument.type.nullable:
1561 return True
1562
1563 if isinstance(argument, IDLAttribute):
1564 return (argument.type.id == 'DOMString') and \
1565 ('Reflect' in argument.ext_attrs)
1566
1567 if isinstance(argument, IDLArgument):
1568 if IsOptional(argument) and not self._IsArgumentOptionalInWebCore(node , argument):
1569 return True
1570 # argument default to null (e.g., DOMString arg = null).
1571 if argument.default_value_is_null:
1572 return True
1573 if _IsOptionalStringArgumentInInitEventMethod(self._interface, node, a rgument):
1574 return True
1575
1576 return False
1577
1578 if AllowsNull():
1579 function += 'WithNullCheck'
1580
1581 argument_name = DartDomNameOfAttribute(argument)
1582 if type_info.pass_native_by_ref():
1583 invocation_template =\
1584 ' $TYPE $ARGUMENT_NAME;\n'\
1585 ' $CLS::$FUNCTION(args, $INDEX, $ARGUMENT_NAME, exception);\n '
1586 else:
1587 if not auto_scope_setup and type_info.native_type() == 'String':
1588 invocation_template =\
1589 ' $TYPE $ARGUMENT_NAME = $CLS::$FUNCTION(args, $INDEX, exce ption, false);\n'
1590 else:
1591 invocation_template =\
1592 ' $TYPE $ARGUMENT_NAME = $CLS::$FUNCTION(args, $INDEX, exce ption);\n'
1593 body_emitter.Emit(
1594 '\n' +
1595 invocation_template +
1596 ' if (exception)\n'
1597 ' goto fail;\n',
1598 TYPE=type,
1599 ARGUMENT_NAME=argument_name,
1600 CLS=cls,
1601 FUNCTION=function,
1602 INDEX=start_index + i)
1603 self._cpp_impl_includes.add('"%s.h"' % cls)
1604 cpp_arguments.append(argument_expression_template % argument_name)
1605
1606 body_emitter.Emit('\n')
1607
1608 if 'NeedsUserGestureCheck' in ext_attrs:
1609 cpp_arguments.append('DartUtilities::processingUserGesture')
1610
1611 invocation_emitter = body_emitter
1612 if raises_dom_exception:
1613 cpp_arguments.append('es')
1614 invocation_emitter = body_emitter.Emit(
1615 ' DartExceptionState es;\n'
1616 '$!INVOCATION'
1617 ' if (es.hadException()) {\n'
1618 ' exception = DartDOMWrapper::exceptionCodeToDartException(es );\n'
1619 ' goto fail;\n'
1620 ' }\n')
1621
1622
1623 interface_name = self._interface_type_info.native_type()
1624
1625 if needs_receiver:
1626 # Hack to determine if this came from the _cpp_callback_map.
1627 # In this case, the getter is mapped to a static method.
1628 if function_expression.startswith('SVGTests::'):
1629 cpp_arguments.insert(0, 'receiver')
1630 elif (not function_expression.startswith('receiver->') and
1631 not function_expression.startswith(interface_name + '::')):
1632 if (interface_name in ['DOMWindow', 'Element', 'Navigator', 'WorkerGloba lScope']
1633 or (interface_name in ['SVGViewSpec', 'SVGViewElement', 'SVGSVGEleme nt']
1634 and callback_name in ['setZoomAndPan', 'zoomAndPanSetter', 'zoomAn dPan'])
1635 or (interface_name == 'Screen'
1636 and callback_name in ['_lockOrientation_1Callback', '_lockOrientat ion_2Callback', 'unlockOrientation', 'orientation'])):
1637 cpp_arguments.insert(0, 'receiver')
1638 else:
1639 cpp_arguments.append('receiver')
1640 elif self._IsStatic(node.id):
1641 cpp_arguments.insert(0, 'receiver')
1642
1643 if interface_name in ['SVGPropertyTearOff<SVGTransform>', 'SVGPropertyTearOf f<SVGAngle>', 'SVGMatrixTearOff'] and function_expression.startswith('receiver-> '):
1644 # This is a horrible hack. I don't know why this one case has to be
1645 # special cased.
1646 if not (self._interface.id == 'SVGTransformList' and callback_name == 'cre ateSVGTransformFromMatrixCallback'):
1647 function_expression = 'receiver->propertyReference().%s' % (function_exp ression[len('receiver->'):])
1648
1649 function_call = '%s(%s)' % (function_expression, ', '.join(cpp_arguments))
1650 if return_type == 'void':
1651 invocation_emitter.Emit(
1652 ' $FUNCTION_CALL;\n',
1653 FUNCTION_CALL=function_call)
1654 else:
1655 return_type_info = self._TypeInfo(return_type)
1656 self._cpp_impl_includes |= set(return_type_info.conversion_includes())
1657
1658 if return_type_is_nullable:
1659 invocation_emitter.Emit(
1660 ' bool isNull = false;\n'
1661 ' $NATIVE_TYPE result = $FUNCTION_CALL;\n'
1662 ' if (isNull)\n'
1663 ' return;\n',
1664 NATIVE_TYPE=return_type_info.parameter_type(),
1665 FUNCTION_CALL=function_call)
1666 value_expression = 'result'
1667 else:
1668 value_expression = function_call
1669
1670 # Generate to Dart conversion of C++ value.
1671 if return_type_info.dart_type() == 'bool':
1672 set_return_value = 'Dart_SetBooleanReturnValue(args, %s)' % (value_expre ssion)
1673 elif return_type_info.dart_type() == 'int':
1674 if return_type_info.native_type() == 'unsigned':
1675 set_return_value = 'DartUtilities::setDartUnsignedReturnValue(args, %s )' % (value_expression)
1676 elif return_type_info.native_type() == 'unsigned long long':
1677 set_return_value = 'DartUtilities::setDartUnsignedLongLongReturnValue( args, %s)' % (value_expression)
1678 else:
1679 assert (return_type_info.native_type() == 'int' or return_type_info.na tive_type() == 'long long')
1680 set_return_value = 'DartUtilities::setDartIntegerReturnValue(args, %s) ' % (value_expression)
1681 elif return_type_info.dart_type() == 'double':
1682 set_return_value = 'Dart_SetDoubleReturnValue(args, %s)' % (value_expres sion)
1683 elif return_type_info.dart_type() == 'String':
1684 auto_dart_scope='true' if auto_scope_setup else 'false'
1685 if ext_attrs and 'TreatReturnedNullStringAs' in ext_attrs:
1686 set_return_value = 'DartUtilities::setDartStringReturnValueWithNullChe ck(args, %s, %s)' % (value_expression, auto_dart_scope)
1687 else:
1688 set_return_value = 'DartUtilities::setDartStringReturnValue(args, %s, %s)' % (value_expression, auto_dart_scope)
1689 elif return_type_info.dart_type() == 'num' and return_type_info.native_typ e() == 'double':
1690 set_return_value = 'Dart_SetDoubleReturnValue(args, %s)' % (value_expres sion)
1691 else:
1692 return_to_dart_conversion = return_type_info.return_to_dart_conversion(
1693 value_expression,
1694 auto_scope_setup,
1695 self._interface.id,
1696 ext_attrs)
1697 set_return_value = '%s' % (return_to_dart_conversion)
1698 invocation_emitter.Emit(
1699 ' $RETURN_VALUE;\n',
1700 RETURN_VALUE=set_return_value)
1701 924
1702 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration, 925 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration,
1703 static, return_type, parameters, native_suffix, is_custom, 926 static, return_type, parameters, native_suffix, is_custom,
1704 auto_scope_setup=True, emit_metadata=True, emit_to_native=False, 927 auto_scope_setup=True, emit_metadata=True, emit_to_native=False,
1705 native_entry=None, wrap_unwrap_list=[]): 928 native_entry=None, wrap_unwrap_list=[], dictionary_return=False):
1706 metadata = [] 929 metadata = []
1707 if emit_metadata: 930 if emit_metadata:
1708 metadata = self._metadata.GetFormattedMetadata( 931 metadata = self._metadata.GetFormattedMetadata(
1709 self._renamer.GetLibraryName(self._interface), 932 self._renamer.GetLibraryName(self._interface),
1710 self._interface, idl_name, ' ') 933 self._interface, idl_name, ' ')
1711 934
1712 if (native_entry): 935 if (native_entry):
1713 dart_native_name, native_binding = native_entry 936 dart_native_name, native_binding = native_entry
1714 else: 937 else:
1715 dart_native_name = \ 938 dart_native_name = \
(...skipping 22 matching lines...) Expand all
1738 caller_emitter.Emit( 961 caller_emitter.Emit(
1739 '\n' 962 '\n'
1740 ' $METADATA$DART_DECLARATION;\n', 963 ' $METADATA$DART_DECLARATION;\n',
1741 METADATA=metadata, 964 METADATA=metadata,
1742 DART_DECLARATION=dart_declaration) 965 DART_DECLARATION=dart_declaration)
1743 else: 966 else:
1744 emit_template = ''' 967 emit_template = '''
1745 $METADATA$DART_DECLARATION => $DART_NAME($ACTUALS); 968 $METADATA$DART_DECLARATION => $DART_NAME($ACTUALS);
1746 ''' 969 '''
1747 if wrap_unwrap_list and wrap_unwrap_list[0]: 970 if wrap_unwrap_list and wrap_unwrap_list[0]:
1748 emit_jso_template = '''
1749 $METADATA$DART_DECLARATION => %s($DART_NAME($ACTUALS));
1750 '''
1751 if return_type == 'Rectangle': 971 if return_type == 'Rectangle':
1752 jso_util_method = 'make_dart_rectangle' 972 jso_util_method = 'make_dart_rectangle'
1753 elif wrap_unwrap_list[0]: 973 elif wrap_unwrap_list[0]:
1754 jso_util_method = 'wrap_jso' 974 jso_util_method = 'wrap_jso'
1755 975
976 if dictionary_return:
977 emit_jso_template = '''
978 $METADATA$DART_DECLARATION => convertNativeDictionaryToDartDictionary(%s($DART _NAME($ACTUALS)));
979 '''
980 else:
981 emit_jso_template = '''
982 $METADATA$DART_DECLARATION => %s($DART_NAME($ACTUALS));
983 '''
1756 emit_template = emit_jso_template % jso_util_method 984 emit_template = emit_jso_template % jso_util_method
1757 985
1758 if caller_emitter: 986 if caller_emitter:
1759 caller_emitter.Emit(emit_template, 987 caller_emitter.Emit(emit_template,
1760 METADATA=metadata, 988 METADATA=metadata,
1761 DART_DECLARATION=dart_declaration, 989 DART_DECLARATION=dart_declaration,
1762 DART_NAME=full_dart_name, 990 DART_NAME=full_dart_name,
1763 ACTUALS=actuals) 991 ACTUALS=actuals)
1764 cpp_callback_name = '%s%s' % (idl_name, native_suffix) 992 cpp_callback_name = '%s%s' % (idl_name, native_suffix)
1765 993
(...skipping 22 matching lines...) Expand all
1788 'onmousedown', 'onmousemove', 'onmouseout', 'onmouseover', 1016 'onmousedown', 'onmousemove', 'onmouseout', 'onmouseover',
1789 'onmouseup', 'onresize', 'onscroll', 'onunload'] 1017 'onmouseup', 'onresize', 'onscroll', 'onunload']
1790 if self._interface.id.startswith('SVG') and not attr.id in svg_exceptions: 1018 if self._interface.id.startswith('SVG') and not attr.id in svg_exceptions:
1791 namespace = 'SVGNames' 1019 namespace = 'SVGNames'
1792 self._cpp_impl_includes.add('"%s.h"' % namespace) 1020 self._cpp_impl_includes.add('"%s.h"' % namespace)
1793 1021
1794 attribute_name = attr.ext_attrs['Reflect'] or attr.id.lower() 1022 attribute_name = attr.ext_attrs['Reflect'] or attr.id.lower()
1795 return 'WebCore::%s::%sAttr' % (namespace, attribute_name) 1023 return 'WebCore::%s::%sAttr' % (namespace, attribute_name)
1796 1024
1797 def _IsStatic(self, attribute_name): 1025 def _IsStatic(self, attribute_name):
1798 cpp_type_name = self._interface_type_info.native_type()
1799 if cpp_type_name in _cpp_static_call_map:
1800 return attribute_name in _cpp_static_call_map[cpp_type_name]
1801 return False 1026 return False
1802 1027
1803 def _GenerateWebCoreFunctionExpression(self, function_name, idl_node, cpp_call back_name=None): 1028 def _GenerateWebCoreFunctionExpression(self, function_name, idl_node, cpp_call back_name=None):
1804 if 'ImplementedBy' in idl_node.ext_attrs: 1029 return None
1805 return '%s::%s' % (idl_node.ext_attrs['ImplementedBy'], function_name)
1806 cpp_type_name = self._interface_type_info.native_type()
1807 impl_type_name = _GetCPPTypeName(cpp_type_name, function_name, cpp_callback_ name)
1808 if idl_node.is_static or self._IsStatic(idl_node.id):
1809 return '%s::%s' % (impl_type_name, function_name)
1810 if cpp_type_name == impl_type_name:
1811 return '%s%s' % (self._interface_type_info.receiver(), function_name)
1812 else:
1813 return '%s::%s' % (impl_type_name, function_name)
1814 1030
1815 def _IsArgumentOptionalInWebCore(self, operation, argument): 1031 def _IsArgumentOptionalInWebCore(self, operation, argument):
1816 if not IsOptional(argument): 1032 if not IsOptional(argument):
1817 return False 1033 return False
1818 if 'Callback' in argument.ext_attrs: 1034 if 'Callback' in argument.ext_attrs:
1819 return False 1035 return False
1820 if operation.id in ['addEventListener', 'removeEventListener'] and argument. id == 'useCapture': 1036 if operation.id in ['addEventListener', 'removeEventListener'] and argument. id == 'useCapture':
1821 return False 1037 return False
1822 if 'DartForceOptional' in argument.ext_attrs: 1038 if 'DartForceOptional' in argument.ext_attrs:
1823 return False 1039 return False
1824 if argument.type.id == 'Dictionary': 1040 if argument.type.id == 'Dictionary':
1825 return False 1041 return False
1826 return True 1042 return True
1827 1043
1828 def _GenerateCPPIncludes(self, includes): 1044 def _GenerateCPPIncludes(self, includes):
1829 return ''.join(['#include %s\n' % include for include in sorted(includes)]) 1045 return None
1830 1046
1831 def _ToWebKitName(self, name): 1047 def _ToWebKitName(self, name):
1832 name = name[0].lower() + name[1:] 1048 name = name[0].lower() + name[1:]
1833 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(), 1049 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(),
1834 name) 1050 name)
1835 return re.sub(r'^(create|exclusive)', 1051 return re.sub(r'^(create|exclusive)',
1836 lambda s: 'is' + s.group(1).capitalize(), 1052 lambda s: 'is' + s.group(1).capitalize(),
1837 name) 1053 name)
1838 1054
1839 class CPPLibraryEmitter(): 1055 class CPPLibraryEmitter():
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
2032 1248
2033 def _IsCustom(op_or_attr): 1249 def _IsCustom(op_or_attr):
2034 assert(isinstance(op_or_attr, IDLMember)) 1250 assert(isinstance(op_or_attr, IDLMember))
2035 return 'Custom' in op_or_attr.ext_attrs or 'DartCustom' in op_or_attr.ext_attr s 1251 return 'Custom' in op_or_attr.ext_attrs or 'DartCustom' in op_or_attr.ext_attr s
2036 1252
2037 def _IsCustomValue(op_or_attr, value): 1253 def _IsCustomValue(op_or_attr, value):
2038 if _IsCustom(op_or_attr): 1254 if _IsCustom(op_or_attr):
2039 return op_or_attr.ext_attrs.get('Custom') == value \ 1255 return op_or_attr.ext_attrs.get('Custom') == value \
2040 or op_or_attr.ext_attrs.get('DartCustom') == value 1256 or op_or_attr.ext_attrs.get('DartCustom') == value
2041 return False 1257 return False
OLDNEW
« no previous file with comments | « tools/dom/scripts/systemhtml.py ('k') | tools/dom/templates/html/impl/impl_CanvasRenderingContext2D.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698