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

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

Issue 93933014: Changes for Chrome 32 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: More fixes for chrome 32/1700 roll Created 6 years, 11 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 | Annotate | Revision Log
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 13 from idlnode import IDLArgument, IDLAttribute
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 16 # TODO(vsm): This logic needs to pulled from the source IDL. These tables are
17 # an ugly workaround. 17 # an ugly workaround.
18 _cpp_callback_map = { 18 _cpp_callback_map = {
19 ('DataTransferItem', 'webkitGetAsEntry'): 'DataTransferItemFileSystem', 19 ('DataTransferItem', 'webkitGetAsEntry'): 'DataTransferItemFileSystem',
20 ('Document', 'fonts'): 'DocumentFontFaceSet',
20 ('Document', 'webkitIsFullScreen'): 'DocumentFullscreen', 21 ('Document', 'webkitIsFullScreen'): 'DocumentFullscreen',
21 ('Document', 'webkitFullScreenKeyboardInputAllowed'): 'DocumentFullscreen', 22 ('Document', 'webkitFullScreenKeyboardInputAllowed'): 'DocumentFullscreen',
22 ('Document', 'webkitCurrentFullScreenElement'): 'DocumentFullscreen', 23 ('Document', 'webkitCurrentFullScreenElement'): 'DocumentFullscreen',
23 ('Document', 'webkitCancelFullScreen'): 'DocumentFullscreen', 24 ('Document', 'webkitCancelFullScreen'): 'DocumentFullscreen',
24 ('Document', 'webkitFullscreenEnabled'): 'DocumentFullscreen', 25 ('Document', 'webkitFullscreenEnabled'): 'DocumentFullscreen',
25 ('Document', 'webkitFullscreenElement'): 'DocumentFullscreen', 26 ('Document', 'webkitFullscreenElement'): 'DocumentFullscreen',
26 ('Document', 'webkitExitFullscreen'): 'DocumentFullscreen', 27 ('Document', 'webkitExitFullscreen'): 'DocumentFullscreen',
27 ('DOMWindow', 'crypto'): 'DOMWindowCrypto', 28 ('DOMWindow', 'crypto'): 'DOMWindowCrypto',
28 ('DOMWindow', 'indexedDB'): 'DOMWindowIndexedDatabase', 29 ('DOMWindow', 'indexedDB'): 'DOMWindowIndexedDatabase',
29 ('DOMWindow', 'speechSynthesis'): 'DOMWindowSpeechSynthesis', 30 ('DOMWindow', 'speechSynthesis'): 'DOMWindowSpeechSynthesis',
30 ('DOMWindow', 'webkitNotifications'): 'DOMWindowNotifications', 31 ('DOMWindow', 'webkitNotifications'): 'DOMWindowNotifications',
31 ('DOMWindow', 'storage'): 'DOMWindowQuota', 32 ('DOMWindow', 'storage'): 'DOMWindowQuota',
32 ('DOMWindow', 'webkitStorageInfo'): 'DOMWindowQuota', 33 ('DOMWindow', 'webkitStorageInfo'): 'DOMWindowQuota',
33 ('DOMWindow', 'openDatabase'): 'DOMWindowWebDatabase', 34 ('DOMWindow', 'openDatabase'): 'DOMWindowWebDatabase',
34 ('DOMWindow', 'webkitRequestFileSystem'): 'DOMWindowFileSystem', 35 ('DOMWindow', 'webkitRequestFileSystem'): 'DOMWindowFileSystem',
35 ('DOMWindow', 'webkitResolveLocalFileSystemURL'): 'DOMWindowFileSystem', 36 ('DOMWindow', 'webkitResolveLocalFileSystemURL'): 'DOMWindowFileSystem',
36 ('DOMWindow', 'atob'): 'DOMWindowBase64', 37 ('DOMWindow', 'atob'): 'DOMWindowBase64',
37 ('DOMWindow', 'btoa'): 'DOMWindowBase64', 38 ('DOMWindow', 'btoa'): 'DOMWindowBase64',
38 ('DOMWindow', 'clearTimeout'): 'DOMWindowTimers', 39 ('DOMWindow', 'clearTimeout'): 'DOMWindowTimers',
39 ('DOMWindow', 'clearInterval'): 'DOMWindowTimers', 40 ('DOMWindow', 'clearInterval'): 'DOMWindowTimers',
40 ('DOMWindow', 'createImageBitmap'): 'ImageBitmapFactories', 41 ('DOMWindow', 'createImageBitmap'): 'ImageBitmapFactories',
41 ('HTMLInputElement', 'webkitEntries'): 'HTMLInputElementFileSystem', 42 ('HTMLInputElement', 'webkitEntries'): 'HTMLInputElementFileSystem',
43 ('HTMLVideoElement', 'getVideoPlaybackQuality'): 'HTMLVideoElementMediaSource' ,
42 ('Navigator', 'doNotTrack'): 'NavigatorDoNotTrack', 44 ('Navigator', 'doNotTrack'): 'NavigatorDoNotTrack',
43 ('Navigator', 'geolocation'): 'NavigatorGeolocation', 45 ('Navigator', 'geolocation'): 'NavigatorGeolocation',
44 ('Navigator', 'webkitPersistentStorage'): 'NavigatorStorageQuota', 46 ('Navigator', 'webkitPersistentStorage'): 'NavigatorStorageQuota',
45 ('Navigator', 'webkitTemporaryStorage'): 'NavigatorStorageQuota', 47 ('Navigator', 'webkitTemporaryStorage'): 'NavigatorStorageQuota',
46 ('Navigator', 'registerProtocolHandler'): 'NavigatorContentUtils', 48 ('Navigator', 'registerProtocolHandler'): 'NavigatorContentUtils',
47 ('Navigator', 'unregisterProtocolHandler'): 'NavigatorContentUtils', 49 ('Navigator', 'unregisterProtocolHandler'): 'NavigatorContentUtils',
48 ('Navigator', 'webkitGetUserMedia'): 'NavigatorMediaStream', 50 ('Navigator', 'webkitGetUserMedia'): 'NavigatorMediaStream',
49 ('Navigator', 'webkitGetGamepads'): 'NavigatorGamepad', 51 ('Navigator', 'webkitGetGamepads'): 'NavigatorGamepad',
50 ('Navigator', 'requestMIDIAccess'): 'NavigatorWebMIDI', 52 ('Navigator', 'requestMIDIAccess'): 'NavigatorWebMIDI',
51 ('Navigator', 'vibrate'): 'NavigatorVibration', 53 ('Navigator', 'vibrate'): 'NavigatorVibration',
52 ('Navigator', 'appName'): 'NavigatorID', 54 ('Navigator', 'appName'): 'NavigatorID',
53 ('Navigator', 'appVersion'): 'NavigatorID', 55 ('Navigator', 'appVersion'): 'NavigatorID',
54 ('Navigator', 'appCodeName'): 'NavigatorID', 56 ('Navigator', 'appCodeName'): 'NavigatorID',
55 ('Navigator', 'platform'): 'NavigatorID', 57 ('Navigator', 'platform'): 'NavigatorID',
56 ('Navigator', 'product'): 'NavigatorID', 58 ('Navigator', 'product'): 'NavigatorID',
57 ('Navigator', 'userAgent'): 'NavigatorID', 59 ('Navigator', 'userAgent'): 'NavigatorID',
58 ('Navigator', 'onLine'): 'NavigatorOnLine', 60 ('Navigator', 'onLine'): 'NavigatorOnLine',
59 ('Navigator', 'registerServiceWorker'): 'NavigatorServiceWorker', 61 ('Navigator', 'registerServiceWorker'): 'NavigatorServiceWorker',
60 ('Navigator', 'unregisterServiceWorker'): 'NavigatorServiceWorker', 62 ('Navigator', 'unregisterServiceWorker'): 'NavigatorServiceWorker',
63 ('Navigator', 'maxTouchPoints'): 'NavigatorEvents',
61 ('WorkerGlobalScope', 'crypto'): 'WorkerGlobalScopeCrypto', 64 ('WorkerGlobalScope', 'crypto'): 'WorkerGlobalScopeCrypto',
62 ('WorkerGlobalScope', 'indexedDB'): 'WorkerGlobalScopeIndexedDatabase', 65 ('WorkerGlobalScope', 'indexedDB'): 'WorkerGlobalScopeIndexedDatabase',
63 ('WorkerGlobalScope', 'webkitNotifications'): 'WorkerGlobalScopeNotifications' , 66 ('WorkerGlobalScope', 'webkitNotifications'): 'WorkerGlobalScopeNotifications' ,
64 ('WorkerGlobalScope', 'openDatabase'): 'WorkerGlobalScopeWebDatabase', 67 ('WorkerGlobalScope', 'openDatabase'): 'WorkerGlobalScopeWebDatabase',
65 ('WorkerGlobalScope', 'openDatabaseSync'): 'WorkerGlobalScopeWebDatabase', 68 ('WorkerGlobalScope', 'openDatabaseSync'): 'WorkerGlobalScopeWebDatabase',
66 ('WorkerGlobalScope', 'performance'): 'WorkerGlobalScopePerformance', 69 ('WorkerGlobalScope', 'performance'): 'WorkerGlobalScopePerformance',
67 ('WorkerGlobalScope', 'webkitRequestFileSystem'): 'WorkerGlobalScopeFileSystem ', 70 ('WorkerGlobalScope', 'webkitRequestFileSystem'): 'WorkerGlobalScopeFileSystem ',
68 ('WorkerGlobalScope', 'webkitRequestFileSystemSync'): 'WorkerGlobalScopeFileSy stem', 71 ('WorkerGlobalScope', 'webkitRequestFileSystemSync'): 'WorkerGlobalScopeFileSy stem',
69 ('WorkerGlobalScope', 'webkitResolveLocalFileSystemURL'): 'WorkerGlobalScopeFi leSystem', 72 ('WorkerGlobalScope', 'webkitResolveLocalFileSystemURL'): 'WorkerGlobalScopeFi leSystem',
70 ('WorkerGlobalScope', 'webkitResolveLocalFileSystemSyncURL'): 'WorkerGlobalSco peFileSystem', 73 ('WorkerGlobalScope', 'webkitResolveLocalFileSystemSyncURL'): 'WorkerGlobalSco peFileSystem',
(...skipping 22 matching lines...) Expand all
93 ('Node', 'firstChild', 'Getter'), 96 ('Node', 'firstChild', 'Getter'),
94 ('Node', 'lastChild', 'Getter'), 97 ('Node', 'lastChild', 'Getter'),
95 ('Node', 'nextSibling', 'Getter'), 98 ('Node', 'nextSibling', 'Getter'),
96 ('Node', 'previousSibling', 'Getter'), 99 ('Node', 'previousSibling', 'Getter'),
97 ('Node', 'childNodes', 'Getter'), 100 ('Node', 'childNodes', 'Getter'),
98 ('NodeList', 'length', 'Getter'), 101 ('NodeList', 'length', 'Getter'),
99 ('NodeList', 'item', 'Callback'), 102 ('NodeList', 'item', 'Callback'),
100 ('Document', 'body', 'Getter'), 103 ('Document', 'body', 'Getter'),
101 ]) 104 ])
102 105
106 # TODO(vsm): This should be recoverable from IDL, but we appear to not
107 # track the necessary info.
108 _url_utils = ['hash', 'host', 'hostname', 'origin',
109 'password', 'pathname', 'port', 'protocol',
110 'search', 'username']
111 _cpp_static_call_map = {
112 'DOMURL': _url_utils + ['href', 'toString'],
113 'HTMLAnchorElement': _url_utils,
114 'HTMLAreaElement': _url_utils,
115 }
116
103 def _GetCPPPartialNames(interface): 117 def _GetCPPPartialNames(interface):
104 interface_name = interface.ext_attrs.get('ImplementedAs', interface.id) 118 interface_name = interface.ext_attrs.get('ImplementedAs', interface.id)
105 if not _cpp_partial_map: 119 if not _cpp_partial_map:
106 for (type, member) in _cpp_callback_map.keys(): 120 for (type, member) in _cpp_callback_map.keys():
107 if type not in _cpp_partial_map: 121 if type not in _cpp_partial_map:
108 _cpp_partial_map[type] = set([]) 122 _cpp_partial_map[type] = set([])
109 123
110 name_with_path = _cpp_callback_map[(type, member)] 124 name_with_path = _cpp_callback_map[(type, member)]
111 if name_with_path in _cpp_import_map: 125 if name_with_path in _cpp_import_map:
112 name_with_path = _cpp_import_map[name_with_path] 126 name_with_path = _cpp_import_map[name_with_path]
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 def GenerateCallback(self, info): 181 def GenerateCallback(self, info):
168 if IsPureInterface(self._interface.id) or IsCustomType(self._interface.id): 182 if IsPureInterface(self._interface.id) or IsCustomType(self._interface.id):
169 return 183 return
170 184
171 cpp_impl_includes = set(['"' + partial + '.h"' 185 cpp_impl_includes = set(['"' + partial + '.h"'
172 for partial in _GetCPPPartialNames(self._interface) ]) 186 for partial in _GetCPPPartialNames(self._interface) ])
173 cpp_header_handlers_emitter = emitter.Emitter() 187 cpp_header_handlers_emitter = emitter.Emitter()
174 cpp_impl_handlers_emitter = emitter.Emitter() 188 cpp_impl_handlers_emitter = emitter.Emitter()
175 class_name = 'Dart%s' % self._interface.id 189 class_name = 'Dart%s' % self._interface.id
176 for operation in self._interface.operations: 190 for operation in self._interface.operations:
191 function_name = operation.id
177 parameters = [] 192 parameters = []
178 arguments = [] 193 arguments = []
194 if operation.ext_attrs.get('CallWith') == 'ThisValue':
195 parameters.append('ScriptValue scriptValue')
179 conversion_includes = [] 196 conversion_includes = []
180 for argument in operation.arguments: 197 for argument in operation.arguments:
181 argument_type_info = self._TypeInfo(argument.type.id) 198 argument_type_info = self._TypeInfo(argument.type.id)
182 parameters.append('%s %s' % (argument_type_info.parameter_type(), 199 parameters.append('%s %s' % (argument_type_info.parameter_type(),
183 argument.id)) 200 argument.id))
184 arguments.append(argument_type_info.to_dart_conversion(argument.id)) 201 arguments.append(argument_type_info.to_dart_conversion(argument.id))
185 conversion_includes.extend(argument_type_info.conversion_includes()) 202 conversion_includes.extend(argument_type_info.conversion_includes())
186 203
204 # FIXME(vsm): Handle ThisValue attribute.
Jacob 2014/01/06 17:35:37 should there be a bug tracking this?
205 if operation.ext_attrs.get('CallWith') == 'ThisValue':
206 cpp_header_handlers_emitter.Emit(
207 '\n'
208 ' virtual bool $FUNCTION($PARAMETERS) {\n'
209 ' DART_UNIMPLEMENTED();\n'
210 ' return false;\n'
211 ' }\n',
212 FUNCTION=function_name,
213 PARAMETERS=', '.join(parameters))
214 continue
215
187 cpp_header_handlers_emitter.Emit( 216 cpp_header_handlers_emitter.Emit(
188 '\n' 217 '\n'
189 ' virtual bool handleEvent($PARAMETERS);\n', 218 ' virtual bool $FUNCTION($PARAMETERS);\n',
219 FUNCTION=function_name,
190 PARAMETERS=', '.join(parameters)) 220 PARAMETERS=', '.join(parameters))
191 221
192 if 'Custom' in operation.ext_attrs: 222 if 'Custom' in operation.ext_attrs:
193 continue 223 continue
194 224
195 cpp_impl_includes |= set(conversion_includes) 225 cpp_impl_includes |= set(conversion_includes)
196 arguments_declaration = 'Dart_Handle arguments[] = { %s }' % ', '.join(arg uments) 226 arguments_declaration = 'Dart_Handle arguments[] = { %s }' % ', '.join(arg uments)
197 if not len(arguments): 227 if not len(arguments):
198 arguments_declaration = 'Dart_Handle* arguments = 0' 228 arguments_declaration = 'Dart_Handle* arguments = 0'
199 cpp_impl_handlers_emitter.Emit( 229 cpp_impl_handlers_emitter.Emit(
200 '\n' 230 '\n'
201 'bool $CLASS_NAME::handleEvent($PARAMETERS)\n' 231 'bool $CLASS_NAME::$FUNCTION($PARAMETERS)\n'
202 '{\n' 232 '{\n'
203 ' if (!m_callback.isIsolateAlive())\n' 233 ' if (!m_callback.isIsolateAlive())\n'
204 ' return false;\n' 234 ' return false;\n'
205 ' DartIsolateScope scope(m_callback.isolate());\n' 235 ' DartIsolateScope scope(m_callback.isolate());\n'
206 ' DartApiScope apiScope;\n' 236 ' DartApiScope apiScope;\n'
207 ' $ARGUMENTS_DECLARATION;\n' 237 ' $ARGUMENTS_DECLARATION;\n'
208 ' return m_callback.handleEvent($ARGUMENT_COUNT, arguments);\n' 238 ' return m_callback.handleEvent($ARGUMENT_COUNT, arguments);\n'
209 '}\n', 239 '}\n',
210 CLASS_NAME=class_name, 240 CLASS_NAME=class_name,
241 FUNCTION=function_name,
211 PARAMETERS=', '.join(parameters), 242 PARAMETERS=', '.join(parameters),
212 ARGUMENTS_DECLARATION=arguments_declaration, 243 ARGUMENTS_DECLARATION=arguments_declaration,
213 ARGUMENT_COUNT=len(arguments)) 244 ARGUMENT_COUNT=len(arguments))
214 245
215 cpp_header_emitter = self._cpp_library_emitter.CreateHeaderEmitter( 246 cpp_header_emitter = self._cpp_library_emitter.CreateHeaderEmitter(
216 self._interface.id, 247 self._interface.id,
217 self._renamer.GetLibraryName(self._interface), 248 self._renamer.GetLibraryName(self._interface),
218 True) 249 True)
219 cpp_header_emitter.Emit( 250 cpp_header_emitter.Emit(
220 self._template_loader.Load('cpp_callback_header.template'), 251 self._template_loader.Load('cpp_callback_header.template'),
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 ' DartApiScope apiScope();\n' 484 ' DartApiScope apiScope();\n'
454 ' Dart_SetReturnValue(args, createWrapper(domData, value) );\n' 485 ' Dart_SetReturnValue(args, createWrapper(domData, value) );\n'
455 ' }\n' 486 ' }\n'
456 ' }\n' 487 ' }\n'
457 ' }\n', 488 ' }\n',
458 INTERFACE=self._interface.id) 489 INTERFACE=self._interface.id)
459 490
460 if ('CustomToV8' in ext_attrs or 491 if ('CustomToV8' in ext_attrs or
461 'PureInterface' in ext_attrs or 492 'PureInterface' in ext_attrs or
462 'CPPPureInterface' in ext_attrs or 493 'CPPPureInterface' in ext_attrs or
494 'SpecialWrapFor' in ext_attrs or
463 self._interface_type_info.custom_to_dart()): 495 self._interface_type_info.custom_to_dart()):
464 to_dart_emitter.Emit( 496 to_dart_emitter.Emit(
465 ' static Dart_Handle createWrapper(DartDOMData* domData, NativeType * value);\n') 497 ' static Dart_Handle createWrapper(DartDOMData* domData, NativeType * value);\n')
466 else: 498 else:
467 to_dart_emitter.Emit( 499 to_dart_emitter.Emit(
468 ' static Dart_Handle createWrapper(DartDOMData* domData, NativeType * value)\n' 500 ' static Dart_Handle createWrapper(DartDOMData* domData, NativeType * value)\n'
469 ' {\n' 501 ' {\n'
470 ' return DartDOMWrapper::createWrapper<Dart$(INTERFACE)>(domDat a, value);\n' 502 ' return DartDOMWrapper::createWrapper<Dart$(INTERFACE)>(domDat a, value);\n'
471 ' }\n', 503 ' }\n',
472 INTERFACE=self._interface.id) 504 INTERFACE=self._interface.id)
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 dart_declaration = 'void set %s(%s value)' % (html_name, self._DartType(attr .type.id)) 580 dart_declaration = 'void set %s(%s value)' % (html_name, self._DartType(attr .type.id))
549 is_custom = set(['Custom', 'CustomSetter', 'V8CustomSetter']) & set(attr.ext _attrs) 581 is_custom = set(['Custom', 'CustomSetter', 'V8CustomSetter']) & set(attr.ext _attrs)
550 cpp_callback_name = self._GenerateNativeBinding(attr.id, 2, 582 cpp_callback_name = self._GenerateNativeBinding(attr.id, 2,
551 dart_declaration, 'Setter', is_custom) 583 dart_declaration, 'Setter', is_custom)
552 if is_custom: 584 if is_custom:
553 return 585 return
554 586
555 if 'Reflect' in attr.ext_attrs: 587 if 'Reflect' in attr.ext_attrs:
556 webcore_function_name = self._TypeInfo(attr.type.id).webcore_setter_name() 588 webcore_function_name = self._TypeInfo(attr.type.id).webcore_setter_name()
557 else: 589 else:
558 webcore_function_name = re.sub(r'^(xml(?=[A-Z])|\w)', 590 webcore_function_name = re.sub(r'^(xml|css|(?=[A-Z])|\w)',
559 lambda s: s.group(1).upper(), 591 lambda s: s.group(1).upper(),
560 attr.id) 592 attr.id)
561 webcore_function_name = 'set%s' % webcore_function_name 593 webcore_function_name = 'set%s' % webcore_function_name
562 594
563 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr) 595 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr)
564 self._GenerateNativeCallback( 596 self._GenerateNativeCallback(
565 cpp_callback_name, 597 cpp_callback_name,
566 True, 598 True,
567 function_expression, 599 function_expression,
568 attr, 600 attr,
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 needs_receiver, 779 needs_receiver,
748 function_expression, 780 function_expression,
749 node, 781 node,
750 arguments, 782 arguments,
751 return_type, 783 return_type,
752 return_type_is_nullable, 784 return_type_is_nullable,
753 raises_dom_exception, 785 raises_dom_exception,
754 generate_custom_element_scope_if_needed=False): 786 generate_custom_element_scope_if_needed=False):
755 787
756 ext_attrs = node.ext_attrs 788 ext_attrs = node.ext_attrs
789 if self._IsStatic(node.id):
790 needs_receiver = True
757 791
758 cpp_arguments = [] 792 cpp_arguments = []
759 runtime_check = None 793 runtime_check = None
760 raises_exceptions = raises_dom_exception or arguments 794 raises_exceptions = raises_dom_exception or arguments
761 needs_custom_element_callbacks = False 795 needs_custom_element_callbacks = False
762 796
763 # TODO(antonm): unify with ScriptState below. 797 # TODO(antonm): unify with ScriptState below.
764 requires_stack_info = (ext_attrs.get('CallWith') == 'ScriptArguments|ScriptS tate' or 798 requires_stack_info = (ext_attrs.get('CallWith') == 'ScriptArguments|ScriptS tate' or
765 ext_attrs.get('ConstructorCallWith') == 'ScriptArgume nts|ScriptState' or 799 ext_attrs.get('ConstructorCallWith') == 'ScriptArgume nts|ScriptState' or
766 ext_attrs.get('CallWith') == 'ScriptArguments&ScriptS tate' or 800 ext_attrs.get('CallWith') == 'ScriptArguments&ScriptS tate' or
767 ext_attrs.get('ConstructorCallWith') == 'ScriptArgume nts&ScriptState') 801 ext_attrs.get('ConstructorCallWith') == 'ScriptArgume nts&ScriptState')
768 if requires_stack_info: 802 if requires_stack_info:
769 raises_exceptions = True 803 raises_exceptions = True
770 cpp_arguments = ['&state', 'scriptArguments.release()'] 804 cpp_arguments = ['&state', 'scriptArguments.release()']
771 # WebKit uses scriptArguments to reconstruct last argument, so 805 # WebKit uses scriptArguments to reconstruct last argument, so
772 # it's not needed and should be just removed. 806 # it's not needed and should be just removed.
773 arguments = arguments[:-1] 807 arguments = arguments[:-1]
774 808
775 # TODO(antonm): unify with ScriptState below. 809 # TODO(antonm): unify with ScriptState below.
776 requires_script_arguments = (ext_attrs.get('CallWith') == 'ScriptArguments' or 810 requires_script_arguments = (ext_attrs.get('CallWith') == 'ScriptArguments' or
777 ext_attrs.get('ConstructorCallWith') == 'Script Arguments') 811 ext_attrs.get('ConstructorCallWith') == 'Script Arguments')
778 if requires_script_arguments: 812 if requires_script_arguments:
779 raises_exceptions = True 813 raises_exceptions = True
780 cpp_arguments = ['scriptArguments.release()'] 814 cpp_arguments = ['scriptArguments.release()']
781 # WebKit uses scriptArguments to reconstruct last argument, so 815 # WebKit uses scriptArguments to reconstruct last argument, so
782 # it's not needed and should be just removed. 816 # it's not needed and should be just removed.
783 arguments = arguments[:-1] 817 arguments = arguments[:-1]
784 818
785 requires_script_execution_context = (ext_attrs.get('CallWith') == 'ScriptExe cutionContext' or 819 requires_script_execution_context = (ext_attrs.get('CallWith') == 'Execution Context' or
786 ext_attrs.get('ConstructorCallWith') == 'ScriptExecutionContext') 820 ext_attrs.get('ConstructorCallWith') == 'ExecutionContext')
787 821
788 requires_document = ext_attrs.get('ConstructorCallWith') == 'Document' 822 requires_document = ext_attrs.get('ConstructorCallWith') == 'Document'
789 823
790 if requires_script_execution_context: 824 if requires_script_execution_context:
791 raises_exceptions = True 825 raises_exceptions = True
792 cpp_arguments = ['context'] 826 cpp_arguments = ['context']
793 827
794 requires_script_state = (ext_attrs.get('CallWith') == 'ScriptState' or 828 requires_script_state = (ext_attrs.get('CallWith') == 'ScriptState' or
795 ext_attrs.get('ConstructorCallWith') == 'ScriptStat e') 829 ext_attrs.get('ConstructorCallWith') == 'ScriptStat e')
796 if requires_script_state: 830 if requires_script_state:
797 raises_exceptions = True 831 raises_exceptions = True
798 cpp_arguments = ['&state'] 832 cpp_arguments = ['&state']
799 833
800 requires_dom_window = 'NamedConstructor' in ext_attrs 834 requires_dom_window = 'NamedConstructor' in ext_attrs
801 if requires_dom_window or requires_document: 835 if requires_dom_window or requires_document:
802 raises_exceptions = True 836 raises_exceptions = True
803 cpp_arguments = ['document'] 837 cpp_arguments = ['document']
804 838
805 if 'ImplementedBy' in ext_attrs: 839 if 'ImplementedBy' in ext_attrs:
806 assert needs_receiver 840 assert needs_receiver
807 self._cpp_impl_includes.add('"%s.h"' % ext_attrs['ImplementedBy']) 841 self._cpp_impl_includes.add('"%s.h"' % ext_attrs['ImplementedBy'])
808 cpp_arguments.append('receiver') 842 cpp_arguments.append('receiver')
809 843
810 if 'Reflect' in ext_attrs: 844 if 'Reflect' in ext_attrs:
811 cpp_arguments = [self._GenerateWebCoreReflectionAttributeName(node)] 845 cpp_arguments = [self._GenerateWebCoreReflectionAttributeName(node)]
812 846
813 if generate_custom_element_scope_if_needed and (ext_attrs.get('CustomElement Callbacks', 'None') != 'None' or 'Reflect' in ext_attrs): 847 if generate_custom_element_scope_if_needed and (ext_attrs.get('CustomElement Callbacks', 'None') != 'None' or 'Reflect' in ext_attrs):
814 self._cpp_impl_includes.add('"core/dom/CustomElementCallbackDispatcher.h"' ) 848 self._cpp_impl_includes.add('"core/dom/custom/CustomElementCallbackDispatc her.h"')
815 needs_custom_element_callbacks = True 849 needs_custom_element_callbacks = True
816 850
817 if return_type_is_nullable: 851 if return_type_is_nullable:
818 cpp_arguments = ['isNull'] 852 cpp_arguments = ['isNull']
819 853
820 v8EnabledPerContext = ext_attrs.get('synthesizedV8EnabledPerContext', ext_at trs.get('V8EnabledPerContext')) 854 v8EnabledPerContext = ext_attrs.get('synthesizedV8EnabledPerContext', ext_at trs.get('V8EnabledPerContext'))
821 v8EnabledAtRuntime = ext_attrs.get('synthesizedV8EnabledAtRuntime', ext_attr s.get('V8EnabledAtRuntime')) 855 v8EnabledAtRuntime = ext_attrs.get('synthesizedV8EnabledAtRuntime', ext_attr s.get('V8EnabledAtRuntime'))
822 assert(not (v8EnabledPerContext and v8EnabledAtRuntime)) 856 assert(not (v8EnabledPerContext and v8EnabledAtRuntime))
823 857
824 if v8EnabledPerContext: 858 if v8EnabledPerContext:
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 ' return;\n' 899 ' return;\n'
866 ' }\n') 900 ' }\n')
867 901
868 if runtime_check: 902 if runtime_check:
869 body_emitter.Emit( 903 body_emitter.Emit(
870 '$RUNTIME_CHECK\n', 904 '$RUNTIME_CHECK\n',
871 RUNTIME_CHECK=runtime_check) 905 RUNTIME_CHECK=runtime_check)
872 906
873 if requires_script_execution_context: 907 if requires_script_execution_context:
874 body_emitter.Emit( 908 body_emitter.Emit(
875 ' ScriptExecutionContext* context = DartUtilities::scriptExecut ionContext();\n' 909 ' ExecutionContext* context = DartUtilities::scriptExecutionCon text();\n'
876 ' if (!context) {\n' 910 ' if (!context) {\n'
877 ' exception = Dart_NewStringFromCString("Failed to retrieve a context");\n' 911 ' exception = Dart_NewStringFromCString("Failed to retrieve a context");\n'
878 ' goto fail;\n' 912 ' goto fail;\n'
879 ' }\n\n') 913 ' }\n\n')
880 914
881 if requires_script_state: 915 if requires_script_state:
882 body_emitter.Emit( 916 body_emitter.Emit(
883 ' ScriptState* currentState = DartUtilities::currentScriptState ();\n' 917 ' ScriptState* currentState = DartUtilities::currentScriptState ();\n'
884 ' if (!currentState) {\n' 918 ' if (!currentState) {\n'
885 ' exception = Dart_NewStringFromCString("Failed to retrieve a script state");\n' 919 ' exception = Dart_NewStringFromCString("Failed to retrieve a script state");\n'
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 if needs_receiver: 1046 if needs_receiver:
1013 interface_name = self._interface_type_info.native_type() 1047 interface_name = self._interface_type_info.native_type()
1014 # Hack to determine if this came from the _cpp_callback_map. 1048 # Hack to determine if this came from the _cpp_callback_map.
1015 # In this case, the getter is mapped to a static method. 1049 # In this case, the getter is mapped to a static method.
1016 if (not function_expression.startswith('receiver->') and 1050 if (not function_expression.startswith('receiver->') and
1017 not function_expression.startswith(interface_name + '::')): 1051 not function_expression.startswith(interface_name + '::')):
1018 if interface_name == 'DOMWindow' or interface_name == 'Navigator' or int erface_name == 'WorkerGlobalScope': 1052 if interface_name == 'DOMWindow' or interface_name == 'Navigator' or int erface_name == 'WorkerGlobalScope':
1019 cpp_arguments.insert(0, 'receiver') 1053 cpp_arguments.insert(0, 'receiver')
1020 else: 1054 else:
1021 cpp_arguments.append('receiver') 1055 cpp_arguments.append('receiver')
1056 elif self._IsStatic(node.id):
1057 cpp_arguments.insert(0, 'receiver')
1022 1058
1023 function_call = '%s(%s)' % (function_expression, ', '.join(cpp_arguments)) 1059 function_call = '%s(%s)' % (function_expression, ', '.join(cpp_arguments))
1024 if return_type == 'void': 1060 if return_type == 'void':
1025 invocation_emitter.Emit( 1061 invocation_emitter.Emit(
1026 ' $FUNCTION_CALL;\n', 1062 ' $FUNCTION_CALL;\n',
1027 FUNCTION_CALL=function_call) 1063 FUNCTION_CALL=function_call)
1028 else: 1064 else:
1029 return_type_info = self._TypeInfo(return_type) 1065 return_type_info = self._TypeInfo(return_type)
1030 self._cpp_impl_includes |= set(return_type_info.conversion_includes()) 1066 self._cpp_impl_includes |= set(return_type_info.conversion_includes())
1031 1067
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 svg_exceptions = ['class', 'id', 'onabort', 'onclick', 'onerror', 'onload', 1157 svg_exceptions = ['class', 'id', 'onabort', 'onclick', 'onerror', 'onload',
1122 'onmousedown', 'onmousemove', 'onmouseout', 'onmouseover', 1158 'onmousedown', 'onmousemove', 'onmouseout', 'onmouseover',
1123 'onmouseup', 'onresize', 'onscroll', 'onunload'] 1159 'onmouseup', 'onresize', 'onscroll', 'onunload']
1124 if self._interface.id.startswith('SVG') and not attr.id in svg_exceptions: 1160 if self._interface.id.startswith('SVG') and not attr.id in svg_exceptions:
1125 namespace = 'SVGNames' 1161 namespace = 'SVGNames'
1126 self._cpp_impl_includes.add('"%s.h"' % namespace) 1162 self._cpp_impl_includes.add('"%s.h"' % namespace)
1127 1163
1128 attribute_name = attr.ext_attrs['Reflect'] or attr.id.lower() 1164 attribute_name = attr.ext_attrs['Reflect'] or attr.id.lower()
1129 return 'WebCore::%s::%sAttr' % (namespace, attribute_name) 1165 return 'WebCore::%s::%sAttr' % (namespace, attribute_name)
1130 1166
1167 def _IsStatic(self, attribute_name):
1168 cpp_type_name = self._interface_type_info.native_type()
1169 if cpp_type_name in _cpp_static_call_map:
1170 return attribute_name in _cpp_static_call_map[cpp_type_name]
1171 return False
1172
1131 def _GenerateWebCoreFunctionExpression(self, function_name, idl_node, cpp_call back_name=None): 1173 def _GenerateWebCoreFunctionExpression(self, function_name, idl_node, cpp_call back_name=None):
1132 if 'ImplementedBy' in idl_node.ext_attrs: 1174 if 'ImplementedBy' in idl_node.ext_attrs:
1133 return '%s::%s' % (idl_node.ext_attrs['ImplementedBy'], function_name) 1175 return '%s::%s' % (idl_node.ext_attrs['ImplementedBy'], function_name)
1134 cpp_type_name = self._interface_type_info.native_type() 1176 cpp_type_name = self._interface_type_info.native_type()
1135 impl_type_name = _GetCPPTypeName(cpp_type_name, function_name, cpp_callback_ name) 1177 impl_type_name = _GetCPPTypeName(cpp_type_name, function_name, cpp_callback_ name)
1136 if idl_node.is_static: 1178 if idl_node.is_static or self._IsStatic(idl_node.id):
1137 return '%s::%s' % (impl_type_name, function_name) 1179 return '%s::%s' % (impl_type_name, function_name)
1138 if cpp_type_name == impl_type_name: 1180 if cpp_type_name == impl_type_name:
1139 return '%s%s' % (self._interface_type_info.receiver(), function_name) 1181 return '%s%s' % (self._interface_type_info.receiver(), function_name)
1140 else: 1182 else:
1141 return '%s::%s' % (impl_type_name, function_name) 1183 return '%s::%s' % (impl_type_name, function_name)
1142 1184
1143 def _IsArgumentOptionalInWebCore(self, operation, argument): 1185 def _IsArgumentOptionalInWebCore(self, operation, argument):
1144 if not IsOptional(argument): 1186 if not IsOptional(argument):
1145 return False 1187 return False
1146 if 'Callback' in argument.ext_attrs: 1188 if 'Callback' in argument.ext_attrs:
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1302 e.Emit("};\n"); 1344 e.Emit("};\n");
1303 e.Emit('\n'); 1345 e.Emit('\n');
1304 e.Emit('} // namespace WebCore\n'); 1346 e.Emit('} // namespace WebCore\n');
1305 1347
1306 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): 1348 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument):
1307 return ( 1349 return (
1308 interface.id.endswith('Event') and 1350 interface.id.endswith('Event') and
1309 operation.id.startswith('init') and 1351 operation.id.startswith('init') and
1310 argument.ext_attrs.get('Default') == 'Undefined' and 1352 argument.ext_attrs.get('Default') == 'Undefined' and
1311 argument.type.id == 'DOMString') 1353 argument.type.id == 'DOMString')
OLDNEW
« no previous file with comments | « tools/dom/scripts/generator.py ('k') | tools/dom/templates/html/dartium/cpp_callback_header.template » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698