Skip to content

Commit a6ff42e

Browse files
committed
Core - IAudioHandler now implements IDisposable
IAudioHandler.Dispose is called when the ChromiumWebBrowser instance is being Disposed. This is a breaking change. Resolves #3598
1 parent e1ac768 commit a6ff42e

File tree

6 files changed

+37
-5
lines changed

6 files changed

+37
-5
lines changed

CefSharp.OffScreen/ChromiumWebBrowser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ protected virtual void Dispose(bool disposing)
275275

276276
// Release reference to handlers, except LifeSpanHandler which is done after Disposing
277277
// ManagedCefBrowserAdapter otherwise the ILifeSpanHandler.DoClose will not be invoked.
278-
this.SetHandlersToNullExceptLifeSpan();
278+
FreeHandlersExceptLifeSpan();
279279

280280
browser = null;
281281

CefSharp.WinForms/ChromiumWebBrowser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ private void InternalDispose(bool disposing)
407407

408408
// Release reference to handlers, except LifeSpanHandler which is done after Disposing
409409
// ManagedCefBrowserAdapter otherwise the ILifeSpanHandler.DoClose will not be invoked.
410-
this.SetHandlersToNullExceptLifeSpan();
410+
FreeHandlersExceptLifeSpan();
411411

412412
browser = null;
413413

CefSharp.Wpf/ChromiumWebBrowser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ private void InternalDispose(bool disposing)
637637

638638
// Release reference to handlers, except LifeSpanHandler which is done after Disposing
639639
// ManagedCefBrowserAdapter otherwise the ILifeSpanHandler.DoClose will not be invoked.
640-
this.SetHandlersToNullExceptLifeSpan();
640+
this.FreeHandlersExceptLifeSpan();
641641

642642
browser = null;
643643

CefSharp/Handler/AudioHandler.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ namespace CefSharp.Handler
1313
/// </summary>
1414
public class AudioHandler : IAudioHandler
1515
{
16+
private bool isDisposed;
17+
18+
/// <summary>
19+
/// Gets a value indicating this <see cref="AudioHandler"/> instance
20+
/// has been disposed.
21+
/// </summary>
22+
public bool IsDisposed
23+
{
24+
get { return isDisposed; }
25+
}
26+
1627
/// <inheritdoc/>
1728
bool IAudioHandler.GetAudioParameters(IWebBrowser chromiumWebBrowser, IBrowser browser, ref AudioParameters parameters)
1829
{
@@ -117,5 +128,21 @@ protected virtual void OnAudioStreamError(IWebBrowser chromiumWebBrowser, IBrows
117128
{
118129

119130
}
131+
132+
/// <summary>
133+
/// Releases unmanaged and managed resources
134+
/// </summary>
135+
/// <param name="disposing"><see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.</param>
136+
protected virtual void Dispose(bool disposing)
137+
{
138+
isDisposed = true;
139+
}
140+
141+
/// <inheritdoc />
142+
public void Dispose()
143+
{
144+
Dispose(disposing: true);
145+
GC.SuppressFinalize(this);
146+
}
120147
}
121148
}

CefSharp/Handler/IAudioHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace CefSharp
1111
/// Implement this interface to handle audio events
1212
/// All methods will be called on the CEF UI thread
1313
/// </summary>
14-
public interface IAudioHandler
14+
public interface IAudioHandler : IDisposable
1515
{
1616
/// <summary>
1717
/// Called on the CEF UI thread to allow configuration of audio stream parameters.

CefSharp/Internals/Partial/ChromiumWebBrowser.Partial.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,13 @@ public Task<LoadUrlAsyncResponse> LoadUrlAsync(string url = null, Synchronizatio
326326

327327
partial void OnAfterBrowserCreated(IBrowser browser);
328328

329-
private void SetHandlersToNullExceptLifeSpan()
329+
/// <summary>
330+
/// Sets the handler references to null.
331+
/// Where required also calls Dispose().
332+
/// </summary>
333+
private void FreeHandlersExceptLifeSpan()
330334
{
335+
AudioHandler?.Dispose();
331336
AudioHandler = null;
332337
DialogHandler = null;
333338
FindHandler = null;

0 commit comments

Comments
 (0)