/// <summary>
        /// The on create.
        /// </summary>
        /// <param name="packet">
        /// The packet.
        /// </param>
        /// <exception cref="Exception">
        /// Rethrown exception on Cef load failure.
        /// </exception>
        protected override void OnCreate(ref CreateWindowPacket packet)
        {
            // Will throw exception if Cef load fails.
            CefRuntime.Load();

            var mainArgs = new CefMainArgs(this.HostConfig.AppArgs);
            var app      = new CefGlueApp(this.HostConfig);

            var exitCode = CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero);

            if (exitCode != -1)
            {
                return;
            }

            var codeBase       = Assembly.GetExecutingAssembly().CodeBase;
            var localFolder    = Path.GetDirectoryName(new Uri(codeBase).LocalPath);
            var localesDirPath = Path.Combine(localFolder, "locales");

            var settings = new CefSettings
            {
                LocalesDirPath           = localesDirPath,
                Locale                   = this.HostConfig.Locale,
                SingleProcess            = false,
                MultiThreadedMessageLoop = true,
                LogSeverity              = (CefLogSeverity)this.HostConfig.LogSeverity,
                LogFile                  = this.HostConfig.LogFile,
                ResourcesDirPath         = Path.GetDirectoryName(new Uri(Assembly.GetEntryAssembly().CodeBase).LocalPath),
                NoSandbox                = true
            };

            // Update configuration settings
            settings.Update(this.HostConfig.CustomSettings);

            CefRuntime.Initialize(mainArgs, settings, app, IntPtr.Zero);

            this.RegisterSchemeHandlers();
            this.RegisterMessageRouters();

            var browserConfig = new CefBrowserConfig
            {
                StartUrl     = this.HostConfig.StartUrl,
                ParentHandle = this.Handle,
                AppArgs      = this.HostConfig.AppArgs,
                CefRectangle =
                    new CefRectangle
                {
                    X      = 0,
                    Y      = 0,
                    Width  = this.HostConfig.HostWidth,
                    Height = this.HostConfig.HostHeight
                }
            };

            this.mBrowser = new CefGlueBrowser(browserConfig);

            base.OnCreate(ref packet);

            Log.Info("Cef browser successfully created.");
        }
示例#2
0
        public void SettingsUpdateTest()
        {
            var hostConfig = GetConfigWithDefaultValues();
            var settings   = new CefSettings
            {
                Locale = hostConfig.Locale,
                MultiThreadedMessageLoop = false,
                LogFile = hostConfig.LogFile
            };

            // Update configuration settings
            settings.Update(hostConfig.CustomSettings);

            Assert.True(settings.MultiThreadedMessageLoop);
            Assert.True(settings.ExternalMessagePump);
            Assert.True(settings.WindowlessRenderingEnabled);
            Assert.True(settings.CommandLineArgsDisabled);
            Assert.True(settings.PackLoadingDisabled);
            Assert.True(settings.IgnoreCertificateErrors);

            Assert.Equal(nameof(CefSettingKeys.BrowserSubprocessPath), settings.BrowserSubprocessPath);
            Assert.Equal(nameof(CefSettingKeys.CachePath), settings.CachePath);
            Assert.Equal(nameof(CefSettingKeys.UserDataPath), settings.UserDataPath);
            Assert.Equal(nameof(CefSettingKeys.UserAgent), settings.UserAgent);
            Assert.Equal(nameof(CefSettingKeys.ProductVersion), settings.ProductVersion);
            Assert.Equal(nameof(CefSettingKeys.Locale), settings.Locale);
            Assert.Equal(nameof(CefSettingKeys.LogFile), settings.LogFile);
            Assert.Equal(nameof(CefSettingKeys.JavaScriptFlags), settings.JavascriptFlags);
            Assert.Equal(nameof(CefSettingKeys.ResourcesDirPath), settings.ResourcesDirPath);
            Assert.Equal(nameof(CefSettingKeys.LocalesDirPath), settings.LocalesDirPath);
            Assert.Equal(nameof(CefSettingKeys.AcceptLanguageList), settings.AcceptLanguageList);

            Assert.Equal(1025, settings.RemoteDebuggingPort);
            Assert.Equal(1000, settings.UncaughtExceptionStackSize);
        }
