5a738100b9774a9d224cf2b2e99ecd66487aa693
[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     no_forward_declaration_types = frozenset([
187         'WebCore::DocumentIdentifier',
188         'WebCore::ServiceWorkerIdentifier',
189         'WebCore::ServiceWorkerOrClientData',
190         'WebCore::ServiceWorkerRegistrationIdentifier',
191         'WebCore::SWServerConnectionIdentifier',
192     ])
193
194     for parameter in receiver.iterparameters():
195         kind = parameter.kind
196         type = parameter.type
197
198         if type.find('<') != -1 or type in no_forward_declaration_types:
199             # Don't forward declare class templates.
200             headers.update(headers_for_type(type))
201             continue
202
203         split = type.split('::')
204
205         # Handle WTF types even if the WTF:: prefix is not given
206         if split[0] in non_template_wtf_types:
207             split.insert(0, 'WTF')
208
209         if len(split) == 2:
210             namespace = split[0]
211             inner_type = split[1]
212             types_by_namespace[namespace].add((kind, inner_type))
213         elif len(split) > 2:
214             # We probably have a nested struct, which means we can't forward declare it.
215             # Include its header instead.
216             headers.update(headers_for_type(type))
217
218     forward_declarations = '\n'.join([forward_declarations_for_namespace(namespace, types) for (namespace, types) in sorted(types_by_namespace.items())])
219     headers = ['#include %s\n' % header for header in sorted(headers)]
220
221     return (forward_declarations, headers)
222
223
224 def generate_messages_header(file):
225     receiver = parser.parse(file)
226
227     result = []
228
229     result.append(_license_header)
230
231     result.append('#pragma once\n')
232     result.append('\n')
233
234     if receiver.condition:
235         result.append('#if %s\n\n' % receiver.condition)
236
237     forward_declarations, headers = forward_declarations_and_headers(receiver)
238
239     result += headers
240     result.append('\n')
241
242     result.append(forward_declarations)
243     result.append('\n')
244
245     result.append('namespace Messages {\nnamespace %s {\n' % receiver.name)
246     result.append('\n')
247     result.append('static inline IPC::StringReference messageReceiverName()\n')
248     result.append('{\n')
249     result.append('    return IPC::StringReference("%s");\n' % receiver.name)
250     result.append('}\n')
251     result.append('\n')
252     result.append('\n'.join([message_to_struct_declaration(x) for x in receiver.messages]))
253     result.append('\n')
254     result.append('} // namespace %s\n} // namespace Messages\n' % receiver.name)
255
256     if receiver.condition:
257         result.append('\n#endif // %s\n' % receiver.condition)
258
259     return ''.join(result)
260
261
262 def handler_function(receiver, message):
263     if message.name.find('URL') == 0:
264         return '%s::%s' % (receiver.name, 'url' + message.name[3:])
265     return '%s::%s' % (receiver.name, message.name[0].lower() + message.name[1:])
266
267
268 def async_message_statement(receiver, message):
269     dispatch_function_args = ['decoder', 'this', '&%s' % handler_function(receiver, message)]
270
271     dispatch_function = 'handleMessage'
272
273     if message.has_attribute(WANTS_CONNECTION_ATTRIBUTE):
274         dispatch_function_args.insert(0, 'connection')
275
276     result = []
277     result.append('    if (decoder.messageName() == Messages::%s::%s::name()) {\n' % (receiver.name, message.name))
278     result.append('        IPC::%s<Messages::%s::%s>(%s);\n' % (dispatch_function, receiver.name, message.name, ', '.join(dispatch_function_args)))
279     result.append('        return;\n')
280     result.append('    }\n')
281     return surround_in_condition(''.join(result), message.condition)
282
283
284 def sync_message_statement(receiver, message):
285     dispatch_function = 'handleMessage'
286     if message.has_attribute(DELAYED_ATTRIBUTE):
287         dispatch_function += 'Delayed'
288
289     wants_connection = message.has_attribute(DELAYED_ATTRIBUTE) or message.has_attribute(WANTS_CONNECTION_ATTRIBUTE)
290
291     result = []
292     result.append('    if (decoder.messageName() == Messages::%s::%s::name()) {\n' % (receiver.name, message.name))
293     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)))
294     result.append('        return;\n')
295     result.append('    }\n')
296     return surround_in_condition(''.join(result), message.condition)
297
298
299 def class_template_headers(template_string):
300     template_string = template_string.strip()
301
302     class_template_types = {
303         'WebCore::RectEdges': {'headers': ['<WebCore/RectEdges.h>'], 'argument_coder_headers': ['"ArgumentCoders.h"']},
304         'HashMap': {'headers': ['<wtf/HashMap.h>'], 'argument_coder_headers': ['"ArgumentCoders.h"']},
305         'HashSet': {'headers': ['<wtf/HashSet.h>'], 'argument_coder_headers': ['"ArgumentCoders.h"']},
306         'std::optional': {'headers': ['<wtf/Optional.h>'], 'argument_coder_headers': ['"ArgumentCoders.h"']},
307         'OptionSet': {'headers': ['<wtf/OptionSet.h>'], 'argument_coder_headers': ['"ArgumentCoders.h"']},
308         'Vector': {'headers': ['<wtf/Vector.h>'], 'argument_coder_headers': ['"ArgumentCoders.h"']},
309         'std::pair': {'headers': ['<utility>'], 'argument_coder_headers': ['"ArgumentCoders.h"']},
310     }
311
312     match = re.match('(?P<template_name>.+?)<(?P<parameter_string>.+)>', template_string)
313     if not match:
314         return {'header_infos': [], 'types': [template_string]}
315
316     template_name = match.groupdict()['template_name']
317     if template_name not in class_template_types:
318         sys.stderr.write("Error: no class template type is defined for '%s'\n" % (template_string))
319         sys.exit(1)
320
321     header_infos = [class_template_types[template_name]]
322     types = []
323
324     for parameter in parser.split_parameters_string(match.groupdict()['parameter_string']):
325         parameter_header_infos_and_types = class_template_headers(parameter)
326
327         header_infos += parameter_header_infos_and_types['header_infos']
328         types += parameter_header_infos_and_types['types']
329
330     return {'header_infos': header_infos, 'types': types}
331
332
333 def argument_coder_headers_for_type(type):
334     header_infos_and_types = class_template_headers(type)
335
336     special_cases = {
337         'String': '"ArgumentCoders.h"',
338         'WebKit::ScriptMessageHandlerHandle': '"WebScriptMessageHandler.h"',
339     }
340
341     headers = []
342     for header_info in header_infos_and_types['header_infos']:
343         headers += header_info['argument_coder_headers']
344
345     for type in header_infos_and_types['types']:
346         if type in special_cases:
347             headers.append(special_cases[type])
348             continue
349
350         split = type.split('::')
351         if len(split) < 2:
352             continue
353         if split[0] == 'WebCore':
354             headers.append('"WebCoreArgumentCoders.h"')
355
356     return headers
357
358
359 def headers_for_type(type):
360     header_infos_and_types = class_template_headers(type)
361
362     special_cases = {
363         'String': ['<wtf/text/WTFString.h>'],
364         'PAL::SessionID': ['<pal/SessionID.h>'],
365         'WebCore::AttachmentDisplayOptions': ['<WebCore/AttachmentTypes.h>'],
366         'WebCore::AutoplayEventFlags': ['<WebCore/AutoplayEvent.h>'],
367         'WebCore::ExceptionDetails': ['<WebCore/JSDOMExceptionHandling.h>'],
368         'WebCore::FileChooserSettings': ['<WebCore/FileChooser.h>'],
369         'WebCore::GrammarDetail': ['<WebCore/TextCheckerClient.h>'],
370         'WebCore::HasInsecureContent': ['<WebCore/FrameLoaderTypes.h>'],
371         'WebCore::Highlight': ['<WebCore/InspectorOverlay.h>'],
372         'WebCore::IncludeSecureCookies': ['<WebCore/CookiesStrategy.h>'],
373         'WebCore::KeyframeValueList': ['<WebCore/GraphicsLayer.h>'],
374         'WebCore::KeypressCommand': ['<WebCore/KeyboardEvent.h>'],
375         'WebCore::MediaConstraints': ['<WebCore/MediaConstraints.h>'],
376         'WebCore::PasteboardCustomData': ['<WebCore/Pasteboard.h>'],
377         'WebCore::PasteboardImage': ['<WebCore/Pasteboard.h>'],
378         'WebCore::PasteboardURL': ['<WebCore/Pasteboard.h>'],
379         'WebCore::PasteboardWebContent': ['<WebCore/Pasteboard.h>'],
380         'WebCore::PaymentAuthorizationResult': ['<WebCore/ApplePaySessionPaymentRequest.h>'],
381         'WebCore::PaymentMethodUpdate': ['<WebCore/ApplePaySessionPaymentRequest.h>'],
382         'WebCore::PluginInfo': ['<WebCore/PluginData.h>'],
383         'WebCore::PolicyAction': ['<WebCore/FrameLoaderTypes.h>'],
384         'WebCore::RecentSearch': ['<WebCore/SearchPopupMenu.h>'],
385         'WebCore::SWServerConnectionIdentifier': ['<WebCore/ServiceWorkerTypes.h>'],
386         'WebCore::ServiceWorkerOrClientData': ['<WebCore/ServiceWorkerTypes.h>', '<WebCore/ServiceWorkerClientData.h>', '<WebCore/ServiceWorkerData.h>'],
387         'WebCore::ServiceWorkerRegistrationIdentifier': ['<WebCore/ServiceWorkerTypes.h>'],
388         'WebCore::ServiceWorkerRegistrationState': ['<WebCore/ServiceWorkerTypes.h>'],
389         'WebCore::ServiceWorkerState': ['<WebCore/ServiceWorkerTypes.h>'],
390         'WebCore::ShippingContactUpdate': ['<WebCore/ApplePaySessionPaymentRequest.h>'],
391         'WebCore::ShippingMethodUpdate': ['<WebCore/ApplePaySessionPaymentRequest.h>'],
392         'WebCore::ShouldNotifyWhenResolved': ['<WebCore/ServiceWorkerTypes.h>'],
393         'WebCore::ShouldSample': ['<WebCore/DiagnosticLoggingClient.h>'],
394         'WebCore::TextCheckingRequestData': ['<WebCore/TextChecking.h>'],
395         'WebCore::TextCheckingResult': ['<WebCore/TextCheckerClient.h>'],
396         'WebCore::TextIndicatorData': ['<WebCore/TextIndicator.h>'],
397         'WebCore::TextureMapperAnimations': ['<WebCore/TextureMapperAnimation.h>'],
398         'WebCore::ViewportAttributes': ['<WebCore/ViewportArguments.h>'],
399         'WebCore::SelectionRect': ['"EditorState.h"'],
400         'WebKit::BackForwardListItemState': ['"SessionState.h"'],
401         'WebKit::LayerHostingMode': ['"LayerTreeContext.h"'],
402         'WebKit::PageState': ['"SessionState.h"'],
403         'WebKit::WebGestureEvent': ['"WebEvent.h"'],
404         'WebKit::WebKeyboardEvent': ['"WebEvent.h"'],
405         'WebKit::WebMouseEvent': ['"WebEvent.h"'],
406         'WebKit::WebTouchEvent': ['"WebEvent.h"'],
407         'WebKit::WebWheelEvent': ['"WebEvent.h"'],
408         'struct WebKit::WebUserScriptData': ['"WebUserContentControllerDataTypes.h"'],
409         'struct WebKit::WebUserStyleSheetData': ['"WebUserContentControllerDataTypes.h"'],
410         'struct WebKit::WebScriptMessageHandlerData': ['"WebUserContentControllerDataTypes.h"'],
411         'std::chrono::system_clock::time_point': ['<chrono>'],
412     }
413
414     headers = []
415     for header_info in header_infos_and_types['header_infos']:
416         headers += header_info['headers']
417
418     for type in header_infos_and_types['types']:
419         if type in special_cases:
420             headers += special_cases[type]
421             continue
422
423         # We assume that we must include a header for a type iff it has a scope
424         # resolution operator (::).
425         split = type.split('::')
426         if len(split) < 2:
427             continue
428
429         if split[0] == 'WebKit' or split[0] == 'IPC':
430             headers.append('"%s.h"' % split[1])
431         else:
432             headers.append('<%s/%s.h>' % tuple(split[0:2]))
433
434     return headers
435
436
437 def generate_message_handler(file):
438     receiver = parser.parse(file)
439     header_conditions = {
440         '"%s"' % messages_header_filename(receiver): [None],
441         '"HandleMessage.h"': [None],
442         '"Decoder.h"': [None],
443     }
444
445     type_conditions = {}
446     for parameter in receiver.iterparameters():
447         if not parameter.type in type_conditions:
448             type_conditions[parameter.type] = []
449
450         if not parameter.condition in type_conditions[parameter.type]:
451             type_conditions[parameter.type].append(parameter.condition)
452
453     for parameter in receiver.iterparameters():
454         type = parameter.type
455         conditions = type_conditions[type]
456
457         argument_encoder_headers = argument_coder_headers_for_type(type)
458         if argument_encoder_headers:
459             for header in argument_encoder_headers:
460                 if header not in header_conditions:
461                     header_conditions[header] = []
462                 header_conditions[header].extend(conditions)
463
464         type_headers = headers_for_type(type)
465         for header in type_headers:
466             if header not in header_conditions:
467                 header_conditions[header] = []
468             header_conditions[header].extend(conditions)
469
470     for message in receiver.messages:
471         if message.reply_parameters is not None:
472             for reply_parameter in message.reply_parameters:
473                 type = reply_parameter.type
474                 argument_encoder_headers = argument_coder_headers_for_type(type)
475                 if argument_encoder_headers:
476                     for header in argument_encoder_headers:
477                         if header not in header_conditions:
478                             header_conditions[header] = []
479                         header_conditions[header].append(message.condition)
480
481                 type_headers = headers_for_type(type)
482                 for header in type_headers:
483                     if header not in header_conditions:
484                         header_conditions[header] = []
485                     header_conditions[header].append(message.condition)
486
487     result = []
488
489     result.append(_license_header)
490     result.append('#include "config.h"\n')
491     result.append('\n')
492
493     if receiver.condition:
494         result.append('#if %s\n\n' % receiver.condition)
495
496     result.append('#include "%s.h"\n\n' % receiver.name)
497     for header in sorted(header_conditions):
498         if header_conditions[header] and not None in header_conditions[header]:
499             result.append('#if %s\n' % ' || '.join(set(header_conditions[header])))
500             result += ['#include %s\n' % header]
501             result.append('#endif\n')
502         else:
503             result += ['#include %s\n' % header]
504     result.append('\n')
505
506     sync_delayed_messages = []
507     for message in receiver.messages:
508         if message.reply_parameters != None and message.has_attribute(DELAYED_ATTRIBUTE):
509             sync_delayed_messages.append(message)
510
511     if sync_delayed_messages:
512         result.append('namespace Messages {\n\nnamespace %s {\n\n' % receiver.name)
513
514         for message in sync_delayed_messages:
515             send_parameters = [(function_parameter_type(x.type, x.kind), x.name) for x in message.reply_parameters]
516
517             if message.condition:
518                 result.append('#if %s\n\n' % message.condition)
519
520             result.append('%s::DelayedReply::DelayedReply(Ref<IPC::Connection>&& connection, std::unique_ptr<IPC::Encoder> encoder)\n' % message.name)
521             result.append('    : m_connection(WTFMove(connection))\n')
522             result.append('    , m_encoder(WTFMove(encoder))\n')
523             result.append('{\n')
524             result.append('}\n')
525             result.append('\n')
526             result.append('%s::DelayedReply::~DelayedReply()\n' % message.name)
527             result.append('{\n')
528             result.append('    ASSERT(!m_connection);\n')
529             result.append('}\n')
530             result.append('\n')
531             result.append('bool %s::DelayedReply::send(%s)\n' % (message.name, ', '.join([' '.join(x) for x in send_parameters])))
532             result.append('{\n')
533             result.append('    ASSERT(m_encoder);\n')
534             result += ['    *m_encoder << %s;\n' % x.name for x in message.reply_parameters]
535             result.append('    bool _result = m_connection->sendSyncReply(WTFMove(m_encoder));\n')
536             result.append('    m_connection = nullptr;\n')
537             result.append('    return _result;\n')
538             result.append('}\n')
539             result.append('\n')
540
541             if message.condition:
542                 result.append('#endif\n\n')
543
544         result.append('} // namespace %s\n\n} // namespace Messages\n\n' % receiver.name)
545
546     result.append('namespace WebKit {\n\n')
547
548     async_messages = []
549     sync_messages = []
550     for message in receiver.messages:
551         if message.reply_parameters is not None:
552             sync_messages.append(message)
553         else:
554             async_messages.append(message)
555
556     if async_messages:
557         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 ''))
558         result.append('{\n')
559         result += [async_message_statement(receiver, message) for message in async_messages]
560         if (receiver.superclass):
561             result.append('    %s::didReceiveMessage(connection, decoder);\n' % (receiver.superclass))
562         else:
563             result.append('    UNUSED_PARAM(connection);\n')
564             result.append('    UNUSED_PARAM(decoder);\n')
565             result.append('    ASSERT_NOT_REACHED();\n')
566         result.append('}\n')
567
568     if sync_messages:
569         result.append('\n')
570         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 ''))
571         result.append('{\n')
572         result += [sync_message_statement(receiver, message) for message in sync_messages]
573         result.append('    UNUSED_PARAM(connection);\n')
574         result.append('    UNUSED_PARAM(decoder);\n')
575         result.append('    UNUSED_PARAM(replyEncoder);\n')
576         result.append('    ASSERT_NOT_REACHED();\n')
577         result.append('}\n')
578
579     result.append('\n} // namespace WebKit\n')
580
581     if receiver.condition:
582         result.append('\n#endif // %s\n' % receiver.condition)
583
584     return ''.join(result)