1717using System . Windows . Interop ;
1818using System . Windows . Threading ;
1919using Window = System . Windows . Window ;
20+ using System . Collections . Generic ;
2021
2122namespace CefSharp . OutOfProcess . Wpf . HwndHost
2223{
@@ -281,7 +282,7 @@ public bool IsDisposed
281282 /// <param name="initialAddress">address to load initially</param>
282283 public ChromiumWebBrowser ( OutOfProcessHost host , string initialAddress = null )
283284 {
284- if ( host == null )
285+ if ( host == null )
285286 {
286287 throw new ArgumentNullException ( nameof ( host ) ) ;
287288 }
@@ -319,6 +320,18 @@ public ChromiumWebBrowser(OutOfProcessHost host, string initialAddress = null)
319320 UseLayoutRounding = true ;
320321 }
321322
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+
322335 /// <inheritdoc/>
323336 int IChromiumWebBrowserInternal . Id
324337 {
@@ -418,6 +431,15 @@ public Task<Response> GoForwardAsync(NavigationOptions options = null)
418431 return _devToolsContext . GoForwardAsync ( options ) ;
419432 }
420433
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+
421443 private void PresentationSourceChangedHandler ( object sender , SourceChangedEventArgs args )
422444 {
423445 if ( args . NewSource != null )
@@ -492,7 +514,7 @@ protected override HandleRef BuildWindowCore(HandleRef hwndParent)
492514 0 ) ;
493515 }
494516
495- _host . CreateBrowser ( this , _hwndHost , url : _initialAddress , out _id ) ;
517+ _host . CreateBrowser ( this , _hwndHost , url : _initialAddress , out _id , requestContextPreferences ) ;
496518
497519 _devToolsContextConnectionTransport = new OutOfProcessConnectionTransport ( _id , _host ) ;
498520
@@ -511,7 +533,7 @@ protected override void DestroyWindowCore(HandleRef hwnd)
511533 ///<inheritdoc/>
512534 protected override bool TabIntoCore ( TraversalRequest request )
513535 {
514- if ( InternalIsBrowserInitialized ( ) )
536+ if ( InternalIsBrowserInitialized ( ) )
515537 {
516538 _host . SetFocus ( _id , true ) ;
517539
@@ -524,7 +546,7 @@ protected override bool TabIntoCore(TraversalRequest request)
524546 ///<inheritdoc/>
525547 protected override void OnGotKeyboardFocus ( KeyboardFocusChangedEventArgs e )
526548 {
527- if ( ! e . Handled )
549+ if ( ! e . Handled )
528550 {
529551 if ( InternalIsBrowserInitialized ( ) )
530552 {
@@ -567,18 +589,18 @@ protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lP
567589 {
568590 case WM_SETFOCUS :
569591 case WM_MOUSEACTIVATE :
570- {
571- if ( InternalIsBrowserInitialized ( ) )
572592 {
573-
574- _host . SetFocus ( _id , true ) ;
593+ if ( InternalIsBrowserInitialized ( ) )
594+ {
595+
596+ _host . SetFocus ( _id , true ) ;
575597
576- handled = true ;
598+ handled = true ;
577599
578- return IntPtr . Zero ;
600+ return IntPtr . Zero ;
601+ }
602+ break ;
579603 }
580- break ;
581- }
582604 }
583605 return base . WndProc ( hwnd , msg , wParam , lParam , ref handled ) ;
584606 }
@@ -727,8 +749,8 @@ void IChromiumWebBrowserInternal.OnAfterBrowserCreated(IntPtr hwnd)
727749 {
728750 return ;
729751 }
730-
731- _browserHwnd = hwnd ;
752+
753+ _browserHwnd = hwnd ;
732754
733755 Interlocked . Exchange ( ref _browserInitialized , 1 ) ;
734756
@@ -1070,6 +1092,11 @@ public IChromiumWebBrowser WebBrowser
10701092 public static readonly DependencyProperty WebBrowserProperty =
10711093 DependencyProperty . Register ( nameof ( WebBrowser ) , typeof ( IChromiumWebBrowser ) , typeof ( ChromiumWebBrowser ) , new UIPropertyMetadata ( defaultValue : null ) ) ;
10721094
1095+ /// <summary>
1096+ /// The requestContextPreferences used for the RequestContext.
1097+ /// </summary>
1098+ private readonly IDictionary < string , object > requestContextPreferences ;
1099+
10731100 /// <summary>
10741101 /// Runs the specific Action on the Dispatcher in an async fashion
10751102 /// </summary>
@@ -1215,22 +1242,22 @@ private void OnWindowStateChanged(object sender, EventArgs e)
12151242 {
12161243 case WindowState . Normal :
12171244 case WindowState . Maximized :
1218- {
1219- if ( _previousWindowState == WindowState . Minimized && InternalIsBrowserInitialized ( ) )
12201245 {
1221- ResizeBrowser ( ( int ) ActualWidth , ( int ) ActualHeight ) ;
1246+ if ( _previousWindowState == WindowState . Minimized && InternalIsBrowserInitialized ( ) )
1247+ {
1248+ ResizeBrowser ( ( int ) ActualWidth , ( int ) ActualHeight ) ;
1249+ }
1250+ break ;
12221251 }
1223- break ;
1224- }
12251252 case WindowState . Minimized :
1226- {
1227- if ( InternalIsBrowserInitialized ( ) )
12281253 {
1229- //Set the browser size to 0,0 to reduce CPU usage
1230- ResizeBrowser ( 0 , 0 ) ;
1254+ if ( InternalIsBrowserInitialized ( ) )
1255+ {
1256+ //Set the browser size to 0,0 to reduce CPU usage
1257+ ResizeBrowser ( 0 , 0 ) ;
1258+ }
1259+ break ;
12311260 }
1232- break ;
1233- }
12341261 }
12351262
12361263 _previousWindowState = window . WindowState ;
0 commit comments