public Menu( CefApp menuCeffApp, CefMainArgs mainArgs, InputProcessor inputProcessor, MenuBrowserClient browserClient, StateManager stateManager, EventBus eventBus ) { // State Initialization _buttons = (GameControllerButton[])Enum.GetValues(typeof(GameControllerButton)); _analogs = (GameControllerAnalog[])Enum.GetValues(typeof(GameControllerAnalog)); _eventTokenList = new List <SubscriptionToken>(); _eventBus = eventBus; #if (DEBUG) var logSeverity = CefLogSeverity.Error; #else var logSeverity = CefLogSeverity.Error; #endif var settings = new CefSettings { WindowlessRenderingEnabled = true, LogSeverity = logSeverity, NoSandbox = true }; CefRuntime.Initialize(mainArgs, settings, menuCeffApp, IntPtr.Zero); // Instruct CEF to not render to a window at all. var cefWindowInfo = CefWindowInfo.Create(); cefWindowInfo.SetAsWindowless(IntPtr.Zero, false); var browserSettings = new CefBrowserSettings() { WindowlessFrameRate = 60, }; _inputProcessor = inputProcessor; _browserClient = browserClient; _browser = CefBrowserHost.CreateBrowserSync( cefWindowInfo, _browserClient, browserSettings, "http://localhost:4200" ); _eventTokenList.Add(_eventBus.Subscribe <OpenMenuEvent>(OnOpenMenuEvent)); _eventTokenList.Add(_eventBus.Subscribe <CloseMenuEvent>(OnCloseMenuEvent)); var game = stateManager.GetGameById("Super Mario World (USA)"); eventBus.Publish(new LoadGameEvent(game)); }
public void Initialize() { IoCManager.Instance !.InjectDependencies(this, oneOff: true); string subProcessName; if (OperatingSystem.IsWindows()) { subProcessName = "Robust.Client.WebView.exe"; } else if (OperatingSystem.IsLinux()) { subProcessName = "Robust.Client.WebView"; } else { throw new NotSupportedException("Unsupported platform for CEF!"); } var subProcessPath = PathHelpers.ExecutableRelativeFile(subProcessName); var cefResourcesPath = LocateCefResources(); // System.Console.WriteLine(AppContext.GetData("NATIVE_DLL_SEARCH_DIRECTORIES")); if (cefResourcesPath == null) { throw new InvalidOperationException("Unable to locate cef_resources directory!"); } var settings = new CefSettings() { WindowlessRenderingEnabled = true, // So we can render to our UI controls. ExternalMessagePump = false, // Unsure, honestly. TODO CEF: Research this? NoSandbox = true, // Not disabling the sandbox crashes CEF. BrowserSubprocessPath = subProcessPath, LocalesDirPath = Path.Combine(cefResourcesPath, "locales"), ResourcesDirPath = cefResourcesPath, RemoteDebuggingPort = 9222, }; Logger.Info($"CEF Version: {CefRuntime.ChromeVersion}"); _app = new RobustCefApp(); // We pass no main arguments... CefRuntime.Initialize(new CefMainArgs(null), settings, _app, IntPtr.Zero); // TODO CEF: After this point, debugging breaks. No, literally. My client crashes but ONLY with the debugger. // I have tried using the DEBUG and RELEASE versions of libcef.so, stripped or non-stripped... // And nothing seemed to work. Odd. }
public CefGlueBrowser(IntPtr parentHandle, CefApp app, CefConfig config) { this.ParentHandle = parentHandle; this.App = app; this.Config = config; var windowInfo = CefWindowInfo.Create(); windowInfo.SetAsChild(parentHandle, new CefRectangle(0, 0, config.Width, config.Height)); this.WebBrowser = new WebBrowser(this); this.WebBrowser.Created += WebBrowser_Created; this.Client = new WebClient(this.WebBrowser); CefBrowserHost.CreateBrowser(windowInfo, Client, config.CefBrowserSettings, config.StartUrl); }
private static Container SetupContainer(CefMainArgs cefMainArgs, CefApp cefApp) { var container = new Container(); // Register Cef related instances container.RegisterInstance(cefMainArgs); container.RegisterInstance(cefApp); container.RegisterInstance <IEventBusConfiguration>( new EventBusConfiguration { ThrowSubscriberException = false } ); // Register renderer (TODO: maybe make it configurable?) container.Register <IRenderer, SurfaceRenderer>(Lifestyle.Singleton); // Register main components container.RegisterSingleton <InputProcessor>(); container.RegisterSingleton <SceneManager>(); container.RegisterSingleton <MenuRenderer>(); container.RegisterSingleton <MenuBrowserClient>(); container.RegisterSingleton <StateManager>(); container.RegisterSingleton <EventProcessor>(); container.RegisterSingleton <EventBus>(); container.RegisterSingleton <Config>(); container.RegisterSingleton <RetroCoreFactory>(); container.RegisterSingleton <RawRenderer>(); // Register Scenes // container.Collection.Register<IScene>(Assembly.GetExecutingAssembly()); // container.RegisterSingleton<RetroCoreManager>(); container.Collection.Register <IScene>(typeof(RetroCoreManager)); // Register API components container.RegisterSingleton <ApiRouter>(); container.Register <CefRequestHandler, ApiRequestHandler>(Lifestyle.Singleton); container.Collection.Register <IAction>(Assembly.GetExecutingAssembly()); return(container); }
public unsafe static void Main(string[] args) { string cefPath = Path.Combine(Path.GetDirectoryName(GetProjectPath()), "cef"); var path = Environment.GetEnvironmentVariable("PATH"); Environment.SetEnvironmentVariable("PATH", Path.Combine(cefPath, "Release") + ";" + path); string libname = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "libcef.dll" : "libcef.so"; IntPtr pLibCef = NativeMethods.LoadLibrary(Path.Combine(cefPath, "Release", libname)); // This executable is called many times, because it // is also used for subprocesses. Let's print args // so we can differentiate between main process and // subprocesses. If one of the first args is for // example "--type=renderer" then it means that // this is a Renderer process. There may be more // subprocesses like GPU (--type=gpu-process) and // others. On Linux there are also special Zygote // processes. Console.Write("\nProcess args: "); if (args.Length == 0) { Console.Write("none (Main process)"); } else { Console.WriteLine(); for (int i = 0; i < args.Length; i++) { if (args[i].Length > 128) { Console.WriteLine(args[i].Remove(128) + "..."); } else { Console.WriteLine(args[i]); } } } Console.Write("\n\n"); if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && !args.Any(arg => arg.StartsWith("--type=")) && !args.Contains("--no-zygote")) { Console.WriteLine("Please run with --no-zygote"); return; } // CEF version if (args.Length == 0) { var version = new int[8]; for (int i = 0; i < version.Length; i++) { version[i] = CefApi.CefVersionInfo((CefVersionComponent)i); } Console.Write("CEF version: {0}\n", string.Join(".", version)); } // Main args CefMainArgs main_args = CefMainArgs.CreateDefault(); // Cef app var app = new CefApp(); // Execute subprocesses. It is also possible to have // a separate executable for subprocesses by setting // cef_settings_t.browser_subprocess_path. In such // case cef_execute_process should not be called here. Console.Write("cef_execute_process, argc={0}\n", args.Length); int code = CefApi.ExecuteProcess(main_args, app, IntPtr.Zero); if (code >= 0) { main_args.Dispose(); Environment.Exit(code); } // Application settings. It is mandatory to set the // "size" member. var settings = new CefSettings(); //settings.MultiThreadedMessageLoop = true; settings.LocalesDirPath = Path.Combine(cefPath, "Resources", "locales"); settings.ResourcesDirPath = Path.Combine(cefPath, "Resources"); settings.LogSeverity = CefLogSeverity.Warning; // Show only warnings/errors settings.NoSandbox = true; settings.WindowlessRenderingEnabled = true; // Initialize CEF Console.Write("cef_initialize\n"); CefApi.Initialize(main_args, settings, app, IntPtr.Zero); GC.KeepAlive(settings); main_args.Dispose(); // Window info var windowInfo = new CefWindowInfo(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { windowInfo.SetAsPopup(IntPtr.Zero, "cefapi example"); } else { windowInfo.WindowName = "cefapi example"; } if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { NativeMethods.XSetErrorHandler(x11_error_handler); NativeMethods.XSetIOErrorHandler(x11_io_error_handler); } var browserSettings = new CefBrowserSettings(); // Client handlers var client = new CefClientClass(); // Create browser asynchronously. There is also a // synchronous version of this function available. Console.WriteLine("cef_browser_host_create_browser"); bool cbok = CefApi.CreateBrowser(windowInfo, client, "https://yandex.com/", browserSettings, null, null); Console.WriteLine("CreateBrowser: {0}", cbok); windowInfo.Dispose(); // Message loop. There is also cef_do_message_loop_work() // that allow for integrating with existing message loops. // On Windows for best performance you should set // cef_settings_t.multi_threaded_message_loop to true. // Note however that when you do that CEF UI thread is no // more application main thread and using CEF API is more // difficult and require using functions like cef_post_task // for running tasks on CEF UI thread. Console.WriteLine("cef_run_message_loop\n"); CefApi.RunMessageLoop(); // Release references to CefBrowser's (if any) GC.Collect(); GC.WaitForPendingFinalizers(); // Shutdown CEF Console.WriteLine("cef_shutdown\n"); CefApi.Shutdown(); GC.KeepAlive(client); }
public RenderProcessHandler(CefApp app) { this.App = app; }
public BrowserProcessHandler(CefApp app) { this.App = app; }
protected int RunInternal(string[] args) { MacHostRuntime.LoadNativeHostFile(_config); _config.ChromelyVersion = CefRuntime.ChromeVersion; var tempFiles = CefBinariesLoader.Load(_config); CefRuntime.EnableHighDpiSupport(); _settings = new CefSettings { MultiThreadedMessageLoop = (_config.Platform == ChromelyPlatform.Windows && !_config.WindowOptions.UseOnlyCefMessageLoop), LogSeverity = CefLogSeverity.Info, LogFile = "logs\\chromely.cef_" + DateTime.Now.ToString("yyyyMMdd") + ".log", ResourcesDirPath = _config.AppExeLocation }; _settings.LocalesDirPath = Path.Combine(_settings.ResourcesDirPath, "locales"); _settings.RemoteDebuggingPort = 20480; _settings.Locale = "en-US"; _settings.NoSandbox = true; var argv = args; if (CefRuntime.Platform != CefRuntimePlatform.Windows) { argv = new string[args.Length + 1]; Array.Copy(args, 0, argv, 1, args.Length); argv[0] = "-"; } // Update configuration settings _settings.Update(_config.CustomSettings); // For Windows- if MultiThreadedMessageLoop is overriden in Setting using CustomSettings, then // It is assumed that the developer way not be aware of IWindowOptions - UseOnlyCefMessageLoop if (_config.Platform == ChromelyPlatform.Windows) { _config.WindowOptions.UseOnlyCefMessageLoop = !_settings.MultiThreadedMessageLoop; } // Set DevTools url string devtoolsUrl = _config.DevToolsUrl; if (string.IsNullOrWhiteSpace(devtoolsUrl)) { _config.DevToolsUrl = $"http://127.0.0.1:{_settings.RemoteDebuggingPort}"; } else { Uri uri = new Uri(devtoolsUrl); if (uri.Port <= 80) { _config.DevToolsUrl = $"{devtoolsUrl}:{_settings.RemoteDebuggingPort}"; } } ResolveHandlers(); var mainArgs = new CefMainArgs(argv); CefApp app = CreateApp(); if (ClientAppUtils.ExecuteProcess(_config.Platform, 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. var exitCode = CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero); if (exitCode >= 0) { // The sub-process has completed so return here. Logger.Instance.Log.LogInformation($"Sub process executes successfully with code: {exitCode}"); return(exitCode); } } CefRuntime.Initialize(mainArgs, _settings, app, IntPtr.Zero); _window.RegisterHandlers(); RegisterDefaultSchemeHandlers(); RegisterCustomSchemeHandlers(); CefBinariesLoader.DeleteTempFiles(tempFiles); _window.Init(_settings); MacHostRuntime.EnsureNativeHostFileExists(_config); NativeHost_CreateAndShowWindow(); NativeHost_Run(); CefRuntime.Shutdown(); NativeHost_Quit(); return(0); }