Skip to content

Commit

Permalink
Add support for Synchronous Bindings when Self Hosting BrowserSubProcess
Browse files Browse the repository at this point in the history
Resolves #4562
  • Loading branch information
amaitland committed Aug 19, 2023
1 parent 1328732 commit 65eef56
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ namespace CefSharp

}

#ifdef NETCOREAPP
/// <summary>
/// This function should be called from the application entry point function (typically Program.Main)
/// to execute a secondary process e.g. gpu, renderer, utility
/// This overload is specifically used for .Net Core. For hosting your own BrowserSubProcess
/// it's preferable to use the Main method provided by this class.
/// - Obtains the command line args via a call to Environment::GetCommandLineArgs
/// </summary>
/// <returns>
/// If called for the browser process (identified by no "type" command-line value) it will return immediately
Expand All @@ -45,6 +45,7 @@ namespace CefSharp
auto subProcess = gcnew BrowserSubprocessExecutable();
return subProcess->Main(args, nullptr);
}
#endif

/// <summary>
/// This function should be called from the application entry point function (typically Program.Main)
Expand Down
18 changes: 18 additions & 0 deletions CefSharp.BrowserSubprocess.Core/WcfBrowserSubprocessExecutable.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ namespace CefSharp
{

}

/// <summary>
/// This function should be called from the application entry point function (typically Program.Main)
/// to execute a secondary process e.g. gpu, renderer, utility
/// This overload is specifically used for .Net 4.x. For hosting your own BrowserSubProcess
/// it's preferable to use the Main method provided by this class.
/// </summary>
/// <returns>
/// 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.
/// </returns
static int MainSelfHost(array<String^>^ args)
{
auto subProcess = gcnew WcfBrowserSubprocessExecutable();
return subProcess->Main(args, nullptr);
}

protected:
SubProcess^ GetSubprocess(IEnumerable<String^>^ args, int parentProcessId, IRenderProcessHandler^ handler) override
{
Expand Down
5 changes: 3 additions & 2 deletions CefSharp.Core/BrowserSubprocess/SelfHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ public static int Main(string[] args)
browserSubprocessDllPath = Path.Combine(Path.GetDirectoryName(typeof(CefSharp.Core.BrowserSettings).Assembly.Location), "CefSharp.BrowserSubprocess.Core.dll");
}
var browserSubprocessDll = System.Runtime.Loader.AssemblyLoadContext.Default.LoadFromAssemblyPath(browserSubprocessDllPath);
var browserSubprocessExecutableType = browserSubprocessDll.GetType("CefSharp.BrowserSubprocess.BrowserSubprocessExecutable");
#else
var browserSubprocessDllPath = Path.Combine(Path.GetDirectoryName(typeof(CefSharp.Core.BrowserSettings).Assembly.Location), "CefSharp.BrowserSubprocess.Core.dll");
var browserSubprocessDll = System.Reflection.Assembly.LoadFrom(browserSubprocessDllPath);

var browserSubprocessExecutableType = browserSubprocessDll.GetType("CefSharp.BrowserSubprocess.WcfBrowserSubprocessExecutable");
#endif
var browserSubprocessExecutableType = browserSubprocessDll.GetType("CefSharp.BrowserSubprocess.BrowserSubprocessExecutable");

var browserSubprocessExecutable = Activator.CreateInstance(browserSubprocessExecutableType);

var mainMethod = browserSubprocessExecutableType.GetMethod("MainSelfHost", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
Expand Down

0 comments on commit 65eef56

Please sign in to comment.