Skip to content

Commit f7ae8d6

Browse files
committed
Add more functionality
1 parent c1e6422 commit f7ae8d6

15 files changed

Lines changed: 458 additions & 78 deletions

CefSharp.OutOfProcess.BrowserProcess/BrowserProcessHandler.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ protected override void OnContextInitialized()
5959

6060
_ = CefThread.ExecuteOnUiThread(() =>
6161
{
62-
6362
var browser = new OutOfProcessChromiumWebBrowser(_jsonRpc, id, url);
6463

6564
var windowInfo = new WindowInfo();

CefSharp.OutOfProcess.BrowserProcess/CefSharp.OutOfProcess.BrowserProcess.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
<ItemGroup>
1616
<PackageReference Include="PInvoke.Kernel32" Version="0.7.104" />
17+
<PackageReference Include="PInvoke.User32" Version="0.7.104" />
1718
<PackageReference Include="StreamJsonRpc" Version="2.11.35" />
1819
</ItemGroup>
1920

CefSharp.OutOfProcess.BrowserProcess/OutOfProcessChromiumWebBrowser.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ void IWebBrowserInternal.OnConsoleMessage(ConsoleMessageEventArgs args)
304304
void IWebBrowserInternal.OnStatusMessage(StatusMessageEventArgs args)
305305
{
306306
StatusMessage?.Invoke(this, args);
307+
308+
_ = _jsonRpc.NotifyAsync("StatusMessage", _id, args.Value);
307309
}
308310

309311
/// <summary>
@@ -873,6 +875,8 @@ void IWebBrowserInternal.SetAddress(AddressChangedEventArgs args)
873875
Address = args.Address;
874876

875877
AddressChanged?.Invoke(this, args);
878+
879+
_ = _jsonRpc.NotifyAsync("AddressChanged", _id, args.Address);
876880
}
877881

878882
/// <summary>
@@ -884,6 +888,8 @@ partial void SetLoadingStateChange(LoadingStateChangedEventArgs args)
884888
CanGoBack = args.CanGoBack;
885889
CanGoForward = args.CanGoForward;
886890
IsLoading = args.IsLoading;
891+
892+
_ = _jsonRpc.NotifyAsync("LoadingStateChange", _id, args.CanGoBack, args.CanGoForward, args.IsLoading);
887893
}
888894

889895
/// <summary>
@@ -893,6 +899,8 @@ partial void SetLoadingStateChange(LoadingStateChangedEventArgs args)
893899
void IWebBrowserInternal.SetTitle(TitleChangedEventArgs args)
894900
{
895901
TitleChanged?.Invoke(this, args);
902+
903+
_ = _jsonRpc.NotifyAsync("TitleChanged", _id, args.Title);
896904
}
897905

898906
/// <summary>

CefSharp.OutOfProcess.Core/CefSharp.OutOfProcess.Core.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@
1313
<ProjectReference Include="..\CefSharp.Puppeteer\lib\PuppeteerSharp\CefSharp.DevTools.OutOfProcess.csproj" />
1414
</ItemGroup>
1515

