Exemplo n.º 1
0
        /// <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.");
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }