@@ -37,6 +37,13 @@ namespace CefSharp.WinForms.Handler
37
37
/// <param name="browser">browser</param>
38
38
public delegate void OnPopupDestroyedDelegate ( ChromiumHostControl control , IBrowser browser ) ;
39
39
40
+ /// <summary>
41
+ /// Called to create a new instance of <see cref="ChromiumHostControl"/>. Allows creation of a derived
42
+ /// implementation of <see cref="ChromiumHostControl"/>.
43
+ /// </summary>
44
+ /// <returns>A custom instance of <see cref="ChromiumHostControl"/>.</returns>
45
+ public delegate ChromiumHostControl CreatePopupChromiumHostControl ( ) ;
46
+
40
47
/// <summary>
41
48
/// A WinForms Specific <see cref="ILifeSpanHandler"/> implementation that simplifies
42
49
/// the process of hosting a Popup as a Control/Tab.
@@ -49,7 +56,13 @@ public class LifeSpanHandler : CefSharp.Handler.LifeSpanHandler
49
56
private OnPopupDestroyedDelegate onPopupDestroyed ;
50
57
private OnPopupBrowserCreatedDelegate onPopupBrowserCreated ;
51
58
private OnPopupCreatedDelegate onPopupCreated ;
52
-
59
+ private CreatePopupChromiumHostControl chromiumHostControlCreatedDelegate ;
60
+
61
+ public LifeSpanHandler ( CreatePopupChromiumHostControl chromiumHostControlCreatedDelegate )
62
+ {
63
+ this . chromiumHostControlCreatedDelegate = chromiumHostControlCreatedDelegate ;
64
+ }
65
+
53
66
/// <inheritdoc/>
54
67
protected override bool DoClose ( IWebBrowser chromiumWebBrowser , IBrowser browser )
55
68
{
@@ -168,10 +181,15 @@ protected override bool OnBeforePopup(IWebBrowser chromiumWebBrowser, IBrowser b
168
181
//We need to execute sync here so IWindowInfo.SetAsChild is called before we return false;
169
182
webBrowser . InvokeSyncOnUiThreadIfRequired ( new Action ( ( ) =>
170
183
{
171
- var control = new ChromiumHostControl
184
+ ChromiumHostControl control = chromiumHostControlCreatedDelegate ? . Invoke ( ) ;
185
+
186
+ if ( control == null )
172
187
{
173
- Dock = DockStyle . Fill
174
- } ;
188
+ control = new ChromiumHostControl
189
+ {
190
+ Dock = DockStyle . Fill
191
+ } ;
192
+ }
175
193
control . CreateControl ( ) ;
176
194
177
195
onPopupCreated ? . Invoke ( control , targetUrl ) ;
@@ -238,10 +256,14 @@ public LifeSpanHandler OnPopupDestroyed(OnPopupDestroyedDelegate onPopupDestroye
238
256
/// of implementing directly you will need to inherit from <see cref="CefSharp.WinForms.Handler.LoadHandler"/>.
239
257
/// As it provides base functionality required to make <see cref="ChromiumHostControl"/> events work correctly.
240
258
/// </summary>
241
- /// <returns>LifeSpanHandlerBuilder</returns>
242
- public static LifeSpanHandlerBuilder Create ( )
259
+ /// <returns>
260
+ /// A <see cref="LifeSpanHandlerBuilder"/> which can be used to fluently create an <see cref="ILifeSpanHandler"/>.
261
+ /// Call <see cref="LifeSpanHandlerBuilder.Build"/> to create the actual instance after you have call
262
+ /// <see cref="LifeSpanHandlerBuilder.OnPopupCreated(OnPopupCreatedDelegate)"/> etc.
263
+ /// </returns>
264
+ public static LifeSpanHandlerBuilder Create ( CreatePopupChromiumHostControl chromiumHostControlCreatedDelegate = null )
243
265
{
244
- return new LifeSpanHandlerBuilder ( ) ;
266
+ return new LifeSpanHandlerBuilder ( chromiumHostControlCreatedDelegate ) ;
245
267
}
246
268
}
247
269
}
0 commit comments