示例#3
0
        /// <summary>
        /// The run internal.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        private int RunInternal(string[] args)
        {
            // For Windows 7 and above, best to include relevant app.manifest entries as well
            Cef.EnableHighDPISupport();

            var codeBase       = Assembly.GetExecutingAssembly().CodeBase;
            var localFolder    = Path.GetDirectoryName(new Uri(codeBase).LocalPath);
            var localesDirPath = Path.Combine(localFolder ?? throw new InvalidOperationException(), "locales");

            _settings = new CefSettings
            {
                LocalesDirPath = localesDirPath,
                Locale         = HostConfig.Locale,

                // MultiThreadedMessageLoop = true,
                // MultiThreadedMessageLoop is not allowed to be used as it will break frameless mode
                MultiThreadedMessageLoop = !(HostConfig.HostPlacement.Frameless || HostConfig.HostPlacement.KioskMode),

                CachePath   = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache"),
                LogSeverity = (CefSharpGlobal.LogSeverity)HostConfig.LogSeverity,
                LogFile     = HostConfig.LogFile
            };

            // Update configuration settings
            _settings.Update(HostConfig.CustomSettings);
            _settings.UpdateCommandLineArgs(HostConfig.CommandLineArgs);

            RegisterSchemeHandlers();

            // Perform dependency check to make sure all relevant resources are in our output directory.
            Cef.Initialize(_settings, true, browserProcessHandler: null);

            Initialize();

            _mainView = CreateMainView(_settings);

            bool centerScreen = HostConfig.HostPlacement.CenterScreen;

            if (centerScreen)
            {
                _mainView.CenterToScreen();
            }

            _windowCreated = true;

            IoC.RegisterInstance(typeof(IChromelyWindow), typeof(IChromelyWindow).FullName, this);

            RunMessageLoop();

            _mainView.Dispose();
            _mainView = null;

            Cef.Shutdown();

            Shutdown();

            return(0);
        }
示例#4
0
        /// <summary>
        /// The run internal.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        private int RunInternal(string[] args)
        {
            // For Windows 7 and above, best to include relevant app.manifest entries as well
            CefSharpGlobal.Cef.EnableHighDPISupport();

            var codeBase       = Assembly.GetExecutingAssembly().CodeBase;
            var localFolder    = Path.GetDirectoryName(new Uri(codeBase).LocalPath);
            var localesDirPath = Path.Combine(localFolder ?? throw new InvalidOperationException(), "locales");

            mSettings = new CefSettings
            {
                LocalesDirPath           = localesDirPath,
                Locale                   = HostConfig.Locale,
                MultiThreadedMessageLoop = true,
                CachePath                = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache"),
                LogSeverity              = (CefSharpGlobal.LogSeverity)HostConfig.LogSeverity,
                LogFile                  = HostConfig.LogFile
            };

            // Update configuration settings
            mSettings.Update(HostConfig.CustomSettings);
            mSettings.UpdateCommandLineArgs(HostConfig.CommandLineArgs);

            RegisterSchemeHandlers();

            // Perform dependency check to make sure all relevant resources are in our output directory.
            CefSharpGlobal.Cef.Initialize(mSettings, performDependencyCheck: true, browserProcessHandler: null);

            Initialize();

            mMainView = CreateMainView(mSettings);

            if (HostConfig.HostCenterScreen)
            {
                mMainView.CenterToScreen();
            }

            mWindowCreated = true;

            RunMessageLoop();

            mMainView.Dispose();
            mMainView = null;

            CefSharpGlobal.Cef.Shutdown();

            Shutdown();

            return(0);
        }
