ProcessLauncherWin.cpp [plain text]
#include "config.h"
#include "ProcessLauncher.h"
#include "Connection.h"
#include <WebCore/RunLoop.h>
#include <shlwapi.h>
#include <wtf/text/WTFString.h>
#ifdef DEBUG_ALL
const LPCWSTR webProcessName = L"WebKit2WebProcess_debug.exe";
#else
const LPCWSTR webProcessName = L"WebKit2WebProcess.exe";
#endif
#ifdef DEBUG_ALL
const LPCWSTR webKitDLLName = L"WebKit_debug.dll";
#else
const LPCWSTR webKitDLLName = L"WebKit.dll";
#endif
using namespace WebCore;
namespace WebKit {
void ProcessLauncher::launchProcess()
{
HANDLE serverIdentifier, clientIdentifier;
if (!CoreIPC::Connection::createServerAndClientIdentifiers(serverIdentifier, clientIdentifier)) {
ASSERT_NOT_REACHED();
}
::SetHandleInformation(clientIdentifier, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
HMODULE webKitModule = ::GetModuleHandleW(webKitDLLName);
ASSERT(webKitModule);
if (!webKitModule)
return;
WCHAR pathStr[MAX_PATH];
if (!::GetModuleFileNameW(webKitModule, pathStr, WTF_ARRAY_LENGTH(pathStr)))
return;
::PathRemoveFileSpecW(pathStr);
if (!::PathAppendW(pathStr, webProcessName))
return;
String commandLine(pathStr);
Vector<UChar> commandLineVector;
append(commandLineVector, "\"");
append(commandLineVector, commandLine);
append(commandLineVector, "\"");
append(commandLineVector, " -type webprocess");
append(commandLineVector, " -clientIdentifier ");
append(commandLineVector, String::number(reinterpret_cast<uintptr_t>(clientIdentifier)));
commandLineVector.append('\0');
STARTUPINFO startupInfo = { 0 };
startupInfo.cb = sizeof(startupInfo);
PROCESS_INFORMATION processInformation = { 0 };
BOOL result = ::CreateProcessW(0, commandLineVector.data(), 0, 0, true, 0, 0, 0, &startupInfo, &processInformation);
::CloseHandle(clientIdentifier);
if (!result) {
DWORD error = ::GetLastError();
ASSERT_NOT_REACHED();
}
::CloseHandle(processInformation.hThread);
RunLoop::main()->dispatch(bind(&ProcessLauncher::didFinishLaunchingProcess, this, processInformation.hProcess, serverIdentifier));
}
void ProcessLauncher::terminateProcess()
{
if (!m_processIdentifier)
return;
::TerminateProcess(m_processIdentifier, 0);
}
void ProcessLauncher::platformInvalidate()
{
if (!m_processIdentifier)
return;
::CloseHandle(m_processIdentifier);
m_processIdentifier = 0;
}
}