示例#1
0
        public static void Initialize(GlobalSettings settings)
        {
            if (CefRuntimeLoader.IsLoaded)
            {
                return;
            }

            globalSettings = settings;

            var cefSettings = new CefSettings {
                LogSeverity = string.IsNullOrWhiteSpace(settings.LogFile) ? CefLogSeverity.Disable : (settings.EnableErrorLogOnly ? CefLogSeverity.Error : CefLogSeverity.Verbose),
                LogFile     = settings.LogFile,
                UncaughtExceptionStackSize = 100, // enable stack capture
                CachePath = settings.CachePath,   // enable cache for external resources to speedup loading
                WindowlessRenderingEnabled = settings.OsrEnabled,
                RemoteDebuggingPort        = settings.GetRemoteDebuggingPort(),
                UserAgent = settings.UserAgent
            };

            if (settings.OverrideCefSettings != null)
            {
                foreach (var property in settings.OverrideCefSettings)
                {
                    cefSettings.GetType().GetProperty(property.Key)?.SetValue(cefSettings, property.Value);
                }
            }

            var customSchemes = CustomSchemes.Select(s => new CustomScheme()
            {
                SchemeName = s, SchemeHandlerFactory = new SchemeHandlerFactory()
            }).ToArray();

            KeyValuePair <string, string>[] customFlags = new[] {
                // enable experimental feature flags
                new KeyValuePair <string, string>("enable-experimental-web-platform-features", null)
            };;

            if (settings.CustomFlags != null)
            {
                customFlags = settings.CustomFlags;
            }

            CefRuntimeLoader.Initialize(settings: cefSettings, flags: customFlags, customSchemes: customSchemes);

            AppDomain.CurrentDomain.ProcessExit += delegate { Cleanup(); };
        }