Example #1
0
        public static int Main(string[] args)
        {
            InitLogging(args);
            var logger = ParagonLogManager.GetLogger();
            var procId = Process.GetCurrentProcess().Id;

            logger.Info("Render process {0} starting", procId);

            try
            {
                if (!ExitWhenParentProcessExits())
                {
                    logger.Warn("Unable to monitor parent process for exit");
                }

                CefRuntime.Load();
                CefRuntime.ExecuteProcess(new CefMainArgs(args), new CefRenderApplication(), IntPtr.Zero);
            }
            catch (Exception ex)
            {
                logger.Error("Fatal error in render process {0} : {1}, StackTrace = {2}", procId, ex.Message, ex.StackTrace);
                return(1);
            }

            logger.Info("Render process {0} stopping.", procId);
            return(0);
        }
Example #2
0
        internal int InitializeProcessOnly()
        {
            var args = Environment.GetCommandLineArgs();

            if (ProcessType == CefProcessType.Browser)
            {
                Logger.Error("This process is just only run as subprocess.");

                return(-1);
            }

            CefRuntime.Load(ChromiumEnvironment.LibCefDir);

            IsRuntimeInitialized = true;

            if (!ChromiumEnvironment.ForceHighDpiSupportDisabled)
            {
                CefRuntime.EnableHighDpiSupport();
            }

            ChromiumEnvironment.CefBrowserSettingConfigurations?.Invoke(WinFormium.DefaultBrowserSettings);

            ApplicationConfiguration.UseExtensions[(int)ExtensionExecutePosition.SubProcessStartup]?.Invoke(this, ApplicationProperties);

            var cefMainArgs = new CefMainArgs(args);

            var app = new WinFormiumApp();

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

            return(exitCode);
        }
Example #3
0
        private static int Main(string[] args)
        {
            try
            {
                CefRuntime.Load();
            }
            catch (DllNotFoundException ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(1);
            }
            catch (CefRuntimeException ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(2);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(3);
            }

            var mainArgs = new CefMainArgs(args);
            var app      = new DemoApp();

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

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

            var codeBase           = Assembly.GetExecutingAssembly().CodeBase;
            var localFolder        = Path.GetDirectoryName(new Uri(codeBase).LocalPath);
            var browserProcessPath = CombinePaths(localFolder, "..", "..", "..",
                                                  "CefGlue.Demo.WinForms", "bin", "Release", "Xilium.CefGlue.Demo.WinForms.exe");

            var settings = new CefSettings
            {
                BrowserSubprocessPath    = browserProcessPath,
                MultiThreadedMessageLoop = true,
                LogSeverity = CefLogSeverity.Disable,
                LogFile     = "CefGlue.log",
            };

            CefRuntime.Initialize(mainArgs, settings, app);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (!settings.MultiThreadedMessageLoop)
            {
                Application.Idle += (sender, e) => { CefRuntime.DoMessageLoopWork(); };
            }

            Application.Run(new MainForm());

            CefRuntime.Shutdown();
            return(0);
        }
Example #4
0
        public static T ConfigureCefGlue <T>(this T builder, string[] args) where T : AppBuilderBase <T>, new()
        {
            return(builder.AfterSetup(b =>
            {
                CefRuntime.Load();
                var mainArgs = new CefMainArgs(args);
                var cefApp = new SampleCefApp();
                cefApp.RegisterCustomSchemes += CefApp_RegisterCustomSchemes;
                cefApp.WebKitInitialized += CefApp_WebKitInitialized;

                var exitCode = CefRuntime.ExecuteProcess(mainArgs, cefApp, IntPtr.Zero);
                if (exitCode != -1)
                {
                    return;
                }

                var cefSettings = new CefSettings
                {
                    SingleProcess = true,
                    WindowlessRenderingEnabled = true,
                    MultiThreadedMessageLoop = false,
                    LogSeverity = CefLogSeverity.Disable,
                    LogFile = "cef.log",
                    ExternalMessagePump = true
                };


                CefRuntime.Initialize(mainArgs, cefSettings, cefApp, IntPtr.Zero);
            }));
        }
        /// <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.");
        }
