[NUI] Fix NUI.WebView concerned with GC (#762)
authorJiyun Yang <ji.yang@samsung.com>
Mon, 25 Mar 2019 06:19:27 +0000 (15:19 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Mon, 25 Mar 2019 06:19:27 +0000 (15:19 +0900)
JavaScriptMessageHandler delegate instances are collectable by GC,
so the concrete root for those instants are needed.

Signed-off-by: Jiyun Yang <ji.yang@samsung.com>
src/Tizen.NUI/src/internal/WebView.cs

index 3702b63..b34feae 100755 (executable)
@@ -17,6 +17,7 @@
 
 using System;
 using System.ComponentModel;
+using System.Collections.Generic;
 using System.Runtime.InteropServices;
 using Tizen.NUI.BaseComponents;
 
@@ -418,6 +419,10 @@ namespace Tizen.NUI
         [EditorBrowsable(EditorBrowsableState.Never)]
         public delegate void JavaScriptMessageHandler(string message);
 
+
+        // For rooting handlers
+        internal Dictionary<string, JavaScriptMessageHandler> handlerRootMap = new Dictionary<string, JavaScriptMessageHandler>();
+
         /// <summary>
         /// Add a message handler into the WebView.
         /// <param name="objectName">The name of exposed object</param>
@@ -426,8 +431,16 @@ namespace Tizen.NUI
         [EditorBrowsable(EditorBrowsableState.Never)]
         public void AddJavaScriptMessageHandler(string objectName, JavaScriptMessageHandler handler)
         {
+            if (handlerRootMap.ContainsKey(objectName))
+            {
+                return;
+            }
+
+            handlerRootMap.Add(objectName, handler);
+
             System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(handler);
             NDalicPINVOKE.WebView_AddJavaScriptMessageHandler(swigCPtr, objectName, new System.Runtime.InteropServices.HandleRef(this, ip));
+
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }