1/*
2 * Copyright (C) 2010-2018 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
17 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
21 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25#include "config.h"
26
27#include "WebProcessPool.h"
28
29#include "ArgumentCoders.h"
30#include "Decoder.h"
31#include "HandleMessage.h"
32#include "StatisticsData.h"
33#include "UserData.h"
34#include "WebCoreArgumentCoders.h"
35#include "WebProcessPoolMessages.h"
36#if ENABLE(SERVICE_WORKER)
37#include <WebCore/MessageWithMessagePorts.h>
38#endif
39#include <WebCore/ProcessIdentifier.h>
40#if ENABLE(SERVICE_WORKER)
41#include <WebCore/ServiceWorkerClientIdentifier.h>
42#endif
43#if ENABLE(SERVICE_WORKER)
44#include <WebCore/ServiceWorkerIdentifier.h>
45#endif
46#if ENABLE(SERVICE_WORKER)
47#include <WebCore/ServiceWorkerTypes.h>
48#endif
49#include <pal/SessionID.h>
50#include <wtf/Seconds.h>
51#include <wtf/text/WTFString.h>
52
53namespace Messages {
54
55namespace WebProcessPool {
56
57void HandleSynchronousMessage::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, const WebKit::UserData& returnData)
58{
59 *encoder << returnData;
60 connection.sendSyncReply(WTFMove(encoder));
61}
62
63} // namespace WebProcessPool
64
65} // namespace Messages
66
67namespace WebKit {
68
69void WebProcessPool::didReceiveMessage(IPC::Connection& connection, IPC::Decoder& decoder)
70{
71 if (decoder.messageName() == Messages::WebProcessPool::HandleMessage::name()) {
72 IPC::handleMessage<Messages::WebProcessPool::HandleMessage>(connection, decoder, this, &WebProcessPool::handleMessage);
73 return;
74 }
75 if (decoder.messageName() == Messages::WebProcessPool::DidGetStatistics::name()) {
76 IPC::handleMessage<Messages::WebProcessPool::DidGetStatistics>(decoder, this, &WebProcessPool::didGetStatistics);
77 return;
78 }
79#if ENABLE(GAMEPAD)
80 if (decoder.messageName() == Messages::WebProcessPool::StartedUsingGamepads::name()) {
81 IPC::handleMessage<Messages::WebProcessPool::StartedUsingGamepads>(connection, decoder, this, &WebProcessPool::startedUsingGamepads);
82 return;
83 }
84#endif
85#if ENABLE(GAMEPAD)
86 if (decoder.messageName() == Messages::WebProcessPool::StoppedUsingGamepads::name()) {
87 IPC::handleMessage<Messages::WebProcessPool::StoppedUsingGamepads>(connection, decoder, this, &WebProcessPool::stoppedUsingGamepads);
88 return;
89 }
90#endif
91 if (decoder.messageName() == Messages::WebProcessPool::AddPlugInAutoStartOriginHash::name()) {
92 IPC::handleMessage<Messages::WebProcessPool::AddPlugInAutoStartOriginHash>(decoder, this, &WebProcessPool::addPlugInAutoStartOriginHash);
93 return;
94 }
95 if (decoder.messageName() == Messages::WebProcessPool::PlugInDidReceiveUserInteraction::name()) {
96 IPC::handleMessage<Messages::WebProcessPool::PlugInDidReceiveUserInteraction>(decoder, this, &WebProcessPool::plugInDidReceiveUserInteraction);
97 return;
98 }
99 if (decoder.messageName() == Messages::WebProcessPool::ReportWebContentCPUTime::name()) {
100 IPC::handleMessage<Messages::WebProcessPool::ReportWebContentCPUTime>(decoder, this, &WebProcessPool::reportWebContentCPUTime);
101 return;
102 }
103 if (decoder.messageName() == Messages::WebProcessPool::SetWebProcessHasUploads::name()) {
104 IPC::handleMessage<Messages::WebProcessPool::SetWebProcessHasUploads>(decoder, this, &WebProcessPool::setWebProcessHasUploads);
105 return;
106 }
107 if (decoder.messageName() == Messages::WebProcessPool::ClearWebProcessHasUploads::name()) {
108 IPC::handleMessage<Messages::WebProcessPool::ClearWebProcessHasUploads>(decoder, this, &WebProcessPool::clearWebProcessHasUploads);
109 return;
110 }
111#if ENABLE(SERVICE_WORKER)
112 if (decoder.messageName() == Messages::WebProcessPool::PostMessageToServiceWorkerClient::name()) {
113 IPC::handleMessage<Messages::WebProcessPool::PostMessageToServiceWorkerClient>(decoder, this, &WebProcessPool::postMessageToServiceWorkerClient);
114 return;
115 }
116#endif
117#if ENABLE(SERVICE_WORKER)
118 if (decoder.messageName() == Messages::WebProcessPool::PostMessageToServiceWorker::name()) {
119 IPC::handleMessage<Messages::WebProcessPool::PostMessageToServiceWorker>(decoder, this, &WebProcessPool::postMessageToServiceWorker);
120 return;
121 }
122#endif
123 UNUSED_PARAM(connection);
124 UNUSED_PARAM(decoder);
125 ASSERT_NOT_REACHED();
126}
127
128void WebProcessPool::didReceiveSyncMessage(IPC::Connection& connection, IPC::Decoder& decoder, std::unique_ptr<IPC::Encoder>& replyEncoder)
129{
130 if (decoder.messageName() == Messages::WebProcessPool::HandleSynchronousMessage::name()) {
131 IPC::handleMessageSynchronousWantsConnection<Messages::WebProcessPool::HandleSynchronousMessage>(connection, decoder, replyEncoder, this, &WebProcessPool::handleSynchronousMessage);
132 return;
133 }
134 UNUSED_PARAM(connection);
135 UNUSED_PARAM(decoder);
136 UNUSED_PARAM(replyEncoder);
137 ASSERT_NOT_REACHED();
138}
139
140} // namespace WebKit
141
142