WinForms - Improve handling of Load method when called after CreateBrowser and before OnAfterBrowserCreated

Call MainFrame.Load after the browser has been created if the Address property has been set after CreateBrowser and before OnAfterBrowserCreated
This commit is contained in:
amaitland
2019-12-03 07:08:08 +10:00
parent ca2837f928
commit daeb4fb13f
+15
View File
@@ -52,6 +52,12 @@ namespace CefSharp.WinForms
/// </summary>
private bool browserCreated;
/// <summary>
/// A flag indicating if the <see cref="Address"/> was used when calling CreateBrowser
/// If false and <see cref="Address"/> contains a non empty string Load will be called
/// on the main frame
/// </summary>
private bool initialAddressLoaded;
/// <summary>
/// Browser initialization settings
/// </summary>
private IBrowserSettings browserSettings;
@@ -645,6 +651,8 @@ namespace CefSharp.WinForms
{
var windowInfo = CreateBrowserWindowInfo(Handle);
initialAddressLoaded = !string.IsNullOrEmpty(Address);
managedCefBrowserAdapter.CreateBrowser(windowInfo, browserSettings as BrowserSettings, requestContext as RequestContext, Address);
browserSettings = null;
@@ -681,6 +689,13 @@ namespace CefSharp.WinForms
ResizeBrowser();
//If Load was called after the call to CreateBrowser we'll call Load
//on the MainFrame
if (!initialAddressLoaded && !string.IsNullOrEmpty(Address))
{
browser.MainFrame.LoadUrl(Address);
}
IsBrowserInitializedChanged?.Invoke(this, EventArgs.Empty);
}