[WebView][TCSACR-219] Add Policy Decision APIs (#689)
authorBasavarajPS <45586075+BasavarajPS@users.noreply.github.com>
Mon, 15 Apr 2019 23:38:09 +0000 (05:08 +0530)
committeryounghajung <35090305+younghajung@users.noreply.github.com>
Mon, 15 Apr 2019 23:38:09 +0000 (08:38 +0900)
Signed-off-by: basavarajps <basavaraj.ps@samsung.com>
src/Tizen.WebView/Interop/Interop.ChromiumEwk.PolicyDecision.cs [new file with mode: 0644]
src/Tizen.WebView/Tizen.WebView/PolicyDecisionEventArgs.cs [new file with mode: 0644]
src/Tizen.WebView/Tizen.WebView/WebView.cs

diff --git a/src/Tizen.WebView/Interop/Interop.ChromiumEwk.PolicyDecision.cs b/src/Tizen.WebView/Interop/Interop.ChromiumEwk.PolicyDecision.cs
new file mode 100644 (file)
index 0000000..94fee74
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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.Runtime.InteropServices;
+using Tizen.WebView;
+
+internal static partial class Interop
+{
+    internal static partial class ChromiumEwk
+    {
+        public enum PolicyDecisionType {
+            Use,
+            Download,
+            Ignore
+        };
+
+        [DllImport(Libraries.ChromiumEwk, EntryPoint = "ewk_policy_decision_url_get", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)]
+        internal static extern IntPtr _ewk_policy_decision_url_get(IntPtr policydecision);
+        internal static string ewk_policy_decision_url_get(IntPtr policydecision)
+        {
+            IntPtr ptr = _ewk_policy_decision_url_get(policydecision);
+            return Marshal.PtrToStringAnsi(ptr);
+        }
+
+        [DllImport(Libraries.ChromiumEwk, EntryPoint = "ewk_policy_decision_scheme_get", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)]
+        internal static extern IntPtr _ewk_policy_decision_scheme_get(IntPtr policydecision);
+        internal static string ewk_policy_decision_scheme_get(IntPtr policydecision)
+        {
+            IntPtr ptr = _ewk_policy_decision_scheme_get(policydecision);
+            return Marshal.PtrToStringAnsi(ptr);
+        }
+
+        [DllImport(Libraries.ChromiumEwk, EntryPoint = "ewk_policy_decision_cookie_get", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)]
+        internal static extern IntPtr _ewk_policy_decision_cookie_get(IntPtr policydecision);
+        internal static string ewk_policy_decision_cookie_get(IntPtr policydecision)
+        {
+            IntPtr ptr = _ewk_policy_decision_cookie_get(policydecision);
+            return Marshal.PtrToStringAnsi(ptr);
+        }
+
+        [DllImport(Libraries.ChromiumEwk)]
+        internal static extern NavigationType ewk_policy_decision_navigation_type_get(IntPtr policydecision);
+
+        [DllImport(Libraries.ChromiumEwk)]
+        internal static extern PolicyDecisionType ewk_policy_decision_type_get(IntPtr policydecision);
+
+        [DllImport(Libraries.ChromiumEwk)]
+        internal static extern int ewk_policy_decision_response_status_code_get(IntPtr policydecision);
+
+        [DllImport(Libraries.ChromiumEwk)]
+        [return: MarshalAs(UnmanagedType.U1)]
+        internal static extern bool ewk_policy_decision_is_main_frame(IntPtr policydecision);
+
+        [DllImport(Libraries.ChromiumEwk)]
+        [return: MarshalAs(UnmanagedType.U1)]
+        internal static extern bool ewk_policy_decision_ignore(IntPtr policydecision);
+
+        [DllImport(Libraries.ChromiumEwk)]
+        [return: MarshalAs(UnmanagedType.U1)]
+        internal static extern bool ewk_policy_decision_use(IntPtr policydecision);
+    }
+}
diff --git a/src/Tizen.WebView/Tizen.WebView/PolicyDecisionEventArgs.cs b/src/Tizen.WebView/Tizen.WebView/PolicyDecisionEventArgs.cs
new file mode 100644 (file)
index 0000000..8f7df9c
--- /dev/null
@@ -0,0 +1,236 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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.WebView
+{
+    /// <summary>
+    /// Enumeration values used to specify Policy Navigation Type.
+    /// </summary>
+    public enum NavigationType {
+        /// <summary>
+        /// Link Clicked.
+        /// </summary>
+        LinkClicked = 0,
+        /// <summary>
+        /// Form Submitted.
+        /// </summary>
+        FormSubmitted = 1,
+        /// <summary>
+        /// Back Forward.
+        /// </summary>
+        BackForward = 2,
+        /// <summary>
+        /// Reload.
+        /// </summary>
+        Reload = 3,
+        /// <summary>
+        /// Form Submitted.
+        /// </summary>
+        FormResubmitted = 4,
+        /// <summary>
+        /// Other.
+        /// </summary>
+        Other = 5
+    };
+
+    /// <summary>
+    /// Arguments from the policy decision events.
+    /// This class also provides the properties for Policy Decision of WebView.
+    /// </summary>
+    /// <since_tizen> 6 </since_tizen>
+    public abstract class PolicyDecisionEventArgs : EventArgs
+    {
+        private IntPtr _handle;
+
+        internal PolicyDecisionEventArgs(IntPtr handle)
+        {
+            _handle = handle;
+        }
+
+        /// <summary>
+        /// Gets the Url.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public string Url
+        {
+            get
+            {
+                return Interop.ChromiumEwk.ewk_policy_decision_url_get(_handle);
+            }
+        }
+
+        /// <summary>
+        /// Gets the scheme.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public string Scheme
+        {
+            get
+            {
+                return Interop.ChromiumEwk.ewk_policy_decision_scheme_get(_handle);
+            }
+        }
+
+        /// <summary>
+        /// Ignores the action which triggers this decision.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public void Ignore()
+        {
+            Interop.ChromiumEwk.ewk_policy_decision_ignore(_handle);
+        }
+
+        /// <summary>
+        /// Accepts the action which triggers this decision.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public void Use()
+        {
+            Interop.ChromiumEwk.ewk_policy_decision_use(_handle);
+        }
+
+        /// <summary>
+        /// Checks if frame requested in policy decision is main frame.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public bool IsMainFrame()
+        {
+            return Interop.ChromiumEwk.ewk_policy_decision_is_main_frame(_handle);
+        } 
+    }
+
+    /// <summary>
+    /// This class is derived from PolicyDecisionEventArgs.
+    /// This class provides the properties for New Window Policy of WebView.
+    /// </summary>
+    /// <since_tizen> 6 </since_tizen>
+    public class NewWindowPolicyEventArgs : PolicyDecisionEventArgs 
+    {
+        private IntPtr _handle;
+        internal NewWindowPolicyEventArgs(IntPtr handle) : base(handle)
+        {
+            _handle = handle;
+        }
+        
+        internal static NewWindowPolicyEventArgs CreateFromSmartEvent(IntPtr data, IntPtr obj, IntPtr info)
+        {
+            return new NewWindowPolicyEventArgs(info);
+        }
+    }
+
+
+    /// <summary>
+    /// This class is derived from PolicyDecisionEventArgs.
+    /// This class provides the properties for Navigation Policy of WebView.
+    /// </summary>
+    /// <since_tizen> 6 </since_tizen>
+    public class NavigationPolicyEventArgs : PolicyDecisionEventArgs
+    {
+        private IntPtr _handle;
+        internal NavigationPolicyEventArgs(IntPtr handle) : base(handle)
+        {
+            _handle = handle;
+        }
+
+        /// <summary>
+        /// Gets the Navigation Type of policy.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public NavigationType NavigationType
+        {
+            get
+            {
+                return Interop.ChromiumEwk.ewk_policy_decision_navigation_type_get(_handle);
+            }
+        }
+
+        /// <summary>
+        /// Gets the cookie.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public string Cookie
+        {
+            get
+            {
+                return Interop.ChromiumEwk.ewk_policy_decision_cookie_get(_handle);
+            }
+        }
+
+        internal static NavigationPolicyEventArgs CreateFromSmartEvent(IntPtr data, IntPtr obj, IntPtr info)
+        {
+            return new NavigationPolicyEventArgs(info);
+        }
+    }
+
+    /// <summary>
+    /// This class is derived from PolicyDecisionEventArgs.
+    /// This class provides the properties for Response Policy of WebView.
+    /// </summary>
+    /// <since_tizen> 6 </since_tizen>
+    public class ResponsePolicyEventArgs : PolicyDecisionEventArgs
+    {
+        private IntPtr _handle;
+        internal ResponsePolicyEventArgs(IntPtr handle) : base(handle)
+        {
+            _handle = handle;
+        }
+
+        /// <summary>
+        /// Gets http response status code.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public int StatusCode
+        {
+            get
+            {
+                return Interop.ChromiumEwk.ewk_policy_decision_response_status_code_get(_handle);
+            }
+        }
+
+        /// <summary>
+        /// Gets the cookie.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public string Cookie
+        {
+            get
+            {
+                return Interop.ChromiumEwk.ewk_policy_decision_cookie_get(_handle);
+            }
+        }
+        
+        /// <summary>
+        /// Checks policy decision type is Download.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public bool IsDownload
+        {
+            get
+            {
+                return Interop.ChromiumEwk.ewk_policy_decision_type_get(_handle) == Interop.ChromiumEwk.PolicyDecisionType.Download;
+            }
+        }
+
+        internal static ResponsePolicyEventArgs CreateFromSmartEvent(IntPtr data, IntPtr obj, IntPtr info)
+        {
+            return new ResponsePolicyEventArgs(info);
+        }
+    }
+}
index 02d3f53..fd322d4 100644 (file)
@@ -44,6 +44,9 @@ namespace Tizen.WebView
         private SmartEvent<SmartCallbackLoadErrorArgs> _loadError;
         private SmartEvent<SmartCallbackArgs> _titleChanged;
         private SmartEvent<SmartCallbackArgs> _urlChanged;
+        private SmartEvent<NavigationPolicyEventArgs> _policyNavigationDecide;
+        private SmartEvent<NewWindowPolicyEventArgs> _policyNewWindowDecide;
+        private SmartEvent<ResponsePolicyEventArgs> _policyResponseDecide;
 
         private SmartEvent<ContextMenuItemEventArgs> _contextMenuItemSelected;
         private SmartEvent<ContextMenuCustomizeEventArgs> _contextMenuCustomize;
@@ -81,17 +84,36 @@ namespace Tizen.WebView
         public event EventHandler<SmartCallbackArgs> UrlChanged;
 
         /// <summary>
-        /// The delegate is invoked when context menu customization is needed.
+
+        /// Event that occurs when the policy navigation is decided.
         /// </summary>
-        /// <param name="menu">The instance of ContextMenu.</param>
         /// <since_tizen> 6 </since_tizen>
-        public delegate void ContextMenuCustomize(ContextMenu menu);
+        public event EventHandler<NavigationPolicyEventArgs> NavigationPolicyDecideRequested;
+
+        /// <summary>
+        /// Event that occurs when the policy new window is decided.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public event EventHandler<NewWindowPolicyEventArgs> NewWindowPolicyDecideRequested;
+
+        /// <summary>
+        /// Event that occurs when the policy response is decided.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public event EventHandler<ResponsePolicyEventArgs> ResponsePolicyDecideRequested;
 
         /// <summary>
         /// Event that occurs when the context menu item selected.
         /// </summary>
         /// <since_tizen> 6 </since_tizen>
         public event EventHandler<ContextMenuItemEventArgs> ContextMenuItemSelected;
+        
+        /// The delegate is invoked when context menu customization is needed.
+        /// </summary>
+        /// <param name="menu">The instance of ContextMenu.</param>
+        /// <since_tizen> 6 </since_tizen>
+        public delegate void ContextMenuCustomize(ContextMenu menu);
+
 
         /// <summary>
         /// Current URL of the main frame.
@@ -414,13 +436,18 @@ namespace Tizen.WebView
             _urlChanged = new SmartEvent<SmartCallbackArgs>(this, _realHandle, "url,changed", SmartCallbackArgs.CreateFromSmartEvent);
             _contextMenuCustomize = new SmartEvent<ContextMenuCustomizeEventArgs>(this, _realHandle, "contextmenu,customize", ContextMenuCustomizeEventArgs.CreateFromSmartEvent);
             _contextMenuItemSelected = new SmartEvent<ContextMenuItemEventArgs>(this, _realHandle, "contextmenu,selected", ContextMenuItemEventArgs.CreateFromSmartEvent);
+            _policyNavigationDecide = new SmartEvent<NavigationPolicyEventArgs>(this, _realHandle, "policy,navigation,decide", NavigationPolicyEventArgs.CreateFromSmartEvent);
+            _policyNewWindowDecide = new SmartEvent<NewWindowPolicyEventArgs>(this, _realHandle, "policy,newwindow,decide", NewWindowPolicyEventArgs.CreateFromSmartEvent);
+            _policyResponseDecide = new SmartEvent<ResponsePolicyEventArgs>(this, _realHandle, "policy,response,decide", ResponsePolicyEventArgs.CreateFromSmartEvent);            
 
             _loadStarted.On += (s, e) => { LoadStarted?.Invoke(this, EventArgs.Empty); };
             _loadFinished.On += (s, e) => { LoadFinished?.Invoke(this, EventArgs.Empty); };
             _loadError.On += (s, e) => { LoadError?.Invoke(this, e); };
             _titleChanged.On += (s, e) => { TitleChanged?.Invoke(this, e); };
             _urlChanged.On += (s, e) => { UrlChanged?.Invoke(this, e); };
-
+            _policyNavigationDecide.On += (s, e) => { NavigationPolicyDecideRequested?.Invoke(this, e); };
+            _policyNewWindowDecide.On += (s, e) => { NewWindowPolicyDecideRequested?.Invoke(this, e); };
+            _policyResponseDecide.On += (s, e) => { ResponsePolicyDecideRequested?.Invoke(this, e); };
             _contextMenuItemSelected.On += (s, e) => { ContextMenuItemSelected?.Invoke(this, e); };
             _contextMenuCustomize.On += (s, e) => { _contextMenuCustomizeDelegate?.Invoke(e.Menu); };
         }