PluginProcess.cpp revision 65f03d4f644ce73618e5f4f50dd694b26f55ae12
1/* 2 * Copyright (C) 2010 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'' 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. 24 */ 25 26#if ENABLE(PLUGIN_PROCESS) 27 28#include "PluginProcess.h" 29 30#include "MachPort.h" 31#include "NetscapePluginModule.h" 32#include "PluginProcessProxyMessages.h" 33#include "PluginProcessCreationParameters.h" 34#include "WebProcessConnection.h" 35 36namespace WebKit { 37 38static const double shutdownTimeout = 15.0; 39 40PluginProcess& PluginProcess::shared() 41{ 42 DEFINE_STATIC_LOCAL(PluginProcess, pluginProcess, ()); 43 return pluginProcess; 44} 45 46PluginProcess::PluginProcess() 47 : m_shutdownTimer(RunLoop::main(), this, &PluginProcess::shutdownTimerFired) 48#if USE(ACCELERATED_COMPOSITING) && PLATFORM(MAC) 49 , m_compositingRenderServerPort(MACH_PORT_NULL) 50#endif 51{ 52} 53 54PluginProcess::~PluginProcess() 55{ 56} 57 58void PluginProcess::initializeConnection(CoreIPC::Connection::Identifier serverIdentifier) 59{ 60 ASSERT(!m_connection); 61 62 m_connection = CoreIPC::Connection::createClientConnection(serverIdentifier, this, RunLoop::main()); 63 m_connection->open(); 64} 65 66void PluginProcess::removeWebProcessConnection(WebProcessConnection* webProcessConnection) 67{ 68 size_t vectorIndex = m_webProcessConnections.find(webProcessConnection); 69 ASSERT(vectorIndex != notFound); 70 71 m_webProcessConnections.remove(vectorIndex); 72 73 if (m_webProcessConnections.isEmpty()) { 74 // Start the shutdown timer. 75 m_shutdownTimer.startOneShot(shutdownTimeout); 76 } 77} 78 79NetscapePluginModule* PluginProcess::netscapePluginModule() 80{ 81 if (!m_pluginModule) { 82 ASSERT(!m_pluginPath.isNull()); 83 m_pluginModule = NetscapePluginModule::getOrCreate(m_pluginPath); 84 85#if PLATFORM(MAC) 86 if (m_pluginModule) { 87 if (m_pluginModule->pluginQuirks().contains(PluginQuirks::PrognameShouldBeWebKitPluginHost)) 88 setprogname("WebKitPluginHost"); 89 } 90#endif 91 } 92 93 return m_pluginModule.get(); 94} 95 96void PluginProcess::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments) 97{ 98 didReceivePluginProcessMessage(connection, messageID, arguments); 99} 100 101void PluginProcess::didClose(CoreIPC::Connection*) 102{ 103 // The UI process has crashed, just go ahead and quit. 104 // FIXME: If the plug-in is spinning in the main loop, we'll never get this message. 105 RunLoop::current()->stop(); 106} 107 108void PluginProcess::didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::MessageID) 109{ 110} 111 112void PluginProcess::initialize(const PluginProcessCreationParameters& parameters) 113{ 114 ASSERT(!m_pluginModule); 115 116 m_pluginPath = parameters.pluginPath; 117 118#if USE(ACCELERATED_COMPOSITING) && PLATFORM(MAC) 119 m_compositingRenderServerPort = parameters.acceleratedCompositingPort.port(); 120#endif 121} 122 123void PluginProcess::createWebProcessConnection() 124{ 125 // FIXME: This is platform specific! 126 127 // Create the listening port. 128 mach_port_t listeningPort; 129 mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &listeningPort); 130 131 // Create a listening connection. 132 RefPtr<WebProcessConnection> connection = WebProcessConnection::create(listeningPort); 133 m_webProcessConnections.append(connection.release()); 134 135 CoreIPC::MachPort clientPort(listeningPort, MACH_MSG_TYPE_MAKE_SEND); 136 m_connection->send(Messages::PluginProcessProxy::DidCreateWebProcessConnection(clientPort), 0); 137 138 // Stop the shutdown timer. 139 m_shutdownTimer.stop(); 140} 141 142void PluginProcess::shutdownTimerFired() 143{ 144 RunLoop::current()->stop(); 145} 146 147} // namespace WebKit 148 149#endif // ENABLE(PLUGIN_PROCESS) 150 151