From dfb2cd55f140027a4192ee49559ca728bd27ef4d Mon Sep 17 00:00:00 2001 From: amaitland Date: Fri, 5 Apr 2019 11:56:45 +1000 Subject: [PATCH] WPF - Add ChromiumWebBrowser constructor overload with initialAddress param Allows for address to be passed directly to CefBrowserHost::CreateBrowser which is required for CefExtension support Resolves #2645 --- CefSharp.Wpf/ChromiumWebBrowser.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index 7e429a9de..5a4f4f9a4 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -63,6 +63,10 @@ namespace CefSharp.Wpf /// private bool ignoreUriChange; /// + /// Initial address + /// + private readonly string initialAddress; + /// /// Has the underlying Cef Browser been created (slightly different to initliazed in that /// the browser is initialized in an async fashion) /// @@ -463,6 +467,13 @@ namespace CefSharp.Wpf } } + public ChromiumWebBrowser(string initialAddress) + { + this.initialAddress = initialAddress; + + NoInliningConstructor(); + } + /// /// Constructor logic has been moved into this method /// Required for designer support - this method cannot be inlined as the designer @@ -1097,8 +1108,8 @@ namespace CefSharp.Wpf { SetCurrentValue(IsBrowserInitializedProperty, true); - // If Address was previously set, only now can we actually do the load - if (!string.IsNullOrEmpty(Address)) + // Only call Load if initialAddress is null and Address is not empty + if (string.IsNullOrEmpty(initialAddress) && !string.IsNullOrEmpty(Address)) { Load(Address); } @@ -1789,7 +1800,7 @@ namespace CefSharp.Wpf var windowInfo = CreateOffscreenBrowserWindowInfo(source == null ? IntPtr.Zero : source.Handle); //Pass null in for Address and rely on Load being called in OnAfterBrowserCreated //Workaround for issue https://github.com/cefsharp/CefSharp/issues/2300 - managedCefBrowserAdapter.CreateBrowser(windowInfo, browserSettings as BrowserSettings, requestContext as RequestContext, address: null); + managedCefBrowserAdapter.CreateBrowser(windowInfo, browserSettings as BrowserSettings, requestContext as RequestContext, address: initialAddress); browserSettings = null; }