From 3b0c3f12a0171b3afebb0e9baca479e8b169cbf8 Mon Sep 17 00:00:00 2001 From: "dongsug.song" Date: Tue, 15 Oct 2024 21:41:13 +0900 Subject: [PATCH] [NUI] Add remove WebContext callbacks when disposed - fix the crash issue : A callback was made on a garbage collected delegate of type 'Tizen.NUI!Tizen.NUI.WebContext+WebContextHttpRequestInterceptedProxyCallback::Invoke' --- src/Tizen.NUI/src/internal/WebView/WebContext.cs | 12 ++++++++---- src/Tizen.NUI/src/public/WebView/WebView.cs | 4 ++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Tizen.NUI/src/internal/WebView/WebContext.cs b/src/Tizen.NUI/src/internal/WebView/WebContext.cs index c8bad400905..9a4469c7122 100755 --- a/src/Tizen.NUI/src/internal/WebView/WebContext.cs +++ b/src/Tizen.NUI/src/internal/WebView/WebContext.cs @@ -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) { @@ -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(); @@ -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(); diff --git a/src/Tizen.NUI/src/public/WebView/WebView.cs b/src/Tizen.NUI/src/public/WebView/WebView.cs index 94e127f2cb1..2a3fbe4d233 100755 --- a/src/Tizen.NUI/src/public/WebView/WebView.cs +++ b/src/Tizen.NUI/src/public/WebView/WebView.cs @@ -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