Пример #1
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);
            }));
        }
Пример #2
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();
            }
        }
Пример #3
0
        /// <summary>
        /// Initializes the cef.
        /// </summary>
        private void InitializeCef()
        {
            CefRuntime.Load();

            var cefSettings = new CefSettings
            {
                MultiThreadedMessageLoop = true,
                SingleProcess            = false,
                LogSeverity             = CefLogSeverity.Warning,
                LogFile                 = LogsDirectoryPath + "/cef.log",
                CachePath               = CacheDirectoryPath,
                ResourcesDirPath        = PathUtility.WorkingDirectory,
                RemoteDebuggingPort     = 20480,
                NoSandbox               = true,
                CommandLineArgsDisabled = true
            };

            // arguments
            var arguments = new List <string>();

            if (!EnableD3D11 && !arguments.Contains(Argument.DisableD3D11.Value))
            {
                arguments.Add(Argument.DisableD3D11.Value);
            }

            // initialize
            var mainArgs = new CefMainArgs(arguments.ToArray());
            var app      = new App();

            CefRuntime.Initialize(mainArgs, cefSettings, app, IntPtr.Zero);
        }
Пример #4
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;
            }
        }
Пример #5
0
        public Initializer()
        {
            var settings = new CefSettings
            {
                MultiThreadedMessageLoop = true,
                SingleProcess            = false,
                LogSeverity                = CefLogSeverity.Error,
                LogFile                    = "cef.log",
                ResourcesDirPath           = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                BrowserSubprocessPath      = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "DSerfozo.CefGlue.SubProcess.exe"),
                RemoteDebuggingPort        = 20480,
                WindowlessRenderingEnabled = true,
                NoSandbox                  = true,
            };

            var startEvent = new AutoResetEvent(false);

            stopEvent = new AutoResetEvent(false);
            var app           = new TestApp();
            var cefMainThread = new Thread(() =>
            {
                CefRuntime.Initialize(new CefMainArgs(new string[] {}), settings, app, IntPtr.Zero);
                startEvent.Set();
                stopEvent.WaitOne();
                CefRuntime.Shutdown();
                stopEvent.Set();
            });

            cefMainThread.SetApartmentState(ApartmentState.STA);
            cefMainThread.IsBackground = true;
            cefMainThread.Start();

            startEvent.WaitOne();
        }
Пример #6
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.");
        }
Пример #7
0
        public static void Initialize(string cefRoot)
        {
            string environmentVariable = Environment.GetEnvironmentVariable("PATH");

            if (Marshal.SizeOf(typeof(IntPtr)) == 4)
            {
                Environment.SetEnvironmentVariable("PATH", cefRoot + "\\cef_x86;" + environmentVariable);
            }
            else
            {
                Environment.SetEnvironmentVariable("PATH", cefRoot + "\\cef_x64;" + environmentVariable);
            }

            CefRuntime.Load();
            CefMainArgs args2    = new CefMainArgs(new string[] {});
            var         cefApp   = new SharpDXCefApp();
            CefSettings settings = new CefSettings
            {
                SingleProcess            = false,
                MultiThreadedMessageLoop = true,
                LogSeverity = CefLogSeverity.Disable,
                LogFile     = "Cef.log"
            };

            try
            {
                CefRuntime.Initialize(args2, settings, cefApp);
            }
            catch (CefRuntimeException ex)
            {
                throw new Exception("Cef failed to initialize");
            }
        }
Пример #8
0
        // Main entry point when called by vvvv
        void IStartable.Start()
        {
            CefRuntime.Load();

            var cefSettings = new CefSettings();

            cefSettings.WindowlessRenderingEnabled = true;
            cefSettings.PackLoadingDisabled        = false;
            cefSettings.MultiThreadedMessageLoop   = true;
            cefSettings.BrowserSubprocessPath      = Assembly.GetExecutingAssembly().Location;
            cefSettings.CommandLineArgsDisabled    = false;
            cefSettings.IgnoreCertificateErrors    = true;
            //// We do not meet the requirements - see cef_sandbox_win.h
            //cefSettings.NoSandbox = true;
#if DEBUG
            cefSettings.LogSeverity = CefLogSeverity.Error;
            // Set to true to debug DOM / JavaScript
            cefSettings.SingleProcess = false;
#else
            cefSettings.LogSeverity = CefLogSeverity.Disable;
#endif

            var args     = Environment.GetCommandLineArgs();
            var mainArgs = new CefMainArgs(args);
            CefRuntime.Initialize(mainArgs, cefSettings, new HTMLTextureApp(), IntPtr.Zero);

            var schemeName = "cef";
            if (!CefRuntime.RegisterSchemeHandlerFactory(SchemeHandlerFactory.SCHEME_NAME, null, new SchemeHandlerFactory()))
            {
                throw new Exception(string.Format("Couldn't register custom scheme factory for '{0}'.", schemeName));
            }
        }
