|
17 | 17 | using System.Windows.Interop; |
18 | 18 | using System.Windows.Threading; |
19 | 19 | using Window = System.Windows.Window; |
| 20 | +using System.Collections.Generic; |
20 | 21 |
|
21 | 22 | namespace CefSharp.OutOfProcess.Wpf.HwndHost |
22 | 23 | { |
@@ -319,6 +320,18 @@ public ChromiumWebBrowser(OutOfProcessHost host, string initialAddress = null) |
319 | 320 | UseLayoutRounding = true; |
320 | 321 | } |
321 | 322 |
|
| 323 | + /// <summary> |
| 324 | + /// Initializes a new instance of the <see cref="ChromiumWebBrowser"/> instance. |
| 325 | + /// </summary> |
| 326 | + /// <param name="host">Out of process host</param> |
| 327 | + /// <param name="initialAddress">address to load initially</param> |
| 328 | + /// <param name="requestContextPreferences">requestContextPreferences to set</param> |
| 329 | + public ChromiumWebBrowser(OutOfProcessHost host, string initialAddress = null, IDictionary<string, object> requestContextPreferences = null) |
| 330 | + : this(host, initialAddress) |
| 331 | + { |
| 332 | + this.requestContextPreferences = requestContextPreferences; |
| 333 | + } |
| 334 | + |
322 | 335 | /// <inheritdoc/> |
323 | 336 | int IChromiumWebBrowserInternal.Id |
324 | 337 | { |
@@ -418,6 +431,15 @@ public Task<Response> GoForwardAsync(NavigationOptions options = null) |
418 | 431 | return _devToolsContext.GoForwardAsync(options); |
419 | 432 | } |
420 | 433 |
|
| 434 | + /// <summary> |
| 435 | + /// Update Global Request Context Preferences for all browsers. |
| 436 | + /// </summary> |
| 437 | + /// <param name="preferences">The preferences.</param> |
| 438 | + public void UpdateRequestContextPreferences(IDictionary<string, object> preferences) |
| 439 | + { |
| 440 | + _host.UpdateRequestContextPreferences(this._id, preferences); |
| 441 | + } |
| 442 | + |
421 | 443 | private void PresentationSourceChangedHandler(object sender, SourceChangedEventArgs args) |
422 | 444 | { |
423 | 445 | if (args.NewSource != null) |
@@ -492,7 +514,7 @@ protected override HandleRef BuildWindowCore(HandleRef hwndParent) |
492 | 514 | 0); |
493 | 515 | } |
494 | 516 |
|
495 | | - _host.CreateBrowser(this, _hwndHost, url: _initialAddress, out _id); |
| 517 | + _host.CreateBrowser(this, _hwndHost, url: _initialAddress, out _id, requestContextPreferences); |
496 | 518 |
|
497 | 519 | _devToolsContextConnectionTransport = new OutOfProcessConnectionTransport(_id, _host); |
498 | 520 |
|
@@ -1070,6 +1092,11 @@ public IChromiumWebBrowser WebBrowser |
1070 | 1092 | public static readonly DependencyProperty WebBrowserProperty = |
1071 | 1093 | DependencyProperty.Register(nameof(WebBrowser), typeof(IChromiumWebBrowser), typeof(ChromiumWebBrowser), new UIPropertyMetadata(defaultValue: null)); |
1072 | 1094 |
|
| 1095 | + /// <summary> |
| 1096 | + /// The requestContextPreferences used for the RequestContext. |
| 1097 | + /// </summary> |
| 1098 | + private readonly IDictionary<string, object> requestContextPreferences; |
| 1099 | + |
1073 | 1100 | /// <summary> |
1074 | 1101 | /// Runs the specific Action on the Dispatcher in an async fashion |
1075 | 1102 | /// </summary> |
|
0 commit comments