WebProcessConnection.cpp [plain text]
#include "config.h"
#include "WebProcessConnection.h"
#if ENABLE(PLUGIN_PROCESS)
#include "ArgumentCoders.h"
#include "NPRemoteObjectMap.h"
#include "PluginControllerProxy.h"
#include "PluginCreationParameters.h"
#include "PluginProcess.h"
#include "PluginProcessConnectionMessages.h"
#include <WebCore/RunLoop.h>
using namespace WebCore;
namespace WebKit {
class ConnectionStack {
public:
CoreIPC::Connection* current()
{
return m_connectionStack.last();
}
class CurrentConnectionPusher {
public:
CurrentConnectionPusher(ConnectionStack& connectionStack, CoreIPC::Connection* connection)
: m_connectionStack(connectionStack)
#if !ASSERT_DISABLED
, m_connection(connection)
#endif
{
m_connectionStack.m_connectionStack.append(connection);
}
~CurrentConnectionPusher()
{
ASSERT(m_connectionStack.current() == m_connection);
m_connectionStack.m_connectionStack.removeLast();
}
private:
ConnectionStack& m_connectionStack;
#if !ASSERT_DISABLED
CoreIPC::Connection* m_connection;
#endif
};
private:
Vector<CoreIPC::Connection*, 4> m_connectionStack;
};
static ConnectionStack& connectionStack()
{
DEFINE_STATIC_LOCAL(ConnectionStack, connectionStack, ());
return connectionStack;
}
PassRefPtr<WebProcessConnection> WebProcessConnection::create(CoreIPC::Connection::Identifier connectionIdentifier)
{
return adoptRef(new WebProcessConnection(connectionIdentifier));
}
WebProcessConnection::~WebProcessConnection()
{
ASSERT(m_pluginControllers.isEmpty());
ASSERT(!m_npRemoteObjectMap);
ASSERT(!m_connection);
}
WebProcessConnection::WebProcessConnection(CoreIPC::Connection::Identifier connectionIdentifier)
{
m_connection = CoreIPC::Connection::createServerConnection(connectionIdentifier, this, RunLoop::main());
m_npRemoteObjectMap = NPRemoteObjectMap::create(m_connection.get());
m_connection->setOnlySendMessagesAsDispatchWhenWaitingForSyncReplyWhenProcessingSuchAMessage(true);
m_connection->open();
}
void WebProcessConnection::addPluginControllerProxy(PassOwnPtr<PluginControllerProxy> pluginController)
{
uint64_t pluginInstanceID = pluginController->pluginInstanceID();
ASSERT(!m_pluginControllers.contains(pluginInstanceID));
m_pluginControllers.set(pluginInstanceID, pluginController.leakPtr());
}
void WebProcessConnection::destroyPluginControllerProxy(PluginControllerProxy* pluginController)
{
pluginController->destroy();
}
void WebProcessConnection::removePluginControllerProxy(PluginControllerProxy* pluginController, Plugin* plugin)
{
{
ASSERT(m_pluginControllers.contains(pluginController->pluginInstanceID()));
OwnPtr<PluginControllerProxy> pluginControllerOwnPtr = adoptPtr(m_pluginControllers.take(pluginController->pluginInstanceID()));
ASSERT(pluginControllerOwnPtr == pluginController);
}
if (plugin)
m_npRemoteObjectMap->pluginDestroyed(plugin);
if (!m_pluginControllers.isEmpty())
return;
m_npRemoteObjectMap = nullptr;
m_connection->invalidate();
m_connection = nullptr;
PluginProcess::shared().removeWebProcessConnection(this);
}
void WebProcessConnection::setGlobalException(const String& exceptionString)
{
CoreIPC::Connection* connection = connectionStack().current();
if (!connection)
return;
connection->sendSync(Messages::PluginProcessConnection::SetException(exceptionString), Messages::PluginProcessConnection::SetException::Reply(), 0);
}
void WebProcessConnection::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments)
{
ConnectionStack::CurrentConnectionPusher currentConnection(connectionStack(), connection);
if (!arguments->destinationID()) {
ASSERT_NOT_REACHED();
return;
}
PluginControllerProxy* pluginControllerProxy = m_pluginControllers.get(arguments->destinationID());
if (!pluginControllerProxy)
return;
PluginController::PluginDestructionProtector protector(pluginControllerProxy->asPluginController());
pluginControllerProxy->didReceivePluginControllerProxyMessage(connection, messageID, arguments);
}
void WebProcessConnection::didReceiveSyncMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments, OwnPtr<CoreIPC::ArgumentEncoder>& reply)
{
ConnectionStack::CurrentConnectionPusher currentConnection(connectionStack(), connection);
uint64_t destinationID = arguments->destinationID();
if (!destinationID) {
didReceiveSyncWebProcessConnectionMessage(connection, messageID, arguments, reply);
return;
}
if (messageID.is<CoreIPC::MessageClassNPObjectMessageReceiver>()) {
m_npRemoteObjectMap->didReceiveSyncMessage(connection, messageID, arguments, reply);
return;
}
PluginControllerProxy* pluginControllerProxy = m_pluginControllers.get(arguments->destinationID());
if (!pluginControllerProxy)
return;
PluginController::PluginDestructionProtector protector(pluginControllerProxy->asPluginController());
pluginControllerProxy->didReceiveSyncPluginControllerProxyMessage(connection, messageID, arguments, reply);
}
void WebProcessConnection::didClose(CoreIPC::Connection*)
{
Vector<PluginControllerProxy*> pluginControllers;
copyValuesToVector(m_pluginControllers, pluginControllers);
for (size_t i = 0; i < pluginControllers.size(); ++i)
destroyPluginControllerProxy(pluginControllers[i]);
}
void WebProcessConnection::destroyPlugin(uint64_t pluginInstanceID)
{
PluginControllerProxy* pluginControllerProxy = m_pluginControllers.get(pluginInstanceID);
ASSERT(pluginControllerProxy);
destroyPluginControllerProxy(pluginControllerProxy);
}
void WebProcessConnection::didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::MessageID)
{
}
void WebProcessConnection::syncMessageSendTimedOut(CoreIPC::Connection*)
{
}
void WebProcessConnection::createPlugin(const PluginCreationParameters& creationParameters, bool& result, bool& wantsWheelEvents, uint32_t& remoteLayerClientID)
{
OwnPtr<PluginControllerProxy> pluginControllerProxy = PluginControllerProxy::create(this, creationParameters);
PluginControllerProxy* pluginControllerProxyPtr = pluginControllerProxy.get();
addPluginControllerProxy(pluginControllerProxy.release());
result = pluginControllerProxyPtr->initialize(creationParameters);
if (!result)
return;
wantsWheelEvents = pluginControllerProxyPtr->wantsWheelEvents();
#if PLATFORM(MAC)
remoteLayerClientID = pluginControllerProxyPtr->remoteLayerClientID();
#endif
}
}
#endif // ENABLE(PLUGIN_PROCESS)