Add webview API for url,change event.
authorhuayong.xu <huayong.xu@samsung.com>
Mon, 28 Nov 2022 11:24:08 +0000 (19:24 +0800)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Mon, 28 Nov 2022 11:50:33 +0000 (20:50 +0900)
src/Tizen.NUI/src/internal/Interop/Interop.WebView.cs
src/Tizen.NUI/src/internal/WebView.cs
src/Tizen.NUI/src/internal/WebViewUrlChangedEventArgs.cs [new file with mode: 0755]

index 088266c..7e852ab 100755 (executable)
@@ -129,6 +129,9 @@ namespace Tizen.NUI
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_RegisterScrollEdgeReachedCallback")]
             public static extern void RegisterScrollEdgeReachedCallback(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
 
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_RegisterScrollEdgeReachedCallback")]
             public static extern void RegisterScrollEdgeReachedCallback(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
 
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_RegisterUrlChangedCallback")]
+            public static extern void RegisterUrlChangedCallback(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_RegisterNavigationPolicyDecidedCallback")]
             public static extern void RegisterNavigationPolicyDecidedCallback(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
 
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_RegisterNavigationPolicyDecidedCallback")]
             public static extern void RegisterNavigationPolicyDecidedCallback(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
 
index 236ffe3..0894b1b 100755 (executable)
@@ -40,6 +40,9 @@ namespace Tizen.NUI
         private delegate void WebViewScrollEdgeReachedCallback(int edge);
 
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         private delegate void WebViewScrollEdgeReachedCallback(int edge);
 
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+        private delegate void WebViewUrlChangedCallbackDelegate(string pageUrl);
+
+        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         private delegate void WebViewPolicyDecidedCallback(IntPtr maker);
 
         private EventHandler<WebViewPageLoadEventArgs> pageLoadStartedEventHandler;
         private delegate void WebViewPolicyDecidedCallback(IntPtr maker);
 
         private EventHandler<WebViewPageLoadEventArgs> pageLoadStartedEventHandler;
@@ -54,6 +57,9 @@ namespace Tizen.NUI
         private EventHandler<WebViewScrollEdgeReachedEventArgs> scrollEdgeReachedEventHandler;
         private WebViewScrollEdgeReachedCallback scrollEdgeReachedCallback;
 
         private EventHandler<WebViewScrollEdgeReachedEventArgs> scrollEdgeReachedEventHandler;
         private WebViewScrollEdgeReachedCallback scrollEdgeReachedCallback;
 
+        private EventHandler<WebViewUrlChangedEventArgs> urlChangedEventHandler;
+        private WebViewUrlChangedCallbackDelegate urlChangedCallback;
+
         private EventHandler<WebViewPolicyDecidedEventArgs> navigationPolicyDecidedEventHandler;
         private WebViewPolicyDecidedCallback navigationPolicyDecidedCallback;
 
         private EventHandler<WebViewPolicyDecidedEventArgs> navigationPolicyDecidedEventHandler;
         private WebViewPolicyDecidedCallback navigationPolicyDecidedCallback;
 
@@ -162,6 +168,11 @@ namespace Tizen.NUI
             scrollEdgeReachedEventHandler?.Invoke(this, new WebViewScrollEdgeReachedEventArgs((WebViewScrollEdgeReachedEventArgs.Edge)edge));
         }
 
             scrollEdgeReachedEventHandler?.Invoke(this, new WebViewScrollEdgeReachedEventArgs((WebViewScrollEdgeReachedEventArgs.Edge)edge));
         }
 
+        private void OnUrlChanged(string pageUrl)
+        {
+            urlChangedEventHandler?.Invoke(this, new WebViewUrlChangedEventArgs(pageUrl));
+        }
+
         private void OnNavigationPolicyDecided(IntPtr maker)
         {
             navigationPolicyDecidedEventHandler?.Invoke(this, new WebViewPolicyDecidedEventArgs(new WebPolicyDecisionMaker(maker, true)));
         private void OnNavigationPolicyDecided(IntPtr maker)
         {
             navigationPolicyDecidedEventHandler?.Invoke(this, new WebViewPolicyDecidedEventArgs(new WebPolicyDecisionMaker(maker, true)));
@@ -612,6 +623,29 @@ namespace Tizen.NUI
         }
 
         /// <summary>
         }
 
         /// <summary>
+        /// Event for the UrlChanged signal which can be used to subscribe or unsubscribe the event handler.<br />
+        /// This signal is emitted when url is changed.<br />
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public event EventHandler<WebViewUrlChangedEventArgs> UrlChanged
+        {
+            add
+            {
+                if (urlChangedEventHandler == null)
+                {
+                    urlChangedCallback = OnUrlChanged;
+                    IntPtr ip = Marshal.GetFunctionPointerForDelegate(urlChangedCallback);
+                    Interop.WebView.RegisterUrlChangedCallback(SwigCPtr, new HandleRef(this, ip));
+                }
+                urlChangedEventHandler += value;
+            }
+            remove
+            {
+                urlChangedEventHandler -= value;
+            }
+        }
+
+        /// <summary>
         /// Event for the NavigationPolicyDecided signal which can be used to subscribe or unsubscribe the event handler.<br />
         /// This signal is emitted when response policy would be decided.<br />
         /// </summary>
         /// Event for the NavigationPolicyDecided signal which can be used to subscribe or unsubscribe the event handler.<br />
         /// This signal is emitted when response policy would be decided.<br />
         /// </summary>
diff --git a/src/Tizen.NUI/src/internal/WebViewUrlChangedEventArgs.cs b/src/Tizen.NUI/src/internal/WebViewUrlChangedEventArgs.cs
new file mode 100755 (executable)
index 0000000..af44631
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2021 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.UrlChanged.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class WebViewUrlChangedEventArgs : EventArgs
+    {
+        internal WebViewUrlChangedEventArgs(string url)
+        {
+            NewPageUrl = url;
+        }
+
+        /// <summary>
+        /// The URL of new web page.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public string NewPageUrl { get; }
+    }
+}