Example #6
0
        public static void Initialize()
        {
            if (!initialized)
            {
                CefRuntime.Load();

                var cefMainArgs = new CefMainArgs(new string[0]);
                var cefApp      = new App();
                if (CefRuntime.ExecuteProcess(cefMainArgs, cefApp, IntPtr.Zero) != -1)
                {
                    Console.Error.WriteLine("Couldn't execute secondary process.");
                }

                var cefSettings = new CefSettings
                {
                    CachePath                = "cache",
                    SingleProcess            = true,
                    MultiThreadedMessageLoop = true,
                    LogSeverity              = CefLogSeverity.Disable
                };

                CefRuntime.Initialize(cefMainArgs, cefSettings, cefApp, IntPtr.Zero);

                initialized = true;
            }
        }
Example #7
0
        /// <summary>
        /// 初始化浏览器
        /// </summary>
        private void InitializeBrowser()
        {
            if (IsDesignMode())
            {
                return;
            }
            CefRuntime.Load(ConfigurationManager.AppSettings["CefLibraryPath"]);
            var mainArgs = new CefMainArgs(new string[] { });
            var cefApp   = new WebApp();
            var exitCode = CefRuntime.ExecuteProcess(mainArgs, cefApp, IntPtr.Zero);

            if (exitCode != -1)
            {
                return;
            }
            var settings = new CefSettings
            {
                SingleProcess            = false,
                MultiThreadedMessageLoop = true,
                LogSeverity = CefLogSeverity.Disable,
                Locale      = "zh-CN"
            };

            CefRuntime.Initialize(mainArgs, settings, cefApp, IntPtr.Zero);
            if (!settings.MultiThreadedMessageLoop)
            {
                Application.Idle += (sender, e) => CefRuntime.DoMessageLoopWork();
            }
        }
Example #8
0
        private static int Main(string[] args)
        {
            try
            {
                CefRuntime.Load();
            }
            catch (DllNotFoundException ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(1);
            }
            catch (CefRuntimeException ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(2);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(3);
            }

            var mainArgs = new CefMainArgs(args);
            var app      = new DemoApp();

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

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

            var settings = new CefSettings
            {
                // BrowserSubprocessPath = @"D:\fddima\Projects\Xilium\Xilium.CefGlue\CefGlue.Demo\bin\Release\Xilium.CefGlue.Demo.exe",
                SingleProcess            = false,
                MultiThreadedMessageLoop = true,
                LogSeverity         = CefLogSeverity.Disable,
                LogFile             = "CefGlue.log",
                RemoteDebuggingPort = 7777,
            };

            CefRuntime.Initialize(mainArgs, settings, app);
            CefRuntime.RegisterSchemeHandlerFactory("http", "server", new MySchemeHandlerFactory());

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (!settings.MultiThreadedMessageLoop)
            {
                Application.Idle += (sender, e) => { CefRuntime.DoMessageLoopWork(); };
            }

            Application.Run(new MainForm());

            CefRuntime.Shutdown();
            return(0);
        }
