private void Form_Load(object sender, EventArgs e) { var config = new CefSettings(); config.MultiThreadedMessageLoop = true; config.CachePath = Path.GetDirectoryName(Application.ExecutablePath) + "/cache"; config.LogFile = Path.GetDirectoryName(Application.ExecutablePath) + "/cef.log"; config.LogSeverity = CefLogSeverity.Warning; Cef.Initialize(config); var settings = new CefBrowserSettings(); webView = new CefWebBrowser(settings, ConfigurationManager.ConnectionStrings["HomeUrl"].ConnectionString); webView.Dock = DockStyle.Fill; webView.Parent = this; webView.BringToFront(); this.Controls.Add(webView); }
/// <summary> /// This function should be called on the main application thread to initialize /// CEF when the application is started. /// </summary> /// <param name="settings"></param> /// <exception cref="Exception"></exception> public static void Initialize(CefSettings settings, CefApp app = null) { if (IsInitialized) throw new CefException("CEF already initialized."); #if DIAGNOSTICS cef_string_t.OnCreate = (ptr, str) => { if (string.IsNullOrEmpty(str)) { Cef.Logger.Trace(LogTarget.CefString, IntPtr.Zero, LogOperation.Create, "Empty."); } else { Cef.Logger.Trace(LogTarget.CefString, ptr, LogOperation.Create, "Value=[{0}].", str.Length <= 1024 ? str : (str.Substring(0, 1024) + "...") ); } }; cef_string_t.OnDispose = (ptr) => { Cef.Logger.Trace(LogTarget.CefString, ptr, LogOperation.Dispose); }; Logger.SetAllTargets(true); Logger.Trace(LogTarget.Default, "Initialize"); #endif var n_settings = settings.CreateNative(); var n_app = app == null ? null : app.GetNativePointerAndAddRef(); // FIXME: not sure if application should be null var initialized = NativeMethods.cef_initialize(n_settings, n_app) != 0; cef_settings_t.Free(n_settings); if (!initialized) throw new CefException("CEF failed to initialize."); CurrentSettings = settings; }