示例#5
0
        protected override void OnCreate(ref CreateWindowPacket packet)
        {
            //For Windows 7 and above, best to include relevant app.manifest entries as well
            Cef.EnableHighDPISupport();

            var codeBase       = Assembly.GetExecutingAssembly().CodeBase;
            var localFolder    = Path.GetDirectoryName(new Uri(codeBase).LocalPath);
            var localesDirPath = Path.Combine(localFolder, "locales");

            m_settings = new CefSettings
            {
                LocalesDirPath           = localesDirPath,
                Locale                   = HostConfig.Locale,
                MultiThreadedMessageLoop = true,
                CachePath                = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache"),
                LogSeverity              = (CefSharpGlobal.LogSeverity)HostConfig.LogSeverity,
                LogFile                  = HostConfig.LogFile
            };

            // Update configuration settings
            m_settings.Update(HostConfig.CustomSettings);
            m_settings.UpdateCommandLineArgs(HostConfig.CommandLineArgs);

            RegisterSchemeHandlers();

            //Perform dependency check to make sure all relevant resources are in our output directory.
            Cef.Initialize(m_settings, performDependencyCheck: HostConfig.PerformDependencyCheck, browserProcessHandler: null);

            m_browser = new ChromiumWebBrowser(Handle, HostConfig.StartUrl);
            m_browser.IsBrowserInitializedChanged += IsBrowserInitializedChanged;

            // Set handlers
            m_browser.SetHandlers();

            RegisterJsHandlers();

            base.OnCreate(ref packet);

            Log.Info("Cef browser successfully created.");
        }
示例#6
0
        /// <summary>
        /// The run internal.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        private int RunInternal(string[] args)
        {
            CefRuntime.Load();

            var settings = new CefSettings
            {
                MultiThreadedMessageLoop = true,
                SingleProcess            = false,
                LogSeverity      = (CefLogSeverity)this.HostConfig.LogSeverity,
                LogFile          = this.HostConfig.LogFile,
                ResourcesDirPath = Path.GetDirectoryName(
                    new Uri(Assembly.GetEntryAssembly().CodeBase).LocalPath)
            };

            settings.LocalesDirPath      = Path.Combine(settings.ResourcesDirPath, "locales");
            settings.RemoteDebuggingPort = 20480;
            settings.NoSandbox           = true;
            settings.Locale = this.HostConfig.Locale;

            var argv = args;

            if (CefRuntime.Platform != CefRuntimePlatform.Windows)
            {
                argv = new string[args.Length + 1];
                Array.Copy(args, 0, argv, 1, args.Length);
                argv[0] = "-";
            }

            // Update configuration settings
            settings.Update(this.HostConfig.CustomSettings);

            var mainArgs = new CefMainArgs(argv);
            var app      = new CefGlueApp(this.HostConfig);

            var exitCode = CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero);

            Log.Info(string.Format("CefRuntime.ExecuteProcess() returns {0}", exitCode));

            if (exitCode != -1)
            {
                // An error has occured.
                return(exitCode);
            }

            // guard if something wrong
            foreach (var arg in args)
            {
                if (arg.StartsWith("--type="))
                {
                    return(-2);
                }
            }

            CefRuntime.Initialize(mainArgs, settings, app, IntPtr.Zero);

            this.RegisterSchemeHandlers();
            this.RegisterMessageRouters();

            this.PlatformInitialize();

            this.MainView = this.CreateMainView();

            this.PlatformRunMessageLoop();

            this.MainView.Dispose();
            this.MainView = null;

            CefRuntime.Shutdown();

            this.PlatformShutdown();

            return(0);
        }
