Browse Source

Work on WebView for Linux

JoshEngebretson 10 years ago
parent
commit
72d1c45fa9

+ 3 - 4
Source/AtomicEditor/Application/Main.cpp

@@ -5,7 +5,7 @@
 // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
 //
 
-#ifdef ATOMIC_PLATFORM_WINDOWS
+#if defined(ATOMIC_PLATFORM_WINDOWS) || defined (ATOMIC_PLATFORM_LINUX)
 #ifdef ATOMIC_WEBVIEW
 #include <AtomicWebView/AtomicWebView.h>
 #endif
@@ -112,8 +112,9 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, in
 #else
 int main(int argc, char** argv)
 {
+  Atomic::ParseArguments(argc, argv);
 
-#ifdef ATOMIC_PLATFORM_WINDOWS
+#if defined(ATOMIC_PLATFORM_WINDOWS) || defined (ATOMIC_PLATFORM_LINUX)
 #ifdef ATOMIC_WEBVIEW
 
     int exit_code = Atomic::WebMain(argc, argv);
@@ -127,8 +128,6 @@ int main(int argc, char** argv)
 #endif
 #endif
 
-    Atomic::ParseArguments(argc, argv);
-
     const Vector<String>& arguments = GetArguments();
 
     bool runPlayer = false;

+ 1 - 1
Source/AtomicEditor/CMakeLists.txt

@@ -59,7 +59,7 @@ if (OS_WINDOWS)
 endif()
 
 if (OS_LINUX)
-    target_link_libraries(AtomicEditor AtomicWebView libcef_dll_wrapper "${CEF_LIB_RELEASE}")
+    target_link_libraries(AtomicEditor AtomicWebView X11 libcef_dll_wrapper "${CEF_LIB_RELEASE}")
 endif()
 
 if(OS_MACOSX)

+ 2 - 2
Source/AtomicWebView/Internal/WebApp.cpp

@@ -10,7 +10,7 @@ namespace Atomic
 // These flags must match the Chromium values.
 static const char kProcessType[] = "type";
 static const char kRendererProcess[] = "renderer";
-#if defined(OS_LINUX)
+#ifdef ATOMIC_PLATFORM_LINUX
 static const char kZygoteProcess[] = "zygote";
 #endif
 
@@ -31,7 +31,7 @@ WebApp::ProcessType WebApp::GetProcessType(CefRefPtr<CefCommandLine> command_lin
     if (processType == kRendererProcess)
         return RendererProcess;
 
-#if defined(OS_LINUX)
+#ifdef ATOMIC_PLATFORM_LINUX
     else if (processType == kZygoteProcess)
         return ZygoteProcess;
 #endif

+ 9 - 1
Source/AtomicWebView/Internal/WebMain.cpp

@@ -10,12 +10,16 @@ using namespace Atomic;
 
 int WebMain(int argc, char* argv[])
 {
+
     CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine();
 
     // Provide CEF with command-line arguments.
 #ifdef ATOMIC_PLATFORM_WINDOWS
     CefMainArgs main_args;
     command_line->InitFromString(::GetCommandLineW());
+#elif ATOMIC_PLATFORM_OSX
+    CefMainArgs main_args(argc, argv);
+    command_line->InitFromArgv(argc, argv);
 #else
     CefMainArgs main_args(argc, argv);
     command_line->InitFromArgv(argc, argv);
@@ -24,8 +28,12 @@ int WebMain(int argc, char* argv[])
     // Create a ClientApp of the correct type.
     CefRefPtr<CefApp> app;
     WebApp::ProcessType process_type = WebApp::GetProcessType(command_line);
-    if (process_type == WebApp::RendererProcess)
+    if (process_type == WebApp::RendererProcess || process_type == WebApp::ZygoteProcess)
     {
+        // On Linux the zygote process is used to spawn other process types. Since
+        // we don't know what type of process it will be give it the renderer
+        // client.
+
         app = new WebAppRenderer();
     }
     else if (process_type == WebApp::OtherProcess)

+ 37 - 1
Source/AtomicWebView/WebBrowserHost.cpp

@@ -20,6 +20,28 @@
 #include "WebClient.h"
 #include "WebBrowserHost.h"
 
+#ifdef ATOMIC_PLATFORM_LINUX
+
+#include <X11/Xlib.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <signal.h>
+
+static int XErrorHandlerImpl(Display *display, XErrorEvent *event) {
+  return 0;
+}
+
+static int XIOErrorHandlerImpl(Display *display) {
+  return 0;
+}
+
+static void TerminationSignalHandler(int signatl) {
+
+}
+
+#endif
+
+
 
 namespace Atomic
 {
@@ -54,12 +76,26 @@ WebBrowserHost::WebBrowserHost(Context* context) : Object (context)
 
     const Vector<String>& arguments = GetArguments();
 
+    #ifdef ATOMIC_PLATFORM_LINUX
+      XSetErrorHandler(XErrorHandlerImpl);
+      XSetIOErrorHandler(XIOErrorHandlerImpl);
+
+      // Install a signal handler so we clean up after ourselves.
+      signal(SIGINT, TerminationSignalHandler);
+      signal(SIGTERM, TerminationSignalHandler);
+
+    #endif
+
+
     // IMPORTANT: Cef::App contains virtual void OnBeforeCommandLineProcessing(), which should make it possible
     // to setup args on Windows
 
 #ifdef ATOMIC_PLATFORM_OSX
     const char* _argv[3] = { "", "--enable-media-stream", "--enable-usermedia-screen-capturing" };
     CefMainArgs args(3, (char**) &_argv);
+#elif ATOMIC_PLATFORM_LINUX
+    static const char* _argv[3] = { "AtomicWebView", "--disable-setuid-sandbox", "--off-screen-rendering-enabled" };
+    CefMainArgs args(3, (char**) &_argv);
 #else
     CefMainArgs args;
 #endif
@@ -76,7 +112,7 @@ WebBrowserHost::WebBrowserHost(Context* context) : Object (context)
         LOGERROR("CefInitialize - Error");
     }
 
-    RegisterWebSchemeHandlers(this);    
+    RegisterWebSchemeHandlers(this);
 
     SubscribeToEvent(E_BEGINFRAME, HANDLER(WebBrowserHost, HandleBeginFrame));