[NUI] Add remove WebContext callbacks when disposed
authordongsug.song <dongsug.song@samsung.com>
Tue, 15 Oct 2024 12:41:13 +0000 (21:41 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Wed, 16 Oct 2024 07:13:25 +0000 (16:13 +0900)
- 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
src/Tizen.NUI/src/public/WebView/WebView.cs

index c8bad4009054dd01c6f2faa7c3a4ed00351a5706..9a4469c71222f9eb344b96c3180befe03be41179 100755 (executable)
@@ -40,6 +40,8 @@ namespace Tizen.NUI
         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 @@ namespace Tizen.NUI
         [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 @@ namespace Tizen.NUI
         [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();
index 94e127f2cb11d2ee2b6ddf7a0ef97c1adb79991e..2a3fbe4d2333e6fabeb47d95de4c617a52c1d8ee 100755 (executable)
@@ -244,6 +244,10 @@ namespace Tizen.NUI.BaseComponents
                 return;
             }
 
+            Context.RegisterDownloadStartedCallback(null);
+            Context.RegisterMimeOverriddenCallback(null);
+            Context.RegisterHttpRequestInterceptedCallback(null);
+
             if (type == DisposeTypes.Explicit)
             {
                 //Called by User