Example #9
0
        static void Main()
        {
            vt1 = new VisualStudio2012DarkTheme();
            //vt2 = new Office2013DarkTheme();
            //vt3 = new VisualStudio2012LightTheme();
            //vt4 = new Windows7Theme();
            //vt5 = new Windows8Theme();

            CefRuntime.Load();
            var mainArgs = new CefMainArgs(new string[] { });
            var settings = new CefSettings();

            settings.MultiThreadedMessageLoop = CefRuntime.Platform == CefRuntimePlatform.Windows;
            settings.SingleProcess            = false;
            settings.LogSeverity         = CefLogSeverity.Verbose;
            settings.LogFile             = "cef.log";
            settings.Locale              = "zh-CN";
            settings.ResourcesDirPath    = System.IO.Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetEntryAssembly().CodeBase).LocalPath);
            settings.RemoteDebuggingPort = 20480;
            settings.NoSandbox           = true;

            //settings.CachePath = @"E:\mine\工作相关\工作代码\Spot Trade System\UseOnlineTradingSystem\UseOnlineTradingSystem\bin\Debug";

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

            if (exitCode != -1)
            {
                return;
            }
            CefRuntime.Initialize(mainArgs, settings, app, IntPtr.Zero);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            if (!settings.MultiThreadedMessageLoop)
            {
                Application.Idle += (sender, e) => { CefRuntime.DoMessageLoopWork(); };
            }

            LoginFm = new FormLogin();
            main    = new MainForm();
            //mf = new MainForm();
            //Application.Run(mf);
            // Application.Run(LoginFm);
            try
            {
                Application.Run(LoginFm);
            }
            catch (Exception err)
            {
                Logger.LogError(err.ToString());
            }
            Logger.LogInfo("退出程序!");
            USeManager.Instance.Stop();
            KillProcess();
            //CefRuntime.Shutdown();
            //Environment.Exit(0);
        }
        public CefWebBrowser()
        {
            /* BEG: modbyme */
            if (LicenseManager.UsageMode != LicenseUsageMode.Designtime)
            {
                CefRuntime.Load();

                CefSettings settings = new CefSettings();
                settings.CachePath = @"Cache"; //Cache Folder
                settings.MultiThreadedMessageLoop = false;
                settings.NoSandbox = true;
                //settings.LogSeverity = CefLogSeverity.Error;
                //settings.LogFile = "cef.log";
                //settings.ResourcesDirPath = System.IO.Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetEntryAssembly().CodeBase).LocalPath);
                //settings.RemoteDebuggingPort = 20480;
                // // settings.SingleProcess = true;

                CefMainArgs mainArgs = new CefMainArgs(Environment.GetCommandLineArgs());
                CefWebApp app = new CefWebApp(this);

                if (CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero) != -1)
                {
                    MessageBox.Show("ExecuteProcess failed");
                }

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

                Application.Idle += (s, e) => CefRuntime.DoMessageLoopWork();
            }
            /* END: modbyme */

            SetStyle(
                ControlStyles.ContainerControl
                | ControlStyles.ResizeRedraw
                | ControlStyles.FixedWidth
                | ControlStyles.FixedHeight
                | ControlStyles.StandardClick
                | ControlStyles.UserMouse
                | ControlStyles.SupportsTransparentBackColor
                | ControlStyles.StandardDoubleClick
                | ControlStyles.OptimizedDoubleBuffer
                | ControlStyles.CacheText
                | ControlStyles.EnableNotifyMessage
                | ControlStyles.DoubleBuffer
                | ControlStyles.OptimizedDoubleBuffer
                | ControlStyles.UseTextForAccessibility
                | ControlStyles.Opaque,
                false);

            SetStyle(
                ControlStyles.UserPaint
                | ControlStyles.AllPaintingInWmPaint
                | ControlStyles.Selectable,
                true);

            StartUrl = "about:blank";
        }
Example #11
0
        public int Run(string[] args)
        {
            CefRuntime.Load();

            var settings = new CefSettings();

            settings.MultiThreadedMessageLoop = CefRuntime.Platform == CefRuntimePlatform.Windows;
            settings.ReleaseDCheckEnabled     = true;
            settings.LogSeverity         = CefLogSeverity.Verbose;
            settings.LogFile             = "cef.log";
            settings.ResourcesDirPath    = System.IO.Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetEntryAssembly().CodeBase).LocalPath);
            settings.RemoteDebuggingPort = 20480;

            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);
            var app      = new DemoCefApp();

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

            Console.WriteLine("CefRuntime.ExecuteProcess() returns {0}", exitCode);
            if (exitCode != -1)
            {
                return(exitCode);
            }



            CefRuntime.Initialize(mainArgs, settings, app);

            // register custom scheme handler
            CefRuntime.RegisterSchemeHandlerFactory("http", DumpRequestDomain, new DemoAppSchemeHandlerFactory());

            PlatformInitialize();

            var mainMenu = CreateMainMenu();

            _mainView = CreateMainView(mainMenu);
            _mainView.NewTab(HomeUrl);

            PlatformRunMessageLoop();

            _mainView.Dispose();
            _mainView = null;

            CefRuntime.Shutdown();

            PlatformShutdown();
            return(0);
        }
Example #12
0
        /// <summary>
        /// Run internal.
        /// </summary>
        protected override void RunInternal()
        {
            CefRuntime.Load();

            var arguments = Environment.GetCommandLineArgs();
            var mainArgs  = new CefMainArgs(arguments.ToArray());
            var app       = new App();

            CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero);
        }
