diff options
Diffstat (limited to 'Source/WebKit2/PluginProcess/unix/PluginProcessMainUnix.cpp')
-rw-r--r-- | Source/WebKit2/PluginProcess/unix/PluginProcessMainUnix.cpp | 109 |
1 files changed, 40 insertions, 69 deletions
diff --git a/Source/WebKit2/PluginProcess/unix/PluginProcessMainUnix.cpp b/Source/WebKit2/PluginProcess/unix/PluginProcessMainUnix.cpp index 6a4c26ef2..02a816b27 100644 --- a/Source/WebKit2/PluginProcess/unix/PluginProcessMainUnix.cpp +++ b/Source/WebKit2/PluginProcess/unix/PluginProcessMainUnix.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 Igalia S.L. + * Copyright (C) 2011, 2014 Igalia S.L. * Copyright (C) 2011 Apple Inc. * Copyright (C) 2012 Samsung Electronics * @@ -30,96 +30,67 @@ #if ENABLE(PLUGIN_PROCESS) +#include "ChildProcessMain.h" #include "Logging.h" #include "NetscapePlugin.h" #include "PluginProcess.h" -#include "WebKit2Initialize.h" -#include <libgen.h> -#include <wtf/RunLoop.h> +#include <WebCore/FileSystem.h> +#include <stdlib.h> + #if PLATFORM(GTK) #include <gtk/gtk.h> -#if PLATFORM(X11) && defined(GDK_WINDOWING_X11) -#include <gdk/gdkx.h> -#endif -#elif PLATFORM(EFL) && HAVE_ECORE_X -#include <Ecore_X.h> #endif -using namespace WebCore; +#if defined(XP_UNIX) +#include <WebCore/PlatformDisplayX11.h> +#include <WebCore/XErrorTrapper.h> +#endif namespace WebKit { -#ifdef XP_UNIX - -#if !LOG_DISABLED -static const char xErrorString[] = "The program '%s' received an X Window System error.\n" - "This probably reflects a bug in a browser plugin.\n" - "The error was '%s'.\n" - " (Details: serial %ld error_code %d request_code %d minor_code %d)\n"; -#endif /* !LOG_DISABLED */ - -static char* programName = 0; - -static int webkitXError(Display* xdisplay, XErrorEvent* error) -{ - char errorMessage[64]; - XGetErrorText(xdisplay, error->error_code, errorMessage, 63); - - LOG(Plugins, xErrorString, - programName, errorMessage, - error->serial, error->error_code, - error->request_code, error->minor_code); - - return 0; -} -#endif - -WK_EXPORT int PluginProcessMainUnix(int argc, char* argv[]) -{ -#if PLUGIN_ARCHITECTURE(X11) - bool scanPlugin = !strcmp(argv[1], "-scanPlugin"); -#endif - ASSERT_UNUSED(argc, argc == 3); +#if defined(XP_UNIX) +static std::unique_ptr<WebCore::XErrorTrapper> xErrorTrapper; +#endif // XP_UNIX +class PluginProcessMain final: public ChildProcessMainBase { +public: + bool platformInitialize() override + { #if PLATFORM(GTK) - gtk_init(&argc, &argv); -#elif PLATFORM(EFL) -#ifdef HAVE_ECORE_X - if (!ecore_x_init(0)) -#endif - return 1; + gtk_init(nullptr, nullptr); #endif - InitializeWebKit2(); + return true; + } + + bool parseCommandLine(int argc, char** argv) override + { + ASSERT(argc == 3); + if (argc != 3) + return false; + if (!strcmp(argv[1], "-scanPlugin")) #if PLUGIN_ARCHITECTURE(X11) - if (scanPlugin) { - String pluginPath(argv[2]); - if (!NetscapePluginModule::scanPlugin(pluginPath)) - return EXIT_FAILURE; - return EXIT_SUCCESS; - } + exit(NetscapePluginModule::scanPlugin(argv[2]) ? EXIT_SUCCESS : EXIT_FAILURE); +#else + exit(EXIT_FAILURE); #endif - // Plugins can produce X errors that are handled by the GDK X error handler, which - // exits the process. Since we don't want to crash due to plugin bugs, we install a - // custom error handler to show a warning when a X error happens without aborting. #if defined(XP_UNIX) - programName = basename(argv[0]); - XSetErrorHandler(webkitXError); + if (WebCore::PlatformDisplay::sharedDisplay().type() == WebCore::PlatformDisplay::Type::X11) { + auto* display = downcast<WebCore::PlatformDisplayX11>(WebCore::PlatformDisplay::sharedDisplay()).native(); + xErrorTrapper = std::make_unique<WebCore::XErrorTrapper>(display, WebCore::XErrorTrapper::Policy::Warn); + } #endif - int socket = atoi(argv[1]); - - WebKit::ChildProcessInitializationParameters parameters; - parameters.connectionIdentifier = socket; - parameters.extraInitializationData.add("plugin-path", argv[2]); - - WebKit::PluginProcess::shared().initialize(parameters); - - RunLoop::run(); + m_parameters.extraInitializationData.add("plugin-path", argv[2]); + return ChildProcessMainBase::parseCommandLine(argc, argv); + } +}; - return 0; +int PluginProcessMainUnix(int argc, char** argv) +{ + return ChildProcessMain<PluginProcess, PluginProcessMain>(argc, argv); } } // namespace WebKit |