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