Example #1
0
        internal static void Initialize()
        {
            if(initialized)
                throw new HtmlUIException("ChromiumWebBrowser library already initialized.");

            int retval = CfxRuntime.ExecuteProcess();
            if(retval >= 0)
                Environment.Exit(retval);

            app = new CfxApp();
            processHandler = new CfxBrowserProcessHandler();

            app.GetBrowserProcessHandler += (s, e) => e.SetReturnValue(processHandler);
            app.OnBeforeCommandLineProcessing += (s, e) => HtmlUILauncher.RaiseOnBeforeCommandLineProcessing(e);
            app.OnRegisterCustomSchemes += (s, e) => HtmlUILauncher.RaiseOnRegisterCustomSchemes(e);

            var settings = new CfxSettings();
            settings.MultiThreadedMessageLoop = true;
            settings.NoSandbox = true;

            HtmlUILauncher.RaiseOnBeforeCfxInitialize(settings, processHandler);

            if(!CfxRuntime.Initialize(settings, app, RenderProcess.RenderProcessMain))
                throw new HtmlUIException("Failed to initialize CEF library.");

            initialized = true;
        }
        private void Initialize() 
        {
            CfxRuntime.LibCefDirPath = @"cef\Release";
            int retval = CfxRuntime.ExecuteProcess();

            var app = new CfxApp();
            var processHandler = new CfxBrowserProcessHandler();
            app.GetBrowserProcessHandler += (sender, e) => e.SetReturnValue(processHandler);

            var path = Path.Combine(GetType().Assembly.GetPath(), "ChromiumFXRenderProcess.exe");

            var settings = new CfxSettings 
            {
                SingleProcess = false,
                BrowserSubprocessPath = path,
                WindowlessRenderingEnabled = true,
                MultiThreadedMessageLoop = true,
                NoSandbox = true,
                LocalesDirPath = System.IO.Path.GetFullPath(@"cef\Resources\locales"),
                ResourcesDirPath = System.IO.Path.GetFullPath(@"cef\Resources")
            };

            if (!CfxRuntime.Initialize(settings, app, RenderProcessStartup))
                throw new Exception("Failed to initialize CEF library.");

            Thread.Sleep(200);

        }
 static void Main() 
 {
     CfxRuntime.LibCefDirPath = @"cef\Release";
     var app = new CfxApp();
     var handler = new CfxRenderProcessHandler();
     app.GetRenderProcessHandler += (sender, args) => args.SetReturnValue(handler);
     int retval = CfxRuntime.ExecuteProcess(app);
     Environment.Exit(retval);
 }
Example #4
0
 /// <summary>
 /// This function should be called from the application entry point function to
 /// execute a secondary process. It can be used to run secondary processes from
 /// the browser client executable (default behavior) or from a separate
 /// executable specified by the CfxSettings.BrowserSubprocessPath value. If
 /// called for the browser process (identified by no "type" command-line value)
 /// it will return immediately with a value of -1. If called for a recognized
 /// secondary process it will block until the process should exit and then return
 /// the process exit code. The |application| parameter may be NULL. The
 /// |windowsSandboxInfo| parameter is only used on Windows and may be NULL (see
 /// cef_sandbox_win.h for details).
 /// </summary>
 /// <remarks>
 /// See also the original CEF documentation in
 /// <see href="https://bitbucket.org/chromiumfx/chromiumfx/src/tip/cef/include/capi/cef_app_capi.h">cef/include/capi/cef_app_capi.h</see>.
 /// </remarks>
 private static int ExecuteProcessPrivate(CfxMainArgs args, CfxApp application, IntPtr windowsSandboxInfo)
 {
     return(CfxApi.cfx_execute_process(CfxMainArgs.Unwrap(args), CfxApp.Unwrap(application), windowsSandboxInfo));
 }
Example #5
0
 internal static int ExecuteProcessInternal(CfxApp application)
 {
     switch(CfxApi.PlatformOS) {
         case CfxPlatformOS.Windows:
             return ExecuteProcessPrivate(null, application, IntPtr.Zero);
         case CfxPlatformOS.Linux:
             using(var mainArgs = CfxMainArgs.ForLinux()) {
                 var retval = ExecuteProcessPrivate(mainArgs, application, IntPtr.Zero);
                 mainArgs.mainArgsLinux.Free();
                 return retval;
             }
         default:
             throw new CfxException("Unsupported platform.");
     }
 }
