PluginProcessConnectionManager.cpp [plain text]
#include "config.h"
#include "PluginProcessConnectionManager.h"
#if ENABLE(PLUGIN_PROCESS)
#include "ArgumentDecoder.h"
#include "ArgumentEncoder.h"
#include "PluginProcessConnection.h"
#include "WebCoreArgumentCoders.h"
#include "WebProcess.h"
#include "WebProcessProxyMessages.h"
#if PLATFORM(MAC)
#include "MachPort.h"
#endif
namespace WebKit {
PluginProcessConnectionManager::PluginProcessConnectionManager()
{
}
PluginProcessConnectionManager::~PluginProcessConnectionManager()
{
}
PluginProcessConnection* PluginProcessConnectionManager::getPluginProcessConnection(const String& pluginPath)
{
for (size_t i = 0; i < m_pluginProcessConnections.size(); ++i) {
if (m_pluginProcessConnections[i]->pluginPath() == pluginPath)
return m_pluginProcessConnections[i].get();
}
CoreIPC::Attachment encodedConnectionIdentifier;
if (!WebProcess::shared().connection()->sendSync(Messages::WebProcessProxy::GetPluginProcessConnection(pluginPath),
Messages::WebProcessProxy::GetPluginProcessConnection::Reply(encodedConnectionIdentifier), 0))
return 0;
#if PLATFORM(MAC)
CoreIPC::Connection::Identifier connectionIdentifier = encodedConnectionIdentifier.port();
if (!connectionIdentifier)
return 0;
#elif USE(UNIX_DOMAIN_SOCKETS)
CoreIPC::Connection::Identifier connectionIdentifier = encodedConnectionIdentifier.fileDescriptor();
if (connectionIdentifier == -1)
return 0;
#endif
RefPtr<PluginProcessConnection> pluginProcessConnection = PluginProcessConnection::create(this, pluginPath, connectionIdentifier);
m_pluginProcessConnections.append(pluginProcessConnection);
{
MutexLocker locker(m_pathsAndConnectionsMutex);
ASSERT(!m_pathsAndConnections.contains(pluginProcessConnection->pluginPath()));
m_pathsAndConnections.set(pluginPath, pluginProcessConnection->connection());
}
return pluginProcessConnection.get();
}
void PluginProcessConnectionManager::removePluginProcessConnection(PluginProcessConnection* pluginProcessConnection)
{
size_t vectorIndex = m_pluginProcessConnections.find(pluginProcessConnection);
ASSERT(vectorIndex != notFound);
{
MutexLocker locker(m_pathsAndConnectionsMutex);
ASSERT(m_pathsAndConnections.contains(pluginProcessConnection->pluginPath()));
m_pathsAndConnections.remove(pluginProcessConnection->pluginPath());
}
m_pluginProcessConnections.remove(vectorIndex);
}
void PluginProcessConnectionManager::pluginProcessCrashed(const String& pluginPath)
{
MutexLocker locker(m_pathsAndConnectionsMutex);
CoreIPC::Connection* connection = m_pathsAndConnections.get(pluginPath).get();
if (!connection)
return;
connection->postConnectionDidCloseOnConnectionWorkQueue();
}
}
#endif // ENABLE(PLUGIN_PROCESS)