Example #13
0
        /// <summary>
        /// 加载 Cef
        /// </summary>
        /// <returns></returns>
        public int RunInternal(string[] args)
        {
            try
            {
                CefRuntime.Load();
            }
            catch (DllNotFoundException ex)
            {
                PlatformMessageBox(ex.Message);
                return(1);
            }
            catch (CefRuntimeException ex)
            {
                PlatformMessageBox(ex.Message);
                return(2);
            }
            catch (Exception ex)
            {
                PlatformMessageBox(ex.ToString());
                return(3);
            }

            CefSettings settings = new CefSettings();

            settings.MultiThreadedMessageLoop = MultiThreadedMessageLoop = CefRuntime.Platform == CefRuntimePlatform.Windows;
            //settings.MultiThreadedMessageLoop = false;
            settings.LogSeverity         = CefLogSeverity.Error | CefLogSeverity.ErrorReport;
            settings.LogFile             = "cef.log";
            settings.ResourcesDirPath    = System.IO.Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetEntryAssembly().CodeBase).LocalPath);
            settings.RemoteDebuggingPort = 20480;
            settings.NoSandbox           = true;
            settings.Locale = "zh-CN";
            settings.CommandLineArgsDisabled = false;

            CefMainArgs    mainArgs       = new CefMainArgs(args);
            MonitorCefApp  app            = new MonitorCefApp();
            CefMenuHandler cefMenuHandler = new CefMenuHandler();

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

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

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

            PlatformInitialize();

            PlatformRunMessageLoop();

            CefRuntime.Shutdown();

            return(0);
        }
Example #14
0
        protected override void OnCreate(ref CreateWindowPacket packet)
        {
            try
            {
                CefRuntime.Load();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            var mainArgs = new CefMainArgs(HostConfig.CefAppArgs);
            var app      = new CefWebApp();

            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           = localFolder,
                Locale                   = HostConfig.CefLocale,
                SingleProcess            = false,
                MultiThreadedMessageLoop = true,
                LogSeverity              = (CefLogSeverity)HostConfig.CefLogSeverity,
                LogFile                  = HostConfig.CefLogFile
            };

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

            RegisterSchemeHandlers();
            RegisterMessageRouters();

            CefBrowserConfig browserConfig = new CefBrowserConfig();

            browserConfig.StartUrl     = HostConfig.CefStartUrl;
            browserConfig.ParentHandle = Handle;
            browserConfig.AppArgs      = HostConfig.CefAppArgs;
            browserConfig.CefRectangle = new CefRectangle {
                X = 0, Y = 0, Width = HostConfig.CefHostWidth, Height = HostConfig.CefHostHeight
            };

            m_browser = new CefWebBrowser(browserConfig);

            base.OnCreate(ref packet);

            Log.Info("Cef browser successfully created.");
        }
Example #15
0
        private void StartCef()
        {
#if UNITY_EDITOR
            CefRuntime.Load(Path.Combine(Application.dataPath, "Plugins", "Cef", "Windows"));
#else
            CefRuntime.Load();
#endif


            var cefMainArgs = new CefMainArgs(new string[] { });
            var cefApp      = new OffscreenCEFClient.OffscreenCEFApp();

            // This is where the code path diverges for child processes.
            if (CefRuntime.ExecuteProcess(cefMainArgs, cefApp, IntPtr.Zero) != -1)
            {
                Debug.LogError("Could not start the secondary process.");
            }

            var cefSettings = new CefSettings
            {
                //ExternalMessagePump = true,
                MultiThreadedMessageLoop = false,
                SingleProcess            = true,
                LogSeverity = CefLogSeverity.Verbose,
                LogFile     = "cef.log",
                WindowlessRenderingEnabled = true,
                NoSandbox = true
            };

            // Start the browser process (a child process).
            CefRuntime.Initialize(cefMainArgs, cefSettings, cefApp, IntPtr.Zero);

            // Instruct CEF to not render to a window.
            CefWindowInfo cefWindowInfo = CefWindowInfo.Create();
            cefWindowInfo.SetAsWindowless(IntPtr.Zero, true);

            // Settings for the browser window itself (e.g. enable JavaScript?).
            CefBrowserSettings cefBrowserSettings = new CefBrowserSettings()
            {
            };

            Debug.Log("Start with window: " + this.windowWidth + ", " + this.windowHeight);

            // Initialize some of the custom interactions with the browser process.
            this.cefClient = new OffscreenCEFClient(
                this.windowWidth,
                this.windowHeight,
                this.hideScrollbars,
                this.BrowserTexture,
                this
                );

            // Start up the browser instance.
            CefBrowserHost.CreateBrowser(cefWindowInfo, this.cefClient, cefBrowserSettings, string.IsNullOrEmpty(this.overlayUrl) ? "http://www.google.com" : this.overlayUrl);
        }
