/// <summary> /// This function should be called on the main application thread to initialize /// the CEF browser process. The |application| parameter may be empty. A return /// value of true indicates that it succeeded and false indicates that it failed. /// </summary> public static void Initialize(CefMainArgs args, CefSettings settings, CefApp application) { LoadIfNeed(); if (args == null) { throw new ArgumentNullException("args"); } if (settings == null) { throw new ArgumentNullException("settings"); } // if (_initialized) throw ExceptionBuilder.CefRuntimeAlreadyInitialized(); var n_main_args = args.ToNative(); var n_settings = settings.ToNative(); var n_app = application != null?application.ToNative() : null; try { if (libcef.initialize(n_main_args, n_settings, n_app) != 0) { _initialized = true; } else { throw ExceptionBuilder.CefRuntimeFailedToInitialize(); } } finally { CefMainArgs.Free(n_main_args); CefSettings.Free(n_settings); } }
/// <summary> /// This function should be called on the main application thread to initialize /// the CEF browser process. The |application| parameter may be empty. A return /// value of true indicates that it succeeded and false indicates that it failed. /// </summary> public static void Initialize(CefMainArgs args, CefSettings settings, CefApp application) { LoadIfNeed(); if (args == null) throw new ArgumentNullException("args"); if (settings == null) throw new ArgumentNullException("settings"); // if (_initialized) throw ExceptionBuilder.CefRuntimeAlreadyInitialized(); var n_main_args = args.ToNative(); var n_settings = settings.ToNative(); var n_app = application != null ? application.ToNative() : null; try { if (libcef.initialize(n_main_args, n_settings, n_app) != 0) { _initialized = true; } else { throw ExceptionBuilder.CefRuntimeFailedToInitialize(); } } finally { CefMainArgs.Free(n_main_args); CefSettings.Free(n_settings); } }
public int Initialize() { if (initialized) { if (!created) { CreateBrowser(); } return 0; } CefRuntime.Load(); var settings = new CefSettings(); settings.MultiThreadedMessageLoop = CefRuntime.Platform == CefRuntimePlatform.Windows; settings.ReleaseDCheckEnabled = true; settings.SingleProcess = true; settings.PersistSessionCookies = true; settings.CommandLineArgsDisabled = false; settings.ContextSafetyImplementation = CefContextSafetyImplementation.SafeDefault; settings.IgnoreCertificateErrors = true; settings.ResourcesDirPath = "/res"; settings.PackLoadingDisabled = false; settings.LogSeverity = CefLogSeverity.Default; settings.LogFile = "cef.log"; settings.ResourcesDirPath = System.IO.Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetEntryAssembly().CodeBase).LocalPath); settings.RemoteDebuggingPort = 9000; settings.UserAgent = browserSettings.UserAgent; settings.Locale = browserSettings.Locale; settings.LocalesDirPath = browserSettings.LocaleDirPath; settings.CachePath = browserSettings.CachePath; var args = new string[] { }; var argv = args; if (CefRuntime.Platform != CefRuntimePlatform.Windows) { argv = new string[args.Length + 1]; Array.Copy(args, 0, argv, 1, args.Length); argv[0] = "-"; } var mainArgs = new CefMainArgs(argv); Global.app = new ClientApp(); Global.app.SetBrowserControl(Global.instance); var exitCode = CefRuntime.ExecuteProcess(mainArgs, Global.app); Console.WriteLine("CefRuntime.ExecuteProcess() returns {0}", exitCode); if (exitCode != -1) return exitCode; foreach (var arg in args) { if (arg.StartsWith("--type=")) { return -2; } } CefRuntime.Initialize(mainArgs, settings, Global.app); CefRuntime.RegisterSchemeHandlerFactory("http", DumpRequestDomain, new AppSchemeHandlerFactory()); bool b = CefRuntime.AddCrossOriginWhitelistEntry("http://localhost", "http", "", true); CreateBrowser(); initialized = true; return 0; }