示例#7
0
        private int RunInternal(string[] args)
        {
            Initialize();

            _config.ChromelyVersion = CefRuntime.ChromeVersion;

            var tempFiles = CefBinariesLoader.Load(_config);

            CefRuntime.EnableHighDpiSupport();

            var settings = new CefSettings
            {
                MultiThreadedMessageLoop = _config.Platform == ChromelyPlatform.Windows,
                LogSeverity      = CefLogSeverity.Info,
                LogFile          = "logs\\chromely.cef_" + DateTime.Now.ToString("yyyyMMdd") + ".log",
                ResourcesDirPath = _config.AppExeLocation
            };

            if (_config.WindowOptions.WindowFrameless || _config.WindowOptions.KioskMode)
            {
                // MultiThreadedMessageLoop is not allowed to be used as it will break frameless mode
                settings.MultiThreadedMessageLoop = false;
            }

            settings.LocalesDirPath      = Path.Combine(settings.ResourcesDirPath, "locales");
            settings.RemoteDebuggingPort = 20480;
            settings.Locale    = "en-US";
            settings.NoSandbox = true;

            var argv = args;

            if (CefRuntime.Platform != CefRuntimePlatform.Windows)
            {
                argv = new string[args.Length + 1];
                Array.Copy(args, 0, argv, 1, args.Length);
                argv[0] = "-";
            }

            // Update configuration settings
            settings.Update(_config.CustomSettings);

            // Set DevTools url
            _config.DevToolsUrl = $"http://127.0.0.1:{settings.RemoteDebuggingPort}";

            var    mainArgs = new CefMainArgs(argv);
            CefApp app      = new CefGlueApp(_config);

            if (ClientAppUtils.ExecuteProcess(_config.Platform, argv))
            {
                // CEF applications have multiple sub-processes (render, plugin, GPU, etc)
                // that share the same executable. This function checks the command-line and,
                // if this is a sub-process, executes the appropriate logic.
                var exitCode = CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero);
                if (exitCode >= 0)
                {
                    // The sub-process has completed so return here.
                    Logger.Instance.Log.Info($"Sub process executes successfully with code: {exitCode}");
                    return(exitCode);
                }
            }

            CefRuntime.Initialize(mainArgs, settings, app, IntPtr.Zero);

            ScanAssemblies();
            RegisterRoutes();
            RegisterMessageRouters();
            RegisterResourceHandlers();
            RegisterSchemeHandlers();
            RegisterAjaxSchemeHandlers();

            CefBinariesLoader.DeleteTempFiles(tempFiles);

            CreateMainWindow();

            Run();

            _mainWindow.Dispose();
            _mainWindow = null;

            Shutdown();

            return(0);
        }
示例#8
0
        /// <summary>
        /// The run internal.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        private int RunInternal(string[] args)
        {
            var tempFiles = CefBinariesLoader.Load(HostConfig);

            CefRuntime.EnableHighDpiSupport();

            var assembly = Assembly.GetEntryAssembly() ?? typeof(ChromelyConfiguration).Assembly;
            var settings = new CefSettings
            {
                MultiThreadedMessageLoop = true,
                LogSeverity      = (CefLogSeverity)HostConfig.LogSeverity,
                LogFile          = HostConfig.LogFile,
                ResourcesDirPath = Path.GetDirectoryName(new Uri(assembly.CodeBase).LocalPath)
            };

            if (HostConfig.HostFrameless || HostConfig.KioskMode)
            {
                if (HostConfig.HostApi == ChromelyHostApi.Gtk)
                {
                    throw new NotSupportedException("Chromely currently does not support frameless windows using GTK.");
                }

                // MultiThreadedMessageLoop is not allowed to be used as it will break frameless mode
                settings.MultiThreadedMessageLoop = false;
            }

            settings.LocalesDirPath      = Path.Combine(settings.ResourcesDirPath, "locales");
            settings.RemoteDebuggingPort = 20480;
            settings.NoSandbox           = true;
            settings.Locale = HostConfig.Locale;

            if (HostConfig.UseDefaultSubprocess)
            {
                var subprocessExeFullpath = DefaultSubprocessExe.FulPath;
                settings.BrowserSubprocessPath = subprocessExeFullpath ?? settings.BrowserSubprocessPath;
            }

            var argv = args;

            if (CefRuntime.Platform != CefRuntimePlatform.Windows)
            {
                argv = new string[args.Length + 1];
                Array.Copy(args, 0, argv, 1, args.Length);
                argv[0] = "-";
            }

            // Update configuration settings
            settings.Update(HostConfig.CustomSettings);

            var mainArgs = new CefMainArgs(argv);
            var app      = new CefGlueApp(HostConfig);

            // CEF applications have multiple sub-processes (render, plugin, GPU, etc)
            // that share the same executable. This function checks the command-line and,
            // if this is a sub-process, executes the appropriate logic.
            var exitCode = CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero);

            if (exitCode >= 0)
            {
                // The sub-process has completed so return here.
                CefBinariesLoader.DeleteTempFiles(tempFiles);
                Log.Info($"Sub process executes successfully with code: {exitCode}");
                return(exitCode);
            }

            // guard if something wrong
            foreach (var arg in args)
            {
                if (arg.StartsWith("--type="))
                {
                    return(-2);
                }
            }

            CefRuntime.Initialize(mainArgs, settings, app, IntPtr.Zero);

            RegisterSchemeHandlers();
            RegisterMessageRouters();

            Initialize();

            _mainView = CreateMainView();

            if (HostConfig.HostCenterScreen)
            {
                _mainView.CenterToScreen();
            }

            _windowCreated = true;

            CefBinariesLoader.DeleteTempFiles(tempFiles);

            RunMessageLoop();

            _mainView.Dispose();
            _mainView = null;

            CefRuntime.Shutdown();

            Shutdown();

            return(0);
        }
