Skip to content

Commit bc466ef

Browse files
committed
Core - Add IBrowserHost.TryCloseBrowser
1 parent 891e5c5 commit bc466ef

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

CefSharp.Core/Internals/CefBrowserHostWrapper.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ void CefBrowserHostWrapper::CloseBrowser(bool forceClose)
150150
_browserHost->CloseBrowser(forceClose);
151151
}
152152

153+
bool CefBrowserHostWrapper::TryCloseBrowser()
154+
{
155+
ThrowIfDisposed();
156+
157+
return _browserHost->TryCloseBrowser();
158+
}
159+
153160
void CefBrowserHostWrapper::ShowDevTools(IWindowInfo^ windowInfo, int inspectElementAtX, int inspectElementAtY)
154161
{
155162
ThrowIfDisposed();

CefSharp.Core/Internals/CefBrowserHostWrapper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ namespace CefSharp
5050
virtual Task<double>^ GetZoomLevelAsync();
5151
virtual IntPtr GetWindowHandle();
5252
virtual void CloseBrowser(bool forceClose);
53+
virtual bool TryCloseBrowser();
5354

5455
virtual void DragTargetDragEnter(IDragData^ dragData, MouseEvent mouseEvent, DragOperationsMask allowedOperations);
5556
virtual void DragTargetDragOver(MouseEvent mouseEvent, DragOperationsMask allowedOperations);

CefSharp/IBrowserHost.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ public interface IBrowserHost : IDisposable
3636
/// </param>
3737
void CloseBrowser(bool forceClose);
3838

39+
/// <summary>
40+
/// Helper for closing a browser. Call this method from the top-level window close handler. Internally this calls CloseBrowser(false) if the close has not yet been initiated. This method returns false while the close is pending and true after the close has completed.
41+
/// See <see cref="CloseBrowser(bool)"/> and <see cref="ILifeSpanHandler.DoClose(IWebBrowser, IBrowser)"/> documentation for additional usage information. This method must be called on the CEF UI thread.
42+
/// </summary>
43+
/// <returns>
44+
/// This method returns false while the close is pending and true after the close has completed
45+
/// </returns>
46+
bool TryCloseBrowser();
47+
3948
/// <summary>
4049
/// Explicitly close the developer tools window if one exists for this browser instance.
4150
/// </summary>

0 commit comments

Comments
 (0)