diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebKit2/UIProcess/Launcher | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebKit2/UIProcess/Launcher')
3 files changed, 52 insertions, 109 deletions
diff --git a/Source/WebKit2/UIProcess/Launcher/ProcessLauncher.cpp b/Source/WebKit2/UIProcess/Launcher/ProcessLauncher.cpp index f20c19c5a..089c17c33 100644 --- a/Source/WebKit2/UIProcess/Launcher/ProcessLauncher.cpp +++ b/Source/WebKit2/UIProcess/Launcher/ProcessLauncher.cpp @@ -26,42 +26,32 @@ #include "config.h" #include "ProcessLauncher.h" -#include "WorkQueue.h" #include <wtf/StdLibExtras.h> +#include <wtf/WorkQueue.h> namespace WebKit { -static WorkQueue* processLauncherWorkQueue() -{ - static WorkQueue* processLauncherWorkQueue = WorkQueue::create("com.apple.WebKit.ProcessLauncher").leakRef(); - return processLauncherWorkQueue; -} - ProcessLauncher::ProcessLauncher(Client* client, const LaunchOptions& launchOptions) : m_client(client) + , m_weakPtrFactory(this) , m_launchOptions(launchOptions) , m_processIdentifier(0) { - // Launch the process. m_isLaunching = true; - processLauncherWorkQueue()->dispatch(bind(&ProcessLauncher::launchProcess, this)); + launchProcess(); } -void ProcessLauncher::didFinishLaunchingProcess(PlatformProcessIdentifier processIdentifier, IPC::Connection::Identifier identifier) +void ProcessLauncher::didFinishLaunchingProcess(pid_t processIdentifier, IPC::Connection::Identifier identifier) { m_processIdentifier = processIdentifier; m_isLaunching = false; if (!m_client) { // FIXME: Make Identifier a move-only object and release port rights/connections in the destructor. -#if PLATFORM(MAC) +#if OS(DARWIN) && !PLATFORM(GTK) + // FIXME: Should really be something like USE(MACH) if (identifier.port) mach_port_mod_refs(mach_task_self(), identifier.port, MACH_PORT_RIGHT_RECEIVE, -1); - - if (identifier.xpcConnection) { - xpc_release(identifier.xpcConnection); - identifier.xpcConnection = 0; - } #endif return; } @@ -75,57 +65,4 @@ void ProcessLauncher::invalidate() platformInvalidate(); } -const char* ProcessLauncher::processTypeAsString(ProcessType processType) -{ - switch (processType) { - case WebProcess: - return "webprocess"; -#if ENABLE(NETSCAPE_PLUGIN_API) - case PluginProcess: - return "pluginprocess"; -#endif -#if ENABLE(NETWORK_PROCESS) - case NetworkProcess: - return "networkprocess"; -#endif -#if ENABLE(DATABASE_PROCESS) - case DatabaseProcess: - return "databaseprocess"; -#endif - } - - ASSERT_NOT_REACHED(); - return 0; -} - -bool ProcessLauncher::getProcessTypeFromString(const char* string, ProcessType& processType) -{ - if (!strcmp(string, "webprocess")) { - processType = WebProcess; - return true; - } - -#if ENABLE(NETSCAPE_PLUGIN_API) - if (!strcmp(string, "pluginprocess")) { - processType = PluginProcess; - return true; - } -#endif - -#if ENABLE(NETWORK_PROCESS) - if (!strcmp(string, "networkprocess")) { - processType = NetworkProcess; - return true; - } -#endif - -#if ENABLE(DATABASE_PROCESS) - if (!strcmp(string, "databaseprocess")) { - processType = DatabaseProcess; - return true; - } -#endif - return false; -} - } // namespace WebKit diff --git a/Source/WebKit2/UIProcess/Launcher/ProcessLauncher.h b/Source/WebKit2/UIProcess/Launcher/ProcessLauncher.h index 6996bfe64..399506948 100644 --- a/Source/WebKit2/UIProcess/Launcher/ProcessLauncher.h +++ b/Source/WebKit2/UIProcess/Launcher/ProcessLauncher.h @@ -23,14 +23,13 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef WebProcessLauncher_h -#define WebProcessLauncher_h +#pragma once #include "Connection.h" -#include "PlatformProcessIdentifier.h" #include <wtf/HashMap.h> #include <wtf/RefPtr.h> #include <wtf/Threading.h> +#include <wtf/WeakPtr.h> #include <wtf/text/StringHash.h> #include <wtf/text/WTFString.h> @@ -45,64 +44,56 @@ public: virtual void didFinishLaunching(ProcessLauncher*, IPC::Connection::Identifier) = 0; }; - enum ProcessType { - WebProcess, + enum class ProcessType { + Web, #if ENABLE(NETSCAPE_PLUGIN_API) - PluginProcess, -#endif -#if ENABLE(NETWORK_PROCESS) - NetworkProcess, + Plugin32, + Plugin64, #endif + Network, #if ENABLE(DATABASE_PROCESS) - DatabaseProcess, + Database, #endif }; struct LaunchOptions { ProcessType processType; HashMap<String, String> extraInitializationData; -#if PLATFORM(MAC) - static const cpu_type_t MatchCurrentArchitecture = 0; - cpu_type_t architecture; - bool executableHeap; - bool useXPC; -#endif -#if PLATFORM(EFL) || PLATFORM(GTK) -#ifndef NDEBUG + +#if ENABLE(DEVELOPER_MODE) && PLATFORM(GTK) String processCmdPrefix; #endif -#endif }; - static PassRefPtr<ProcessLauncher> create(Client* client, const LaunchOptions& launchOptions) + static Ref<ProcessLauncher> create(Client* client, const LaunchOptions& launchOptions) { - return adoptRef(new ProcessLauncher(client, launchOptions)); + return adoptRef(*new ProcessLauncher(client, launchOptions)); } bool isLaunching() const { return m_isLaunching; } - PlatformProcessIdentifier processIdentifier() const { return m_processIdentifier; } + pid_t processIdentifier() const { return m_processIdentifier; } void terminateProcess(); void invalidate(); - static bool getProcessTypeFromString(const char*, ProcessType&); - static const char* processTypeAsString(ProcessType); - private: ProcessLauncher(Client*, const LaunchOptions& launchOptions); void launchProcess(); - void didFinishLaunchingProcess(PlatformProcessIdentifier, IPC::Connection::Identifier); + void didFinishLaunchingProcess(pid_t, IPC::Connection::Identifier); void platformInvalidate(); Client* m_client; +#if PLATFORM(COCOA) + OSObjectPtr<xpc_connection_t> m_xpcConnection; +#endif + + WeakPtrFactory<ProcessLauncher> m_weakPtrFactory; const LaunchOptions m_launchOptions; bool m_isLaunching; - PlatformProcessIdentifier m_processIdentifier; + pid_t m_processIdentifier; }; } // namespace WebKit - -#endif // WebProcessLauncher_h diff --git a/Source/WebKit2/UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp b/Source/WebKit2/UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp index 89d367c77..add147995 100644 --- a/Source/WebKit2/UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp +++ b/Source/WebKit2/UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp @@ -38,10 +38,11 @@ #include <glib.h> #include <locale.h> #include <wtf/RunLoop.h> +#include <wtf/UniStdExtras.h> +#include <wtf/glib/GLibUtilities.h> +#include <wtf/glib/GUniquePtr.h> #include <wtf/text/CString.h> #include <wtf/text/WTFString.h> -#include <wtf/gobject/GUniquePtr.h> -#include <wtf/gobject/GlibUtilities.h> using namespace WebCore; @@ -62,18 +63,28 @@ void ProcessLauncher::launchProcess() String executablePath, pluginPath; CString realExecutablePath, realPluginPath; switch (m_launchOptions.processType) { - case WebProcess: + case ProcessLauncher::ProcessType::Web: executablePath = executablePathOfWebProcess(); break; - case PluginProcess: +#if ENABLE(NETSCAPE_PLUGIN_API) + case ProcessLauncher::ProcessType::Plugin64: + case ProcessLauncher::ProcessType::Plugin32: executablePath = executablePathOfPluginProcess(); +#if ENABLE(PLUGIN_PROCESS_GTK2) + if (m_launchOptions.extraInitializationData.contains("requires-gtk2")) + executablePath.append('2'); +#endif pluginPath = m_launchOptions.extraInitializationData.get("plugin-path"); realPluginPath = fileSystemRepresentation(pluginPath); break; -#if ENABLE(NETWORK_PROCESS) - case NetworkProcess: +#endif + case ProcessLauncher::ProcessType::Network: executablePath = executablePathOfNetworkProcess(); break; +#if ENABLE(DATABASE_PROCESS) + case ProcessLauncher::ProcessType::Database: + executablePath = executablePathOfDatabaseProcess(); + break; #endif default: ASSERT_NOT_REACHED(); @@ -85,7 +96,7 @@ void ProcessLauncher::launchProcess() unsigned nargs = 4; // size of the argv array for g_spawn_async() -#ifndef NDEBUG +#if ENABLE(DEVELOPER_MODE) Vector<CString> prefixArgs; if (!m_launchOptions.processCmdPrefix.isNull()) { Vector<String> splitArgs; @@ -98,7 +109,7 @@ void ProcessLauncher::launchProcess() char** argv = g_newa(char*, nargs); unsigned i = 0; -#ifndef NDEBUG +#if ENABLE(DEVELOPER_MODE) // If there's a prefix command, put it before the rest of the args. for (auto it = prefixArgs.begin(); it != prefixArgs.end(); it++) argv[i++] = const_cast<char*>(it->data()); @@ -115,14 +126,18 @@ void ProcessLauncher::launchProcess() } // Don't expose the parent socket to potential future children. - while (fcntl(socketPair.client, F_SETFD, FD_CLOEXEC) == -1) - RELEASE_ASSERT(errno != EINTR); + if (!setCloseOnExec(socketPair.client)) + RELEASE_ASSERT_NOT_REACHED(); close(socketPair.client); m_processIdentifier = pid; // We've finished launching the process, message back to the main run loop. - RunLoop::main()->dispatch(bind(&ProcessLauncher::didFinishLaunchingProcess, this, m_processIdentifier, socketPair.server)); + RefPtr<ProcessLauncher> protector(this); + IPC::Connection::Identifier serverSocket = socketPair.server; + RunLoop::main().dispatch([protector, pid, serverSocket] { + protector->didFinishLaunchingProcess(pid, serverSocket); + }); } void ProcessLauncher::terminateProcess() |