Example #6
0
 /// <summary>
 /// This function should be called on the main application thread to initialize
 /// the CEF browser process. The |application| parameter may be NULL. A return
 /// value of true (1) indicates that it succeeded and false (0) indicates that it
 /// failed.
 /// 
 /// The chromium sandbox is currently not supported within ChromiumFX.
 /// </summary>
 public static bool Initialize(CfxSettings settings, CfxApp application)
 {
     CfxApi.Probe();
     switch(CfxApi.PlatformOS) {
         case CfxPlatformOS.Windows:
             return InitializePrivate(null, settings, application, IntPtr.Zero);
         case CfxPlatformOS.Linux:
             using(var mainArgs = CfxMainArgs.ForLinux()) {
                 var retval = InitializePrivate(mainArgs, settings, application, IntPtr.Zero);
                 mainArgs.mainArgsLinux.Free();
                 return retval;
             }
         default:
             throw new CfxException();
     }
 }
Example #7
0
 /// <summary>
 /// This function should be called on the main application thread to initialize
 /// the CEF browser process with support for the remote interface to the render
 /// process. The |application| parameter may be NULL. A return value of true (1) 
 /// indicates that it succeeded and false (0) indicates that it failed.
 /// 
 /// If |renderProcessMain| is provided, then every newly created render process 
 /// main thread will be redirected through this callback and the callee is
 /// responsible for calling CfrRuntime.ExecuteProcess() from within the 
 /// scope of this callback.
 /// 
 /// The chromium sandbox is currently not supported within ChromiumFX.
 /// </summary>
 public static bool Initialize(CfxSettings settings, CfxApp application, CfxRenderProcessMainDelegate renderProcessMain)
 {
     CfxApi.Probe();
     Chromium.Remote.RemoteService.Initialize(renderProcessMain, ref application);
     return Initialize(settings, application);
 }
Example #8
0
        /// <summary>
        /// This function should be called from the application entry point function to
        /// execute a secondary process. It can be used to run secondary processes from
        /// the browser client executable (default behavior) or from a separate
        /// executable specified by the CefSettings.browser_subprocess_path value. If
        /// called for the browser process (identified by no "type" command-line value)
        /// it will return immediately with a value of -1. If called for a recognized
        /// secondary process it will block until the process should exit and then return
        /// the process exit code. The |application| parameter may be NULL.
        /// 
        /// If the browser process was initialized with a valid render process startup callback,
        /// the render main thread will be redirected through the remoting interface into the
        /// browser process. The browser process' render process startup callback routine
        /// is then responsible for calling CfrRuntime.ExecuteProcess() and the |application|
        /// parameter will be ignored.
        /// 
        /// The chromium sandbox is currently not supported within ChromiumFX.
        /// </summary>
        public static int ExecuteProcess(CfxApp application)
        {
            CfxApi.Probe();

            var cmd = Environment.CommandLine;
            var ex = new System.Text.RegularExpressions.Regex(@"cfxremote=(\w+)");
            var m = ex.Match(cmd);

            if(m.Success) {
                return Chromium.Remote.RemoteClient.ExecuteProcess(m.Groups[1].Value);
            } else {
                return ExecuteProcessInternal(application);
            }
        }
 /// <summary>
 /// This function should be called on the main application thread to initialize
 /// the CEF browser process with support for the remote interface to the render
 /// process. The |application| parameter may be NULL. A return value of true (1)
 /// indicates that it succeeded and false (0) indicates that it failed.
 ///
 /// If |renderProcessMain| is provided, then every newly created render process
 /// main thread will be redirected through this callback and the callee is
 /// responsible for calling CfrRuntime.ExecuteProcess() from within the
 /// scope of this callback.
 ///
 /// The chromium sandbox is currently not supported within ChromiumFX.
 /// </summary>
 public static bool Initialize(CfxSettings settings, CfxApp application, CfxRenderProcessMainDelegate renderProcessMain)
 {
     CfxApi.Probe();
     Chromium.Remote.RemoteService.Initialize(renderProcessMain, ref application);
     return(Initialize(settings, application));
 }
Example #10
0
 /// <summary>
 /// This function should be called on the main application thread to initialize
 /// the CEF browser process. The |application| parameter may be NULL. A return
 /// value of true (1) indicates that it succeeded and false (0) indicates that it
 /// failed. The |windowsSandboxInfo| parameter is only used on Windows and may
 /// be NULL (see cef_sandbox_win.h for details).
 /// </summary>
 /// <remarks>
 /// See also the original CEF documentation in
 /// <see href="https://bitbucket.org/chromiumfx/chromiumfx/src/tip/cef/include/capi/cef_app_capi.h">cef/include/capi/cef_app_capi.h</see>.
 /// </remarks>
 private static bool InitializePrivate(CfxMainArgs args, CfxSettings settings, CfxApp application, IntPtr windowsSandboxInfo)
 {
     return(0 != CfxApi.cfx_initialize(CfxMainArgs.Unwrap(args), CfxSettings.Unwrap(settings), CfxApp.Unwrap(application), windowsSandboxInfo));
 }