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); }
public bool CreateBrowser(BrowserSource browserSource, BrowserConfig browserConfig) { Debug.Assert(Status == BrowserStatus.Initial); InitClient(browserSource); Debug.Assert(browserClient != null); Debug.Assert(browserConfig != null); BrowserConfig = browserConfig; CefWindowInfo windowInfo = CefWindowInfo.Create(); windowInfo.TransparentPainting = true; windowInfo.SetAsOffScreen(IntPtr.Zero); windowInfo.Width = (int)browserConfig.BrowserSourceSettings.Width; windowInfo.Height = (int)browserConfig.BrowserSourceSettings.Height; windowInfo.MenuHandle = IntPtr.Zero; windowInfo.ParentHandle = IntPtr.Zero; String base64EncodedDataUri = "data:text/css;charset=utf-8;base64,"; String base64EncodedCss = Convert.ToBase64String(Encoding.UTF8.GetBytes(browserConfig.BrowserSourceSettings.CSS)); BrowserInstanceSettings settings = AbstractSettings.DeepClone(BrowserSettings.Instance.InstanceSettings); settings.MergeWith(browserConfig.BrowserInstanceSettings); CefBrowserSettings browserSettings = new CefBrowserSettings { AcceleratedCompositing = settings.AcceleratedCompositing, ApplicationCache = settings.ApplicationCache, AuthorAndUserStyles = settings.AuthorAndUserStyles, CaretBrowsing = settings.CaretBrowsing, CursiveFontFamily = settings.CursiveFontFamily, Databases = settings.Databases, DefaultEncoding = settings.DefaultEncoding, DefaultFixedFontSize = settings.DefaultFixedFontSize, DefaultFontSize = settings.DefaultFontSize, DeveloperTools = settings.DeveloperTools, 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, PageCache = settings.PageCache, Plugins = settings.Plugins, RemoteFonts = settings.RemoteFonts, SansSerifFontFamily = settings.SansSerifFontFamily, SerifFontFamily = settings.SerifFontFamily, StandardFontFamily = settings.StandardFontFamily, //TabToLinks = settings.TabToLinks, //TextAreaResize = settings.TextAreaResize, UniversalAccessFromFileUrls = settings.UniversalAccessFromFileUrls, UserStyleSheetLocation = base64EncodedDataUri + base64EncodedCss, WebGL = settings.WebGL, WebSecurity = settings.WebSecurity, }; String url = browserConfig.BrowserSourceSettings.Url; if (browserConfig.BrowserSourceSettings.IsApplyingTemplate) { String resolvedTemplate = browserConfig.BrowserSourceSettings.Template; resolvedTemplate = resolvedTemplate.Replace("$(FILE)", browserConfig.BrowserSourceSettings.Url); resolvedTemplate = resolvedTemplate.Replace("$(WIDTH)", browserConfig.BrowserSourceSettings.Width.ToString()); resolvedTemplate = resolvedTemplate.Replace("$(HEIGHT)", browserConfig.BrowserSourceSettings.Height.ToString()); url = "http://absolute"; } // must be sync invoke because wrapper can be destroyed before it is run try { // Since the event methods can be called before the next statement // set the status before we call it Status = BrowserStatus.Creating; CefBrowserHost.CreateBrowser(windowInfo, browserClient, browserSettings, url); } catch (InvalidOperationException e) { API.Instance.Log("BrowserWrapper::CreateBrowser failed; {0}", e.Message); UninitClient(); return(false); } BrowserManager.Instance.IncrementBrowserInstanceCount(); return(true); }