Skip to content

Commit

Permalink
[NUI] Add remove WebContext callbacks when disposed
Browse files Browse the repository at this point in the history
- fix the crash issue : A callback was made on a garbage collected delegate of type 'Tizen.NUI!Tizen.NUI.WebContext+WebContextHttpRequestInterceptedProxyCallback::Invoke'
  • Loading branch information
dongsug-song committed Oct 16, 2024
1 parent d805d71 commit 3b0c3f1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Tizen.NUI/src/internal/WebView/WebContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class WebContext : Disposable
private readonly WebContextPasswordDataListAcquiredProxyCallback passwordDataListAcquiredProxyCallback;
private HttpRequestInterceptedCallback httpRequestInterceptedCallback;
private readonly WebContextHttpRequestInterceptedProxyCallback httpRequestInterceptedProxyCallback;
private DownloadStartedCallback downloadStartedCallback;
private MimeOverriddenCallback mimeOverriddenCallback;

internal WebContext(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
{
Expand Down Expand Up @@ -518,10 +520,11 @@ public void GetFormPasswordList(PasswordDataListAcquiredCallback callback)
[EditorBrowsable(EditorBrowsableState.Never)]
public void RegisterDownloadStartedCallback(DownloadStartedCallback callback)
{
downloadStartedCallback = callback;
IntPtr ip = IntPtr.Zero;
if (callback != null)
if (downloadStartedCallback != null)
{
ip = Marshal.GetFunctionPointerForDelegate(callback);
ip = Marshal.GetFunctionPointerForDelegate(downloadStartedCallback);
}
Interop.WebContext.RegisterDownloadStartedCallback(SwigCPtr, new HandleRef(this, ip));
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
Expand All @@ -534,10 +537,11 @@ public void RegisterDownloadStartedCallback(DownloadStartedCallback callback)
[EditorBrowsable(EditorBrowsableState.Never)]
public void RegisterMimeOverriddenCallback(MimeOverriddenCallback callback)
{
mimeOverriddenCallback = callback;
IntPtr ip = IntPtr.Zero;
if (callback != null)
if (mimeOverriddenCallback != null)
{
ip = Marshal.GetFunctionPointerForDelegate(callback);
ip = Marshal.GetFunctionPointerForDelegate(mimeOverriddenCallback);
}
Interop.WebContext.RegisterMimeOverriddenCallback(SwigCPtr, new HandleRef(this, ip));
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
Expand Down
4 changes: 4 additions & 0 deletions src/Tizen.NUI/src/public/WebView/WebView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ protected override void Dispose(DisposeTypes type)
return;
}

Context.RegisterDownloadStartedCallback(null);
Context.RegisterMimeOverriddenCallback(null);
Context.RegisterHttpRequestInterceptedCallback(null);

if (type == DisposeTypes.Explicit)
{
//Called by User
Expand Down

0 comments on commit 3b0c3f1

Please sign in to comment.