Browse Source

Adding WebMain for chromium subprocesses

JoshEngebretson 10 years ago
parent
commit
b93c388738

+ 5 - 11
Source/AtomicEditor/Application/Main.cpp

@@ -7,8 +7,7 @@
 
 #ifdef ATOMIC_PLATFORM_WINDOWS
 #ifdef ATOMIC_WEBVIEW
-#include <include/cef_app.h>
-#include <include/cef_client.h>
+#include <AtomicWebView/AtomicWebView.h>
 #endif
 #endif
 
@@ -117,18 +116,13 @@ int main(int argc, char** argv)
 #ifdef ATOMIC_PLATFORM_WINDOWS
 #ifdef ATOMIC_WEBVIEW
 
-      // Provide CEF with command-line arguments.
-      CefMainArgs main_args;
+    int exit_code = Atomic::WebMain(argc, argv);
 
-      // CEF applications have multiple sub-processes (render, plugin, GPU, etc)
-      // that share the same executable. This function checks the command-line and,
-      // if this is a sub-process, executes the appropriate logic.
-      int exit_code = CefExecuteProcess(main_args, nullptr, nullptr);
-
-      if (exit_code >= 0) {
+    if (exit_code >= 0)
+    {
         // The sub-process has completed so return here.
         return exit_code;
-      }
+    }
 
 #endif
 #endif

+ 9 - 0
Source/AtomicWebView/AtomicWebView.h

@@ -0,0 +1,9 @@
+
+#pragma once
+
+namespace Atomic
+{
+
+int WebMain(int argc, char* argv[]);
+
+}

+ 41 - 0
Source/AtomicWebView/Internal/WebMain.cpp

@@ -0,0 +1,41 @@
+
+#include <include/cef_app.h>
+#include "WebAppOther.h"
+#include "WebAppRenderer.h"
+
+namespace Atomic
+{
+
+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());
+#else
+    CefMainArgs main_args(argc, argv);
+    command_line->InitFromArgv(argc, argv);
+#endif
+
+    // Create a ClientApp of the correct type.
+    CefRefPtr<CefApp> app;
+    WebApp::ProcessType process_type = WebApp::GetProcessType(command_line);
+    if (process_type == WebApp::RendererProcess)
+    {
+        app = new WebAppRenderer();
+    }
+    else if (process_type == WebApp::OtherProcess)
+    {
+        app = new WebAppOther();
+    }
+
+    // Execute the secondary process.
+    return CefExecuteProcess(main_args, app, NULL);
+}
+
+
+}