Implement "UpdateWorkerState" and use it
[WebKit-https.git] / Source / WebKit / Scripts / webkit / messages.py
1 # Copyright (C) 2010-2017 Apple Inc. All rights reserved.
2 #
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions
5 # are met:
6 # 1.  Redistributions of source code must retain the above copyright
7 #     notice, this list of conditions and the following disclaimer.
8 # 2.  Redistributions in binary form must reproduce the above copyright
9 #     notice, this list of conditions and the following disclaimer in the
10 #     documentation and/or other materials provided with the distribution.
11 #
12 # THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
13 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15 # DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
16 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
18 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
19 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
20 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
21 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
23 import collections
24 import re
25 import sys
26
27 from webkit import parser
28
29 WANTS_CONNECTION_ATTRIBUTE = 'WantsConnection'
30 LEGACY_RECEIVER_ATTRIBUTE = 'LegacyReceiver'
31 DELAYED_ATTRIBUTE = 'Delayed'
32
33 _license_header = """/*
34  * Copyright (C) 2010 Apple Inc. All rights reserved.
35  *
36  * Redistribution and use in source and binary forms, with or without
37  * modification, are permitted provided that the following conditions
38  * are met:
39  * 1.  Redistributions of source code must retain the above copyright
40  *     notice, this list of conditions and the following disclaimer.
41  * 2.  Redistributions in binary form must reproduce the above copyright
42  *     notice, this list of conditions and the following disclaimer in the
43  *     documentation and/or other materials provided with the distribution.
44  *
45  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
46  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
47  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48  * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
49  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
51  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
52  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
53  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
54  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55  */
56
57 """
58
59
60 def messages_header_filename(receiver):
61     return '%sMessages.h' % receiver.name
62
63
64 def surround_in_condition(string, condition):
65     if not condition:
66         return string
67     return '#if %s\n%s#endif\n' % (condition, string)
68
69
70 def function_parameter_type(type, kind):
71     # Don't use references for built-in types.
72     builtin_types = frozenset([
73         'bool',
74         'float',
75         'double',
76         'uint8_t',
77         'uint16_t',
78         'uint32_t',
79         'uint64_t',
80         'int8_t',
81         'int16_t',
82         'int32_t',
83         'int64_t',
84     ])
85
86     if type in builtin_types:
87         return type
88
89     if kind == 'enum':
90         return type
91
92     return 'const %s&' % type
93
94
95 def reply_parameter_type(type):
96     return '%s&' % type
97
98
99 def arguments_type(message):
100     return 'std::tuple<%s>' % ', '.join(function_parameter_type(parameter.type, parameter.kind) for parameter in message.parameters)
101
102
103 def reply_type(message):
104     return 'std::tuple<%s>' % (', '.join(reply_parameter_type(parameter.type) for parameter in message.reply_parameters))
105
106
107 def message_to_struct_declaration(message):
108     result = []
109     function_parameters = [(function_parameter_type(x.type, x.kind), x.name) for x in message.parameters]
110     result.append('class %s {\n' % message.name)
111     result.append('public:\n')
112     result.append('    typedef %s Arguments;\n' % arguments_type(message))
113     result.append('\n')
114     result.append('    static IPC::StringReference receiverName() { return messageReceiverName(); }\n')
115     result.append('    static IPC::StringReference name() { return IPC::StringReference("%s"); }\n' % message.name)
116     result.append('    static const bool isSync = %s;\n' % ('false', 'true')[message.reply_parameters != None])
117     result.append('\n')
118     if message.reply_parameters != None:
119         if message.has_attribute(DELAYED_ATTRIBUTE):
120             send_parameters = [(function_parameter_type(x.type, x.kind), x.name) for x in message.reply_parameters]
121             result.append('    struct DelayedReply : public ThreadSafeRefCounted<DelayedReply> {\n')
122             result.append('        DelayedReply(Ref<IPC::Connection>&&, std::unique_ptr<IPC::Encoder>);\n')
123             result.append('        ~DelayedReply();\n')
124             result.append('\n')
125             result.append('        bool send(%s);\n' % ', '.join([' '.join(x) for x in send_parameters]))
126             result.append('\n')
127             result.append('    private:\n')
128             result.append('        RefPtr<IPC::Connection> m_connection;\n')
129             result.append('        std::unique_ptr<IPC::Encoder> m_encoder;\n')
130             result.append('    };\n\n')
131
132         result.append('    typedef %s Reply;\n' % reply_type(message))
133
134     if len(function_parameters):
135         result.append('    %s%s(%s)' % (len(function_parameters) == 1 and 'explicit ' or '', message.name, ', '.join([' '.join(x) for x in function_parameters])))
136         result.append('\n        : m_arguments(%s)\n' % ', '.join([x[1] for x in function_parameters]))
137         result.append('    {\n')
138         result.append('    }\n\n')
139     result.append('    const Arguments& arguments() const\n')
140     result.append('    {\n')
141     result.append('        return m_arguments;\n')
142     result.append('    }\n')
143     result.append('\n')
144     result.append('private:\n')
145     result.append('    Arguments m_arguments;\n')
146     result.append('};\n')
147     return surround_in_condition(''.join(result), message.condition)
148
149
150 def forward_declaration(namespace, kind_and_type):
151     kind, type = kind_and_type
152
153     qualified_name = '%s::%s' % (namespace, type)
154     if kind == 'struct':
155         return 'struct %s' % type
156     elif kind == 'enum':
157         return 'enum class %s' % type
158     else:
159         return 'class %s' % type
160
161
162 def forward_declarations_for_namespace(namespace, kind_and_types):
163     result = []
164     result.append('namespace %s {\n' % namespace)
165     result += ['    %s;\n' % forward_declaration(namespace, x) for x in kind_and_types]
166     result.append('}\n')
167     return ''.join(result)
168
169
170 def forward_declarations_and_headers(receiver):
171     types_by_namespace = collections.defaultdict(set)
172
173     headers = set([
174         '"ArgumentCoders.h"',
175     ])
176
177     non_template_wtf_types = frozenset([
178         'String',
179     ])
180
181     for message in receiver.messages:
182         if message.reply_parameters != None and message.has_attribute(DELAYED_ATTRIBUTE):
183             headers.add('<wtf/ThreadSafeRefCounted.h>')
184             types_by_namespace['IPC'].update([('class', 'Connection')])
185
186     for parameter in receiver.iterparameters():
187         kind = parameter.kind
188         type = parameter.type
189
190         if type.find('<') != -1 or type == "WebCore::ServiceWorkerIdentifier":
191             # Don't forward declare class templates or ServiceWorkerIdentifier.
192             headers.update(headers_for_type(type))
193             continue
194
195         split = type.split('::')
196
197         # Handle WTF types even if the WTF:: prefix is not given
198         if split[0] in non_template_wtf_types:
199             split.insert(0, 'WTF')
200
201         if len(split) == 2:
202             namespace = split[0]
203             inner_type = split[1]
204             types_by_namespace[namespace].add((kind, inner_type))
205         elif len(split) > 2:
206             # We probably have a nested struct, which means we can't forward declare it.
207             # Include its header instead.
208             headers.update(headers_for_type(type))
209
210     forward_declarations = '\n'.join([forward_declarations_for_namespace(namespace, types) for (namespace, types) in sorted(types_by_namespace.items())])
211     headers = ['#include %s\n' % header for header in sorted(headers)]
212
213     return (forward_declarations, headers)
214
215
216 def generate_messages_header(file):
217     receiver = parser.parse(file)
218
219     result = []
220
221     result.append(_license_header)
222
223     result.append('#pragma once\n')
224     result.append('\n')
225
226     if receiver.condition:
227         result.append('#if %s\n\n' % receiver.condition)
228
229     forward_declarations, headers = forward_declarations_and_headers(receiver)
230
231     result += headers
232     result.append('\n')
233
234     result.append(forward_declarations)
235     result.append('\n')
236
237     result.append('namespace Messages {\nnamespace %s {\n' % receiver.name)
238     result.append('\n')
239     result.append('static inline IPC::StringReference messageReceiverName()\n')
240     result.append('{\n')
241     result.append('    return IPC::StringReference("%s");\n' % receiver.name)
242     result.append('}\n')
243     result.append('\n')
244     result.append('\n'.join([message_to_struct_declaration(x) for x in receiver.messages]))
245     result.append('\n')
246     result.append('} // namespace %s\n} // namespace Messages\n' % receiver.name)
247
248     if receiver.condition:
249         result.append('\n#endif // %s\n' % receiver.condition)
250
251     return ''.join(result)
252
253
254 def handler_function(receiver, message):
255     if message.name.find('URL') == 0:
256         return '%s::%s' % (receiver.name, 'url' + message.name[3:])
257     return '%s::%s' % (receiver.name, message.name[0].lower() + message.name[1:])
258
259
260 def async_message_statement(receiver, message):
261     dispatch_function_args = ['decoder', 'this', '&%s' % handler_function(receiver, message)]
262
263     dispatch_function = 'handleMessage'
264
265     if message.has_attribute(WANTS_CONNECTION_ATTRIBUTE):
266         dispatch_function_args.insert(0, 'connection')
267
268     result = []
269     result.append('    if (decoder.messageName() == Messages::%s::%s::name()) {\n' % (receiver.name, message.name))
270     result.append('        IPC::%s<Messages::%s::%s>(%s);\n' % (dispatch_function, receiver.name, message.name, ', '.join(dispatch_function_args)))
271     result.append('        return;\n')
272     result.append('    }\n')
273     return surround_in_condition(''.join(result), message.condition)
274
275
276 def sync_message_statement(receiver, message):
277     dispatch_function = 'handleMessage'
278     if message.has_attribute(DELAYED_ATTRIBUTE):
279         dispatch_function += 'Delayed'
280
281     wants_connection = message.has_attribute(DELAYED_ATTRIBUTE) or message.has_attribute(WANTS_CONNECTION_ATTRIBUTE)
282
283     result = []
284     result.append('    if (decoder.messageName() == Messages::%s::%s::name()) {\n' % (receiver.name, message.name))
285     result.append('        IPC::%s<Messages::%s::%s>(%sdecoder, %sreplyEncoder, this, &%s);\n' % (dispatch_function, receiver.name, message.name, 'connection, ' if wants_connection else '', '' if message.has_attribute(DELAYED_ATTRIBUTE) else '*', handler_function(receiver, message)))
286     result.append('        return;\n')
287     result.append('    }\n')
288     return surround_in_condition(''.join(result), message.condition)
289
290
291 def class_template_headers(template_string):
292     template_string = template_string.strip()
293
294     class_template_types = {
295         'WebCore::RectEdges': {'headers': ['<WebCore/RectEdges.h>'], 'argument_coder_headers': ['"ArgumentCoders.h"']},
296         'HashMap': {'headers': ['<wtf/HashMap.h>'], 'argument_coder_headers': ['"ArgumentCoders.h"']},
297         'std::optional': {'headers': ['<wtf/Optional.h>'], 'argument_coder_headers': ['"ArgumentCoders.h"']},
298         'OptionSet': {'headers': ['<wtf/OptionSet.h>'], 'argument_coder_headers': ['"ArgumentCoders.h"']},
299         'Vector': {'headers': ['<wtf/Vector.h>'], 'argument_coder_headers': ['"ArgumentCoders.h"']},
300         'std::pair': {'headers': ['<utility>'], 'argument_coder_headers': ['"ArgumentCoders.h"']},
301     }
302
303     match = re.match('(?P<template_name>.+?)<(?P<parameter_string>.+)>', template_string)
304     if not match:
305         return {'header_infos': [], 'types': [template_string]}
306
307     template_name = match.groupdict()['template_name']
308     if template_name not in class_template_types:
309         sys.stderr.write("Error: no class template type is defined for '%s'\n" % (template_string))
310         sys.exit(1)
311
312     header_infos = [class_template_types[template_name]]
313     types = []
314
315     for parameter in parser.split_parameters_string(match.groupdict()['parameter_string']):
316         parameter_header_infos_and_types = class_template_headers(parameter)
317
318         header_infos += parameter_header_infos_and_types['header_infos']
319         types += parameter_header_infos_and_types['types']
320
321     return {'header_infos': header_infos, 'types': types}
322
323
324 def argument_coder_headers_for_type(type):
325     header_infos_and_types = class_template_headers(type)
326
327     special_cases = {
328         'String': '"ArgumentCoders.h"',
329         'WebKit::ScriptMessageHandlerHandle': '"WebScriptMessageHandler.h"',
330     }
331
332     headers = []
333     for header_info in header_infos_and_types['header_infos']:
334         headers += header_info['argument_coder_headers']
335
336     for type in header_infos_and_types['types']:
337         if type in special_cases:
338             headers.append(special_cases[type])
339             continue
340
341         split = type.split('::')
342         if len(split) < 2:
343             continue
344         if split[0] == 'WebCore':
345             headers.append('"WebCoreArgumentCoders.h"')
346
347     return headers
348
349
350 def headers_for_type(type):
351     header_infos_and_types = class_template_headers(type)
352
353     special_cases = {
354         'String': ['<wtf/text/WTFString.h>'],
355         'PAL::SessionID': ['<pal/SessionID.h>'],
356         'WebCore::AutoplayEventFlags': ['<WebCore/AutoplayEvent.h>'],
357         'WebCore::ExceptionDetails': ['<WebCore/JSDOMExceptionHandling.h>'],
358         'WebCore::FileChooserSettings': ['<WebCore/FileChooser.h>'],
359         'WebCore::GrammarDetail': ['<WebCore/TextCheckerClient.h>'],
360         'WebCore::HasInsecureContent': ['<WebCore/FrameLoaderTypes.h>'],
361         'WebCore::Highlight': ['<WebCore/InspectorOverlay.h>'],
362         'WebCore::IncludeSecureCookies': ['<WebCore/CookiesStrategy.h>'],
363         'WebCore::KeyframeValueList': ['<WebCore/GraphicsLayer.h>'],
364         'WebCore::KeypressCommand': ['<WebCore/KeyboardEvent.h>'],
365         'WebCore::MediaConstraints': ['<WebCore/MediaConstraints.h>'],
366         'WebCore::PasteboardCustomData': ['<WebCore/Pasteboard.h>'],
367         'WebCore::PasteboardImage': ['<WebCore/Pasteboard.h>'],
368         'WebCore::PasteboardURL': ['<WebCore/Pasteboard.h>'],
369         'WebCore::PasteboardWebContent': ['<WebCore/Pasteboard.h>'],
370         'WebCore::PaymentAuthorizationResult': ['<WebCore/ApplePaySessionPaymentRequest.h>'],
371         'WebCore::PaymentMethodUpdate': ['<WebCore/ApplePaySessionPaymentRequest.h>'],
372         'WebCore::PluginInfo': ['<WebCore/PluginData.h>'],
373         'WebCore::PolicyAction': ['<WebCore/FrameLoaderTypes.h>'],
374         'WebCore::RecentSearch': ['<WebCore/SearchPopupMenu.h>'],
375         'WebCore::ServiceWorkerRegistrationState': ['<WebCore/ServiceWorkerTypes.h>'],
376         'WebCore::ServiceWorkerState': ['<WebCore/ServiceWorkerTypes.h>'],
377         'WebCore::ShippingContactUpdate': ['<WebCore/ApplePaySessionPaymentRequest.h>'],
378         'WebCore::ShippingMethodUpdate': ['<WebCore/ApplePaySessionPaymentRequest.h>'],
379         'WebCore::ShouldSample': ['<WebCore/DiagnosticLoggingClient.h>'],
380         'WebCore::TextCheckingRequestData': ['<WebCore/TextChecking.h>'],
381         'WebCore::TextCheckingResult': ['<WebCore/TextCheckerClient.h>'],
382         'WebCore::TextIndicatorData': ['<WebCore/TextIndicator.h>'],
383         'WebCore::TextureMapperAnimations': ['<WebCore/TextureMapperAnimation.h>'],
384         'WebCore::ViewportAttributes': ['<WebCore/ViewportArguments.h>'],
385         'WebCore::SelectionRect': ['"EditorState.h"'],
386         'WebKit::BackForwardListItemState': ['"SessionState.h"'],
387         'WebKit::LayerHostingMode': ['"LayerTreeContext.h"'],
388         'WebKit::PageState': ['"SessionState.h"'],
389         'WebKit::WebGestureEvent': ['"WebEvent.h"'],
390         'WebKit::WebKeyboardEvent': ['"WebEvent.h"'],
391         'WebKit::WebMouseEvent': ['"WebEvent.h"'],
392         'WebKit::WebTouchEvent': ['"WebEvent.h"'],
393         'WebKit::WebWheelEvent': ['"WebEvent.h"'],
394         'struct WebKit::WebUserScriptData': ['"WebUserContentControllerDataTypes.h"'],
395         'struct WebKit::WebUserStyleSheetData': ['"WebUserContentControllerDataTypes.h"'],
396         'struct WebKit::WebScriptMessageHandlerData': ['"WebUserContentControllerDataTypes.h"'],
397         'std::chrono::system_clock::time_point': ['<chrono>'],
398     }
399
400     headers = []
401     for header_info in header_infos_and_types['header_infos']:
402         headers += header_info['headers']
403
404     for type in header_infos_and_types['types']:
405         if type in special_cases:
406             headers += special_cases[type]
407             continue
408
409         # We assume that we must include a header for a type iff it has a scope
410         # resolution operator (::).
411         split = type.split('::')
412         if len(split) < 2:
413             continue
414
415         if split[0] == 'WebKit' or split[0] == 'IPC':
416             headers.append('"%s.h"' % split[1])
417         else:
418             headers.append('<%s/%s.h>' % tuple(split[0:2]))
419
420     return headers
421
422
423 def generate_message_handler(file):
424     receiver = parser.parse(file)
425     header_conditions = {
426         '"%s"' % messages_header_filename(receiver): [None],
427         '"HandleMessage.h"': [None],
428         '"Decoder.h"': [None],
429     }
430
431     type_conditions = {}
432     for parameter in receiver.iterparameters():
433         if not parameter.type in type_conditions:
434             type_conditions[parameter.type] = []
435
436         if not parameter.condition in type_conditions[parameter.type]:
437             type_conditions[parameter.type].append(parameter.condition)
438
439     for parameter in receiver.iterparameters():
440         type = parameter.type
441         conditions = type_conditions[type]
442
443         argument_encoder_headers = argument_coder_headers_for_type(type)
444         if argument_encoder_headers:
445             for header in argument_encoder_headers:
446                 if header not in header_conditions:
447                     header_conditions[header] = []
448                 header_conditions[header].extend(conditions)
449
450         type_headers = headers_for_type(type)
451         for header in type_headers:
452             if header not in header_conditions:
453                 header_conditions[header] = []
454             header_conditions[header].extend(conditions)
455
456     for message in receiver.messages:
457         if message.reply_parameters is not None:
458             for reply_parameter in message.reply_parameters:
459                 type = reply_parameter.type
460                 argument_encoder_headers = argument_coder_headers_for_type(type)
461                 if argument_encoder_headers:
462                     for header in argument_encoder_headers:
463                         if header not in header_conditions:
464                             header_conditions[header] = []
465                         header_conditions[header].append(message.condition)
466
467                 type_headers = headers_for_type(type)
468                 for header in type_headers:
469                     if header not in header_conditions:
470                         header_conditions[header] = []
471                     header_conditions[header].append(message.condition)
472
473     result = []
474
475     result.append(_license_header)
476     result.append('#include "config.h"\n')
477     result.append('\n')
478
479     if receiver.condition:
480         result.append('#if %s\n\n' % receiver.condition)
481
482     result.append('#include "%s.h"\n\n' % receiver.name)
483     for header in sorted(header_conditions):
484         if header_conditions[header] and not None in header_conditions[header]:
485             result.append('#if %s\n' % ' || '.join(set(header_conditions[header])))
486             result += ['#include %s\n' % header]
487             result.append('#endif\n')
488         else:
489             result += ['#include %s\n' % header]
490     result.append('\n')
491
492     sync_delayed_messages = []
493     for message in receiver.messages:
494         if message.reply_parameters != None and message.has_attribute(DELAYED_ATTRIBUTE):
495             sync_delayed_messages.append(message)
496
497     if sync_delayed_messages:
498         result.append('namespace Messages {\n\nnamespace %s {\n\n' % receiver.name)
499
500         for message in sync_delayed_messages:
501             send_parameters = [(function_parameter_type(x.type, x.kind), x.name) for x in message.reply_parameters]
502
503             if message.condition:
504                 result.append('#if %s\n\n' % message.condition)
505
506             result.append('%s::DelayedReply::DelayedReply(Ref<IPC::Connection>&& connection, std::unique_ptr<IPC::Encoder> encoder)\n' % message.name)
507             result.append('    : m_connection(WTFMove(connection))\n')
508             result.append('    , m_encoder(WTFMove(encoder))\n')
509             result.append('{\n')
510             result.append('}\n')
511             result.append('\n')
512             result.append('%s::DelayedReply::~DelayedReply()\n' % message.name)
513             result.append('{\n')
514             result.append('    ASSERT(!m_connection);\n')
515             result.append('}\n')
516             result.append('\n')
517             result.append('bool %s::DelayedReply::send(%s)\n' % (message.name, ', '.join([' '.join(x) for x in send_parameters])))
518             result.append('{\n')
519             result.append('    ASSERT(m_encoder);\n')
520             result += ['    *m_encoder << %s;\n' % x.name for x in message.reply_parameters]
521             result.append('    bool _result = m_connection->sendSyncReply(WTFMove(m_encoder));\n')
522             result.append('    m_connection = nullptr;\n')
523             result.append('    return _result;\n')
524             result.append('}\n')
525             result.append('\n')
526
527             if message.condition:
528                 result.append('#endif\n\n')
529
530         result.append('} // namespace %s\n\n} // namespace Messages\n\n' % receiver.name)
531
532     result.append('namespace WebKit {\n\n')
533
534     async_messages = []
535     sync_messages = []
536     for message in receiver.messages:
537         if message.reply_parameters is not None:
538             sync_messages.append(message)
539         else:
540             async_messages.append(message)
541
542     if async_messages:
543         result.append('void %s::didReceive%sMessage(IPC::Connection& connection, IPC::Decoder& decoder)\n' % (receiver.name, receiver.name if receiver.has_attribute(LEGACY_RECEIVER_ATTRIBUTE) else ''))
544         result.append('{\n')
545         result += [async_message_statement(receiver, message) for message in async_messages]
546         if (receiver.superclass):
547             result.append('    %s::didReceiveMessage(connection, decoder);\n' % (receiver.superclass))
548         else:
549             result.append('    UNUSED_PARAM(connection);\n')
550             result.append('    UNUSED_PARAM(decoder);\n')
551             result.append('    ASSERT_NOT_REACHED();\n')
552         result.append('}\n')
553
554     if sync_messages:
555         result.append('\n')
556         result.append('void %s::didReceiveSync%sMessage(IPC::Connection& connection, IPC::Decoder& decoder, std::unique_ptr<IPC::Encoder>& replyEncoder)\n' % (receiver.name, receiver.name if receiver.has_attribute(LEGACY_RECEIVER_ATTRIBUTE) else ''))
557         result.append('{\n')
558         result += [sync_message_statement(receiver, message) for message in sync_messages]
559         result.append('    UNUSED_PARAM(connection);\n')
560         result.append('    UNUSED_PARAM(decoder);\n')
561         result.append('    UNUSED_PARAM(replyEncoder);\n')
562         result.append('    ASSERT_NOT_REACHED();\n')
563         result.append('}\n')
564
565     result.append('\n} // namespace WebKit\n')
566
567     if receiver.condition:
568         result.append('\n#endif // %s\n' % receiver.condition)
569
570     return ''.join(result)