Example #16
0
        static bool CefRintimePrepare(string[] args, string temporaryDirectoryPath)
        {
            try {
                string path        = Directory.GetCurrentDirectory();
                var    runtimepath = path;

                var clientpath = Path.Combine(runtimepath, "cefclient.exe");
                Log.InfoFormat("using client path {0}", clientpath);
                var resourcepath = runtimepath;
                var localepath   = Path.Combine(resourcepath, "locales");
                Log.Info("===============START================");
                CefRuntime.Load(runtimepath); //using native render helper
                Log.Info("appending disable cache keys");
                CefMainArgs cefMainArgs = new CefMainArgs(args)
                {
                };
                if (parametres._enableWebRTC)
                {
                    Log.Info("starting with webrtc");
                }
                var cefApp    = new WorkerCefApp(parametres._enableWebRTC, parametres._enableGPU);
                int exit_code = CefRuntime.ExecuteProcess(cefMainArgs, cefApp, IntPtr.Zero);

                if (exit_code >= 0)
                {
                    Log.ErrorFormat("CefRuntime return " + exit_code);
                    return(false);
                }
                var cefSettings = new CefSettings
                {
                    SingleProcess              = false,
                    MultiThreadedMessageLoop   = true,
                    WindowlessRenderingEnabled = true,
                    //
                    BrowserSubprocessPath = clientpath,
                    FrameworkDirPath      = runtimepath,
                    ResourcesDirPath      = resourcepath,
                    LocalesDirPath        = localepath,
                    LogFile     = Path.Combine(Path.GetTempPath(), "cefruntime-" + Guid.NewGuid() + ".log"),
                    Locale      = "en-US",
                    LogSeverity = CefLogSeverity.Error,
                    //RemoteDebuggingPort = 8088,
                    NoSandbox = true,
                    //CachePath = temporaryDirectoryPath
                };
                CefRuntime.Initialize(cefMainArgs, cefSettings, cefApp, IntPtr.Zero);
                /////////////
            }
            catch (Exception ex) {
                Log.Info("EXCEPTION ON CEF INITIALIZATION:" + ex.Message + "\n" + ex.StackTrace);
                return(false);
            }
            return(true);
        }
Example #17
0
        private static int Main(string[] args)
        {
            try
            {
                CefRuntime.Load();
            }
            catch (DllNotFoundException ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(1);
            }
            catch (CefRuntimeException ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(2);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(3);
            }


            var mainArgs = new CefMainArgs(args);
            var app      = new DemoApp();

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

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

            var settings = new CefSettings
            {
                MultiThreadedMessageLoop = true,

                LogSeverity = CefLogSeverity.Disable,
                LogFile     = "CefGlue.log",

                NoSandbox = true
            };

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

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Application.Run(new Form1());

            CefRuntime.Shutdown();

            return(0);
        }
        private void StartCef()
        {
#if UNITY_EDITOR
            CefRuntime.Load("./Assets/Plugins/x86_64");
#else
            CefRuntime.Load();
#endif

            var cefMainArgs = new CefMainArgs(new string[] { });
            var cefApp      = new OffscreenCEFClient.OffscreenCEFApp();

            // This is where the code path diverges for child processes.
            if (CefRuntime.ExecuteProcess(cefMainArgs, cefApp, IntPtr.Zero) != -1)
            {
                Debug.LogError("Could not start the secondary process.");
            }

            var cefSettings = new CefSettings
            {
                //ExternalMessagePump = true,
                MultiThreadedMessageLoop = false,
                SingleProcess            = true,
                LogSeverity = CefLogSeverity.Verbose,
                LogFile     = "cef.log",
                WindowlessRenderingEnabled = true,
                NoSandbox = true,
            };

            // Start the browser process (a child process).
            CefRuntime.Initialize(cefMainArgs, cefSettings, cefApp, IntPtr.Zero);

            // Instruct CEF to not render to a window.
            CefWindowInfo cefWindowInfo = CefWindowInfo.Create();
            cefWindowInfo.SetAsWindowless(IntPtr.Zero, false);

            // Settings for the browser window itself (e.g. enable JavaScript?).
            CefBrowserSettings cefBrowserSettings = new CefBrowserSettings()
            {
                BackgroundColor           = new CefColor(255, 60, 85, 115),
                JavaScript                = CefState.Enabled,
                JavaScriptAccessClipboard = CefState.Disabled,
                JavaScriptCloseWindows    = CefState.Disabled,
                JavaScriptDomPaste        = CefState.Disabled,
                JavaScriptOpenWindows     = CefState.Disabled,
                LocalStorage              = CefState.Disabled
            };

            // Initialize some of the custom interactions with the browser process.
            this.cefClient = new OffscreenCEFClient(this.windowSize, this.hideScrollbars);

            // Start up the browser instance.
            CefBrowserHost.CreateBrowser(cefWindowInfo, this.cefClient, cefBrowserSettings, string.IsNullOrEmpty(this.url) ? "http://www.google.com" : this.url);
        }
