[UNIX] Reorganize and cleanup main functions of GTK and EFL ports
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 23 May 2014 09:57:56 +0000 (09:57 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 23 May 2014 09:57:56 +0000 (09:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=131024

Reviewed by Gustavo Noronha Silva.

Move main function implementation files to <process-dir>/EntryPoint/unix/<ProcessName>Main.cpp
files that are now shared by GTK and EFL ports. These files call a
main method that wraps a new method ChildProcessMain that contains
the common code and uses a helper class for the platform specific
code. GTK+ and EFL ports implement that helper class for every process type.

* NetworkProcess/EntryPoint/unix/NetworkProcessMain.cpp: Renamed from Source/WebKit2/efl/MainEfl.cpp.
(main):
* NetworkProcess/efl/NetworkProcessMainEfl.cpp: Renamed from Source/WebKit2/unix/NetworkMainUnix.cpp.
(WebKit::NetworkProcessMainUnix):
* NetworkProcess/gtk/NetworkProcessMainGtk.cpp: Renamed from Source/WebKit2/NetworkProcess/unix/NetworkProcessMainUnix.cpp.
(WebKit::NetworkProcessMainUnix):
* NetworkProcess/unix/NetworkProcessMainUnix.h:
* PlatformEfl.cmake:
* PlatformGTK.cmake:
* PluginProcess/EntryPoint/unix/PluginProcessMain.cpp: Renamed from Source/WebKit2/unix/PluginMainUnix.cpp.
(main):
* PluginProcess/unix/PluginProcessMainUnix.cpp:
(WebKit::webkitXError):
(WebKit::PluginProcessMainUnix):
* PluginProcess/unix/PluginProcessMainUnix.h:
* Shared/unix/ChildProcessMain.cpp: Copied from Source/WebKit2/WebProcess/efl/WebProcessMainEfl.h.
(WebKit::ChildProcessMainBase::parseCommandLine):
* Shared/unix/ChildProcessMain.h: Renamed from Source/WebKit2/WebProcess/gtk/WebProcessMainGtk.h.
(WebKit::ChildProcessMainBase::platformInitialize):
(WebKit::ChildProcessMainBase::platformFinalize):
(WebKit::ChildProcessMainBase::initializationParameters):
(WebKit::ChildProcessMain):
* WebProcess/EntryPoint/unix/WebProcessMain.cpp: Renamed from Source/WebKit2/gtk/MainGtk.cpp.
(main):
* WebProcess/efl/WebProcessMainEfl.cpp:
(WebKit::WebProcessMainUnix):
(dummyExtensionErrorHandler): Deleted.
* WebProcess/gtk/WebProcessMainGtk.cpp:
(WebKit::WebProcessMainUnix):
* WebProcess/unix/WebProcessMainUnix.h: Renamed from Source/WebKit2/WebProcess/efl/WebProcessMainEfl.h.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@169255 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/NetworkProcess/EntryPoint/unix/NetworkProcessMain.cpp [moved from Source/WebKit2/efl/MainEfl.cpp with 90% similarity]
Source/WebKit2/NetworkProcess/efl/NetworkProcessMainEfl.cpp [moved from Source/WebKit2/unix/NetworkMainUnix.cpp with 56% similarity]
Source/WebKit2/NetworkProcess/gtk/NetworkProcessMainGtk.cpp [moved from Source/WebKit2/NetworkProcess/unix/NetworkProcessMainUnix.cpp with 53% similarity]
Source/WebKit2/NetworkProcess/unix/NetworkProcessMainUnix.h
Source/WebKit2/PlatformEfl.cmake
Source/WebKit2/PlatformGTK.cmake
Source/WebKit2/PluginProcess/EntryPoint/unix/PluginProcessMain.cpp [moved from Source/WebKit2/unix/PluginMainUnix.cpp with 88% similarity]
Source/WebKit2/PluginProcess/unix/PluginProcessMainUnix.cpp
Source/WebKit2/PluginProcess/unix/PluginProcessMainUnix.h
Source/WebKit2/Shared/unix/ChildProcessMain.cpp [new file with mode: 0644]
Source/WebKit2/Shared/unix/ChildProcessMain.h [moved from Source/WebKit2/WebProcess/gtk/WebProcessMainGtk.h with 56% similarity]
Source/WebKit2/WebProcess/EntryPoint/unix/WebProcessMain.cpp [moved from Source/WebKit2/gtk/MainGtk.cpp with 86% similarity]
Source/WebKit2/WebProcess/efl/WebProcessMainEfl.cpp
Source/WebKit2/WebProcess/gtk/WebProcessMainGtk.cpp
Source/WebKit2/WebProcess/unix/WebProcessMainUnix.h [moved from Source/WebKit2/WebProcess/efl/WebProcessMainEfl.h with 84% similarity]

index 87c8c88..5a0a8d8 100644 (file)
@@ -1,3 +1,47 @@
+2014-05-23  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [UNIX] Reorganize and cleanup main functions of GTK and EFL ports
+        https://bugs.webkit.org/show_bug.cgi?id=131024
+
+        Reviewed by Gustavo Noronha Silva.
+
+        Move main function implementation files to <process-dir>/EntryPoint/unix/<ProcessName>Main.cpp
+        files that are now shared by GTK and EFL ports. These files call a
+        main method that wraps a new method ChildProcessMain that contains
+        the common code and uses a helper class for the platform specific
+        code. GTK+ and EFL ports implement that helper class for every process type.
+
+        * NetworkProcess/EntryPoint/unix/NetworkProcessMain.cpp: Renamed from Source/WebKit2/efl/MainEfl.cpp.
+        (main):
+        * NetworkProcess/efl/NetworkProcessMainEfl.cpp: Renamed from Source/WebKit2/unix/NetworkMainUnix.cpp.
+        (WebKit::NetworkProcessMainUnix):
+        * NetworkProcess/gtk/NetworkProcessMainGtk.cpp: Renamed from Source/WebKit2/NetworkProcess/unix/NetworkProcessMainUnix.cpp.
+        (WebKit::NetworkProcessMainUnix):
+        * NetworkProcess/unix/NetworkProcessMainUnix.h:
+        * PlatformEfl.cmake:
+        * PlatformGTK.cmake:
+        * PluginProcess/EntryPoint/unix/PluginProcessMain.cpp: Renamed from Source/WebKit2/unix/PluginMainUnix.cpp.
+        (main):
+        * PluginProcess/unix/PluginProcessMainUnix.cpp:
+        (WebKit::webkitXError):
+        (WebKit::PluginProcessMainUnix):
+        * PluginProcess/unix/PluginProcessMainUnix.h:
+        * Shared/unix/ChildProcessMain.cpp: Copied from Source/WebKit2/WebProcess/efl/WebProcessMainEfl.h.
+        (WebKit::ChildProcessMainBase::parseCommandLine):
+        * Shared/unix/ChildProcessMain.h: Renamed from Source/WebKit2/WebProcess/gtk/WebProcessMainGtk.h.
+        (WebKit::ChildProcessMainBase::platformInitialize):
+        (WebKit::ChildProcessMainBase::platformFinalize):
+        (WebKit::ChildProcessMainBase::initializationParameters):
+        (WebKit::ChildProcessMain):
+        * WebProcess/EntryPoint/unix/WebProcessMain.cpp: Renamed from Source/WebKit2/gtk/MainGtk.cpp.
+        (main):
+        * WebProcess/efl/WebProcessMainEfl.cpp:
+        (WebKit::WebProcessMainUnix):
+        (dummyExtensionErrorHandler): Deleted.
+        * WebProcess/gtk/WebProcessMainGtk.cpp:
+        (WebKit::WebProcessMainUnix):
+        * WebProcess/unix/WebProcessMainUnix.h: Renamed from Source/WebKit2/WebProcess/efl/WebProcessMainEfl.h.
+
 2014-05-22  Zan Dobersek  <zdobersek@igalia.com>
 
         Have the decoded element in VectorArgumentCoder::decode() moved into Vector::append()
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Samsung Electronics. All rights reserved.
+ * Copyright (C) 2014 Igalia S.L.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include "WebProcessMainEfl.h"
+#include "NetworkProcessMainUnix.h"
+
+using namespace WebKit;
 
 int main(int argc, char** argv)
 {
-    return WebKit::WebProcessMainEfl(argc, argv);
+    return NetworkProcessMainUnix(argc, argv);
 }
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 University of Szeged. All rights reserved.
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
  * Copyright (C) 2013 Company 100 Inc.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -11,7 +11,7 @@
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
  *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS''
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS''
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
  */
 
 #include "config.h"
+#include "NetworkProcessMainUnix.h"
 
 #if ENABLE(NETWORK_PROCESS)
 
-#include "NetworkProcessMainUnix.h"
+#include "ChildProcessMain.h"
+#include "NetworkProcess.h"
+#include <Ecore.h>
+#include <WebCore/SoupNetworkSession.h>
+#include <libsoup/soup.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+class NetworkProcessMain final: public ChildProcessMainBase {
+public:
+    bool platformInitialize() override
+    {
+        if (!ecore_init())
+            return false;
 
-int main(int argc, char** argv)
+        if (!ecore_main_loop_glib_integrate())
+            return false;
+
+        SoupNetworkSession::defaultSession().setupHTTPProxyFromEnvironment();
+        return true;
+    }
+
+    void platformFinalize() override
+    {
+        if (SoupCache* soupCache = SoupNetworkSession::defaultSession().cache()) {
+            soup_cache_flush(soupCache);
+            soup_cache_dump(soupCache);
+        }
+
+        ecore_shutdown();
+    }
+};
+
+int NetworkProcessMainUnix(int argc, char** argv)
 {
-    return WebKit::NetworkProcessMain(argc, argv);
+    return ChildProcessMain<NetworkProcess, NetworkProcessMain>(argc, argv);
 }
 
+} // namespace WebKit
+
 #endif // ENABLE(NETWORK_PROCESS)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2014 Igalia S.L.
  * Copyright (C) 2013 Company 100 Inc.
  *
  * Redistribution and use in source and binary forms, with or without
 
 #if ENABLE(NETWORK_PROCESS)
 
