Skip to content

Commit 4afca24

Browse files
committed
Remove parameterless constructor for now.
- Need to find a clean way to create an OutOfProcessHost and assign it to a ChromiumWebBrowser instance
1 parent 8a10672 commit 4afca24

File tree

3 files changed

+22
-65
lines changed

3 files changed

+22
-65
lines changed

CefSharp.OutOfProcess.WinForms/ChromiumWebBrowser.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,18 @@ public class ChromiumWebBrowser : Control, IChromiumWebBrowserInternal
5959
/// <inheritdoc/>
6060
public event EventHandler DevToolsContextAvailable;
6161

62+
/// <summary>
63+
/// ChromiumWebBrowser constructor
64+
/// </summary>
65+
/// <param name="host">Out of process host</param>
66+
/// <param name="initialAddress">address that will be initially loaded in the browser</param>
6267
public ChromiumWebBrowser(OutOfProcessHost host, string initialAddress)
6368
{
69+
if(host == null)
70+
{
71+
throw new ArgumentNullException(nameof(host));
72+
}
73+
6474
_host = host;
6575
_initialAddress = initialAddress;
6676
}
Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
// Copyright © 2019 The CefSharp Authors. All rights reserved.
1+
// Copyright © 2022 The CefSharp Authors. All rights reserved.
22
//
33
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
44

5-
using System;
6-
using System.IO;
75
using System.Windows;
86

97
namespace CefSharp.OutOfProcess.Wpf.HwndHost.Example
@@ -13,26 +11,6 @@ namespace CefSharp.OutOfProcess.Wpf.HwndHost.Example
1311
/// </summary>
1412
public partial class App : Application
1513
{
16-
#if DEBUG
17-
private string _buildType = "Debug";
18-
#else
19-
private string _buildType = "Release";
20-
#endif
2114

22-
#if NETCOREAPP3_1_OR_GREATER
23-
private string _targetFramework = "netcoreapp3.1";
24-
#else
25-
private string _targetFramework = "net462";
26-
#endif
27-
28-
protected override void OnStartup(StartupEventArgs e)
29-
{
30-
base.OnStartup(e);
31-
32-
var outOfProcessHostPath = Path.GetFullPath($"..\\..\\..\\..\\CefSharp.OutOfProcess.BrowserProcess\\bin\\{_buildType}\\{_targetFramework}");
33-
outOfProcessHostPath = Path.Combine(outOfProcessHostPath, OutOfProcessHost.HostExeName);
34-
35-
ChromiumWebBrowser.SetHostProcessPath(outOfProcessHostPath);
36-
}
3715
}
3816
}

CefSharp.OutOfProcess.Wpf.HwndHost/ChromiumWebBrowser.cs

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,11 @@ namespace CefSharp.OutOfProcess.Wpf.HwndHost
2828
/// and https://stackoverflow.com/questions/6500336/custom-dwm-drawn-window-frame-flickers-on-resizing-if-the-window-contains-a-hwnd/17471534#17471534
2929
public class ChromiumWebBrowser : System.Windows.Interop.HwndHost, IChromiumWebBrowserInternal
3030
{
31-
public const string BrowserNotInitializedExceptionErrorMessage =
31+
private const string BrowserNotInitializedExceptionErrorMessage =
3232
"The ChromiumWebBrowser instance creates the underlying Chromium Embedded Framework (CEF) browser instance in an async fashion. " +
3333
"The undelying CefBrowser instance is not yet initialized. Use the IsBrowserInitializedChanged event and check " +
3434
"the IsBrowserInitialized property to determine when the browser has been initialized.";
3535

36-
private static string _defaultHostProcessPath;
37-
3836
private const int WS_CHILD = 0x40000000,
3937
WS_VISIBLE = 0x10000000,
4038
LBS_NOTIFY = 0x00000001,
@@ -275,21 +273,18 @@ public bool IsDisposed
275273
/// <value>The redo command.</value>
276274
public ICommand RedoCommand { get; private set; }
277275

278-
/// <summary>
279-
/// Initializes a new instance of the <see cref="ChromiumWebBrowser"/> instance.
280-
/// </summary>
281-
public ChromiumWebBrowser() : this(null, null)
282-
{
283-
284-
}
285-
286276
/// <summary>
287277
/// Initializes a new instance of the <see cref="ChromiumWebBrowser"/> instance.
288278
/// </summary>
289279
/// <param name="host">Out of process host</param>
290280
/// <param name="initialAddress">address to load initially</param>
291-
public ChromiumWebBrowser(OutOfProcessHost host, string initialAddress)
281+
public ChromiumWebBrowser(OutOfProcessHost host, string initialAddress = null)
292282
{
283+
if(host == null)
284+
{
285+
throw new ArgumentNullException(nameof(host));
286+
}
287+
293288
_host = host;
294289
_initialAddress = initialAddress;
295290

@@ -323,15 +318,6 @@ public ChromiumWebBrowser(OutOfProcessHost host, string initialAddress)
323318
UseLayoutRounding = true;
324319
}
325320

326-
/// <summary>
327-
/// Used when control is created through xaml or using default constructor
328-
/// </summary>
329-
/// <param name="path"></param>
330-
public static void SetHostProcessPath(string path)
331-
{
332-
_defaultHostProcessPath = path;
333-
}
334-
335321
/// <inheritdoc/>
336322
int IChromiumWebBrowserInternal.Id
337323
{
@@ -505,29 +491,12 @@ protected override HandleRef BuildWindowCore(HandleRef hwndParent)
505491
0);
506492
}
507493

508-
if (_host == null)
509-
{
510-
_ = OutOfProcessHost.CreateAsync(_defaultHostProcessPath).ContinueWith((t) =>
511-
{
512-
_host = t.Result;
513-
514-
_host.CreateBrowser(this, _hwndHost, url: _initialAddress, out _id);
515-
516-
_devToolsContextConnectionTransport = new OutOfProcessConnectionTransport(_id, _host);
517-
518-
var connection = DevToolsConnection.Attach(_devToolsContextConnectionTransport);
519-
_devToolsContext = Puppeteer.DevToolsContext.CreateForOutOfProcess(connection);
520-
}, TaskScheduler.Default);
521-
}
522-
else
523-
{
524-
_host.CreateBrowser(this, _hwndHost, url: _initialAddress, out _id);
494+
_host.CreateBrowser(this, _hwndHost, url: _initialAddress, out _id);
525495

526-
_devToolsContextConnectionTransport = new OutOfProcessConnectionTransport(_id, _host);
496+
_devToolsContextConnectionTransport = new OutOfProcessConnectionTransport(_id, _host);
527497

528-
var connection = DevToolsConnection.Attach(_devToolsContextConnectionTransport);
529-
_devToolsContext = Puppeteer.DevToolsContext.CreateForOutOfProcess(connection);
530-
}
498+
var connection = DevToolsConnection.Attach(_devToolsContextConnectionTransport);
499+
_devToolsContext = Puppeteer.DevToolsContext.CreateForOutOfProcess(connection);
531500

532501
return new HandleRef(null, _hwndHost);
533502
}

0 commit comments

Comments
 (0)