Skip to content

Commit c1e6422

Browse files
committed
Import Tabbed form from CefSharp.WinForms.Example
1 parent bead438 commit c1e6422

28 files changed

Lines changed: 2823 additions & 49 deletions

CefSharp.OutOfProcess.BrowserProcess/BrowserProcessHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected override void OnContextInitialized()
7676

7777
var threadId = Kernel32.GetCurrentThreadId();
7878

79-
_ = _jsonRpc.NotifyAsync("OnContextInitialized", threadId);
79+
_ = _jsonRpc.NotifyAsync("OnContextInitialized", threadId, Cef.CefSharpVersion, Cef.CefVersion, Cef.ChromiumVersion);
8080
}
8181

8282
protected override void Dispose(bool disposing)
Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using CefSharp.Puppeteer;
2+
using System.Threading.Tasks;
23

34
namespace CefSharp.OutOfProcess
45
{
@@ -8,25 +9,74 @@ namespace CefSharp.OutOfProcess
89
public interface IChromiumWebBrowser
910
{
1011
/// <summary>
11-
/// Identifier
12+
/// Loads the specified <paramref name="url"/> in the Main Frame.
1213
/// </summary>
13-
int Id { get; }
14+
/// <param name="url">The URL to be loaded.</param>
15+
/// <remarks>
16+
/// This is exactly the same as calling Load(string), it was added
17+
/// as the method name is more meaningful and easier to discover
18+
/// via Intellisense.
19+
/// </remarks>
20+
void LoadUrl(string url);
1421

1522
/// <summary>
16-
/// Set the browser Hwnd
23+
/// A flag that indicates whether the WebBrowser is initialized (true) or not (false).
1724
/// </summary>
18-
/// <param name="hwnd">Hwnd</param>
19-
void SetBrowserHwnd(IntPtr hwnd);
25+
/// <value><c>true</c> if this instance is browser initialized; otherwise, <c>false</c>.</value>
26+
bool IsBrowserInitialized { get; }
2027

2128
/// <summary>
22-
/// Called when a DevTools message arrives from the browser process
29+
/// A flag that indicates whether the WebBrowser has been disposed (<see langword="true" />) or not (<see langword="false" />)
2330
/// </summary>
24-
/// <param name="jsonMsg"></param>
25-
void OnDevToolsMessage(string jsonMsg);
31+
/// <value><see langword="true" /> if this instance is disposed; otherwise, <see langword="false" /></value>
32+
bool IsDisposed { get; }
2633

2734
/// <summary>
28-
/// DevTools is ready in the browser process to create the DevToolsContext
35+
/// The address (URL) which the browser control is currently displaying.
36+
/// Will automatically be updated as the user navigates to another page (e.g. by clicking on a link).
2937
/// </summary>
30-
void OnDevToolsReady();
38+
/// <value>The address.</value>
39+
/// <remarks>In the WPF control, this property is implemented as a Dependency Property and fully supports data
40+
/// binding.</remarks>
41+
string Address { get; }
42+
43+
/// <summary>
44+
/// Gets all frames attached to the page.
45+
/// </summary>
46+
/// <value>An array of all frames attached to the page.</value>
47+
Frame[] Frames { get; }
48+
49+
/// <summary>
50+
/// Gets page's main frame
51+
/// </summary>
52+
/// <remarks>
53+
/// Page is guaranteed to have a main frame which persists during navigations.
54+
/// </remarks>
55+
Frame MainFrame { get; }
56+
57+
/// <summary>
58+
/// Navigates to an url
59+
/// </summary>
60+
/// <param name="url">URL to navigate page to. The url should include scheme, e.g. https://.</param>
61+
/// <param name="timeout">Maximum navigation time in milliseconds, defaults to 30 seconds, pass <c>0</c> to disable timeout. </param>
62+
/// <param name="waitUntil">When to consider navigation succeeded, defaults to <see cref="WaitUntilNavigation.Load"/>. Given an array of <see cref="WaitUntilNavigation"/>, navigation is considered to be successful after all events have been fired</param>
63+
/// <returns>Task which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect</returns>
64+
Task<Response> LoadUrlAsync(string url, int? timeout = null, WaitUntilNavigation[] waitUntil = null);
65+
66+
/// <summary>
67+
/// Navigate to the previous page in history.
68+
/// </summary>
69+
/// <returns>Task that resolves to the main resource response. In case of multiple redirects,
70+
/// the navigation will resolve with the response of the last redirect. If can not go back, resolves to null.</returns>
71+
/// <param name="options">Navigation parameters.</param>
72+
Task<Response> GoBackAsync(NavigationOptions options = null);
73+
74+
/// <summary>
75+
/// Navigate to the next page in history.
76+
/// </summary>
77+
/// <returns>Task that resolves to the main resource response. In case of multiple redirects,
78+
/// the navigation will resolve with the response of the last redirect. If can not go forward, resolves to null.</returns>
79+
/// <param name="options">Navigation parameters.</param>
80+
Task<Response> GoForwardAsync(NavigationOptions options = null);
3181
}
3282
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
3+
namespace CefSharp.OutOfProcess.Internal
4+
{
5+
public interface IChromiumWebBrowserInternal : IChromiumWebBrowser
6+
{
7+
/// <summary>
8+
/// Identifier
9+
/// </summary>
10+
int Id { get; }
11+
12+
/// <summary>
13+
/// Set the browser Hwnd
14+
/// </summary>
15+
/// <param name="hwnd">Hwnd</param>
16+
void SetBrowserHwnd(IntPtr hwnd);
17+
18+
/// <summary>
19+
/// Called when a DevTools message arrives from the browser process
20+
/// </summary>
21+
/// <param name="jsonMsg"></param>
22+
void OnDevToolsMessage(string jsonMsg);
23+
24+
/// <summary>
25+
/// DevTools is ready in the browser process to create the DevToolsContext
26+
/// </summary>
27+
void OnDevToolsReady();
28+
}
29+
}

CefSharp.OutOfProcess.Core/OutOfProcessConnectionTransport.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void InvokeMessageReceived(string message)
3030

3131
public Task SendAsync(string message)
3232
{
33-
return OutOfProcessHost.SendDevToolsMessage(BrowserId, message);
33+
return OutOfProcessHost.SendDevToolsMessageAsync(BrowserId, message);
3434
}
3535

3636
public void StopReading()

CefSharp.OutOfProcess.Core/OutOfProcessHost.cs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using PInvoke;
1+
using CefSharp.OutOfProcess.Internal;
2+
using PInvoke;
23
using StreamJsonRpc;
34
using System;
45
using System.Collections.Concurrent;
@@ -17,11 +18,14 @@ public class OutOfProcessHost : IDisposable
1718

1819
private Process _browserProcess;
1920
private JsonRpc _jsonRpc;
21+
private string _cefSharpVersion;
22+
private string _cefVersion;
23+
private string _chromiumVersion;
2024
private int _uiThreadId;
2125
private int _remoteuiThreadId;
2226
private int _browserIdentifier = 1;
2327
private string _outofProcessFilePath;
24-
private ConcurrentDictionary<int, IChromiumWebBrowser> _browsers = new ConcurrentDictionary<int, IChromiumWebBrowser>();
28+
private ConcurrentDictionary<int, IChromiumWebBrowserInternal> _browsers = new ConcurrentDictionary<int, IChromiumWebBrowserInternal>();
2529

2630
private TaskCompletionSource<OutOfProcessHost> _processInitialized = new TaskCompletionSource<OutOfProcessHost>(TaskCreationOptions.RunContinuationsAsynchronously);
2731

@@ -30,15 +34,30 @@ private OutOfProcessHost(string path)
3034
_outofProcessFilePath = path;
3135
}
3236

