Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions CefSharp.OutOfProcess.BrowserProcess/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using CefSharp.Internals;

Expand All @@ -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();
Expand Down Expand Up @@ -66,5 +68,32 @@ public static int Main(string[] args)

return 0;
}

private static void AddArgs(CefSettings settings, IEnumerable<string> args)
{
foreach (var arg in args)
{
List<string> 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;
}
}
}
}
14 changes: 9 additions & 5 deletions CefSharp.OutOfProcess.Core/OutOfProcessHost.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -28,13 +30,15 @@ public class OutOfProcessHost : IOutOfProcessHostRpc, IDisposable
private int _browserIdentifier = 1;
private string _outofProcessHostExePath;
private string _cachePath;
private readonly IEnumerable<string> _cefCommandLineArgs;
private ConcurrentDictionary<int, IChromiumWebBrowserInternal> _browsers = new ConcurrentDictionary<int, IChromiumWebBrowserInternal>();
private TaskCompletionSource<OutOfProcessHost> _processInitialized = new TaskCompletionSource<OutOfProcessHost>(TaskCreationOptions.RunContinuationsAsynchronously);

private OutOfProcessHost(string outOfProcessHostExePath, string cachePath = null)
private OutOfProcessHost(string outOfProcessHostExePath, string cachePath = null, IEnumerable<string> cefCommandLineArgs = null)
{
_outofProcessHostExePath = outOfProcessHostExePath;
_cachePath = cachePath;
_cefCommandLineArgs = cefCommandLineArgs;
}

/// <summary>
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -234,7 +238,7 @@ public void Dispose()
_jsonRpc = null;
}

public static Task<OutOfProcessHost> CreateAsync(string path = HostExeName, string cachePath = null)
public static Task<OutOfProcessHost> CreateAsync(string path = HostExeName, string cachePath = null, IEnumerable<string> cefCommandLineArgs = null)
{
if(string.IsNullOrEmpty(path))
{
Expand All @@ -248,7 +252,7 @@ public static Task<OutOfProcessHost> 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();

Expand Down