@@ -19,21 +19,22 @@ public class OutOfProcessHost : IOutOfProcessHostRpc, IDisposable
1919
2020 private Process _browserProcess ;
2121 private JsonRpc _jsonRpc ;
22- private IOutOfProcessClientRpc _browserProcessServer ;
22+ private IOutOfProcessClientRpc _outOfProcessClient ;
2323 private string _cefSharpVersion ;
2424 private string _cefVersion ;
2525 private string _chromiumVersion ;
2626 private int _uiThreadId ;
2727 private int _remoteuiThreadId ;
2828 private int _browserIdentifier = 1 ;
29- private string _outofProcessFilePath ;
30-
29+ private string _outofProcessHostExePath ;
30+ private string _cachePath ;
3131 private ConcurrentDictionary < int , IChromiumWebBrowserInternal > _browsers = new ConcurrentDictionary < int , IChromiumWebBrowserInternal > ( ) ;
3232 private TaskCompletionSource < OutOfProcessHost > _processInitialized = new TaskCompletionSource < OutOfProcessHost > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
3333
34- private OutOfProcessHost ( string path )
34+ private OutOfProcessHost ( string outOfProcessHostExePath , string cachePath = null )
3535 {
36- _outofProcessFilePath = path ;
36+ _outofProcessHostExePath = outOfProcessHostExePath ;
37+ _cachePath = cachePath ;
3738 }
3839
3940 /// <summary>
@@ -88,14 +89,14 @@ public string ChromiumVersion
8889 public bool CreateBrowser ( IChromiumWebBrowserInternal browser , IntPtr handle , string url , out int id )
8990 {
9091 id = _browserIdentifier ++ ;
91- _ = _browserProcessServer . CreateBrowser ( handle , url , id ) ;
92+ _ = _outOfProcessClient . CreateBrowser ( handle , url , id ) ;
9293
9394 return _browsers . TryAdd ( id , browser ) ;
9495 }
9596
9697 internal Task SendDevToolsMessageAsync ( int browserId , string message )
9798 {
98- return _browserProcessServer . SendDevToolsMessage ( browserId , message ) ;
99+ return _outOfProcessClient . SendDevToolsMessage ( browserId , message ) ;
99100 }
100101
101102 private Task < OutOfProcessHost > InitializedTask
@@ -107,24 +108,31 @@ private void Init()
107108 {
108109 var currentProcess = Process . GetCurrentProcess ( ) ;
109110
110- var args = $ "--parentProcessId={ currentProcess . Id } ";
111+ var args = $ "--parentProcessId={ currentProcess . Id } --cachePath= { _cachePath } ";
111112
112- _browserProcess = Process . Start ( new ProcessStartInfo ( _outofProcessFilePath , args )
113+ _browserProcess = Process . Start ( new ProcessStartInfo ( _outofProcessHostExePath , args )
113114 {
114115 RedirectStandardInput = true ,
115116 RedirectStandardOutput = true ,
116117 } ) ;
117118
119+ _browserProcess . Exited += OnBrowserProcessExited ;
120+
118121 _jsonRpc = JsonRpc . Attach ( _browserProcess . StandardInput . BaseStream , _browserProcess . StandardOutput . BaseStream ) ;
119122
120- _browserProcessServer = _jsonRpc . Attach < IOutOfProcessClientRpc > ( ) ;
123+ _outOfProcessClient = _jsonRpc . Attach < IOutOfProcessClientRpc > ( ) ;
121124 _jsonRpc . AllowModificationWhileListening = true ;
122125 _jsonRpc . AddLocalRpcTarget < IOutOfProcessHostRpc > ( this , null ) ;
123126 _jsonRpc . AllowModificationWhileListening = false ;
124127
125128 _uiThreadId = Kernel32 . GetCurrentThreadId ( ) ;
126129 }
127130
131+ private void OnBrowserProcessExited ( object sender , EventArgs e )
132+ {
133+ var exitCode = _browserProcess . ExitCode ;
134+ }
135+
128136 void IOutOfProcessHostRpc . NotifyAddressChanged ( int browserId , string address )
129137 {
130138 if ( _browsers . TryGetValue ( browserId , out var chromiumWebBrowser ) )
@@ -137,7 +145,7 @@ void IOutOfProcessHostRpc.NotifyBrowserCreated(int browserId, IntPtr browserHwnd
137145 {
138146 if ( _browsers . TryGetValue ( browserId , out var chromiumWebBrowser ) )
139147 {
140- chromiumWebBrowser . SetBrowserHwnd ( browserHwnd ) ;
148+ chromiumWebBrowser . OnAfterBrowserCreated ( browserHwnd ) ;
141149 }
142150 }
143151
@@ -199,19 +207,34 @@ void IOutOfProcessHostRpc.NotifyTitleChanged(int browserId, string title)
199207 }
200208 }
201209
210+ public void NotifyMoveOrResizeStarted ( int id )
211+ {
212+ _outOfProcessClient . NotifyMoveOrResizeStarted ( id ) ;
213+ }
214+
215+ /// <summary>
216+ /// Set whether the browser is focused. (Used for Normal Rendering e.g. WinForms)
217+ /// </summary>
218+ /// <param name="id">browser id</param>
219+ /// <param name="focus">set focus</param>
220+ public void SetFocus ( int id , bool focus )
221+ {
222+ _outOfProcessClient . SetFocus ( id , focus ) ;
223+ }
224+
202225 public void CloseBrowser ( int id )
203226 {
204- _browserProcessServer . CloseBrowser ( id ) ;
227+ _ = _outOfProcessClient . CloseBrowser ( id ) ;
205228 }
206229
207230 public void Dispose ( )
208231 {
209- _browserProcessServer . CloseHost ( ) ;
232+ _ = _outOfProcessClient . CloseHost ( ) ;
210233 _jsonRpc ? . Dispose ( ) ;
211234 _jsonRpc = null ;
212235 }
213236
214- public static Task < OutOfProcessHost > CreateAsync ( string path = HostExeName )
237+ public static Task < OutOfProcessHost > CreateAsync ( string path = HostExeName , string cachePath = null )
215238 {
216239 if ( string . IsNullOrEmpty ( path ) )
217240 {
@@ -225,7 +248,7 @@ public static Task<OutOfProcessHost> CreateAsync(string path = HostExeName)
225248 throw new FileNotFoundException ( "Unable to find Host executable." , path ) ;
226249 }
227250
228- var host = new OutOfProcessHost ( fullPath ) ;
251+ var host = new OutOfProcessHost ( fullPath , cachePath ) ;
229252
230253 host . Init ( ) ;
231254
0 commit comments