16+
<ItemGroup>
17+
<Folder Include="EventArgs\" />
18+
</ItemGroup>
19+
1620
</Project>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright © 2014 The CefSharp Authors. All rights reserved.
2+
//
3+
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4+
5+
using System;
6+
7+
namespace CefSharp.OutOfProcess
8+
{
9+
/// <summary>
10+
/// Event arguments for the AddressChanged event handler.
11+
/// </summary>
12+
public class AddressChangedEventArgs : EventArgs
13+
{
14+
/// <summary>
15+
/// The new address
16+
/// </summary>
17+
public string Address { get; private set; }
18+
19+
/// <summary>
20+
/// Creates a new AddressChangedEventArgs event argument.
21+
/// </summary>
22+
/// <param name="address">the address</param>
23+
public AddressChangedEventArgs(string address)
24+
{
25+
Address = address;
26+
}
27+
}
28+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright © 2014 The CefSharp Authors. All rights reserved.
2+
//
3+
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4+
5+
using System;
6+
7+
namespace CefSharp.OutOfProcess
8+
{
9+
/// <summary>
10+
/// Event arguments to the LoadingStateChanged event handler set up in IWebBrowser.
11+
/// </summary>
12+
public class LoadingStateChangedEventArgs : EventArgs
13+
{
14+
/// <summary>
15+
/// Returns true if the browser can navigate forwards.
16+
/// </summary>
17+
public bool CanGoForward { get; private set; }
18+
/// <summary>
19+
/// Returns true if the browser can navigate backwards.
20+
/// </summary>
21+
public bool CanGoBack { get; private set; }
22+
/// <summary>
23+
/// Returns true if the browser is loading.
24+
/// </summary>
25+
public bool IsLoading { get; private set; }
26+
27+
/// <summary>
28+
/// LoadingStateChangedEventArgs
29+
/// </summary>
30+
/// <param name="browser">browser</param>
31+
/// <param name="canGoBack">can go back</param>
32+
/// <param name="canGoForward">can go forward</param>
33+
/// <param name="isLoading">is loading</param>
34+
public LoadingStateChangedEventArgs(bool canGoBack, bool canGoForward, bool isLoading)
35+
{
36+
CanGoBack = canGoBack;
37+
CanGoForward = canGoForward;
38+
IsLoading = isLoading;
39+
}
40+
}
41+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright © 2014 The CefSharp Authors. All rights reserved.
2+
//
3+
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4+
5+
using System;
6+
7+
namespace CefSharp.OutOfProcess
8+
{
9+
/// <summary>
10+
/// Event arguments to the StatusMessage event handler.
11+
/// </summary>
12+
public class StatusMessageEventArgs : EventArgs
13+
{
14+
/// <summary>
15+
/// StatusMessageEventArgs
16+
/// </summary>
17+
/// <param name="value">status message value</param>
18+
public StatusMessageEventArgs(string value)
19+
{
20+
Value = value;
21+
}
22+
23+
/// <summary>
24+
/// The value of the status message.
25+
/// </summary>
26+
public string Value { get; private set; }
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright © 2014 The CefSharp Authors. All rights reserved.
2+
//
3+
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4+
5+
using System;
6+
7+
namespace CefSharp.OutOfProcess
8+
{
9+
/// <summary>
10+
/// Event arguments to the TitleChanged event handler.
11+
/// </summary>
12+
public class TitleChangedEventArgs : EventArgs
13+
{
14+
/// <summary>
15+
/// The new title
16+
/// </summary>
17+
public string Title { get; private set; }
18+
19+
/// <summary>
20+
/// Creates a new TitleChanged event arg
21+
/// </summary>
22+
/// <param name="title">the new title</param>
23+
public TitleChangedEventArgs(string title)
24+
{
25+
Title = title;
26+
}
27+
}
28+
}

CefSharp.OutOfProcess.Core/IChromiumWebBrowser.cs

Lines changed: 119 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using CefSharp.Puppeteer;
2+
using System;
23
using System.Threading.Tasks;
34

45
namespace CefSharp.OutOfProcess
@@ -8,6 +9,119 @@ namespace CefSharp.OutOfProcess
89
/// </summary>
910
public interface IChromiumWebBrowser
1011
{
12+
/// <summary>
13+
/// Occurs when the browser address changed.
14+
/// </summary>
15+
event EventHandler<AddressChangedEventArgs> AddressChanged;
16+
/// <summary>
17+
/// Occurs when document title changes.
18+
/// </summary>
19+
event EventHandler<TitleChangedEventArgs> TitleChanged;
20+
21+
/// <summary>
22+
/// Event handler for changes to the status message.
23+
/// </summary>
24+
event EventHandler<StatusMessageEventArgs> StatusMessage;
25+
26+
/// <summary>
27+
/// Event handler that will get called when the Loading state has changed.
28+
/// This event will be fired twice. Once when loading is initiated either programmatically or
29+
/// by user action, and once when loading is terminated due to completion, cancellation of failure.
30+
/// </summary>
31+
event EventHandler<LoadingStateChangedEventArgs> LoadingStateChanged;
32+
33+
/// <summary>
34+
/// Raised when the JavaScript <c>DOMContentLoaded</c> <see href="https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded"/> event is dispatched.
35+
/// </summary>
36+
event EventHandler DOMContentLoaded;
37+
38+
/// <summary>
39+
/// Raised when the browser crashes
40+
/// </summary>
41+
event EventHandler<ErrorEventArgs> BrowserProcessCrashed;
42+
43+
/// <summary>
44+
/// Raised when a frame is attached.
45+
/// </summary>
46+
event EventHandler<FrameEventArgs> FrameAttached;
47+
48+
/// <summary>
49+
/// Raised when a frame is detached.
50+
/// </summary>
51+
event EventHandler<FrameEventArgs> FrameDetached;
52+
53+
/// <summary>
54+
/// Raised when a frame is navigated to a new url.
55+
/// </summary>
56+
event EventHandler<FrameEventArgs> FrameNavigated;
57+
58+
/// <summary>
59+
/// Raised when JavaScript within the page calls one of console API methods, e.g. <c>console.log</c> or <c>console.dir</c>. Also emitted if the page throws an error or a warning.
60+
/// The arguments passed into <c>console.log</c> appear as arguments on the event handler.
61+
/// </summary>
62+
event EventHandler<ConsoleEventArgs> ConsoleMessage;
63+
64+
/// <summary>
65+
/// Raised when the JavaScript <c>load</c> <see href="https://developer.mozilla.org/en-US/docs/Web/Events/load"/> event is dispatched.
66+
/// </summary>
67+
event EventHandler JavaScriptLoad;
68+
69+
/// <summary>
70+
/// Raised when an uncaught exception happens within the browser.
71+
/// </summary>
72+
event EventHandler<PageErrorEventArgs> RuntimeExceptionThrown;
73+
74+
/// <summary>
75+
/// Raised when the page opens a new tab or window.
76+
/// </summary>
77+
event EventHandler<PopupEventArgs> Popup;
78+
79+
/// <summary>
80+
/// Raised when a browser issues a request. The <see cref="NetworkRequest"/> object is read-only.
81+
/// In order to intercept and mutate requests, see <see cref="IDevToolsContext.SetRequestInterceptionAsync(bool)"/>
82+
/// </summary>
83+
event EventHandler<RequestEventArgs> NetworkRequest;
84+
85+
/// <summary>
86+
/// Raised when a request fails, for example by timing out.
87+
/// </summary>
88+
event EventHandler<RequestEventArgs> NetworkRequestFailed;
89+
90+
/// <summary>
91+
/// Raised when a request finishes successfully.
92+
/// </summary>
93+
event EventHandler<RequestEventArgs> NetworkRequestFinished;
94+
95+
/// <summary>
96+
/// Raised when a request ended up loading from cache.
97+
/// </summary>
98+
event EventHandler<RequestEventArgs> NetworkRequestServedFromCache;
99+
100+
/// <summary>
101+
/// Raised when a <see cref="NetworkResponse"/> is received.
102+
/// </summary>
103+
/// <example>
104+
/// An example of handling <see cref="NetworkResponse"/> event:
105+
/// <code>
106+
/// <![CDATA[
107+
/// var tcs = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
108+
/// browser.Response += async(sender, e) =>
109+
/// {
110+
/// if (e.Response.Url.Contains("script.js"))
111+
/// {
112+
/// tcs.TrySetResult(await e.Response.TextAsync());
113+
/// }
114+
/// };
115+
///
116+
/// await Task.WhenAll(
117+
/// browser.LoadUrlAsync(TestConstants.ServerUrl + "/grid.html"),
118+
/// tcs.Task);
119+
/// Console.WriteLine(await tcs.Task);
120+
/// ]]>
121+
/// </code>
122+
/// </example>
123+
event EventHandler<ResponseCreatedEventArgs> NetworkResponse;
124+
11125
/// <summary>
12126
/// Loads the specified <paramref name="url"/> in the Main Frame.
13127
/// </summary>
@@ -41,23 +155,23 @@ public interface IChromiumWebBrowser
41155
string Address { get; }
42156

43157
/// <summary>
44-
/// Gets all frames attached to the page.
158+
/// Gets all frames attached to the browser.
45159
/// </summary>
46-
/// <value>An array of all frames attached to the page.</value>
160+
/// <value>An array of all frames attached to the browser.</value>
47161
Frame[] Frames { get; }
48162

49163
/// <summary>
50-
/// Gets page's main frame
164+
/// Gets browser's main frame
51165
/// </summary>
52166
/// <remarks>
53-
/// Page is guaranteed to have a main frame which persists during navigations.
167+
/// Browser is guaranteed to have a main frame which persists during navigations.
54168
/// </remarks>
55169
Frame MainFrame { get; }
56170

57171
/// <summary>
58172
/// Navigates to an url
59173
/// </summary>
60-
/// <param name="url">URL to navigate page to. The url should include scheme, e.g. https://.</param>
174+
/// <param name="url">URL to navigate to. The url should include scheme, e.g. https://.</param>
61175
/// <param name="timeout">Maximum navigation time in milliseconds, defaults to 30 seconds, pass <c>0</c> to disable timeout. </param>
62176
/// <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>
63177
/// <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>

CefSharp.OutOfProcess.Core/Internal/IChromiumWebBrowserInternal.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,11 @@ public interface IChromiumWebBrowserInternal : IChromiumWebBrowser
2525
/// DevTools is ready in the browser process to create the DevToolsContext
2626
/// </summary>
2727
void OnDevToolsReady();
28+
29+
void SetStatusMessage(string msg);
30+
void SetTitle(string title);
31+
32+
void SetAddress(string address);
33+
void SetLoadingStateChange(bool canGoBack, bool canGoForward, bool isLoading);
2834
}
2935
}

0 commit comments

Comments
 (0)