示例#9
0
        protected int RunInternal(string[] args)
        {
            MacHostRuntime.LoadNativeHostFile(_config);

            _config.ChromelyVersion = CefRuntime.ChromeVersion;

            var tempFiles = CefBinariesLoader.Load(_config);

            CefRuntime.EnableHighDpiSupport();

            _settings = new CefSettings
            {
                MultiThreadedMessageLoop = _config.Platform == ChromelyPlatform.Windows,
                LogSeverity      = CefLogSeverity.Info,
                LogFile          = "logs\\chromely.cef_" + DateTime.Now.ToString("yyyyMMdd") + ".log",
                ResourcesDirPath = _config.AppExeLocation
            };

            if (_config.WindowOptions.WindowFrameless || _config.WindowOptions.KioskMode)
            {
                // MultiThreadedMessageLoop is not allowed to be used as it will break frameless mode
                _settings.MultiThreadedMessageLoop = false;
            }

            _settings.LocalesDirPath      = Path.Combine(_settings.ResourcesDirPath, "locales");
            _settings.RemoteDebuggingPort = 20480;
            _settings.Locale    = "en-US";
            _settings.NoSandbox = true;

            var argv = args;

            if (CefRuntime.Platform != CefRuntimePlatform.Windows)
            {
                argv = new string[args.Length + 1];
                Array.Copy(args, 0, argv, 1, args.Length);
                argv[0] = "-";
            }

            // Update configuration settings
            _settings.Update(_config.CustomSettings);

            // Set DevTools url
            string devtoolsUrl = _config.DevToolsUrl;

            if (string.IsNullOrWhiteSpace(devtoolsUrl))
            {
                _config.DevToolsUrl = $"http://127.0.0.1:{_settings.RemoteDebuggingPort}";
            }
            else
            {
                Uri uri = new Uri(devtoolsUrl);
                if (uri.Port <= 80)
                {
                    _config.DevToolsUrl = $"{devtoolsUrl}:{_settings.RemoteDebuggingPort}";
                }
            }

            ResolveHandlers();

            var    mainArgs = new CefMainArgs(argv);
            CefApp app      = new CefBrowserApp(_config, _requestSchemeProvider, _handlersResolver);

            if (ClientAppUtils.ExecuteProcess(_config.Platform, argv))
            {
                // CEF applications have multiple sub-processes (render, plugin, GPU, etc)
                // that share the same executable. This function checks the command-line and,
                // if this is a sub-process, executes the appropriate logic.
                var exitCode = CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero);
                if (exitCode >= 0)
                {
                    // The sub-process has completed so return here.
                    Logger.Instance.Log.LogInformation($"Sub process executes successfully with code: {exitCode}");
                    return(exitCode);
                }
            }

            CefRuntime.Initialize(mainArgs, _settings, app, IntPtr.Zero);

            _window.RegisterHandlers();
            RegisterDefaultSchemeHandlers();
            RegisterCustomSchemeHandlers();

            CefBinariesLoader.DeleteTempFiles(tempFiles);

            _window.Init(_settings);

            MacHostRuntime.EnsureNativeHostFileExists(_config);

            NativeHost_CreateAndShowWindow();

            NativeHost_Run();

            CefRuntime.Shutdown();

            NativeHost_Quit();

            return(0);
        }
