From 2f33b08d1df5297c5f9933feb995f703034e7081 Mon Sep 17 00:00:00 2001 From: BasavarajPS <45586075+BasavarajPS@users.noreply.github.com> Date: Tue, 16 Apr 2019 05:08:09 +0530 Subject: [PATCH] [WebView][TCSACR-219] Add Policy Decision APIs (#689) Signed-off-by: basavarajps --- .../Interop/Interop.ChromiumEwk.PolicyDecision.cs | 76 +++++++ .../Tizen.WebView/PolicyDecisionEventArgs.cs | 236 +++++++++++++++++++++ src/Tizen.WebView/Tizen.WebView/WebView.cs | 35 ++- 3 files changed, 343 insertions(+), 4 deletions(-) create mode 100644 src/Tizen.WebView/Interop/Interop.ChromiumEwk.PolicyDecision.cs create mode 100644 src/Tizen.WebView/Tizen.WebView/PolicyDecisionEventArgs.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 index 0000000..94fee74 --- /dev/null +++ b/src/Tizen.WebView/Interop/Interop.ChromiumEwk.PolicyDecision.cs @@ -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 index 0000000..8f7df9c --- /dev/null +++ b/src/Tizen.WebView/Tizen.WebView/PolicyDecisionEventArgs.cs @@ -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 +{ + /// + /// Enumeration values used to specify Policy Navigation Type. + /// + public enum NavigationType { + /// + /// Link Clicked. + /// + LinkClicked = 0, + /// + /// Form Submitted. + /// + FormSubmitted = 1, + /// + /// Back Forward. + /// + BackForward = 2, + /// + /// Reload. + /// + Reload = 3, + /// + /// Form Submitted. + /// + FormResubmitted = 4, + /// + /// Other. + /// + Other = 5 + }; + + /// + /// Arguments from the policy decision events. + /// This class also provides the properties for Policy Decision of WebView. + /// + /// 6 + public abstract class PolicyDecisionEventArgs : EventArgs + { + private IntPtr _handle; + + internal PolicyDecisionEventArgs(IntPtr handle) + { + _handle = handle; + } + + /// + /// Gets the Url. + /// + /// 6 + public string Url + { + get + { + return Interop.ChromiumEwk.ewk_policy_decision_url_get(_handle); + } + } + + /// + /// Gets the scheme. + /// + /// 6 + public string Scheme + { + get + { + return Interop.ChromiumEwk.ewk_policy_decision_scheme_get(_handle); + } + } + + /// + /// Ignores the action which triggers this decision. + /// + /// 6 + public void Ignore() + { + Interop.ChromiumEwk.ewk_policy_decision_ignore(_handle); + } + + /// + /// Accepts the action which triggers this decision. + /// + /// 6 + public void Use() + { + Interop.ChromiumEwk.ewk_policy_decision_use(_handle); + } + + /// + /// Checks if frame requested in policy decision is main frame. + /// + /// 6 + [EditorBrowsable(EditorBrowsableState.Never)] + public bool IsMainFrame() + { + return Interop.ChromiumEwk.ewk_policy_decision_is_main_frame(_handle); + } + } + + /// + /// This class is derived from PolicyDecisionEventArgs. + /// This class provides the properties for New Window Policy of WebView. + /// + /// 6 + 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); + } + } + + + /// + /// This class is derived from PolicyDecisionEventArgs. + /// This class provides the properties for Navigation Policy of WebView. + /// + /// 6 + public class NavigationPolicyEventArgs : PolicyDecisionEventArgs + { + private IntPtr _handle; + internal NavigationPolicyEventArgs(IntPtr handle) : base(handle) + { + _handle = handle; + } + + /// + /// Gets the Navigation Type of policy. + /// + /// 6 + public NavigationType NavigationType + { + get + { + return Interop.ChromiumEwk.ewk_policy_decision_navigation_type_get(_handle); + } + } + + /// + /// Gets the cookie. + /// + /// 6 + 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); + } + } + + /// + /// This class is derived from PolicyDecisionEventArgs. + /// This class provides the properties for Response Policy of WebView. + /// + /// 6 + public class ResponsePolicyEventArgs : PolicyDecisionEventArgs + { + private IntPtr _handle; + internal ResponsePolicyEventArgs(IntPtr handle) : base(handle) + { + _handle = handle; + } + + /// + /// Gets http response status code. + /// + /// 6 + public int StatusCode + { + get + { + return Interop.ChromiumEwk.ewk_policy_decision_response_status_code_get(_handle); + } + } + + /// + /// Gets the cookie. + /// + /// 6 + public string Cookie + { + get + { + return Interop.ChromiumEwk.ewk_policy_decision_cookie_get(_handle); + } + } + + /// + /// Checks policy decision type is Download. + /// + /// 6 + 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); + } + } +} diff --git a/src/Tizen.WebView/Tizen.WebView/WebView.cs b/src/Tizen.WebView/Tizen.WebView/WebView.cs index 02d3f53..fd322d4 100644 --- a/src/Tizen.WebView/Tizen.WebView/WebView.cs +++ b/src/Tizen.WebView/Tizen.WebView/WebView.cs @@ -44,6 +44,9 @@ namespace Tizen.WebView private SmartEvent _loadError; private SmartEvent _titleChanged; private SmartEvent _urlChanged; + private SmartEvent _policyNavigationDecide; + private SmartEvent _policyNewWindowDecide; + private SmartEvent _policyResponseDecide; private SmartEvent _contextMenuItemSelected; private SmartEvent _contextMenuCustomize; @@ -81,17 +84,36 @@ namespace Tizen.WebView public event EventHandler UrlChanged; /// - /// The delegate is invoked when context menu customization is needed. + + /// Event that occurs when the policy navigation is decided. /// - /// The instance of ContextMenu. /// 6 - public delegate void ContextMenuCustomize(ContextMenu menu); + public event EventHandler NavigationPolicyDecideRequested; + + /// + /// Event that occurs when the policy new window is decided. + /// + /// 6 + public event EventHandler NewWindowPolicyDecideRequested; + + /// + /// Event that occurs when the policy response is decided. + /// + /// 6 + public event EventHandler ResponsePolicyDecideRequested; /// /// Event that occurs when the context menu item selected. /// /// 6 public event EventHandler ContextMenuItemSelected; + + /// The delegate is invoked when context menu customization is needed. + /// + /// The instance of ContextMenu. + /// 6 + public delegate void ContextMenuCustomize(ContextMenu menu); + /// /// Current URL of the main frame. @@ -414,13 +436,18 @@ namespace Tizen.WebView _urlChanged = new SmartEvent(this, _realHandle, "url,changed", SmartCallbackArgs.CreateFromSmartEvent); _contextMenuCustomize = new SmartEvent(this, _realHandle, "contextmenu,customize", ContextMenuCustomizeEventArgs.CreateFromSmartEvent); _contextMenuItemSelected = new SmartEvent(this, _realHandle, "contextmenu,selected", ContextMenuItemEventArgs.CreateFromSmartEvent); + _policyNavigationDecide = new SmartEvent(this, _realHandle, "policy,navigation,decide", NavigationPolicyEventArgs.CreateFromSmartEvent); + _policyNewWindowDecide = new SmartEvent(this, _realHandle, "policy,newwindow,decide", NewWindowPolicyEventArgs.CreateFromSmartEvent); + _policyResponseDecide = new SmartEvent(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); }; } -- 2.7.4