From bc466ef434e5f3de3aa2e3812dc2ab3c2bc81e82 Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 11 Feb 2020 06:57:50 +1000 Subject: [PATCH] Core - Add IBrowserHost.TryCloseBrowser --- CefSharp.Core/Internals/CefBrowserHostWrapper.cpp | 7 +++++++ CefSharp.Core/Internals/CefBrowserHostWrapper.h | 1 + CefSharp/IBrowserHost.cs | 9 +++++++++ 3 files changed, 17 insertions(+) diff --git a/CefSharp.Core/Internals/CefBrowserHostWrapper.cpp b/CefSharp.Core/Internals/CefBrowserHostWrapper.cpp index 0d961a5cb..9a8e00180 100644 --- a/CefSharp.Core/Internals/CefBrowserHostWrapper.cpp +++ b/CefSharp.Core/Internals/CefBrowserHostWrapper.cpp @@ -150,6 +150,13 @@ void CefBrowserHostWrapper::CloseBrowser(bool forceClose) _browserHost->CloseBrowser(forceClose); } +bool CefBrowserHostWrapper::TryCloseBrowser() +{ + ThrowIfDisposed(); + + return _browserHost->TryCloseBrowser(); +} + void CefBrowserHostWrapper::ShowDevTools(IWindowInfo^ windowInfo, int inspectElementAtX, int inspectElementAtY) { ThrowIfDisposed(); diff --git a/CefSharp.Core/Internals/CefBrowserHostWrapper.h b/CefSharp.Core/Internals/CefBrowserHostWrapper.h index c243b1051..0eedabe37 100644 --- a/CefSharp.Core/Internals/CefBrowserHostWrapper.h +++ b/CefSharp.Core/Internals/CefBrowserHostWrapper.h @@ -50,6 +50,7 @@ namespace CefSharp virtual Task^ GetZoomLevelAsync(); virtual IntPtr GetWindowHandle(); virtual void CloseBrowser(bool forceClose); + virtual bool TryCloseBrowser(); virtual void DragTargetDragEnter(IDragData^ dragData, MouseEvent mouseEvent, DragOperationsMask allowedOperations); virtual void DragTargetDragOver(MouseEvent mouseEvent, DragOperationsMask allowedOperations); diff --git a/CefSharp/IBrowserHost.cs b/CefSharp/IBrowserHost.cs index 1f5522490..854c15d0e 100644 --- a/CefSharp/IBrowserHost.cs +++ b/CefSharp/IBrowserHost.cs @@ -36,6 +36,15 @@ namespace CefSharp /// void CloseBrowser(bool forceClose); + /// + /// 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. + /// See and documentation for additional usage information. This method must be called on the CEF UI thread. + /// + /// + /// This method returns false while the close is pending and true after the close has completed + /// + bool TryCloseBrowser(); + /// /// Explicitly close the developer tools window if one exists for this browser instance. ///