diff --git a/CefSharp.OutOfProcess.BrowserProcess/Program.cs b/CefSharp.OutOfProcess.BrowserProcess/Program.cs index 39f6b0b..31be59d 100644 --- a/CefSharp.OutOfProcess.BrowserProcess/Program.cs +++ b/CefSharp.OutOfProcess.BrowserProcess/Program.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using System.Diagnostics; +using System.Linq; using System.Threading.Tasks; using CefSharp.Internals; @@ -17,17 +19,17 @@ public static int Main(string[] args) //Debugger.Launch(); var parentProcessId = int.Parse(CommandLineArgsParser.GetArgumentValue(args, "--parentProcessId")); - var cachePath = CommandLineArgsParser.GetArgumentValue(args, "--cachePath"); var parentProcess = Process.GetProcessById(parentProcessId); var settings = new CefSettings() { //By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data - CachePath = cachePath, MultiThreadedMessageLoop = false }; + AddArgs(settings, args); + var browserProcessHandler = new BrowserProcessHandler(parentProcessId); Cef.EnableWaitForBrowsersToClose(); @@ -66,5 +68,32 @@ public static int Main(string[] args) return 0; } + + private static void AddArgs(CefSettings settings, IEnumerable args) + { + foreach (var arg in args) + { + List splitted = arg.Split('=').ToList(); + var key = splitted.First().Substring(2); + var value = splitted.Count == 1 ? string.Empty : splitted.Last(); + AddArg(settings, key, value); + } + } + + private static void AddArg(CefSettings settings, string key, string value) + { + switch (key) + { + case "accept-lang": + settings.AcceptLanguageList = value; + break; + case "cachePath": + settings.CachePath = value; + break; + default: + settings.CefCommandLineArgs.Add(key, value); + break; + } + } } } diff --git a/CefSharp.OutOfProcess.Core/OutOfProcessHost.cs b/CefSharp.OutOfProcess.Core/OutOfProcessHost.cs index 1fec5c4..9749d3a 100644 --- a/CefSharp.OutOfProcess.Core/OutOfProcessHost.cs +++ b/CefSharp.OutOfProcess.Core/OutOfProcessHost.cs @@ -1,11 +1,13 @@ -using CefSharp.OutOfProcess.Interface; +using CefSharp.OutOfProcess.Interface; using CefSharp.OutOfProcess.Internal; using PInvoke; using StreamJsonRpc; using System; using System.Collections.Concurrent; +using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Linq; using System.Threading.Tasks; namespace CefSharp.OutOfProcess @@ -28,13 +30,15 @@ public class OutOfProcessHost : IOutOfProcessHostRpc, IDisposable private int _browserIdentifier = 1; private string _outofProcessHostExePath; private string _cachePath; + private readonly IEnumerable _cefCommandLineArgs; private ConcurrentDictionary _browsers = new ConcurrentDictionary(); private TaskCompletionSource _processInitialized = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - private OutOfProcessHost(string outOfProcessHostExePath, string cachePath = null) + private OutOfProcessHost(string outOfProcessHostExePath, string cachePath = null, IEnumerable cefCommandLineArgs = null) { _outofProcessHostExePath = outOfProcessHostExePath; _cachePath = cachePath; + _cefCommandLineArgs = cefCommandLineArgs; } /// @@ -108,7 +112,7 @@ private void Init() { var currentProcess = Process.GetCurrentProcess(); - var args = $"--parentProcessId={currentProcess.Id} --cachePath={_cachePath}"; + var args = $"--parentProcessId={currentProcess.Id} --cachePath={_cachePath} {_cefCommandLineArgs?.Aggregate((a, p) => $"{a} {p}")}"; _browserProcess = Process.Start(new ProcessStartInfo(_outofProcessHostExePath, args) { @@ -234,7 +238,7 @@ public void Dispose() _jsonRpc = null; } - public static Task CreateAsync(string path = HostExeName, string cachePath = null) + public static Task CreateAsync(string path = HostExeName, string cachePath = null, IEnumerable cefCommandLineArgs = null) { if(string.IsNullOrEmpty(path)) { @@ -248,7 +252,7 @@ public static Task CreateAsync(string path = HostExeName, stri throw new FileNotFoundException("Unable to find Host executable.", path); } - var host = new OutOfProcessHost(fullPath, cachePath); + var host = new OutOfProcessHost(fullPath, cachePath, cefCommandLineArgs); host.Init();