Пример #9
0
        ///////////////////////////////////////////////////////////////////////

        public static void Start()
        {
            if (Instance == null)
            {
                throw new InvalidOperationException("Chromium runtime has not been initialized");
            }

            if (Started)
            {
                throw new InvalidOperationException("Chromium runtime has already been started");
            }

            Log.Trace("Initializing Chromium runtime...");

            CefRuntime.Initialize(
                application: Instance,
                args: Instance.Args,
                settings: new CefSettings
            {
                MultiThreadedMessageLoop = true,
                IgnoreCertificateErrors  = App.IgnoreCertificateErrors,
                RemoteDebuggingPort      = App.DebugPort,
                LogFile                    = App.DebugFile,
                LogSeverity                = (CefLogSeverity)Enum.Parse(typeof(CefLogSeverity), App.DebugLevel),
                ReleaseDCheckEnabled       = false,
                UncaughtExceptionStackSize = 128,
                UserAgent                  = App.UserAgent,
            });

            Log.Trace("Chromium runtime has been initialized");

            Started = true;
        }
Пример #10
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);
        }
Пример #11
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);
        }
Пример #12
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);
        }
Пример #13
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";
        }
Пример #14
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);
        }
Пример #15
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.");
        }
Пример #16
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);
        }
Пример #17
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);
        }
Пример #18
0
        public Menu(
            CefApp menuCeffApp,
            CefMainArgs mainArgs,
            InputProcessor inputProcessor,
            MenuBrowserClient browserClient,
            StateManager stateManager,
            EventBus eventBus
            )
        {
            // State Initialization
            _buttons        = (GameControllerButton[])Enum.GetValues(typeof(GameControllerButton));
            _analogs        = (GameControllerAnalog[])Enum.GetValues(typeof(GameControllerAnalog));
            _eventTokenList = new List <SubscriptionToken>();
            _eventBus       = eventBus;

#if (DEBUG)
            var logSeverity = CefLogSeverity.Error;
#else
            var logSeverity = CefLogSeverity.Error;
#endif

            var settings = new CefSettings
            {
                WindowlessRenderingEnabled = true,
                LogSeverity = logSeverity,
                NoSandbox   = true
            };

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

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

            var browserSettings = new CefBrowserSettings()
            {
                WindowlessFrameRate = 60,
            };

            _inputProcessor = inputProcessor;
            _browserClient  = browserClient;
            _browser        = CefBrowserHost.CreateBrowserSync(
                cefWindowInfo,
                _browserClient,
                browserSettings,
                "http://localhost:4200"
                );

            _eventTokenList.Add(_eventBus.Subscribe <OpenMenuEvent>(OnOpenMenuEvent));
            _eventTokenList.Add(_eventBus.Subscribe <CloseMenuEvent>(OnCloseMenuEvent));

            var game = stateManager.GetGameById("Super Mario World (USA)");
            eventBus.Publish(new LoadGameEvent(game));
        }
Пример #19
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);
        }
Пример #20
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);
        }
Пример #21
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);
        }
Пример #22
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)
                {
                }
            }));
        }
Пример #23
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;
            }
        }
