122 only_if_changed):
123 """Returns .h/.cpp code as (header_text, cpp_text)."""
124 try:
125 interface = definitions.interfaces[interface_name]
126 except KeyError:
127 raise Exception('%s not in IDL definitions' % interface_name)
128
129
130 interfaces.update(definitions.interfaces)
131
132
133 IdlType.set_callback_functions(definitions.callback_functions.keys())
134 IdlType.set_enums((enum.name, enum.values)
135 for enum in definitions.enumerations.values())
136
137
138 if interface.is_callback:
139 header_template_filename = 'callback_interface_h.template'
140 cpp_template_filename = 'callback_interface_cpp.template'
141 generate_contents = dart_callback_interface.generate_callback_interface
142 else:
143 header_template_filename = 'interface_h.template'
144 cpp_template_filename = 'interface_cpp.template'
145 generate_contents = dart_interface.generate_interface
146 header_template = self.jinja_env.get_template(header_template_filename)
147 cpp_template = self.jinja_env.get_template(cpp_template_filename)
148
149
150 template_contents = generate_contents(interface)
151 template_contents['code_generator'] = module_pyname
152
153
154 interface_info = self.interfaces_info[interface_name]
155 template_contents['header_includes'].add(interface_info['include_path'])
156 template_contents['header_includes'] = sorted(
157 template_contents['header_includes'])
158 includes.update(interface_info.get('dependencies_include_paths', []))
159
160
161
162
163
164 includes.discard('core/dom/GlobalEventHandlers.h')
165 includes.discard('core/frame/DOMWindowEventHandlers.h')
166
167 template_contents['cpp_includes'] = sorted(includes)
168
169 idl_world = {'interface': None, 'callback': None}
170
171
172 if os.path.isfile(idl_pickle_filename):
173 with open(idl_pickle_filename) as idl_pickle_file:
174 idl_global_data = pickle.load(idl_pickle_file)
175 idl_pickle_file.close()
176 idl_world['interface'] = idl_global_data['interface']
177 idl_world['callback'] = idl_global_data['callback']
178
179 if 'interface_name' in template_contents:
180 interface_global = {
181 'name':
182 template_contents['interface_name'],
183 'parent_interface':
184 template_contents['parent_interface'],
185 'is_active_dom_object':
186 template_contents['is_active_dom_object'],
187 'is_event_target':
188 template_contents['is_event_target'],
189 'has_resolver':
190 template_contents['interface_name'] not in
191 INTERFACES_WITHOUT_RESOLVERS,
192 'is_node':
193 template_contents['is_node'],
194 'conditional_string':
195 template_contents['conditional_string'],
196 }
197 idl_world['interface'] = interface_global
198 else:
199 callback_global = {'name': template_contents['cpp_class']}
200 idl_world['callback'] = callback_global
201
202 write_pickle_file(idl_pickle_filename, idl_world, only_if_changed)
203
204
205 header_text = header_template.render(template_contents)
206 cpp_text = cpp_template.render(template_contents)
207 return header_text, cpp_text
208