33-
public bool CreateBrowser(IChromiumWebBrowser browser, IntPtr handle, string url, out int id)
37+
public string CefSharpVerson
38+
{
39+
get { return _cefSharpVersion; }
40+
}
41+
42+
public string CefVersion
43+
{
44+
get { return _cefVersion; }
45+
}
46+
47+
public string ChromiumVersion
48+
{
49+
get { return _chromiumVersion; }
50+
}
51+
52+
public bool CreateBrowser(IChromiumWebBrowserInternal browser, IntPtr handle, string url, out int id)
3453
{
3554
id = _browserIdentifier++;
3655
_ = _jsonRpc.NotifyAsync("CreateBrowser", handle.ToInt32(), url, id);
3756

3857
return _browsers.TryAdd(id, browser);
3958
}
4059

41-
internal Task SendDevToolsMessage(int browserId, string message)
60+
internal Task SendDevToolsMessageAsync(int browserId, string message)
4261
{
4362
return _jsonRpc.NotifyAsync("SendDevToolsMessage", browserId, message);
4463
}
@@ -75,9 +94,12 @@ private void Init()
7594
//var attached = User32.AttachThreadInput(_remoteThreadId, _uiThreadId, true);
7695
});
7796

78-
_jsonRpc.AddLocalRpcMethod("OnContextInitialized", (Action<int>) delegate (int threadId)
97+
_jsonRpc.AddLocalRpcMethod("OnContextInitialized", (Action<int, string, string, string>) delegate (int threadId, string cefSharpVersion, string cefVersion, string chromiumVersion)
7998
{
8099
_remoteuiThreadId = threadId;
100+
_cefSharpVersion = cefSharpVersion;
101+
_cefVersion = cefVersion;
102+
_chromiumVersion = chromiumVersion;
81103

82104
_processInitialized.TrySetResult(this);
83105

@@ -118,7 +140,7 @@ public void CloseBrowser(int id)
118140

119141
public void Dispose()
120142
{
121-
_jsonRpc?.NotifyAsync("CloseHost");
143+
_ = _jsonRpc?.NotifyAsync("CloseHost");
122144
_jsonRpc?.Dispose();
123145
_jsonRpc = null;
124146
}

0 commit comments

Comments
 (0)