// Copyright © 2021 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
using CefSharp.Internals;
using System.Threading.Tasks;
namespace CefSharp
{
///
/// Extended WebBrowserExtensions
///
public static class WebBrowserExtensionsEx
{
///
/// Retrieve the current . Contains information like
/// and
///
/// The ChromiumWebBrowser instance this method extends.
///
/// that when executed returns the current or null
///
public static Task GetVisibleNavigationEntryAsync(this IWebBrowser browser)
{
var host = browser.GetBrowserHost();
if (host == null)
{
return Task.FromResult(null);
}
if(Cef.CurrentlyOnThread(CefThreadIds.TID_UI))
{
var entry = host.GetVisibleNavigationEntry();
return Task.FromResult(entry);
}
var tcs = new TaskCompletionSource();
Cef.UIThreadTaskFactory.StartNew(delegate
{
var entry = host.GetVisibleNavigationEntry();
tcs.TrySetResultAsync(entry);
});
return tcs.Task;
}
}
}