Skip to content

Commit 0ecbeb9

Browse files
committed
feat: add requestcontext to winforms web browser
1 parent 05750f8 commit 0ecbeb9

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

CefSharp.OutOfProcess.WinForms/ChromiumWebBrowser.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using CefSharp.OutOfProcess.Internal;
66
using CefSharp.Dom;
77
using PInvoke;
8+
using System.Collections.Generic;
89

910
namespace CefSharp.OutOfProcess.WinForms
1011
{
@@ -17,6 +18,7 @@ public class ChromiumWebBrowser : Control, IChromiumWebBrowserInternal
1718
private IDevToolsContext _devToolsContext;
1819
private OutOfProcessConnectionTransport _devToolsContextConnectionTransport;
1920
private bool _devToolsReady;
21+
private IDictionary<string, object> requestContextPreferences;
2022

2123
/// <inheritdoc/>
2224
public event EventHandler DOMContentLoaded;
@@ -75,6 +77,18 @@ public ChromiumWebBrowser(OutOfProcessHost host, string initialAddress)
7577
_initialAddress = initialAddress;
7678
}
7779

80+
/// <summary>
81+
/// Initializes a new instance of the <see cref="ChromiumWebBrowser"/> instance.
82+
/// </summary>
83+
/// <param name="host">Out of process host</param>
84+
/// <param name="initialAddress">address to load initially</param>
85+
/// <param name="requestContextPreferences">requestContextPreferences to set</param>
86+
public ChromiumWebBrowser(OutOfProcessHost host, string initialAddress = null, IDictionary<string, object> requestContextPreferences = null)
87+
: this(host, initialAddress)
88+
{
89+
this.requestContextPreferences = requestContextPreferences;
90+
}
91+
7892
/// <inheritdoc/>
7993
int IChromiumWebBrowserInternal.Id
8094
{
@@ -128,7 +142,7 @@ protected override void OnHandleCreated(EventArgs e)
128142

129143
var size = Size;
130144

131-
_host.CreateBrowser(this, Handle, url: _initialAddress, out _id);
145+
_host.CreateBrowser(this, Handle, url: _initialAddress, out _id, requestContextPreferences);
132146

133147
_devToolsContextConnectionTransport = new OutOfProcessConnectionTransport(_id, _host);
134148

@@ -305,6 +319,15 @@ public Task<Response> GoBackAsync(NavigationOptions options = null)
305319
return _devToolsContext.GoBackAsync(options);
306320
}
307321

322+
/// <summary>
323+
/// Update Request Context Preferences for this browser.
324+
/// </summary>
325+
/// <param name="preferences">The preferences.</param>
326+
public void UpdateRequestContextPreferences(IDictionary<string, object> preferences)
327+
{
328+
_host.UpdateRequestContextPreferences(this._id, preferences);
329+
}
330+
308331
/// <inheritdoc/>
309332
public Task<Response> GoForwardAsync(NavigationOptions options = null)
310333
{

CefSharp.OutOfProcess.Wpf.HwndHost/ChromiumWebBrowser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ public Task<Response> GoForwardAsync(NavigationOptions options = null)
432432
}
433433

434434
/// <summary>
435-
/// Update Global Request Context Preferences for all browsers.
435+
/// Update Request Context Preferences for this browser.
436436
/// </summary>
437437
/// <param name="preferences">The preferences.</param>
438438
public void UpdateRequestContextPreferences(IDictionary<string, object> preferences)
@@ -749,7 +749,7 @@ void IChromiumWebBrowserInternal.OnAfterBrowserCreated(IntPtr hwnd)
749749
{
750750
return;
751751
}
752-
752+
753753
_browserHwnd = hwnd;
754754

755755
Interlocked.Exchange(ref _browserInitialized, 1);

0 commit comments

Comments
 (0)