示例#10
0
        /// <summary>
        /// The run internal.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        private int RunInternal(string[] args)
        {
            Initialize();

            var tempFiles = CefBinariesLoader.Load(HostConfig);

            CefRuntime.EnableHighDpiSupport();

            var settings = new CefSettings
            {
                MultiThreadedMessageLoop = HostConfig.Platform == ChromelyPlatform.Windows,
                LogSeverity      = (CefLogSeverity)HostConfig.LogSeverity,
                LogFile          = HostConfig.LogFile,
                ResourcesDirPath = HostConfig.AppExeLocation
            };

            if (HostConfig.HostPlacement.Frameless || HostConfig.HostPlacement.KioskMode)
            {
                // MultiThreadedMessageLoop is not allowed to be used as it will break frameless mode
                settings.MultiThreadedMessageLoop = false;
            }

            settings.LocalesDirPath      = Path.Combine(settings.ResourcesDirPath, "locales");
            settings.RemoteDebuggingPort = 20480;
            settings.Locale    = HostConfig.Locale;
            settings.NoSandbox = true;

            var argv = args;

            if (CefRuntime.Platform != CefRuntimePlatform.Windows)
            {
                argv = new string[args.Length + 1];
                Array.Copy(args, 0, argv, 1, args.Length);
                argv[0] = "-";
            }

            // Update configuration settings
            settings.Update(HostConfig.CustomSettings);

            var    mainArgs = new CefMainArgs(argv);
            CefApp app      = new CefGlueApp(HostConfig);

            // CEF applications have multiple sub-processes (render, plugin, GPU, etc)
            // that share the same executable. This function checks the command-line and,
            // if this is a sub-process, executes the appropriate logic.
            var exitCode = CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero);

            if (exitCode >= 0)
            {
                // The sub-process has completed so return here.
                CefBinariesLoader.DeleteTempFiles(tempFiles);
                Log.Info($"Sub process executes successfully with code: {exitCode}");
                return(exitCode);
            }

            CefRuntime.Initialize(mainArgs, settings, app, IntPtr.Zero);

            RegisterSchemeHandlers();
            RegisterMessageRouters();

            CreateMainWindow();

            bool centerScreen = HostConfig.HostPlacement.CenterScreen;

            if (centerScreen)
            {
                _mainView.CenterToScreen();
            }

            _windowCreated = true;


            IoC.RegisterInstance(typeof(IChromelyWindow), typeof(IChromelyWindow).FullName, this);

            CefBinariesLoader.DeleteTempFiles(tempFiles);

            RunMessageLoop();

            _mainView.Dispose();
            _mainView = null;

            CefRuntime.Shutdown();

            Shutdown();

            return(0);
        }