Example #19
0
        public static void Initialize(string MainApplicationPath)
        {
            if (!initialized)
            {
                CefRuntime.Load();

                var Cache    = "Cache";
                var Userdata = "UserData";

                if (MainApplicationPath != "")
                {
                    Cache    = System.IO.Path.Combine(MainApplicationPath, "Cache");
                    Userdata = System.IO.Path.Combine(MainApplicationPath, "UserData");
                }

                // for under 0.3.4.0 users
                if (System.IO.Directory.Exists("cache"))
                {
                    try
                    {
                        var di = new System.IO.DirectoryInfo("cache");
                        di.MoveTo(Cache);
                    }
                    catch
                    {
                        Cache = "cache";
                    }
                }

                var cefMainArgs = new CefMainArgs(new string[0]);
                var cefApp      = new App();

                if (CefRuntime.ExecuteProcess(cefMainArgs, cefApp, IntPtr.Zero) != -1)
                {
                    Console.Error.WriteLine("Couldn't execute secondary process.");
                }

                var cefSettings = new CefSettings
                {
                    CachePath                = Cache,
                    Locale                   = System.Globalization.CultureInfo.CurrentCulture.Name,
                    UserDataPath             = Userdata,
                    SingleProcess            = true,
                    MultiThreadedMessageLoop = true,
                    LogSeverity              = CefLogSeverity.Disable
                };

                CefRuntime.Initialize(cefMainArgs, cefSettings, cefApp, IntPtr.Zero);
                initialized = true;
            }
        }
Example #20
0
        public static T ConfigureCefGlue <T>(this T builder, string[] args) where T : AppBuilderBase <T>, new()
        {
            return(builder.AfterSetup((b) =>
            {
                try
                {
                    CefRuntime.Load();
                }
                catch (DllNotFoundException ex)
                {
                }
                catch (CefRuntimeException ex)
                {
                }
                catch (Exception ex)
                {
                }

                var mainArgs = new CefMainArgs(args);
                var cefApp = new SampleCefApp();
                cefApp.RegisterCustomSchemes += CefApp_RegisterCustomSchemes;
                cefApp.WebKitInitialized += CefApp_WebKitInitialized;

                var exitCode = CefRuntime.ExecuteProcess(mainArgs, cefApp);
                if (exitCode != -1)
                {
                    return;
                }

                var location = System.Reflection.Assembly.GetEntryAssembly().Location;
                var directory = System.IO.Path.GetDirectoryName(location);

                var cefSettings = new CefSettings
                {
                    SingleProcess = true,
                    WindowlessRenderingEnabled = true,
                    MultiThreadedMessageLoop = false,
                    LogSeverity = CefLogSeverity.Disable,
                    LogFile = "cef.log",
                    ExternalMessagePump = true
                };

                try
                {
                    CefRuntime.Initialize(mainArgs, cefSettings, cefApp);
                }
                catch (CefRuntimeException ex)
                {
                }
            }));
        }
