Beispiel #1
0
        private ChromiumFxSession(Action <CfxSettings> settingsBuilder, Action <CfxBrowserSettings> browserSettingsUpdater, Action <CfxOnBeforeCommandLineProcessingEventArgs> commandLineHandler, IWebSessionLogger webSessionLogger)
        {
            _CurrentDirectory        = this.GetType().Assembly.GetPath();
            _SettingsBuilder         = settingsBuilder;
            _CommandLineHandler      = commandLineHandler;
            CfxRuntime.LibCefDirPath = GetPath($@"{CefRepo}\Release");

            ChromiumWebBrowser.OnBeforeCfxInitialize         += ChromiumWebBrowser_OnBeforeCfxInitialize;
            ChromiumWebBrowser.OnBeforeCommandLineProcessing += ChromiumWebBrowser_OnBeforeCommandLineProcessing;

            int value = CfxRuntime.ExecuteProcess();

            if (value >= 0)
            {
                Environment.Exit(value);
            }
            CfxRuntime.EnableHighDpiSupport();
            ChromiumWebBrowser.Initialize();

            browserSettingsUpdater?.Invoke(NeutroniumSettings.NeutroniumBrowserSettings);

            _NeutroniumSchemeHandlerFactory = new NeutroniumSchemeHandlerFactory(webSessionLogger);
            //need this to make request interception work
            CfxRuntime.RegisterSchemeHandlerFactory("https", "application", _NeutroniumSchemeHandlerFactory);
        }
Beispiel #2
0
        /// <summary>
        /// 在浏览器初始化之前执行事件
        /// </summary>
        /// <param name="sender">传递对象</param>
        /// <param name="e">浏览器初始化之前执行事件参数</param>
        private void ChromiumFx_OnBeforeCfxInitialize(object sender, OnBeforeCfxInitializeEventArgs e)
        {
            CfxRuntime.EnableHighDpiSupport();

            e.Settings.SingleProcess = true;
            //e.Settings.BrowserSubprocessPath = Path.GetFullPath("ChromiumFXRenderProcess.exe");

            //缓存数据存放位置
            e.Settings.CachePath = Path.GetFullPath($@"{_basePath}\LocalCache");
            //启用无窗口渲染
            e.Settings.WindowlessRenderingEnabled = true;
            //无沙箱
            e.Settings.NoSandbox = true;
            //集成消息循环(Message Loop Integration)
            //仅 Windows 操作系统有效
            e.Settings.MultiThreadedMessageLoop = true;
            //禁用日志
            e.Settings.LogSeverity = CfxLogSeverity.Disable;
            //指定中文为当前CEF环境的默认语言
            e.Settings.AcceptLanguageList = "zh-CN";
            e.Settings.Locale             = "zh-CN";
            //资源文件及语言环境目录
            e.Settings.LocalesDirPath   = Path.GetFullPath($@"{_basePath}\Resources\locales");
            e.Settings.ResourcesDirPath = Path.GetFullPath($@"{_basePath}\Resources");
        }
        private void ChromiumWebBrowser_OnBeforeCfxInitialize(OnBeforeCfxInitializeEventArgs e)
        {
            CfxRuntime.EnableHighDpiSupport();

            var settings = e.Settings;

            _SettingsBuilder?.Invoke(settings);

            settings.LocalesDirPath           = GetPath($@"{CefRepo}\Resources\locales");
            settings.Locale                   = Thread.CurrentThread.CurrentCulture.ToString();
            settings.ResourcesDirPath         = GetPath($@"{CefRepo}\Resources");
            settings.BrowserSubprocessPath    = GetPath("ChromiumFXRenderProcess.exe");
            settings.MultiThreadedMessageLoop = true;
            settings.NoSandbox                = true;
        }