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,12 @@ public ChromiumWebBrowser(OutOfProcessHost host, string initialAddress = null)
319320 UseLayoutRounding = true ;
320321 }
321322
323+ public ChromiumWebBrowser ( OutOfProcessHost host , string initialAddress = null , IDictionary < string , object > requestContextPreferences = null )
324+ : this ( host , initialAddress )
325+ {
326+ this . requestContextPreferences = requestContextPreferences ;
327+ }
328+
322329 /// <inheritdoc/>
323330 int IChromiumWebBrowserInternal . Id
324331 {
@@ -418,6 +425,15 @@ public Task<Response> GoForwardAsync(NavigationOptions options = null)
418425 return _devToolsContext . GoForwardAsync ( options ) ;
419426 }
420427
428+ /// <summary>
429+ /// Update Global Request Context Preferences for all browsers.
430+ /// </summary>
431+ /// <param name="preferences">The preferences.</param>
432+ public void UpdateRequestContextPreferences ( IDictionary < string , object > preferences )
433+ {
434+ _host . UpdateRequestContextPreferences ( this . _id , preferences ) ;
435+ }
436+
421437 private void PresentationSourceChangedHandler ( object sender , SourceChangedEventArgs args )
422438 {
423439 if ( args . NewSource != null )
@@ -492,7 +508,7 @@ protected override HandleRef BuildWindowCore(HandleRef hwndParent)
492508 0 ) ;
493509 }
494510
495- _host . CreateBrowser ( this , _hwndHost , url : _initialAddress , out _id ) ;
511+ _host . CreateBrowser ( this , _hwndHost , url : _initialAddress , out _id , requestContextPreferences ) ;
496512
497513 _devToolsContextConnectionTransport = new OutOfProcessConnectionTransport ( _id , _host ) ;
498514
@@ -511,7 +527,7 @@ protected override void DestroyWindowCore(HandleRef hwnd)
511527 ///<inheritdoc/>
512528 protected override bool TabIntoCore ( TraversalRequest request )
513529 {
514- if ( InternalIsBrowserInitialized ( ) )
530+ if ( InternalIsBrowserInitialized ( ) )
515531 {
516532 _host . SetFocus ( _id , true ) ;
517533
@@ -524,7 +540,7 @@ protected override bool TabIntoCore(TraversalRequest request)
524540 ///<inheritdoc/>
525541 protected override void OnGotKeyboardFocus ( KeyboardFocusChangedEventArgs e )
526542 {
527- if ( ! e . Handled )
543+ if ( ! e . Handled )
528544 {
529545 if ( InternalIsBrowserInitialized ( ) )
530546 {
@@ -567,18 +583,18 @@ protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lP
567583 {
568584 case WM_SETFOCUS :
569585 case WM_MOUSEACTIVATE :
570- {
571- if ( InternalIsBrowserInitialized ( ) )
572586 {
573-
574- _host . SetFocus ( _id , true ) ;
587+ if ( InternalIsBrowserInitialized ( ) )
588+ {
589+
590+ _host . SetFocus ( _id , true ) ;
575591
576- handled = true ;
592+ handled = true ;
577593
578- return IntPtr . Zero ;
594+ return IntPtr . Zero ;
595+ }
596+ break ;
579597 }
580- break ;
581- }
582598 }
583599 return base . WndProc ( hwnd , msg , wParam , lParam , ref handled ) ;
584600 }
@@ -727,8 +743,8 @@ void IChromiumWebBrowserInternal.OnAfterBrowserCreated(IntPtr hwnd)
727743 {
728744 return ;
729745 }
730-
731- _browserHwnd = hwnd ;
746+
747+ _browserHwnd = hwnd ;
732748
733749 Interlocked . Exchange ( ref _browserInitialized , 1 ) ;
734750
@@ -1070,6 +1086,11 @@ public IChromiumWebBrowser WebBrowser
10701086 public static readonly DependencyProperty WebBrowserProperty =
10711087 DependencyProperty . Register ( nameof ( WebBrowser ) , typeof ( IChromiumWebBrowser ) , typeof ( ChromiumWebBrowser ) , new UIPropertyMetadata ( defaultValue : null ) ) ;
10721088
1089+ /// <summary>
1090+ /// The requestContextPreferences used for the RequestContext.
1091+ /// </summary>
1092+ private readonly IDictionary < string , object > requestContextPreferences ;
1093+
10731094 /// <summary>
10741095 /// Runs the specific Action on the Dispatcher in an async fashion
10751096 /// </summary>
@@ -1215,22 +1236,22 @@ private void OnWindowStateChanged(object sender, EventArgs e)
12151236 {
12161237 case WindowState . Normal :
12171238 case WindowState . Maximized :
1218- {
1219- if ( _previousWindowState == WindowState . Minimized && InternalIsBrowserInitialized ( ) )
12201239 {
1221- ResizeBrowser ( ( int ) ActualWidth , ( int ) ActualHeight ) ;
1240+ if ( _previousWindowState == WindowState . Minimized && InternalIsBrowserInitialized ( ) )
1241+ {
1242+ ResizeBrowser ( ( int ) ActualWidth , ( int ) ActualHeight ) ;
1243+ }
1244+ break ;
12221245 }
1223- break ;
1224- }
12251246 case WindowState . Minimized :
1226- {
1227- if ( InternalIsBrowserInitialized ( ) )
12281247 {
1229- //Set the browser size to 0,0 to reduce CPU usage
1230- ResizeBrowser ( 0 , 0 ) ;
1248+ if ( InternalIsBrowserInitialized ( ) )
1249+ {
1250+ //Set the browser size to 0,0 to reduce CPU usage
1251+ ResizeBrowser ( 0 , 0 ) ;
1252+ }
1253+ break ;
12311254 }
1232- break ;
1233- }
12341255 }
12351256
12361257 _previousWindowState = window . WindowState ;
0 commit comments