Example #21
0
        static void Main(string[] args)
        {
            AppBuilder.Configure <App>()
            .UseSkia().UseWin32().AfterSetup((a) =>
            {
                try
                {
                    CefRuntime.Load();
                }
                catch (DllNotFoundException ex)
                {
                }
                catch (CefRuntimeException ex)
                {
                }
                catch (Exception ex)
                {
                }

                var mainArgs = new CefMainArgs(args);
                var cefApp   = new SampleCefApp();

                var exitCode = CefRuntime.ExecuteProcess(mainArgs, cefApp);
                if (exitCode != -1)
                {
                    return;
                }

                var location  = System.Reflection.Assembly.GetEntryAssembly().Location;
                var directory = System.IO.Path.GetDirectoryName(location);

                var cefSettings = new CefSettings
                {
                    BrowserSubprocessPath      = Path.Combine(directory, "cefclient.exe"),
                    SingleProcess              = false,
                    WindowlessRenderingEnabled = true,
                    MultiThreadedMessageLoop   = false,
                    LogSeverity         = CefLogSeverity.Verbose,
                    LogFile             = "cef.log",
                    ExternalMessagePump = true
                };

                try
                {
                    CefRuntime.Initialize(mainArgs, cefSettings, cefApp);
                }
                catch (CefRuntimeException ex)
                {
                }
            }).Start <MainWindow>();
        }
Example #22
0
        private void Load(string cachePath, string currentDir)
        {
            try
            {
                CefRuntime.Load();
            }
            catch (DllNotFoundException ex)
            {
                ErrorAndExit(ex);
            }
            catch (CefRuntimeException ex)
            {
                ErrorAndExit(ex);
            }
            catch (Exception ex)
            {
                ErrorAndExit(ex);
            }

            var mainArgs = new CefMainArgs(new string[] { });
            var cefApp   = new AppDirectCefApp();

            var exitCode = CefRuntime.ExecuteProcess(mainArgs, cefApp);

            if (exitCode != -1)
            {
                ErrorAndExit(new Exception("CEF Failed to load"));
            }

            var cefSettings = new CefSettings
            {
                BrowserSubprocessPath    = currentDir + Path.DirectorySeparatorChar + CefClientExe,
                SingleProcess            = false,
                MultiThreadedMessageLoop = true,
                LogSeverity           = CefLogSeverity.Verbose,
                PersistSessionCookies = true,
                LogFile   = "cef.log",
                CachePath = cachePath,
                IgnoreCertificateErrors = true
            };

            try
            {
                CefRuntime.Initialize(mainArgs, cefSettings, cefApp);
            }
            catch (CefRuntimeException ex)
            {
                ErrorAndExit(ex);
            }
        }
Example #23
0
        static int Main(String[] args)
        {
            LoadLibrary(Path.Combine(AssemblyDirectory, "d3dcompiler_43.dll"));
            LoadLibrary(Path.Combine(AssemblyDirectory, "d3dcompiler_46.dll"));
            LoadLibrary(Path.Combine(AssemblyDirectory, "libGLESv2.dll"));
            LoadLibrary(Path.Combine(AssemblyDirectory, "libEGL.dll"));
            LoadLibrary(Path.Combine(AssemblyDirectory, "ffmpegsumo.dll"));
            LoadLibrary(Path.Combine(AssemblyDirectory, "icudt.dll"));
            LoadLibrary(Path.Combine(AssemblyDirectory, "libcef.dll"));

            CefMainArgs mainArgs = new CefMainArgs(IntPtr.Zero, args);

            return(CefRuntime.ExecuteProcess(mainArgs, new BrowserApp(), IntPtr.Zero));
        }
