internal int InitializeProcessOnly() { var args = Environment.GetCommandLineArgs(); if (ProcessType == CefProcessType.Browser) { Logger.Error("This process is just only run as subprocess."); return(-1); } CefRuntime.Load(ChromiumEnvironment.LibCefDir); IsRuntimeInitialized = true; if (!ChromiumEnvironment.ForceHighDpiSupportDisabled) { CefRuntime.EnableHighDpiSupport(); } ChromiumEnvironment.CefBrowserSettingConfigurations?.Invoke(WinFormium.DefaultBrowserSettings); ApplicationConfiguration.UseExtensions[(int)ExtensionExecutePosition.SubProcessStartup]?.Invoke(this, ApplicationProperties); var cefMainArgs = new CefMainArgs(args); var app = new WinFormiumApp(); var exitCode = CefRuntime.ExecuteProcess(cefMainArgs, app, IntPtr.Zero); return(exitCode); }
public static int Main(string[] args) { CefRuntime.EnableHighDpiSupport(); CefRuntime.Load(); var app = new WebRendererApp(); var mainArgs = new CefMainArgs(args); var exitCode = CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero); if (exitCode != -1) { return(exitCode); } CefRuntime.Shutdown(); return(0); }
/// <summary> /// Executes the <see cref="Subprocess"/>. /// </summary> /// <param name="args"></param> /// <returns></returns> public static int Execute(string[] args) { int result; var type = args.GetArgumentValue(SubprocessArguments.ArgumentType); // The Crashpad Handler doesn't have any HostProcessIdArgument, so we must not try to // parse it lest we want an ArgumentNullException. if (type != "crashpad-handler") { var parentProcessId = int.Parse(args.GetArgumentValue(SubprocessArguments.HostProcessIdArgument)); if (args.HasArgument(SubprocessArguments.ExitIfParentProcessClosed)) { Task.Factory.StartNew(() => AwaitParentProcessExit(parentProcessId), TaskCreationOptions.LongRunning); } } // For Windows 7 and above, best to include relevant app.manifest entries as well CefRuntime.EnableHighDpiSupport(); if (type == "renderer") { var subProcess = new Subprocess(args); result = subProcess.Run(args); } else { result = ExecuteProcess(args); } if (ChromelyConfiguration.Instance.DebuggingMode) { Console.WriteLine("CefGlue Subprocess shutting down."); } return(result); }
private int RunInternal(string[] args) { Initialize(); _config.ChromelyVersion = CefRuntime.ChromeVersion; var tempFiles = CefBinariesLoader.Load(_config); CefRuntime.EnableHighDpiSupport(); var settings = new CefSettings { MultiThreadedMessageLoop = _config.Platform == ChromelyPlatform.Windows, LogSeverity = CefLogSeverity.Info, LogFile = "logs\\chromely.cef_" + DateTime.Now.ToString("yyyyMMdd") + ".log", ResourcesDirPath = _config.AppExeLocation }; if (_config.WindowOptions.WindowFrameless || _config.WindowOptions.KioskMode) { // MultiThreadedMessageLoop is not allowed to be used as it will break frameless mode settings.MultiThreadedMessageLoop = false; } 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); // Set DevTools url _config.DevToolsUrl = $"http://127.0.0.1:{settings.RemoteDebuggingPort}"; var mainArgs = new CefMainArgs(argv); CefApp app = new CefGlueApp(_config); 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.Info($"Sub process executes successfully with code: {exitCode}"); return(exitCode); } } CefRuntime.Initialize(mainArgs, settings, app, IntPtr.Zero); ScanAssemblies(); RegisterRoutes(); RegisterMessageRouters(); RegisterResourceHandlers(); RegisterSchemeHandlers(); RegisterAjaxSchemeHandlers(); CefBinariesLoader.DeleteTempFiles(tempFiles); CreateMainWindow(); Run(); _mainWindow.Dispose(); _mainWindow = null; Shutdown(); return(0); }
/// <summary> /// The on create. /// </summary> /// <param name="packet"> /// The packet. /// </param> /// <exception cref="Exception"> /// Rethrown exception on Cef load failure. /// </exception> protected override void OnCreate(ref CreateWindowPacket packet) { CefRuntime.EnableHighDpiSupport(); // Will throw exception if Cef load fails. CefRuntime.Load(); var mainArgs = new CefMainArgs(this.HostConfig.AppArgs); var app = new CefGlueApp(this.HostConfig); var exitCode = CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero); if (exitCode != -1) { return; } var codeBase = Assembly.GetExecutingAssembly().CodeBase; var localFolder = Path.GetDirectoryName(new Uri(codeBase).LocalPath); var localesDirPath = Path.Combine(localFolder, "locales"); var settings = new CefSettings { LocalesDirPath = localesDirPath, Locale = this.HostConfig.Locale, SingleProcess = false, MultiThreadedMessageLoop = true, LogSeverity = (CefLogSeverity)this.HostConfig.LogSeverity, LogFile = this.HostConfig.LogFile, ResourcesDirPath = Path.GetDirectoryName(new Uri(Assembly.GetEntryAssembly().CodeBase).LocalPath), NoSandbox = true }; // Update configuration settings settings.Update(this.HostConfig.CustomSettings); CefRuntime.Initialize(mainArgs, settings, app, IntPtr.Zero); this.RegisterSchemeHandlers(); this.RegisterMessageRouters(); var clientSize = this.GetClientSize(); var browserConfig = new CefBrowserConfig { StartUrl = this.HostConfig.StartUrl, ParentHandle = this.Handle, AppArgs = this.HostConfig.AppArgs, StartWebSocket = this.HostConfig.StartWebSocket, WebsocketAddress = this.HostConfig.WebsocketAddress, WebsocketPort = this.HostConfig.WebsocketPort, CefRectangle = new CefRectangle { X = 0, Y = 0, Width = clientSize.Width, Height = clientSize.Height } }; this.mBrowser = new CefGlueBrowser(browserConfig); this.mBrowser.BrowserCreated += OnBrowserCreated; base.OnCreate(ref packet); Log.Info("Cef browser successfully created."); }
/// <summary> /// The run internal. /// </summary> /// <param name="args"> /// The args. /// </param> /// <returns> /// The <see cref="int"/>. /// </returns> private int RunInternal(string[] args) { var tempFiles = CefBinariesLoader.Load(HostConfig); CefRuntime.EnableHighDpiSupport(); var assembly = Assembly.GetEntryAssembly() ?? typeof(ChromelyConfiguration).Assembly; var settings = new CefSettings { MultiThreadedMessageLoop = true, LogSeverity = (CefLogSeverity)HostConfig.LogSeverity, LogFile = HostConfig.LogFile, ResourcesDirPath = Path.GetDirectoryName(new Uri(assembly.CodeBase).LocalPath) }; if (HostConfig.HostFrameless || HostConfig.KioskMode) { if (HostConfig.HostApi == ChromelyHostApi.Gtk) { throw new NotSupportedException("Chromely currently does not support frameless windows using GTK."); } // MultiThreadedMessageLoop is not allowed to be used as it will break frameless mode settings.MultiThreadedMessageLoop = false; } settings.LocalesDirPath = Path.Combine(settings.ResourcesDirPath, "locales"); settings.RemoteDebuggingPort = 20480; settings.NoSandbox = true; settings.Locale = HostConfig.Locale; if (HostConfig.UseDefaultSubprocess) { var subprocessExeFullpath = DefaultSubprocessExe.FulPath; settings.BrowserSubprocessPath = subprocessExeFullpath ?? settings.BrowserSubprocessPath; } 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(HostConfig.CustomSettings); var mainArgs = new CefMainArgs(argv); var app = new CefGlueApp(HostConfig); // 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. CefBinariesLoader.DeleteTempFiles(tempFiles); Log.Info($"Sub process executes successfully with code: {exitCode}"); return(exitCode); } // guard if something wrong foreach (var arg in args) { if (arg.StartsWith("--type=")) { return(-2); } } CefRuntime.Initialize(mainArgs, settings, app, IntPtr.Zero); RegisterSchemeHandlers(); RegisterMessageRouters(); Initialize(); _mainView = CreateMainView(); if (HostConfig.HostCenterScreen) { _mainView.CenterToScreen(); } _windowCreated = true; CefBinariesLoader.DeleteTempFiles(tempFiles); RunMessageLoop(); _mainView.Dispose(); _mainView = null; CefRuntime.Shutdown(); Shutdown(); return(0); }
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, LogSeverity = CefLogSeverity.Info, LogFile = "logs\\chromely.cef_" + DateTime.Now.ToString("yyyyMMdd") + ".log", ResourcesDirPath = _config.AppExeLocation }; if (_config.WindowOptions.WindowFrameless || _config.WindowOptions.KioskMode) { // MultiThreadedMessageLoop is not allowed to be used as it will break frameless mode _settings.MultiThreadedMessageLoop = false; } _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); // 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 = new CefBrowserApp(_config, _requestSchemeProvider, _handlersResolver); 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); }
/// <summary> /// The run internal. /// </summary> /// <param name="args"> /// The args. /// </param> /// <returns> /// The <see cref="int"/>. /// </returns> private int RunInternal(string[] args) { Initialize(); var tempFiles = CefBinariesLoader.Load(HostConfig); CefRuntime.EnableHighDpiSupport(); var settings = new CefSettings { MultiThreadedMessageLoop = HostConfig.Platform == ChromelyPlatform.Windows, LogSeverity = (CefLogSeverity)HostConfig.LogSeverity, LogFile = HostConfig.LogFile, ResourcesDirPath = HostConfig.AppExeLocation }; if (HostConfig.HostPlacement.Frameless || HostConfig.HostPlacement.KioskMode) { // MultiThreadedMessageLoop is not allowed to be used as it will break frameless mode settings.MultiThreadedMessageLoop = false; } settings.LocalesDirPath = Path.Combine(settings.ResourcesDirPath, "locales"); settings.RemoteDebuggingPort = 20480; settings.Locale = HostConfig.Locale; 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(HostConfig.CustomSettings); var mainArgs = new CefMainArgs(argv); CefApp app = new CefGlueApp(HostConfig); // 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. CefBinariesLoader.DeleteTempFiles(tempFiles); Log.Info($"Sub process executes successfully with code: {exitCode}"); return(exitCode); } CefRuntime.Initialize(mainArgs, settings, app, IntPtr.Zero); RegisterSchemeHandlers(); RegisterMessageRouters(); CreateMainWindow(); bool centerScreen = HostConfig.HostPlacement.CenterScreen; if (centerScreen) { _mainView.CenterToScreen(); } _windowCreated = true; IoC.RegisterInstance(typeof(IChromelyWindow), typeof(IChromelyWindow).FullName, this); CefBinariesLoader.DeleteTempFiles(tempFiles); RunMessageLoop(); _mainView.Dispose(); _mainView = null; CefRuntime.Shutdown(); Shutdown(); return(0); }
internal int Initialize() { var args = Environment.GetCommandLineArgs(); if (ProcessType == CefProcessType.Browser) { var currentProcess = Process.GetCurrentProcess(); ApplicationConfiguration.UseExtensions[(int)ExtensionExecutePosition.MainProcessStartup]?.Invoke(this, ApplicationProperties); } CefRuntime.Load(ChromiumEnvironment.LibCefDir); IsRuntimeInitialized = true; if (ProcessType == CefProcessType.Browser) { var info = $@" Welcome to NanUI/0.8 Dev ({WinFormium.PlatformArchitecture}); Chromium/{CefRuntime.ChromeVersion}; WinFormium/{Assembly.GetExecutingAssembly().GetName().Version}; Copyrights (C) 2015-{DateTime.Now.Year} NetDimension Studio all rights reserved. Powered by Xuanchen Lin. {NanUI.Properties.Resources.ASCII_NanUI_Logo} This project is under LGPL-3.0 License. https://github.com/NetDimension/NanUI/blob/master/LICENCE "; Logger.Info(info); } if (!ChromiumEnvironment.ForceHighDpiSupportDisabled) { CefRuntime.EnableHighDpiSupport(); } ChromiumEnvironment.CefBrowserSettingConfigurations?.Invoke(WinFormium.DefaultBrowserSettings); ApplicationConfiguration.UseExtensions[(int)ExtensionExecutePosition.SubProcessStartup]?.Invoke(this, ApplicationProperties); var cefMainArgs = new CefMainArgs(args); var app = new WinFormiumApp(); var exitCode = CefRuntime.ExecuteProcess(cefMainArgs, app, IntPtr.Zero); Logger.Info(string.Format("CefRuntime.ExecuteProcess() returns {0}", exitCode)); if (exitCode != -1) { return(exitCode); } foreach (var arg in args) { if (arg.StartsWith("--type=")) { return(-2); } } RegisterCustomResourceHandler(new ResourceHandler.InternalResource.InternalSchemeConfiguration()); var settings = new CefSettings { LogSeverity = CefLogSeverity.Warning, ResourcesDirPath = ChromiumEnvironment.LibCefResourceDir, LocalesDirPath = ChromiumEnvironment.LibCefLocaleDir, Locale = Thread.CurrentThread.CurrentCulture.ToString(), AcceptLanguageList = Thread.CurrentThread.CurrentCulture.ToString(), JavaScriptFlags = "--expose-gc", CachePath = WinFormium.DefaultAppDataDirectory, }; settings.LogFile = Path.Combine(settings.CachePath, "debug.log"); ChromiumEnvironment.SettingConfigurations?.Invoke(settings); settings.MultiThreadedMessageLoop = true; settings.NoSandbox = true; if (!string.IsNullOrEmpty(ChromiumEnvironment.SubprocessPath)) { settings.BrowserSubprocessPath = ChromiumEnvironment.SubprocessPath; } CefRuntime.Initialize(new CefMainArgs(args), settings, app, IntPtr.Zero); ApplicationConfiguration.UseExtensions[(int)ExtensionExecutePosition.Initialized]?.Invoke(this, ApplicationProperties); foreach (var config in CustomResourceHandlerConfigurations) { config.OnResourceHandlerRegister(); if (!CefRuntime.RegisterSchemeHandlerFactory(config.Scheme, config.DomainName, config)) { throw new InvalidOperationException("ResouceHandler is fail to be registered"); } } var context = GetAppContext(); if (context == null) { context = ApplicationConfiguration.UseApplicationContext?.Invoke(); if (context != null) { context.ThreadExit += (_, args) => { Application.Exit(); }; } } if (context != null) { Application.Run(context); return(0); } Environment.Exit(-1); return(-1); }
/// <summary> /// The run internal. /// </summary> /// <param name="args"> /// The args. /// </param> /// <returns> /// The <see cref="int"/>. /// </returns> private int RunInternal(string[] args) { var tempFiles = CefBinariesLoader.Load(HostConfig); CefRuntime.EnableHighDpiSupport(); var settings = new CefSettings { MultiThreadedMessageLoop = true, LogSeverity = (CefLogSeverity)HostConfig.LogSeverity, LogFile = HostConfig.LogFile, ResourcesDirPath = Path.GetDirectoryName( new Uri(Assembly.GetEntryAssembly().CodeBase).LocalPath) }; settings.LocalesDirPath = Path.Combine(settings.ResourcesDirPath, "locales"); settings.RemoteDebuggingPort = 20480; settings.NoSandbox = true; settings.Locale = HostConfig.Locale; 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(HostConfig.CustomSettings); var mainArgs = new CefMainArgs(argv); var app = new CefGlueApp(HostConfig); var exitCode = CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero); Log.Info($"CefRuntime.ExecuteProcess() returns {exitCode}"); if (exitCode != -1) { // An error has occured. CefBinariesLoader.DeleteTempFiles(tempFiles); return(exitCode); } // guard if something wrong foreach (var arg in args) { if (arg.StartsWith("--type=")) { return(-2); } } CefRuntime.Initialize(mainArgs, settings, app, IntPtr.Zero); RegisterSchemeHandlers(); RegisterMessageRouters(); Initialize(); mMainView = CreateMainView(); if (HostConfig.HostCenterScreen) { mMainView.CenterToScreen(); } mWindowCreated = true; CefBinariesLoader.DeleteTempFiles(tempFiles); RunMessageLoop(); mMainView.Dispose(); mMainView = null; CefRuntime.Shutdown(); Shutdown(); return(0); }
/// <summary> /// The run internal. /// </summary> /// <param name="args"> /// The args. /// </param> /// <returns> /// The <see cref="int"/>. /// </returns> private int RunInternal(string[] args) { CefRuntime.Load(); if (Environment.OSVersion.Version.Major >= 6) { CefRuntime.EnableHighDpiSupport(); } MultiThreadedMessageLoop = true; var configuration = Extension.GetConfiguration(); var ResourcesDir = Path.GetDirectoryName(new Uri(Assembly.GetEntryAssembly().CodeBase).LocalPath); var settings = new CefSettings { MultiThreadedMessageLoop = MultiThreadedMessageLoop, SingleProcess = false, LogSeverity = CefLogSeverity.Error, LogFile = this.HostConfig.LogFile, ResourcesDirPath = ResourcesDir, BackgroundColor = new CefColor(255, 32, 31, 41), LocalesDirPath = Path.Combine(ResourcesDir, "locales"), RemoteDebuggingPort = configuration.RemoteDebuggingPort, NoSandbox = true, Locale = this.HostConfig.Locale }; 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(this.HostConfig.CustomSettings); var mainArgs = new CefMainArgs(argv); var app = new CefGlueApp(this.HostConfig); var exitCode = CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero); Log.Info(string.Format("CefRuntime.ExecuteProcess() returns {0}", exitCode)); if (exitCode != -1) { // An error has occured. return(exitCode); } // guard if something wrong foreach (var arg in args) { if (arg.StartsWith("--type=")) { return(-2); } } CefRuntime.Initialize(mainArgs, settings, app, IntPtr.Zero); this.RegisterSchemeHandlers(); this.RegisterMessageRouters(); this.PlatformInitialize(); this.MainView = this.CreateMainView(); this.PlatformRunMessageLoop(); this.MainView.Dispose(); this.MainView = null; CefRuntime.Shutdown(); this.PlatformShutdown(); return(0); }
internal static bool InitCef(string[] args, string mBSTProcessIdentifier) { try { Logger.Info("Install Boot: CefRuntime.Load"); CefRuntime.Load(RegistryManager.Instance.CefDataPath); } catch (DllNotFoundException ex) { Logger.Info("Install Boot: DllNotFoundException"); int num = (int)MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Hand); return(false); } catch (CefRuntimeException ex) { Logger.Info("Install Boot: CefRuntimeException"); int num = (int)MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Hand); return(false); } catch (Exception ex) { Logger.Info("Install Boot: ex"); int num = (int)MessageBox.Show(ex.ToString(), "Error!", MessageBoxButton.OK, MessageBoxImage.Hand); return(false); } CefMainArgs args1 = new CefMainArgs(args); CefHelper cefHelper = new CefHelper(); CefRuntime.EnableHighDpiSupport(); if (CefRuntime.ExecuteProcess(args1, (CefApp)cefHelper, IntPtr.Zero) != -1) { return(false); } string str = "Mozilla/5.0(Windows NT 6.2; Win64; x64) AppleWebKit/537.36(KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36" + mBSTProcessIdentifier; if (!SystemUtils.IsOs64Bit()) { str = "Mozilla/5.0(Windows NT 6.2; WOW64) AppleWebKit/537.36(KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36" + mBSTProcessIdentifier; } CefSettings settings = new CefSettings() { SingleProcess = false, WindowlessRenderingEnabled = true, MultiThreadedMessageLoop = true, LogSeverity = CefLogSeverity.Verbose, BackgroundColor = new CefColor(byte.MaxValue, (byte)39, (byte)41, (byte)65), CachePath = Path.Combine(RegistryManager.Instance.CefDataPath, "Cache"), PersistSessionCookies = true, UserAgent = str, Locale = RegistryManager.Instance.UserSelectedLocale }; if (RegistryManager.Instance.CefDebugPort != 0) { settings.RemoteDebuggingPort = RegistryManager.Instance.CefDebugPort; } try { CefRuntime.Initialize(args1, settings, (CefApp)cefHelper, IntPtr.Zero); Logger.Info("Install Boot: cef Initialized"); } catch (CefRuntimeException ex) { int num = (int)MessageBox.Show(ex.ToString(), "Error!", MessageBoxButton.OK, MessageBoxImage.Hand); return(false); } CefHelper.CefInited = true; Logger.Info("Install Boot: cef Initialize completed"); return(true); }
private static int Main(string[] args) { PublicClass.currDirectiory = Environment.CurrentDirectory.ToString(); // PublicClass.currDirectiory = System.Windows.Forms.Application.StartupPath; new ProcessHook().InitHook(); try { CefRuntime.Load(); } catch (DllNotFoundException ex) { MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return(1); } catch (CefRuntimeException ex) { MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return(2); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return(3); } var mainArgs = new CefMainArgs(args); var app = new DemoApp(); var exitCode = CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero); if (exitCode != -1) { return(exitCode); } var codeBase = Assembly.GetExecutingAssembly().CodeBase; var localFolder = Path.GetDirectoryName(new Uri(codeBase).LocalPath); var settings = new CefSettings { //BrowserSubprocessPath = browserProcessPath, //SingleProcess = false, //WindowlessRenderingEnabled = true, MultiThreadedMessageLoop = true, LogSeverity = CefLogSeverity.Disable, //LogFile = "CefGlue.log", Locale = "zh-CN", JavaScriptFlags = "js-flags", CommandLineArgsDisabled = false, IgnoreCertificateErrors = true, CachePath = GetAppDir("Cache"), UserAgent = CefConstHelper.UserAgent, //NoSandbox = true, //AcceptLanguageList = "zh-CN", //PersistSessionCookies = true, }; CefRuntime.RegisterSchemeHandlerFactory(CefConstHelper.Branding, CefConstHelper.Branding, new SchemeHandlerFactory()); CefRuntime.Initialize(mainArgs, settings, app, IntPtr.Zero); Application.EnableVisualStyles(); CefRuntime.EnableHighDpiSupport(); Application.SetCompatibleTextRenderingDefault(false); if (!settings.MultiThreadedMessageLoop) { Application.Idle += (sender, e) => { CefRuntime.DoMessageLoopWork(); }; } if (args.Length > 0) { Application.Run(new MainForm(args[0].ToString())); //MessageBox.Show(PublicClass.StartUrl); } else { Application.Run(new MainForm("")); } CefRuntime.Shutdown(); try { //if (Directory.Exists(GetAppDir("Cache"))) // Directory.Delete(GetAppDir("Cache"), true); } catch { } return(0); }