1/* 2 * Copyright (C) 2011 Igalia S.L. 3 * Copyright (C) 2011 Apple Inc. 4 * Copyright (C) 2012 Samsung Electronics 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 17 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 19 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 25 * THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28#include "config.h" 29#include "PluginProcessMainUnix.h" 30 31#if ENABLE(PLUGIN_PROCESS) 32 33#include "Logging.h" 34#include "NetscapePlugin.h" 35#include "PluginProcess.h" 36#include "WebKit2Initialize.h" 37#include <WebCore/RunLoop.h> 38#if PLATFORM(GTK) 39#include <gdk/gdkx.h> 40#include <gtk/gtk.h> 41#elif PLATFORM(EFL) && HAVE_ECORE_X 42#include <Ecore_X.h> 43#endif 44 45using namespace WebCore; 46 47namespace WebKit { 48 49#ifdef XP_UNIX 50 51#if !LOG_DISABLED 52static const char xErrorString[] = "The program '%s' received an X Window System error.\n" 53 "This probably reflects a bug in a browser plugin.\n" 54 "The error was '%s'.\n" 55 " (Details: serial %ld error_code %d request_code %d minor_code %d)\n"; 56#endif /* !LOG_DISABLED */ 57 58static char* programName = 0; 59 60static int webkitXError(Display* xdisplay, XErrorEvent* error) 61{ 62 char errorMessage[64]; 63 XGetErrorText(xdisplay, error->error_code, errorMessage, 63); 64 65 LOG(Plugins, xErrorString, 66 programName, errorMessage, 67 error->serial, error->error_code, 68 error->request_code, error->minor_code); 69 70 return 0; 71} 72#endif 73 74WK_EXPORT int PluginProcessMainUnix(int argc, char* argv[]) 75{ 76 bool scanPlugin = !strcmp(argv[1], "-scanPlugin"); 77 ASSERT_UNUSED(argc, argc == 3); 78 79#if PLATFORM(GTK) 80 gtk_init(&argc, &argv); 81#elif PLATFORM(EFL) 82#ifdef HAVE_ECORE_X 83 if (!ecore_x_init(0)) 84#endif 85 return 1; 86#endif 87 88 InitializeWebKit2(); 89 90 if (scanPlugin) { 91 String pluginPath(argv[2]); 92 if (!NetscapePluginModule::scanPlugin(pluginPath)) 93 return EXIT_FAILURE; 94 return EXIT_SUCCESS; 95 } 96 97 // Plugins can produce X errors that are handled by the GDK X error handler, which 98 // exits the process. Since we don't want to crash due to plugin bugs, we install a 99 // custom error handler to show a warning when a X error happens without aborting. 100#if defined(XP_UNIX) 101 programName = basename(argv[0]); 102 XSetErrorHandler(webkitXError); 103#endif 104 105 int socket = atoi(argv[1]); 106 107 WebKit::ChildProcessInitializationParameters parameters; 108 parameters.connectionIdentifier = socket; 109 parameters.extraInitializationData.add("plugin-path", argv[2]); 110 111 WebKit::PluginProcess::shared().initialize(parameters); 112 113 RunLoop::run(); 114 115 return 0; 116} 117 118} // namespace WebKit 119 120#endif 121