internal static void Initialize(CfxRenderProcessMainDelegate renderProcessMainCallback, ref CfxApp app) { if(app == null) { m_app = new CfxApp(); app = m_app; } else { m_app = app; m_browserProcessHandler = m_app.RetrieveBrowserProcessHandler(); } if(m_browserProcessHandler == null) { m_browserProcessHandler = new CfxBrowserProcessHandler(); m_app.GetBrowserProcessHandler += (sender, e) => e.SetReturnValue(m_browserProcessHandler); } RemoteService.renderProcessMainCallback = renderProcessMainCallback; m_browserProcessHandler.OnBeforeChildProcessLaunch += OnBeforeChildProcessLaunch; }
internal static void Initialize(CfxRenderProcessMainDelegate renderProcessMainCallback, ref CfxApp app) { if (app == null) { m_app = new CfxApp(); app = m_app; } else { m_app = app; m_browserProcessHandler = m_app.RetrieveBrowserProcessHandler(); } if (m_browserProcessHandler == null) { m_browserProcessHandler = new CfxBrowserProcessHandler(); m_app.GetBrowserProcessHandler += (sender, e) => e.SetReturnValue(m_browserProcessHandler); } RemoteService.renderProcessMainCallback = renderProcessMainCallback; m_browserProcessHandler.OnBeforeChildProcessLaunch += OnBeforeChildProcessLaunch; }
public static bool InitializeChromium() { if (ChromiumStartupSettings.PrepareRuntime()) { var exitCode = CfxRuntime.ExecuteProcess(null); if (exitCode >= 0) { Environment.Exit(exitCode); } var settings = new CfxSettings(); settings.WindowlessRenderingEnabled = true; settings.NoSandbox = true; var cachePath = System.IO.Path.Combine(ChromiumStartupSettings.ApplicationDataDir, Application.ProductName, "Cache"); if (!System.IO.Directory.Exists(cachePath)) { System.IO.Directory.CreateDirectory(cachePath); } settings.LocalesDirPath = ChromiumStartupSettings.LocalesDir; settings.ResourcesDirPath = ChromiumStartupSettings.ResourcesDir; settings.Locale = "zh-CN"; settings.CachePath = cachePath; settings.LogSeverity = CfxLogSeverity.Disable; OnRegisterCustomSchemes += args => { args.Registrar.AddCustomScheme("embedded", false, false, false); }; try { var app = new CfxApp(); app.OnBeforeCommandLineProcessing += (s, e) => { // optimizations following recommendations from issue #84 e.CommandLine.AppendSwitch("disable-gpu"); e.CommandLine.AppendSwitch("disable-gpu-compositing"); e.CommandLine.AppendSwitch("disable-gpu-vsync"); }; if (!CfxRuntime.Initialize(settings, app)) { //Environment.Exit(-1); return(false); } Application.Idle += (sender, e) => { CfxRuntime.DoMessageLoopWork(); }; return(true); } catch (Exception ex) { Console.WriteLine(ex); Console.WriteLine(ex.InnerException); MessageBox.Show(string.Format("初始化系统失败。\r\n{0}", ex.Message), "错误", MessageBoxButtons.OK, MessageBoxIcon.Information); } } return(false); }
static void Main() { string nowDir = Environment.CurrentDirectory; CfxRuntime.LibCefDirPath = System.IO.Path.Combine(nowDir, "cef"); CfxRuntime.LibCfxDirPath = nowDir; int exitCode = CfxRuntime.ExecuteProcess(null); if (exitCode >= 0) { Environment.Exit(exitCode); } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); using (var settings = new CfxSettings()) { settings.MultiThreadedMessageLoop = true; settings.WindowlessRenderingEnabled = true; settings.NoSandbox = true; settings.ResourcesDirPath = System.IO.Path.Combine(nowDir, "cef", "Resources"); settings.LocalesDirPath = System.IO.Path.Combine(nowDir, "cef", "Resources", "locales"); var app = new CfxApp(); app.OnBeforeCommandLineProcessing += (s, e) => { // optimizations following recommendations from issue #84 e.CommandLine.AppendSwitch("disable-gpu"); e.CommandLine.AppendSwitch("disable-gpu-compositing"); e.CommandLine.AppendSwitch("disable-gpu-vsync"); }; if (!CfxRuntime.Initialize(settings, app)) { Environment.Exit(-1); } } Manager.mainForm = new Form1 { //FormBorderStyle = System.Windows.Forms.FormBorderStyle.None, BackColor = Color.White, Height = 300, Width = 300, TransparencyKey = Color.White, AllowTransparency = true }; ArkDesktopBrowserControl control = new ArkDesktopBrowserControl { Dock = DockStyle.Fill, Parent = Manager.mainForm }; Manager.mainForm.Controls.Add(control); Manager.Init(); Application.Run(Manager.mainForm); // CfxRuntime.QuitMessageLoop(); CfxRuntime.Shutdown(); }