static public bool InternalLoadLibCefDll(string fullpath) { uint LOAD_WITH_ALTERED_SEARCH_PATH = 0x00000008; IntPtr hr = WindowsInterop.LoadLibraryEx(fullpath, IntPtr.Zero, LOAD_WITH_ALTERED_SEARCH_PATH); if (hr == IntPtr.Zero) { return(false); } WriteDebugLine("libcef.dll Load OK "); if (PrintDebugInformation) { string verstr = LibCefInterop.CefVersionArrFromLibCefDll(); WriteDebugLine("cef_version_info : " + verstr); if (verstr != LibCefInterop.CefVersionArr) { WriteDebugLine(" * WARNING * , version not match for " + LibCefInterop.CefVersionArr); } } _libcefEverLoaded = true; _ApplyOptionsAfterLibCefLoaded(); return(true); }
static public void QuitWindowsEventLoop() { if (IsWindowsEventLoopQuitRequested) { return; } MainThreadSynchronizationContext.Send(delegate { if (IsWindowsEventLoopQuitRequested) { return; } IsWindowsEventLoopQuitRequested = true; #if SUPPORT_WPF if (LoopMode == EventLoopMode.WPF) { _wpfapp?.Shutdown(); } #endif if (LoopMode == EventLoopMode.LibCef) { LibCefInterop.cef_quit_message_loop(); } if (LoopMode == EventLoopMode.WinForms) { WF.Application.Exit(); //This is not a good solution, hang } }, null); }
//Set Options: static public void SetEnableHighDPISupport() { _optionset.Add("SetEnableHighDPISupport"); if (!_libcefEverLoaded) return; LibCefInterop.cef_enable_highdpi_support(); }
static public void CefShutdown() { #if !FXBELOW46 bool tsngc = GC.TryStartNoGCRegion(8 * 1024 * 1024); //there's something wrong , so stop GC while shutdown the CEF if (!tsngc) WriteDebugLine("Warning , TryStartNoGCRegion failed."); #endif _CefShutdownCalled = true; try { WriteDebugLine("cef shutdown .. " + ApplicationElapsed); LibCefInterop.cef_shutdown(); WriteDebugLine("cef shutdown OK " + ApplicationElapsed); } catch (AccessViolationException x)// not able to catch .. { WriteDebugLine(x.ToString()); } finally { _CefShutdownCalled = false; #if !FXBELOW46 if (tsngc) GC.EndNoGCRegion(); #endif } #if DEBUG #if !FXBELOW46 GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, false); #endif #endif }
static void InvokeCefMessageLoopOnce() { if (_cefmessagelooprunning) return; _cefmessagelooprunning = true; LibCefInterop.cef_do_message_loop_work(); _cefmessagelooprunning = false; }
static void _ApplyOptionsAfterLibCefLoaded() { foreach (string option in _optionset) { switch (option) { case "SetEnableHighDPISupport": LibCefInterop.cef_enable_highdpi_support(); break; } } }
} = EventLoopMode.CodeLoop; //No plan to make publish static public void InternalDoEventLoop(Action initHandler) { if (initHandler != null) { PostToAppThread(initHandler); } long tickcount = 0; WF.Timer globaltimer = new WF.Timer(); globaltimer.Interval = 50; globaltimer.Tick += delegate { //for Form.ShowDialog(..) DoMessageLoopOnce(); tickcount++; if (tickcount % 50 == 0 && WF.Application.OpenForms.Count == 0 #if SUPPORT_WPF && (_wpfapp == null || _wpfapp.Windows.Count == 0) #endif ) { QuitWindowsEventLoop(); WriteDebugLine("QuitWindowsEventLoop for no Forms/Window"); } }; globaltimer.Start(); switch (LoopMode) { case EventLoopMode.LibCef: WriteDebugLine("cef_run_message_loop() start."); LibCefInterop.cef_run_message_loop(); WriteDebugLine("cef_run_message_loop() end."); break; #if SUPPORT_WPF case EventLoopMode.WPF: WpfApp.Run(); break; #endif case EventLoopMode.WinForms: WF.Application.Idle += delegate { InvokeCefMessageLoopOnce(); }; WF.Application.Run(); break; case EventLoopMode.CodeLoop: default: while (!IsWindowsEventLoopQuitRequested) { InvokeCefMessageLoopOnce(); WF.Application.DoEvents(); System.Threading.Thread.Sleep(1); } break; } globaltimer.Stop(); WriteDebugLine("Existing event loop start"); if (_app_mutex != null) { if (!_app_mutex_disposed) { _app_mutex_disposed = true; _app_mutex.Dispose(); WriteDebugLine("_app_mutex disposed 2."); } } foreach (WF.Form form in new System.Collections.ArrayList(WF.Application.OpenForms)) { WriteDebugLine("Close Form [" + form.Text + "]"); //form.Close(); form.Dispose(); } #if SUPPORT_WPF if (_wpfapp != null) { WriteDebugLine("Check wpf windows.."); foreach (System.Windows.Window win in _wpfapp.Windows) { win.Close(); } } #endif WriteDebugLine("Existing event loop end"); }
static public unsafe CefInitState InternalCefInitialize(string resourceFolder) { cef_settings_t *settings = LibCefInterop.Settings.FixedPtr; //TODO: better solution for dirs.. if (settings->resources_dir_path.IsNullOrEmpty()) { F.invoke_set(&settings->resources_dir_path, resourceFolder); } string folder; try { folder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); folder = System.IO.Path.Combine(folder, ApplicationName); if (!System.IO.Directory.Exists(folder)) { System.IO.Directory.CreateDirectory(folder); } } catch (Exception x) { WriteDebugLine("Error:Failed to create local app data folder."); WriteDebugLine(x); folder = System.IO.Path.GetTempPath(); } Console.WriteLine("CEF Data Folder : " + folder); if (settings->log_severity != cef_log_severity_t.LOGSEVERITY_DISABLE) { F.invoke_set(&settings->log_file, System.IO.Path.Combine(folder, "ceflog.txt")); } bool continueUseCacheFolder = true; if (SettingAutoClearCacheInStoragePath && DetectIsMainProcess()) { try { void DeleteFolder(string path) { if (!Directory.Exists(path)) { return; } foreach (string file in Directory.GetFiles(path)) { File.Delete(file); } foreach (string subdir in Directory.GetDirectories(path)) { DeleteFolder(subdir); } Directory.Delete(path); } DeleteFolder(Path.Combine(folder, "Cache")); } catch (Exception x) { continueUseCacheFolder = false; WriteDebugLine(x); } } if (SettingAutoSetCacheStoragePath && continueUseCacheFolder) { if (settings->cache_path.IsNullOrEmpty()) { F.invoke_set(&settings->cache_path, folder); F.invoke_set(&settings->root_cache_path, folder); //force the root_cache_path use the same value } } if (SettingAutoSetUserDataStoragePath) { if (settings->user_data_path.IsNullOrEmpty()) { F.invoke_set(&settings->user_data_path, folder); } } var state = LibCefInterop.Initialize(); WriteDebugLine("libcef Initialize : " + state); if (state != CefInitState.Initialized) { CloseSplashScreen(); } return(state); }