diff --git a/CefSharp.OffScreen.Example/Program.cs b/CefSharp.OffScreen.Example/Program.cs index ea0cef447..534bb6e95 100644 --- a/CefSharp.OffScreen.Example/Program.cs +++ b/CefSharp.OffScreen.Example/Program.cs @@ -93,7 +93,7 @@ namespace CefSharp.OffScreen.Example } }; } - await browser.LoadUrlAsync(); + await browser.WaitForInitialLoadAsync(); //Check preferences on the CEF UI Thread await Cef.UIThreadTaskFactory.StartNew(delegate diff --git a/CefSharp.Test/ChromiumWebBrowserOffScreenFixture.cs b/CefSharp.Test/ChromiumWebBrowserOffScreenFixture.cs index b92007d9e..40b47798c 100644 --- a/CefSharp.Test/ChromiumWebBrowserOffScreenFixture.cs +++ b/CefSharp.Test/ChromiumWebBrowserOffScreenFixture.cs @@ -24,7 +24,7 @@ namespace CefSharp.Test { Browser = new ChromiumWebBrowser(CefExample.HelloWorldUrl); - return Browser.LoadUrlAsync(); + return Browser.WaitForInitialLoadAsync(); } } } diff --git a/CefSharp/IWebBrowser.cs b/CefSharp/IWebBrowser.cs index c433abcd7..56169138b 100644 --- a/CefSharp/IWebBrowser.cs +++ b/CefSharp/IWebBrowser.cs @@ -104,12 +104,11 @@ namespace CefSharp /// Load the in the main frame of the browser /// /// url to load - /// SynchronizationContext to execute the continuation on, if null then the ThreadPool will be used. /// /// A that can be awaited to load the and return the HttpStatusCode and . /// A HttpStatusCode equal to 200 and is considered a success. /// - Task LoadUrlAsync(string url = null, SynchronizationContext ctx = null); + Task LoadUrlAsync(string url); /// /// Wait for the Browser to finish loading the initial web page. diff --git a/CefSharp/Internals/Partial/ChromiumWebBrowser.Partial.cs b/CefSharp/Internals/Partial/ChromiumWebBrowser.Partial.cs index 83b46bb61..6f0097be6 100644 --- a/CefSharp/Internals/Partial/ChromiumWebBrowser.Partial.cs +++ b/CefSharp/Internals/Partial/ChromiumWebBrowser.Partial.cs @@ -353,10 +353,10 @@ namespace CefSharp.WinForms } /// - public Task LoadUrlAsync(string url = null, SynchronizationContext ctx = null) + public Task LoadUrlAsync(string url) { //LoadUrlAsync is actually a static method so that CefSharp.Wpf.HwndHost can reuse the code - return CefSharp.WebBrowserExtensions.LoadUrlAsync(this, url, ctx); + return CefSharp.WebBrowserExtensions.LoadUrlAsync(this, url); } /// diff --git a/CefSharp/WebBrowserExtensions.cs b/CefSharp/WebBrowserExtensions.cs index 9aba8568a..12a4ac17a 100644 --- a/CefSharp/WebBrowserExtensions.cs +++ b/CefSharp/WebBrowserExtensions.cs @@ -247,17 +247,21 @@ namespace CefSharp } /// - /// See for details + /// See for details /// /// ChromiumWebBrowser instance (cannot be null) /// /// Load the in the main frame of the browser /// /// url to load - /// SynchronizationContext to execute the continuation on, if null then the ThreadPool will be used. - /// See for details - public static Task LoadUrlAsync(IWebBrowser chromiumWebBrowser, string url = null, SynchronizationContext ctx = null) + /// See for details + public static Task LoadUrlAsync(IWebBrowser chromiumWebBrowser, string url) { + if(string.IsNullOrEmpty(url)) + { + throw new ArgumentNullException(nameof(url)); + } + var tcs = new TaskCompletionSource(); EventHandler loadErrorHandler = null; @@ -265,11 +269,8 @@ namespace CefSharp loadErrorHandler = (sender, args) => { - //Ignore Aborted - //Currently invalid SSL certificates which aren't explicitly allowed - //end up with CefErrorCode.Aborted, I've created the following PR - //in the hopes of getting this fixed. - //https://bitbucket.org/chromiumembedded/cef/pull-requests/373 + //Actions that trigger a download will raise an aborted error. + //Generally speaking Aborted is safe to ignore if (args.ErrorCode == CefErrorCode.Aborted) { return; @@ -281,20 +282,10 @@ namespace CefSharp chromiumWebBrowser.LoadError -= loadErrorHandler; chromiumWebBrowser.LoadingStateChanged -= loadingStateChangeHandler; - if (ctx == null) - { - //Ensure our continuation is executed on the ThreadPool - //For the .Net Core implementation we could use - //TaskCreationOptions.RunContinuationsAsynchronously - tcs.TrySetResultAsync(new LoadUrlAsyncResponse(args.ErrorCode, -1)); - } - else - { - ctx.Post(new SendOrPostCallback((o) => - { - tcs.TrySetResult(new LoadUrlAsyncResponse(args.ErrorCode, -1)); - }), null); - } + //Ensure our continuation is executed on the ThreadPool + //For the .Net Core implementation we could use + //TaskCreationOptions.RunContinuationsAsynchronously + tcs.TrySetResultAsync(new LoadUrlAsyncResponse(args.ErrorCode, -1)); }; loadingStateChangeHandler = (sender, args) => @@ -322,30 +313,17 @@ namespace CefSharp statusCode = -1; } - if (ctx == null) - { - //Ensure our continuation is executed on the ThreadPool - //For the .Net Core implementation we could use - //TaskCreationOptions.RunContinuationsAsynchronously - tcs.TrySetResultAsync(new LoadUrlAsyncResponse(CefErrorCode.None, statusCode)); - } - else - { - ctx.Post(new SendOrPostCallback((o) => - { - tcs.TrySetResult(new LoadUrlAsyncResponse(CefErrorCode.None, statusCode)); - }), null); - } + //Ensure our continuation is executed on the ThreadPool + //For the .Net Core implementation we could use + //TaskCreationOptions.RunContinuationsAsynchronously + tcs.TrySetResultAsync(new LoadUrlAsyncResponse(CefErrorCode.None, statusCode)); } }; chromiumWebBrowser.LoadError += loadErrorHandler; chromiumWebBrowser.LoadingStateChanged += loadingStateChangeHandler; - if (!string.IsNullOrEmpty(url)) - { - chromiumWebBrowser.Load(url); - } + chromiumWebBrowser.Load(url); return tcs.Task; }