[NUI] Add |AddJavaScriptInterface| API for WebView (#676)
authorJiyun Yang <ji.yang@samsung.com>
Mon, 21 Jan 2019 05:44:46 +0000 (14:44 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Mon, 21 Jan 2019 05:44:46 +0000 (14:44 +0900)
This API provides a method of c# delegate injection to JavaScript

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

index ca713a7..73a9e45 100755 (executable)
@@ -15051,6 +15051,11 @@ namespace Tizen.NUI
 
 
 
+        [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint = "CSharp_Dali_WebView_AddJavaScriptMessageHandler")]
+        public static extern void WebView_AddJavaScriptMessageHandler(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2, global::System.Runtime.InteropServices.HandleRef jarg3);
+
+
+
         [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint = "CSharp_Dali_WebView_ClearHistory")]
         public static extern void WebView_ClearHistory(global::System.Runtime.InteropServices.HandleRef jarg1);
 
index 8c11196..d559ce6 100755 (executable)
@@ -409,6 +409,26 @@ namespace Tizen.NUI
         }
 
         /// <summary>
+        /// The callback function that is invoked when the message is received from the script.
+        /// </summary>
+        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public delegate void JavaScriptMessageHandler(string message);
+
+        /// <summary>
+        /// Add a message handler into the WebView.
+        /// <param name="objectName">The name of exposed object</param>
+        /// <param name="handler">The callback function</param>
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void AddJavaScriptMessageHandler(string objectName, JavaScriptMessageHandler 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();
+        }
+
+        /// <summary>
         /// Clears the history of Web.
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]