[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 ca713a7d7272666a9a5b70bd4d766a74b9ccb5c2..73a9e455f1991b12f5ed9843496a4d93ab1bf858 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 8c111969fdd4ce2b5f1604a1f4db723ded1f4855..d559ce66b04dc6aa9142fff257adf50cbc6431fc 100755 (executable)
@@ -408,6 +408,26 @@ namespace Tizen.NUI
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
+        /// <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>