Stop main browser from sending WM_CLOSE by default

Resolves #18
This commit is contained in:
Alex Maitland
2022-09-08 12:34:46 +10:00
parent 756ce3012a
commit e9ec88a8b3
2 changed files with 27 additions and 1 deletions
+1 -1
View File
@@ -670,6 +670,7 @@ namespace CefSharp.Wpf.HwndHost
PresentationSource.AddSourceChangedHandler(this, PresentationSourceChangedHandler);
FocusHandler = new FocusHandler();
LifeSpanHandler = new NoCloseLifespanHandler();
UseLayoutRounding = true;
}
@@ -753,7 +754,6 @@ namespace CefSharp.Wpf.HwndHost
if (browserSettings.AutoDispose)
{
browserSettings.Dispose();
browserSettings = null;
}
browserSettings = null;
@@ -0,0 +1,26 @@
// Copyright © 2022 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.
namespace CefSharp.Wpf.HwndHost.Internals
{
/// <summary>
/// LifeSpanHandler used internally
/// - Cancels sending of WM_CLOSE message for main browser
/// - Allows popups to close
/// </summary>
public class NoCloseLifespanHandler
: CefSharp.Handler.LifeSpanHandler
{
/// <inheritdoc/>
protected override bool DoClose(IWebBrowser chromiumWebBrowser, IBrowser browser)
{
if(browser.IsPopup)
{
return false;
}
return true;
}
}
}