public void Stop() { CefRuntime.PostTask(CefThreadId.UI, BrowserTask.Create(() => { if (!isMultiThreadedMessageLoop) { CefRuntime.QuitMessageLoop(); } })); dispatcher.PostTask(() => { CefRuntime.Shutdown(); }); dispatcher.Shutdown(); int browserMapCount = browserMap.Count; if (browserMapCount != 0) { throw new CefRuntimeException(String.Format( "After shutting down {0} browser instances were undisposed", browserMapCount)); } dispatcher = null; }
public void CloseBrowser(bool isForcingClose) { httpServer.Stop(); closeFinishedEvent = new ManualResetEventSlim(false); // make sure we arent mid browser creation // lock on browser lock (browserLock) { CefRuntime.PostTask(CefThreadId.UI, BrowserTask.Create(() => { if (browser != null) { browserClient.LifeSpanHandler.OnBeforeCloseEvent = new OnBeforeCloseEventHandler(OnBeforeClose); browser.GetHost().CloseBrowser(isForcingClose); } else { closeFinishedEvent.Set(); } })); closeFinishedEvent.Wait(); BrowserManager.Instance.UnregisterBrowser( browser.Identifier); // clean up the other client stuff UninitClient(); // make sure browser doesn't get disposed before close has finished browser = null; } closeFinishedEvent = null; }
public bool CreateBrowser(BrowserSource browserSource, BrowserConfig browserConfig) { if (browserClient == null) { InitClient(browserSource); } Debug.Assert(browserClient != null); Debug.Assert(browserConfig != null); BrowserConfig = browserConfig; CefWindowInfo windowInfo = CefWindowInfo.Create(); windowInfo.Width = (int)browserConfig.BrowserSourceSettings.Width; windowInfo.Height = (int)browserConfig.BrowserSourceSettings.Height; windowInfo.SetAsWindowless(IntPtr.Zero, true); BrowserInstanceSettings settings = AbstractSettings.DeepClone( BrowserSettings.Instance.InstanceSettings); settings.MergeWith(browserConfig.BrowserInstanceSettings); CefBrowserSettings browserSettings = new CefBrowserSettings { WindowlessFrameRate = browserConfig.BrowserSourceSettings.Fps, ApplicationCache = settings.ApplicationCache, CaretBrowsing = settings.CaretBrowsing, CursiveFontFamily = settings.CursiveFontFamily, Databases = settings.Databases, DefaultEncoding = settings.DefaultEncoding, DefaultFixedFontSize = settings.DefaultFixedFontSize, DefaultFontSize = settings.DefaultFontSize, FantasyFontFamily = settings.FantasyFontFamily, FileAccessFromFileUrls = settings.FileAccessFromFileUrls, FixedFontFamily = settings.FixedFontFamily, ImageLoading = settings.ImageLoading, ImageShrinkStandaloneToFit = settings.ImageShrinkStandaloneToFit, Java = settings.Java, JavaScript = settings.JavaScript, JavaScriptAccessClipboard = settings.JavaScriptAccessClipboard, JavaScriptCloseWindows = settings.JavaScriptCloseWindows, JavaScriptDomPaste = settings.JavaScriptDomPaste, JavaScriptOpenWindows = settings.JavaScriptOpenWindows, LocalStorage = settings.LocalStorage, MinimumFontSize = settings.MinimumFontSize, MinimumLogicalFontSize = settings.MinimumLogicalFontSize, Plugins = settings.Plugins, RemoteFonts = settings.RemoteFonts, SansSerifFontFamily = settings.SansSerifFontFamily, SerifFontFamily = settings.SerifFontFamily, StandardFontFamily = settings.StandardFontFamily, //TabToLinks = settings.TabToLinks, //TextAreaResize = settings.TextAreaResize, UniversalAccessFromFileUrls = settings.UniversalAccessFromFileUrls, WebGL = settings.WebGL, WebSecurity = settings.WebSecurity }; String url = browserConfig.BrowserSourceSettings.Url; if (browserConfig.BrowserSourceSettings.IsApplyingTemplate) { url = "http://absolute"; } lock (browserLock) { ManualResetEventSlim createdBrowserEvent = new ManualResetEventSlim(); CefRuntime.PostTask(CefThreadId.UI, BrowserTask.Create(() => { try { browser = CefBrowserHost.CreateBrowserSync(windowInfo, browserClient, browserSettings, new Uri(url)); BrowserManager.Instance.RegisterBrowser(browser.Identifier, this); // request the render process id for volume control browser.SendProcessMessage(CefProcessId.Renderer, CefProcessMessage.Create("renderProcessIdRequest")); } catch (Exception) { browser = null; } finally { createdBrowserEvent.Set(); } })); createdBrowserEvent.Wait(); } return(browser != null); }