-#include "WKBase.h"
-#include "WebKit2Initialize.h"
+#include "ChildProcessMain.h"
+#include "NetworkProcess.h"
 #include <WebCore/SoupNetworkSession.h>
-#include <WebKit/NetworkProcess.h>
-#include <runtime/InitializeThreading.h>
-#include <stdlib.h>
-#include <wtf/MainThread.h>
-#include <wtf/RunLoop.h>
-#include <wtf/gobject/GRefPtr.h>
-
-#if PLATFORM(EFL)
-#include <Ecore.h>
-#endif
-
-#if USE(SOUP)
 #include <libsoup/soup.h>
-#endif
 
 using namespace WebCore;
 
 namespace WebKit {
 
-WK_EXPORT int NetworkProcessMain(int argc, char* argv[])
-{
-    if (argc != 2)
-        return 1;
-
-#if PLATFORM(EFL)
-    if (!ecore_init())
-        return 1;
-
-    if (!ecore_main_loop_glib_integrate())
-        return 1;
-#endif
-
-    InitializeWebKit2();
-
-    SoupNetworkSession::defaultSession().setupHTTPProxyFromEnvironment();
-
-    int socket = atoi(argv[1]);
-
-    WebKit::ChildProcessInitializationParameters parameters;
-    parameters.connectionIdentifier = socket;
-
-    NetworkProcess::shared().initialize(parameters);
-
-#if USE(SOUP)
-    // Despite using system CAs to validate certificates we're
-    // accepting invalid certificates by default. New API will be
-    // added later to let client accept/discard invalid certificates.
-    SoupNetworkSession::defaultSession().setSSLPolicy(SoupNetworkSession::SSLUseSystemCAFile);
-#endif
-
-    RunLoop::run();
+class NetworkProcessMain final: public ChildProcessMainBase {
+public:
+    bool platformInitialize() override
+    {
+        // Despite using system CAs to validate certificates we're
+        // accepting invalid certificates by default. New API will be
+        // added later to let client accept/discard invalid certificates.
+        SoupNetworkSession::defaultSession().setSSLPolicy(SoupNetworkSession::SSLUseSystemCAFile);
+        return true;
+    }
 
-#if USE(SOUP)
-    if (SoupCache* soupCache = SoupNetworkSession::defaultSession().cache()) {
-        soup_cache_flush(soupCache);
-        soup_cache_dump(soupCache);
+    void platformFinalize() override
+    {
+        if (SoupCache* soupCache = SoupNetworkSession::defaultSession().cache()) {
+            soup_cache_flush(soupCache);
+            soup_cache_dump(soupCache);
+        }
     }
-#endif
+};
 
-    return 0;
+int NetworkProcessMainUnix(int argc, char** argv)
+{
+    return ChildProcessMain<NetworkProcess, NetworkProcessMain>(argc, argv);
 }
 
 } // namespace WebKit
index 6a56bd8..fa064c3 100644 (file)
 
 namespace WebKit {
 
-#ifdef __cplusplus
 extern "C" {
-WK_EXPORT int NetworkProcessMain(int argc, char* argv[]);
-} // extern "C"
-#endif // __cplusplus
+WK_EXPORT int NetworkProcessMainUnix(int argc, char** argv);
+}
 
 } // namespace WebKit
 
index fc4339e..256058d 100644 (file)
@@ -1,10 +1,10 @@
 list(APPEND WebKit2_SOURCES
+    NetworkProcess/efl/NetworkProcessMainEfl.cpp
+
     NetworkProcess/soup/NetworkProcessSoup.cpp
     NetworkProcess/soup/NetworkResourceLoadSchedulerSoup.cpp
     NetworkProcess/soup/RemoteNetworkingContextSoup.cpp
 
-    NetworkProcess/unix/NetworkProcessMainUnix.cpp
-
     Platform/IPC/unix/AttachmentUnix.cpp
     Platform/IPC/unix/ConnectionUnix.cpp
 
@@ -52,6 +52,8 @@ list(APPEND WebKit2_SOURCES
 
     Shared/soup/WebCoreArgumentCodersSoup.cpp
 
+    Shared/unix/ChildProcessMain.cpp
+
     UIProcess/DefaultUndoController.cpp
 
     UIProcess/API/C/CoordinatedGraphics/WKView.cpp
@@ -219,6 +221,7 @@ list(APPEND WebKit2_INCLUDE_DIRECTORIES
     "${WEBCORE_DIR}/platform/graphics/opentype"
     "${WEBCORE_DIR}/platform/network/soup"
     "${WEBCORE_DIR}/platform/text/enchant"
+    "${WEBKIT2_DIR}/NetworkProcess/efl"
     "${WEBKIT2_DIR}/NetworkProcess/unix"
     "${WEBKIT2_DIR}/Platform/efl"
     "${WEBKIT2_DIR}/Shared/API/c/efl"
@@ -226,6 +229,7 @@ list(APPEND WebKit2_INCLUDE_DIRECTORIES
     "${WEBKIT2_DIR}/Shared/Downloads/soup"
     "${WEBKIT2_DIR}/Shared/efl"
     "${WEBKIT2_DIR}/Shared/soup"
+    "${WEBKIT2_DIR}/Shared/unix"
     "${WEBKIT2_DIR}/UIProcess/API/C/cairo"
     "${WEBKIT2_DIR}/UIProcess/API/C/CoordinatedGraphics"
     "${WEBKIT2_DIR}/UIProcess/API/C/efl"
@@ -238,6 +242,7 @@ list(APPEND WebKit2_INCLUDE_DIRECTORIES
     "${WEBKIT2_DIR}/UIProcess/soup"
     "${WEBKIT2_DIR}/WebProcess/efl"
     "${WEBKIT2_DIR}/WebProcess/soup"
+    "${WEBKIT2_DIR}/WebProcess/unix"
     "${WEBKIT2_DIR}/WebProcess/WebCoreSupport/efl"
     "${WEBKIT2_DIR}/WebProcess/WebCoreSupport/soup"
     "${WEBKIT2_DIR}/WebProcess/WebPage/CoordinatedGraphics"
@@ -290,11 +295,11 @@ list(APPEND WebKit2_LIBRARIES
 )
 
 list(APPEND WebProcess_SOURCES
-    efl/MainEfl.cpp
+    WebProcess/EntryPoint/unix/WebProcessMain.cpp
 )
 
 list(APPEND NetworkProcess_SOURCES
-        unix/NetworkMainUnix.cpp
+    NetworkProcess/EntryPoint/unix/NetworkProcessMain.cpp
 )
 
 list(APPEND WebProcess_LIBRARIES
@@ -406,7 +411,7 @@ if (ENABLE_PLUGIN_PROCESS)
     include_directories(${PluginProcess_INCLUDE_DIRECTORIES})
 
     list(APPEND PluginProcess_SOURCES
-        ${WEBKIT2_DIR}/unix/PluginMainUnix.cpp
+        ${WEBKIT2_DIR}/PluginProcess/EntryPoint/unix/PluginProcessMain.cpp
     )
 
     if (ENABLE_ECORE_X)
index ec0a44a..d424ee2 100644 (file)
@@ -22,12 +22,12 @@ list(APPEND WebKit2_SOURCES
     ${DERIVED_SOURCES_WEBKIT2GTK_API_DIR}/WebKitEnumTypes.cpp
     ${DERIVED_SOURCES_WEBKIT2GTK_API_DIR}/WebKitMarshal.cpp
 
+    NetworkProcess/gtk/NetworkProcessMainGtk.cpp
+
     NetworkProcess/soup/NetworkProcessSoup.cpp
     NetworkProcess/soup/NetworkResourceLoadSchedulerSoup.cpp
     NetworkProcess/soup/RemoteNetworkingContextSoup.cpp
 
-    NetworkProcess/unix/NetworkProcessMainUnix.cpp
-
     Platform/IPC/unix/AttachmentUnix.cpp
     Platform/IPC/unix/ConnectionUnix.cpp
 
@@ -75,6 +75,8 @@ list(APPEND WebKit2_SOURCES
 
     Shared/soup/WebCoreArgumentCodersSoup.cpp
 
+    Shared/unix/ChildProcessMain.cpp
+
     UIProcess/DefaultUndoController.cpp
     UIProcess/DrawingAreaProxyImpl.cpp
 
@@ -397,12 +399,14 @@ list(APPEND WebKit2_INCLUDE_DIRECTORIES
     "${WEBCORE_DIR}/platform/graphics/opentype"
     "${WEBCORE_DIR}/platform/network/soup"
     "${WEBCORE_DIR}/platform/text/enchant"
+    "${WEBKIT2_DIR}/NetworkProcess/gtk"
+    "${WEBKIT2_DIR}/NetworkProcess/unix"
     "${WEBKIT2_DIR}/Shared/API/c/gtk"
     "${WEBKIT2_DIR}/Shared/Network/CustomProtocols/soup"
     "${WEBKIT2_DIR}/Shared/Downloads/soup"
     "${WEBKIT2_DIR}/Shared/gtk"
     "${WEBKIT2_DIR}/Shared/soup"
-    "${WEBKIT2_DIR}/NetworkProcess/unix"
+    "${WEBKIT2_DIR}/Shared/unix"
     "${WEBKIT2_DIR}/UIProcess/API/C/cairo"
     "${WEBKIT2_DIR}/UIProcess/API/C/gtk"
     "${WEBKIT2_DIR}/UIProcess/API/C/soup"
@@ -415,6 +419,7 @@ list(APPEND WebKit2_INCLUDE_DIRECTORIES
     "${WEBKIT2_DIR}/WebProcess/InjectedBundle/API/gtk"
     "${WEBKIT2_DIR}/WebProcess/gtk"
     "${WEBKIT2_DIR}/WebProcess/soup"
+    "${WEBKIT2_DIR}/WebProcess/unix"
     "${WEBKIT2_DIR}/WebProcess/WebCoreSupport/gtk"
     "${WEBKIT2_DIR}/WebProcess/WebCoreSupport/soup"
     "${WEBKIT2_DIR}/WebProcess/WebPage/atk"
@@ -438,11 +443,11 @@ list(APPEND WebKit2_INCLUDE_DIRECTORIES
 )
 
 list(APPEND WebProcess_SOURCES
-    gtk/MainGtk.cpp
+    WebProcess/EntryPoint/unix/WebProcessMain.cpp
 )
 
 list(APPEND NetworkProcess_SOURCES
-    unix/NetworkMainUnix.cpp
+    NetworkProcess/EntryPoint/unix/NetworkProcessMain.cpp
 )
 
 set(SharedWebKit2Libraries
@@ -595,6 +600,8 @@ if (ENABLE_PLUGIN_PROCESS)
 
         Platform/unix/SharedMemoryUnix.cpp
 
+        PluginProcess/EntryPoint/unix/PluginProcessMain.cpp
+
         PluginProcess/PluginControllerProxy.cpp
         PluginProcess/PluginCreationParameters.cpp
         PluginProcess/PluginProcess.cpp
@@ -642,6 +649,8 @@ if (ENABLE_PLUGIN_PROCESS)
 
         Shared/soup/WebCoreArgumentCodersSoup.cpp
 
+        Shared/unix/ChildProcessMain.cpp
+
         UIProcess/Launcher/ProcessLauncher.cpp
 
         UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp
@@ -658,8 +667,6 @@ if (ENABLE_PLUGIN_PROCESS)
 
         WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp
 
-        unix/PluginMainUnix.cpp
-
         ${DERIVED_SOURCES_WEBKIT2_DIR}/PluginControllerProxyMessageReceiver.cpp
         ${DERIVED_SOURCES_WEBKIT2_DIR}/PluginProcessMessageReceiver.cpp
         ${DERIVED_SOURCES_WEBKIT2_DIR}/WebProcessConnectionMessageReceiver.cpp
@@ -699,7 +706,7 @@ if (ENABLE_PLUGIN_PROCESS)
 
     # GTK3 PluginProcess
     list(APPEND PluginProcess_SOURCES
-        unix/PluginMainUnix.cpp
+        PluginProcess/EntryPoint/unix/PluginProcessMain.cpp
     )
 
 endif () # ENABLE_PLUGIN_PROCESS
@@ -1,6 +1,5 @@
 /*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
- * Portions Copyright (c) 2010 Motorola Mobility, Inc.  All rights reserved.
+ * Copyright (C) 2014 Igalia S.L.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -26,7 +25,9 @@
 
 #include "PluginProcessMainUnix.h"
 
+using namespace WebKit;
+
 int main(int argc, char** argv)
 {
-    return WebKit::PluginProcessMainUnix(argc, argv);
+    return PluginProcessMainUnix(argc, argv);
 }
index 6a4c26e..e071c8f 100644 (file)
@@ -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
  *
 
 #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>
+#include <wtf/text/CString.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;
-
 namespace WebKit {
 
-#ifdef XP_UNIX
+#if defined(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 */
+#endif // !LOG_DISABLED
 
-static char* programName = 0;
+static CString programName;
 
 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);
+    LOG(Plugins, xErrorString, programName.data(), 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);
+#endif // XP_UNIX
 
+class PluginProcessMain final: public ChildProcessMainBase {
+public:
+    bool platformInitialize() override
+    {
 #if PLATFORM(GTK)
-    gtk_init(&argc, &argv);
+        gtk_init(nullptr, nullptr);
 #elif PLATFORM(EFL)
 #ifdef HAVE_ECORE_X
-    if (!ecore_x_init(0))
+        if (!ecore_x_init(0))
 #endif
-        return 1;
+            return false;
 #endif
 
-    InitializeWebKit2();
-
-#if PLUGIN_ARCHITECTURE(X11)
-    if (scanPlugin) {
-        String pluginPath(argv[2]);
-        if (!NetscapePluginModule::scanPlugin(pluginPath))
-            return EXIT_FAILURE;
-        return EXIT_SUCCESS;
+        return true;
     }
-#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);
-#endif
+    bool parseCommandLine(int argc, char** argv) override
+    {
+        ASSERT(argc == 3);
+        if (argc != 3)
+            return false;
 
-    int socket = atoi(argv[1]);
+        if (!strcmp(argv[1], "-scanPlugin"))
+            exit(NetscapePluginModule::scanPlugin(argv[2]) ? EXIT_SUCCESS : EXIT_FAILURE);
 
-    WebKit::ChildProcessInitializationParameters parameters;
-    parameters.connectionIdentifier = socket;
-    parameters.extraInitializationData.add("plugin-path", argv[2]);
-
-    WebKit::PluginProcess::shared().initialize(parameters);
+#if defined(XP_UNIX)
+        programName = WebCore::pathGetFileName(argv[0]).utf8();
+        XSetErrorHandler(webkitXError);
+#endif
 
-    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
index d9d699d..f79c1d2 100644 (file)
 
 namespace WebKit {
 
-#ifdef __cplusplus
 extern "C" {
-WK_EXPORT int PluginProcessMainUnix(int argc, char* argv[]);
-} // extern "C"
-#endif // __cplusplus
+WK_EXPORT int PluginProcessMainUnix(int argc, char** argv);
+}
 
 } // namespace WebKit
 
-#endif // PluginProcessMain_h
+#endif // PluginProcessMainUnix_h
diff --git a/Source/WebKit2/Shared/unix/ChildProcessMain.cpp b/Source/WebKit2/Shared/unix/ChildProcessMain.cpp
new file mode 100644 (file)
index 0000000..628be68
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2014 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ChildProcessMain.h"
+
+#include <stdlib.h>
+
+namespace WebKit {
+
+bool ChildProcessMainBase::parseCommandLine(int argc, char** argv)
+{
+    ASSERT(argc >= 2);
+    if (argc < 2)
+        return false;
+
+    m_parameters.connectionIdentifier = atoi(argv[1]);
+    return true;
+}
+
+} // namespace WebKit
@@ -1,6 +1,5 @@
 /*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
- * Portions Copyright (c) 2010 Motorola Mobility, Inc.  All rights reserved.
+ * Copyright (C) 2014 Igalia S.L.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef WebProcessMainGtk_h
-#define WebProcessMainGtk_h
+#ifndef ChildProcessMain_h
+#define ChildProcessMain_h
 
-#include <WebKit/WKBase.h>
+#include "ChildProcess.h"
+#include "WebKit2Initialize.h"
+#include <wtf/RunLoop.h>
 
 namespace WebKit {
 
-#ifdef __cplusplus
-extern "C" {
-WK_EXPORT int WebProcessMainGtk(int argc, char* argv[]);
-} // extern "C"
-#endif // __cplusplus
+class ChildProcessMainBase {
+public:
+    virtual bool platformInitialize() { return true; }
+    virtual bool parseCommandLine(int argc, char** argv);
+    virtual void platformFinalize() { }
+
+    const ChildProcessInitializationParameters& initializationParameters() const { return m_parameters; }
+
+protected:
+    ChildProcessInitializationParameters m_parameters;
+};
+
+template<typename ChildProcessType, typename ChildProcessMainType>
+int ChildProcessMain(int argc, char** argv)
+{
+    ChildProcessMainType childMain;
+
+    if (!childMain.platformInitialize())
+        return EXIT_FAILURE;
+
+    InitializeWebKit2();
+
+    if (!childMain.parseCommandLine(argc, argv))
+        return EXIT_FAILURE;
+
+    ChildProcessType::shared().initialize(childMain.initializationParameters());
+    RunLoop::run();
+    childMain.platformFinalize();
+
+    return EXIT_SUCCESS;
+}
 
 } // namespace WebKit
 
-#endif // WebProcessMain_h
+#endif // ChildProcessMain_h
@@ -1,6 +1,5 @@
 /*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
- * Portions Copyright (c) 2010 Motorola Mobility, Inc.  All rights reserved.
+ * Copyright (C) 2014 Igalia S.L.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include "WebProcessMainGtk.h"
+#include "WebProcessMainUnix.h"
+
+using namespace WebKit;
 
 int main(int argc, char** argv)
 {
-    return WebKit::WebProcessMainGtk(argc, argv);
+    return WebProcessMainUnix(argc, argv);
 }
index c625b70..cbeb322 100644 (file)
  */
 
 #include "config.h"
-#include "WebProcessMainEfl.h"
+#include "WebProcessMainUnix.h"
 
-#include "ProxyResolverSoup.h"
-#include "WKBase.h"
-#include "WebKit2Initialize.h"
+#include "ChildProcessMain.h"
+#include "WebProcess.h"
 #include <Ecore.h>
 #include <Ecore_Evas.h>
 #include <Edje.h>
 #include <Efreet.h>
-#include <WebCore/AuthenticationChallenge.h>
-#include <WebCore/NetworkingContext.h>
 #include <WebCore/SoupNetworkSession.h>
-#include <WebKit/WebProcess.h>
 #include <libsoup/soup.h>
-#include <runtime/JSCInlines.h>
-#include <unistd.h>
-#include <wtf/RunLoop.h>
-#include <wtf/text/CString.h>
 
 #ifdef HAVE_ECORE_X
 #include <Ecore_X.h>
@@ -58,88 +50,82 @@ using namespace WebCore;
 
 namespace WebKit {
 
-WK_EXPORT int WebProcessMainEfl(int argc, char* argv[])
-{
-    // WebProcess should be launched with an option.
-    if (argc != 2)
-        return 1;
-
-    if (!eina_init())
-        return 1;
+class WebProcessMain final: public ChildProcessMainBase {
+public:
+    bool platformInitialize() override
+    {
+        if (!eina_init())
+            return false;
 
-    if (!ecore_init()) {
-        // Could not init ecore.
-        eina_shutdown();
-        return 1;
-    }
+        if (!ecore_init()) {
+            // Could not init ecore.
+            eina_shutdown();
+            return false;
+        }
 
 #ifdef HAVE_ECORE_X
-    XSetExtensionErrorHandler(dummyExtensionErrorHandler);
-
-    if (!ecore_x_init(0)) {
-        // Could not init ecore_x.
-        // PlatformScreenEfl and systemBeep() functions
-        // depend on ecore_x functionality.
-        ecore_shutdown();
-        eina_shutdown();
-        return 1;
-    }
+        XSetExtensionErrorHandler(dummyExtensionErrorHandler);
+
+        if (!ecore_x_init(0)) {
+            // Could not init ecore_x.
+            // PlatformScreenEfl and systemBeep() functions
+            // depend on ecore_x functionality.
+            ecore_shutdown();
+            eina_shutdown();
+            return false;
+        }
 #endif
 
-    if (!ecore_evas_init()) {
+        if (!ecore_evas_init()) {
 #ifdef HAVE_ECORE_X
-        ecore_x_shutdown();
+            ecore_x_shutdown();
 #endif
-        ecore_shutdown();
-        eina_shutdown();
-        return 1;
-    }
+            ecore_shutdown();
+            eina_shutdown();
+            return false;
+        }
 
-    if (!edje_init()) {
-        ecore_evas_shutdown();
+        if (!edje_init()) {
+            ecore_evas_shutdown();
 #ifdef HAVE_ECORE_X
-        ecore_x_shutdown();
+            ecore_x_shutdown();
 #endif
-        ecore_shutdown();
-        eina_shutdown();
-        return 1;
-    }
+            ecore_shutdown();
+            eina_shutdown();
+            return false;
+        }
 
 #if !GLIB_CHECK_VERSION(2, 35, 0)
-    g_type_init();
+        g_type_init();
 #endif
 
-    if (!ecore_main_loop_glib_integrate())
-        return 1;
-
-    InitializeWebKit2();
-
-    SoupNetworkSession::defaultSession().setupHTTPProxyFromEnvironment();
-
-    int socket = atoi(argv[1]);
+        if (!ecore_main_loop_glib_integrate())
+            return false;
 
-    ChildProcessInitializationParameters parameters;
-    parameters.connectionIdentifier = socket;
-
-    WebProcess::shared().initialize(parameters);
-
-    RunLoop::run();
-
-    if (SoupCache* soupCache = SoupNetworkSession::defaultSession().cache()) {
-        soup_cache_flush(soupCache);
-        soup_cache_dump(soupCache);
+        SoupNetworkSession::defaultSession().setupHTTPProxyFromEnvironment();
+        return true;
     }
 
-    edje_shutdown();
-    ecore_evas_shutdown();
+    void platformFinalize() override
+    {
+        if (SoupCache* soupCache = SoupNetworkSession::defaultSession().cache()) {
+            soup_cache_flush(soupCache);
+            soup_cache_dump(soupCache);
+        }
+
+        edje_shutdown();
+        ecore_evas_shutdown();
 #ifdef HAVE_ECORE_X
-    ecore_x_shutdown();
+        ecore_x_shutdown();
 #endif
-    ecore_shutdown();
-    eina_shutdown();
-
-    return 0;
+        ecore_shutdown();
+        eina_shutdown();
+    }
+};
 
+int WebProcessMainUnix(int argc, char** argv)
+{
+    return ChildProcessMain<WebProcess, WebProcessMain>(argc, argv);
 }
 
 } // namespace WebKit
index 471c007..f4ac3ed 100644 (file)
  */
 
 #include "config.h"
-#include "WebProcessMainGtk.h"
+#include "WebProcessMainUnix.h"
 
-#include "WKBase.h"
-#include "WebKit2Initialize.h"
-#include <WebCore/AuthenticationChallenge.h>
-#include <WebCore/NetworkingContext.h>
+#include "ChildProcessMain.h"
+#include "WebProcess.h"
 #include <WebCore/SoupNetworkSession.h>
-#include <WebKit/WebProcess.h>
 #include <gtk/gtk.h>
 #include <libintl.h>
 #include <libsoup/soup.h>
-#include <unistd.h>
-#include <wtf/RunLoop.h>
-#include <wtf/gobject/GRefPtr.h>
 
 using namespace WebCore;
 
 namespace WebKit {
 
-WK_EXPORT int WebProcessMainGtk(int argc, char* argv[])
-{
-    ASSERT(argc == 2);
-
+class WebProcessMain final: public ChildProcessMainBase {
+public:
+    bool platformInitialize() override
+    {
 #ifndef NDEBUG
-    if (g_getenv("WEBKIT2_PAUSE_WEB_PROCESS_ON_LAUNCH"))
-        sleep(30);
+        if (g_getenv("WEBKIT2_PAUSE_WEB_PROCESS_ON_LAUNCH"))
+            sleep(30);
 #endif
 
-    gtk_init(&argc, &argv);
-
-    bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
-    bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
-
-    InitializeWebKit2();
-
-    int socket = atoi(argv[1]);
+        gtk_init(nullptr, nullptr);
 
-    ChildProcessInitializationParameters parameters;
-    parameters.connectionIdentifier = socket;
+        bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
+        bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
 
-    WebProcess::shared().initialize(parameters);
-
-    // Despite using system CAs to validate certificates we're
-    // accepting invalid certificates by default. New API will be
-    // added later to let client accept/discard invalid certificates.
-    SoupNetworkSession::defaultSession().setSSLPolicy(SoupNetworkSession::SSLUseSystemCAFile);
-
-    RunLoop::run();
+        // Despite using system CAs to validate certificates we're
+        // accepting invalid certificates by default. New API will be
+        // added later to let client accept/discard invalid certificates.
+        SoupNetworkSession::defaultSession().setSSLPolicy(SoupNetworkSession::SSLUseSystemCAFile);
+        return true;
+    }
 
-    if (SoupCache* soupCache = SoupNetworkSession::defaultSession().cache()) {
-        soup_cache_flush(soupCache);
-        soup_cache_dump(soupCache);
+    void platformFinalize() override
+    {
+        if (SoupCache* soupCache = SoupNetworkSession::defaultSession().cache()) {
+            soup_cache_flush(soupCache);
+            soup_cache_dump(soupCache);
+        }
     }
+};
 
-    return 0;
+int WebProcessMainUnix(int argc, char** argv)
+{
+    return ChildProcessMain<WebProcess, WebProcessMain>(argc, argv);
 }
 
 } // namespace WebKit
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Samsung Electronics. All rights reserved.
+ * Copyright (C) 2014 Igalia S.L.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef WebProcessMainEfl_h
-#define WebProcessMainEfl_h
+#ifndef WebProcessMainUnix_h
+#define WebProcessMainUnix_h
 
 #include <WebKit/WKBase.h>
 
 namespace WebKit {
 
-#ifdef __cplusplus
 extern "C" {
-WK_EXPORT int WebProcessMainEfl(int argc, char* argv[]);
-} // extern "C"
-#endif // __cplusplus
+WK_EXPORT int WebProcessMainUnix(int argc, char** argv);
+}
 
 } // namespace WebKit
 
-#endif // WebProcessMainEfl_h
+#endif // WebProcessMainUnix_h