Пример #24
0
        public void Initialize()
        {
            IoCManager.Instance !.InjectDependencies(this, oneOff: true);

            string subProcessName;

            if (OperatingSystem.IsWindows())
            {
                subProcessName = "Robust.Client.WebView.exe";
            }
            else if (OperatingSystem.IsLinux())
            {
                subProcessName = "Robust.Client.WebView";
            }
            else
            {
                throw new NotSupportedException("Unsupported platform for CEF!");
            }

            var subProcessPath   = PathHelpers.ExecutableRelativeFile(subProcessName);
            var cefResourcesPath = LocateCefResources();

            // System.Console.WriteLine(AppContext.GetData("NATIVE_DLL_SEARCH_DIRECTORIES"));

            if (cefResourcesPath == null)
            {
                throw new InvalidOperationException("Unable to locate cef_resources directory!");
            }

            var settings = new CefSettings()
            {
                WindowlessRenderingEnabled = true,  // So we can render to our UI controls.
                ExternalMessagePump        = false, // Unsure, honestly. TODO CEF: Research this?
                NoSandbox             = true,       // Not disabling the sandbox crashes CEF.
                BrowserSubprocessPath = subProcessPath,
                LocalesDirPath        = Path.Combine(cefResourcesPath, "locales"),
                ResourcesDirPath      = cefResourcesPath,
                RemoteDebuggingPort   = 9222,
            };

            Logger.Info($"CEF Version: {CefRuntime.ChromeVersion}");

            _app = new RobustCefApp();

            // We pass no main arguments...
            CefRuntime.Initialize(new CefMainArgs(null), settings, _app, IntPtr.Zero);

            // TODO CEF: After this point, debugging breaks. No, literally. My client crashes but ONLY with the debugger.
            // I have tried using the DEBUG and RELEASE versions of libcef.so, stripped or non-stripped...
            // And nothing seemed to work. Odd.
        }
Пример #25
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>();
        }
Пример #26
0
        public void Initialize()
        {
            if (_initialized)
            {
                throw new Exception("Only one runtime can be initialized.");
            }
            _initialized = true;

            CefRuntime.Load();
            var mainArgs = new CefMainArgs(_commandLineArgs);
            var cefApp   = new CefApp();

            CefRuntime.Initialize(mainArgs, _cefSettings, cefApp, IntPtr.Zero);
        }
Пример #27
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);
            }
        }
Пример #28
0
        public static IResourceProvider <IDisposable> GetRuntimeProvider()
        {
            return(ResourceProvider.New(() =>
            {
                if (Interlocked.Increment(ref initCount) == 1)
                {
                    CefRuntime.Load();

                    var cefSettings = new CefSettings();
                    cefSettings.WindowlessRenderingEnabled = true;
                    cefSettings.PackLoadingDisabled = false;
                    cefSettings.MultiThreadedMessageLoop = true;
                    cefSettings.BrowserSubprocessPath = typeof(WebRendererApp).Assembly.Location;
                    cefSettings.CommandLineArgsDisabled = false;
                    cefSettings.IgnoreCertificateErrors = true;
                    //// We do not meet the requirements - see cef_sandbox_win.h
                    //cefSettings.NoSandbox = true;
#if DEBUG
                    cefSettings.LogSeverity = CefLogSeverity.Error;
#else
                    cefSettings.LogSeverity = CefLogSeverity.Disable;
#endif

                    // Check if we're in package (different folder layout)
                    var filename = Path.GetFileName(cefSettings.BrowserSubprocessPath);
                    var toolsPath = Path.Combine(Path.GetDirectoryName(cefSettings.BrowserSubprocessPath), "..", "..", "runtimes", "win-x64", "native", filename);
                    if (File.Exists(toolsPath))
                    {
                        cefSettings.BrowserSubprocessPath = toolsPath;
                    }

                    var args = Environment.GetCommandLineArgs();
                    var mainArgs = new CefMainArgs(args);
                    CefRuntime.Initialize(mainArgs, cefSettings, new WebRendererApp(), IntPtr.Zero);

                    var schemeName = "cef";
                    if (!CefRuntime.RegisterSchemeHandlerFactory(SchemeHandlerFactory.SCHEME_NAME, null, new SchemeHandlerFactory()))
                    {
                        throw new Exception(string.Format("Couldn't register custom scheme factory for '{0}'.", schemeName));
                    }

                    //return Disposable.Create(() => CefRuntime.Shutdown());
                }
                else
                {
                }
                return Disposable.Empty;
            }).ShareInParallel());
        }
Пример #29
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();
        }
        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);
        }