From c20fa40d3e061c28946031d33e8090fb368adaae Mon Sep 17 00:00:00 2001 From: Jiyun Yang Date: Mon, 25 Mar 2019 15:19:27 +0900 Subject: [PATCH] [NUI] Fix NUI.WebView concerned with GC (#762) JavaScriptMessageHandler delegate instances are collectable by GC, so the concrete root for those instants are needed. Signed-off-by: Jiyun Yang --- src/Tizen.NUI/src/internal/WebView.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Tizen.NUI/src/internal/WebView.cs b/src/Tizen.NUI/src/internal/WebView.cs index 3702b63a2..b34feae21 100755 --- a/src/Tizen.NUI/src/internal/WebView.cs +++ b/src/Tizen.NUI/src/internal/WebView.cs @@ -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 handlerRootMap = new Dictionary(); + /// /// Add a message handler into the WebView. /// The name of exposed object @@ -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(); } -- 2.34.1