Example #24
0
        private static void Main(string[] args)
        {
            // Load CEF. This checks for the correct CEF version.
            CefRuntime.Load();

            // Start the secondary CEF process.
            var cefMainArgs = new CefMainArgs(new string[0]);
            var cefApp      = new DemoCefApp();

            // This is where the code path divereges for child processes.
            if (CefRuntime.ExecuteProcess(cefMainArgs, cefApp) != -1)
            {
                Console.Error.WriteLine("CefRuntime could not the secondary process.");
            }

            // Settings for all of CEF (e.g. process management and control).
            var cefSettings = new CefSettings
            {
                SingleProcess            = false,
                MultiThreadedMessageLoop = true
            };

            // Start the browser process (a child process).
            CefRuntime.Initialize(cefMainArgs, cefSettings, cefApp);

            // Instruct CEF to not render to a window at all.
            CefWindowInfo cefWindowInfo = CefWindowInfo.Create();

            cefWindowInfo.SetAsOffScreen(IntPtr.Zero);

            // Settings for the browser window itself (e.g. should JavaScript be enabled?).
            var cefBrowserSettings = new CefBrowserSettings();

            // Initialize some the cust interactions with the browser process.
            // The browser window will be 1280 x 720 (pixels).
            var cefClient = new DemoCefClient(1280, 720);

            // Start up the browser instance.
            string url = "http://www.reddit.com/";

            CefBrowserHost.CreateBrowser(cefWindowInfo, cefClient, cefBrowserSettings, url);

            // Hang, to let the browser to do its work.
            Console.WriteLine("Press a key at any time to end the program.");
            Console.ReadKey();

            // Clean up CEF.
            CefRuntime.Shutdown();
        }
Example #25
0
        /// <summary>
        /// Run internal.
        /// </summary>
        protected override void RunInternal()
        {
            CefRuntime.Load();

            var mainArgs = new CefMainArgs(EnvironmentUtility.GetCommandLineArgs());

            var app = new App();

            app.BrowserCreated += (s, e) =>
            {
                CefBrowser = e.CefBrowser;
            };

            CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero);
        }
Example #26
0
        static void Main(string[] args)
        {
            CefRuntime.Load();

            var mainArgs = new CefMainArgs(args);

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

            Console.WriteLine("CefRuntime.ExecuteProcess() returns {0}", exitCode);
            if (exitCode != -1)
            {
                Environment.Exit(exitCode);
            }
        }
Example #27
0
        // Main entry point when called by CEF
        public static int Main(string[] args)
        {
            CefRuntime.Load();

            var app      = new HTMLTextureApp();
            var mainArgs = new CefMainArgs(args);
            var exitCode = CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero);

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

            CefRuntime.Shutdown();
            return(0);
        }
Example #28
0
        public static int Main(string[] args)
        {
            CefRuntime.EnableHighDpiSupport();
            CefRuntime.Load();

            var app      = new WebRendererApp();
            var mainArgs = new CefMainArgs(args);
            var exitCode = CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero);

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

            CefRuntime.Shutdown();
            return(0);
        }
Example #29
0
        public static int Main(String[] args)
        {
            String currentDirectory = AppDomain.CurrentDomain.BaseDirectory;
            String libraryDirectory = Path.Combine(currentDirectory, "CLRBrowserSourcePlugin");

            LoadLibrary(Path.Combine(libraryDirectory, "d3dcompiler_43.dll"));
            LoadLibrary(Path.Combine(libraryDirectory, "d3dcompiler_46.dll"));
            LoadLibrary(Path.Combine(libraryDirectory, "libGLESv2.dll"));
            LoadLibrary(Path.Combine(libraryDirectory, "libEGL.dll"));
            LoadLibrary(Path.Combine(libraryDirectory, "ffmpegsumo.dll"));
            LoadLibrary(Path.Combine(libraryDirectory, "icudt.dll"));
            LoadLibrary(Path.Combine(libraryDirectory, "libcef.dll"));

            CefMainArgs mainArgs = new CefMainArgs(args);

            return(CefRuntime.ExecuteProcess(mainArgs, new BrowserApp()));
        }
        private static void InitializeCef()
        {
            CefRuntime.Load();
            CefMainArgs    cefArgs = new CefMainArgs(new[] { "--force-renderer-accessibility" });
            CefApplication cefApp  = new CefApplication();

            CefRuntime.ExecuteProcess(cefArgs, cefApp);
            CefSettings cefSettings = new CefSettings
            {
                SingleProcess            = false,
                MultiThreadedMessageLoop = true,
                LogSeverity = CefLogSeverity.ErrorReport,
                LogFile     = "CefGlue.log",
            };

            CefRuntime.Initialize(cefArgs, cefSettings, cefApp);
        }