[NUI] Add WebAuthDisplayQR and Response for QR code passkey in WebView
authordongsug.song <dongsug.song@samsung.com>
Wed, 4 Sep 2024 10:09:07 +0000 (19:09 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Fri, 11 Oct 2024 08:07:54 +0000 (17:07 +0900)
src/Tizen.NUI/src/internal/Interop/Interop.WebView.cs
src/Tizen.NUI/src/internal/WebView/WebViewWebAuthDisplayQREventArgs.cs [new file with mode: 0755]
src/Tizen.NUI/src/public/WebView/WebView.cs

index c35ad24d03d5ca90761785e952fa4696035f9dd3..a13b711597f8c8942317a456e0c83b33b4d94fff 100755 (executable)
@@ -330,6 +330,15 @@ namespace Tizen.NUI
 
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_GetPlainTextAsynchronously")]
             public static extern void GetPlainTextAsynchronously(global::System.Runtime.InteropServices.HandleRef webViewRef, global::System.Runtime.InteropServices.HandleRef callbackRef);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_WebAuthenticationCancel")]
+            public static extern void WebAuthenticationCancel(global::System.Runtime.InteropServices.HandleRef webViewRef);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_RegisterWebAuthDisplayQRCallback")]
+            public static extern void RegisterWebAuthDisplayQRCallback(global::System.Runtime.InteropServices.HandleRef webViewRef, global::System.Runtime.InteropServices.HandleRef callbackRef);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_RegisterWebAuthResponseCallback")]
+            public static extern void RegisterWebAuthResponseCallback(global::System.Runtime.InteropServices.HandleRef webViewRef, global::System.Runtime.InteropServices.HandleRef callbackRef);
         }
     }
 }
diff --git a/src/Tizen.NUI/src/internal/WebView/WebViewWebAuthDisplayQREventArgs.cs b/src/Tizen.NUI/src/internal/WebView/WebViewWebAuthDisplayQREventArgs.cs
new file mode 100755 (executable)
index 0000000..4e7507b
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+using System;
+using System.ComponentModel;
+
+namespace Tizen.NUI
+{
+    /// <summary>
+    /// Event arguments that passed via the WebView.WebAuthDisplayQR.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class WebViewWebAuthDisplayQREventArgs : EventArgs
+    {
+        internal WebViewWebAuthDisplayQREventArgs(string contents)
+        {
+            Contents = contents;
+        }
+
+        /// <summary>
+        /// The string contents to make QR code image in user side.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public string Contents { get; }
+    }
+}
index ce0a3b6cc705d94d890fb7b926d1d22c42643691..c5a979ad2ce36c98133bfc10f1a2b5441c81100c 100755 (executable)
@@ -105,6 +105,12 @@ namespace Tizen.NUI.BaseComponents
 
         private PlainTextReceivedCallback plainTextReceivedCallback;
 
+        private EventHandler<WebViewWebAuthDisplayQREventArgs> webAuthDisplayQREventHandler;
+        private WebViewWebAuthDisplayQRCallback webAuthDisplayQRCallback;
+
+        private EventHandler webAuthResponseEventHandler;
+        private WebViewWebAuthResponseCallback webAuthResponseCallback;
+
         /// <summary>
         /// Creates a WebView.
         /// </summary>
@@ -302,6 +308,12 @@ namespace Tizen.NUI.BaseComponents
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         private delegate void WebViewTextFoundCallback(uint count);
 
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        private delegate void WebViewWebAuthDisplayQRCallback(string contents);
+
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        private delegate void WebViewWebAuthResponseCallback();
+
         /// <summary>
         /// Event for the PageLoadStarted signal which can be used to subscribe or unsubscribe the event handler.<br />
         /// This signal is emitted when page loading has started.<br />
@@ -890,6 +902,60 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        /// <summary>
+        /// Event to informs user application to display QR code popup for passkey scenario.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public event EventHandler<WebViewWebAuthDisplayQREventArgs> WebAuthDisplayQR
+        {
+            add
+            {
+                if (webAuthDisplayQREventHandler == null)
+                {
+                    webAuthDisplayQRCallback = OnWebAuthDisplayQR;
+                    IntPtr ip = Marshal.GetFunctionPointerForDelegate(webAuthDisplayQRCallback);
+                    Interop.WebView.RegisterWebAuthDisplayQRCallback(SwigCPtr, new HandleRef(this, ip));
+                }
+                webAuthDisplayQREventHandler += value;
+            }
+            remove
+            {
+                webAuthDisplayQREventHandler -= value;
+                if (webAuthDisplayQREventHandler == null)
+                {
+                    IntPtr ip = IntPtr.Zero;
+                    Interop.WebView.RegisterWebAuthDisplayQRCallback(SwigCPtr, new HandleRef(this, ip));
+                }
+            }
+        }
+
+        /// <summary>
+        /// Event to informs user application that the passkey registration and authentication has been successful.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public event EventHandler WebAuthResponse
+        {
+            add
+            {
+                if (webAuthResponseEventHandler == null)
+                {
+                    webAuthResponseCallback = OnWebAuthResponse;
+                    IntPtr ip = Marshal.GetFunctionPointerForDelegate(webAuthResponseCallback);
+                    Interop.WebView.RegisterWebAuthResponseCallback(SwigCPtr, new HandleRef(this, ip));
+                }
+                webAuthResponseEventHandler += value;
+            }
+            remove
+            {
+                webAuthResponseEventHandler -= value;
+                if (webAuthResponseEventHandler == null)
+                {
+                    IntPtr ip = IntPtr.Zero;
+                    Interop.WebView.RegisterWebAuthResponseCallback(SwigCPtr, new HandleRef(this, ip));
+                }
+            }
+        }
+
         /// <summary>
         /// Options for searching texts.
         /// </summary>
@@ -2374,6 +2440,16 @@ namespace Tizen.NUI.BaseComponents
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
+        /// <summary>
+        /// cancel in progress web authentication that is passkey operation.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void WebAuthenticationCancel()
+        {
+            Interop.WebView.WebAuthenticationCancel(SwigCPtr);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
         internal static WebView DownCast(BaseHandle handle)
         {
             WebView ret = new WebView(Interop.WebView.DownCast(BaseHandle.getCPtr(handle)), true);
@@ -2534,5 +2610,16 @@ namespace Tizen.NUI.BaseComponents
         {
             textFoundEventHandler?.Invoke(this, new WebViewTextFoundEventArgs(count));
         }
+
+        private void OnWebAuthDisplayQR(string contents)
+        {
+            webAuthDisplayQREventHandler?.Invoke(this, new WebViewWebAuthDisplayQREventArgs(contents));
+        }
+
+        private void OnWebAuthResponse()
+        {
+            webAuthResponseEventHandler?.Invoke(this, new EventArgs());
+        }
+
     }
 }