2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include "PluginProcess.h"
29 #if ENABLE(PLUGIN_PROCESS)
32 #include "NetscapePluginModule.h"
33 #include "PluginProcessProxyMessages.h"
34 #include "PluginProcessCreationParameters.h"
35 #include "WebProcessConnection.h"
39 static const double shutdownTimeout = 15.0;
41 PluginProcess& PluginProcess::shared()
43 DEFINE_STATIC_LOCAL(PluginProcess, pluginProcess, ());
47 PluginProcess::PluginProcess()
48 : m_shutdownTimer(RunLoop::main(), this, &PluginProcess::shutdownTimerFired)
49 #if USE(ACCELERATED_COMPOSITING) && PLATFORM(MAC)
50 , m_compositingRenderServerPort(MACH_PORT_NULL)
55 PluginProcess::~PluginProcess()
59 void PluginProcess::initialize(CoreIPC::Connection::Identifier serverIdentifier, RunLoop* runLoop)
61 ASSERT(!m_connection);
63 m_connection = CoreIPC::Connection::createClientConnection(serverIdentifier, this, runLoop);
64 m_connection->setDidCloseOnConnectionWorkQueueCallback(didCloseOnConnectionWorkQueue);
68 void PluginProcess::removeWebProcessConnection(WebProcessConnection* webProcessConnection)
70 size_t vectorIndex = m_webProcessConnections.find(webProcessConnection);
71 ASSERT(vectorIndex != notFound);
73 m_webProcessConnections.remove(vectorIndex);
75 if (m_webProcessConnections.isEmpty()) {
76 // Start the shutdown timer.
77 m_shutdownTimer.startOneShot(shutdownTimeout);
81 NetscapePluginModule* PluginProcess::netscapePluginModule()
83 if (!m_pluginModule) {
84 ASSERT(!m_pluginPath.isNull());
85 m_pluginModule = NetscapePluginModule::getOrCreate(m_pluginPath);
89 if (m_pluginModule->pluginQuirks().contains(PluginQuirks::PrognameShouldBeWebKitPluginHost))
90 setprogname("WebKitPluginHost");
95 return m_pluginModule.get();
98 void PluginProcess::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments)
100 didReceivePluginProcessMessage(connection, messageID, arguments);
103 void PluginProcess::didClose(CoreIPC::Connection*)
105 // The UI process has crashed, just go ahead and quit.
106 // FIXME: If the plug-in is spinning in the main loop, we'll never get this message.
107 RunLoop::current()->stop();
110 void PluginProcess::didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::MessageID)
114 NO_RETURN void PluginProcess::didFailToSendSyncMessage(CoreIPC::Connection*)
116 // We were making a synchronous call to a web process that doesn't exist any more.
117 // Callers are unlikely to be prepared for an error like this, so it's best to exit immediately.
121 void PluginProcess::initializePluginProcess(const PluginProcessCreationParameters& parameters)
123 ASSERT(!m_pluginModule);
125 m_pluginPath = parameters.pluginPath;
127 platformInitialize(parameters);
130 void PluginProcess::createWebProcessConnection()
132 // FIXME: This is platform specific!
134 // Create the listening port.
135 mach_port_t listeningPort;
136 mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &listeningPort);
138 // Create a listening connection.
139 RefPtr<WebProcessConnection> connection = WebProcessConnection::create(listeningPort);
140 m_webProcessConnections.append(connection.release());
142 CoreIPC::MachPort clientPort(listeningPort, MACH_MSG_TYPE_MAKE_SEND);
143 m_connection->send(Messages::PluginProcessProxy::DidCreateWebProcessConnection(clientPort), 0);
145 // Stop the shutdown timer.
146 m_shutdownTimer.stop();
149 void PluginProcess::shutdownTimerFired()
151 RunLoop::current()->stop();
154 } // namespace WebKit
156 #endif // ENABLE(PLUGIN_PROCESS)