示例#11
0
        protected int RunInternal(string[] args)
        {
            // For Windows 7 and above, best to include relevant app.manifest entries as well
            Cef.EnableHighDPISupport();

            var localFolder = _config.AppExeLocation;

            if (string.IsNullOrWhiteSpace(localFolder))
            {
                var codeBase = Assembly.GetExecutingAssembly().CodeBase;
                localFolder = Path.GetDirectoryName(new Uri(codeBase).LocalPath);
            }
            var localesDirPath = Path.Combine(localFolder ?? throw new InvalidOperationException(), "locales");

            _settings = new CefSettings
            {
                LocalesDirPath           = localesDirPath,
                Locale                   = "en-US",
                RemoteDebuggingPort      = 20480,
                MultiThreadedMessageLoop = !_config.WindowOptions.UseOnlyCefMessageLoop,
                CachePath                = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache"),
                LogSeverity              = LogSeverity.Default,
                LogFile                  = "logs\\chromely.cef_" + DateTime.Now.ToString("yyyyMMdd") + ".log",
            };

            // Update configuration settings
            _settings.Update(_config.CustomSettings);
            _settings.UpdateCommandOptions(_config.CommandLineOptions);
            _settings.UpdateCommandLineArgs(_config.CommandLineArgs);

            // If MultiThreadedMessageLoop is overriden in Setting using CustomSettings, then
            // It is assumed that the developer way not be aware of IWindowOptions - UseOnlyCefMessageLoop
            _config.WindowOptions.UseOnlyCefMessageLoop = !_settings.MultiThreadedMessageLoop;

            // Set DevTools url
            string devtoolsUrl = _config.DevToolsUrl;

            if (string.IsNullOrWhiteSpace(devtoolsUrl))
            {
                _config.DevToolsUrl = $"http://127.0.0.1:{_settings.RemoteDebuggingPort}";
            }
            else
            {
                Uri uri = new Uri(devtoolsUrl);
                if (uri.Port <= 80)
                {
                    _config.DevToolsUrl = $"{devtoolsUrl}:{_settings.RemoteDebuggingPort}";
                }
            }

            RegisterDefaultSchemeHandlers();
            RegisterCustomSchemeHandlers();

            // Perform dependency check to make sure all relevant resources are in our output directory.
            Cef.Initialize(_settings, true, browserProcessHandler: null);

            _window.RegisterHandlers();
            _window.Init(_settings);

            NativeHost_CreateAndShowWindow();
            NativeHost_Run();

            Cef.Shutdown();

            NativeHost_Quit();

            return(0);
        }
示例#12
0
        /// <summary>
        /// The run internal.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        private int RunInternal(string[] args)
        {
            var tempFiles = CefBinariesLoader.Load(HostConfig);

            CefRuntime.EnableHighDpiSupport();

            var settings = new CefSettings
            {
                MultiThreadedMessageLoop = true,
                LogSeverity      = (CefLogSeverity)HostConfig.LogSeverity,
                LogFile          = HostConfig.LogFile,
                ResourcesDirPath = Path.GetDirectoryName(
                    new Uri(Assembly.GetEntryAssembly().CodeBase).LocalPath)
            };

            settings.LocalesDirPath      = Path.Combine(settings.ResourcesDirPath, "locales");
            settings.RemoteDebuggingPort = 20480;
            settings.NoSandbox           = true;
            settings.Locale = HostConfig.Locale;

            var argv = args;

            if (CefRuntime.Platform != CefRuntimePlatform.Windows)
            {
                argv = new string[args.Length + 1];
                Array.Copy(args, 0, argv, 1, args.Length);
                argv[0] = "-";
            }

            // Update configuration settings
            settings.Update(HostConfig.CustomSettings);

            var mainArgs = new CefMainArgs(argv);
            var app      = new CefGlueApp(HostConfig);

            var exitCode = CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero);

            Log.Info($"CefRuntime.ExecuteProcess() returns {exitCode}");

            if (exitCode != -1)
            {
                // An error has occured.
                CefBinariesLoader.DeleteTempFiles(tempFiles);
                return(exitCode);
            }

            // guard if something wrong
            foreach (var arg in args)
            {
                if (arg.StartsWith("--type="))
                {
                    return(-2);
                }
            }

            CefRuntime.Initialize(mainArgs, settings, app, IntPtr.Zero);

            RegisterSchemeHandlers();
            RegisterMessageRouters();

            Initialize();

            mMainView = CreateMainView();

            if (HostConfig.HostCenterScreen)
            {
                mMainView.CenterToScreen();
            }

            mWindowCreated = true;

            CefBinariesLoader.DeleteTempFiles(tempFiles);

            RunMessageLoop();

            mMainView.Dispose();
            mMainView = null;

            CefRuntime.Shutdown();

            Shutdown();

            return(0);
        }