From 6574f6971e70a86647e67691be663624e74b3b1b Mon Sep 17 00:00:00 2001 From: "huayong.xu" Date: Thu, 8 Sep 2022 20:05:07 +0800 Subject: [PATCH] Implement navigation decision policy. --- .../src/internal/Interop/Interop.WebFrame.cs | 28 ++ .../Interop/Interop.WebPolicyDecisionMaker.cs | 61 +++++ .../src/internal/Interop/Interop.WebView.cs | 44 +--- src/Tizen.NUI/src/internal/WebFrame.cs | 44 ++++ .../src/internal/WebPolicyDecisionMaker.cs | 239 ++++++++++++++++++ src/Tizen.NUI/src/internal/WebView.cs | 120 ++++----- .../internal/WebViewPageLoadErrorSignal.cs | 57 ----- .../src/internal/WebViewPageLoadSignal.cs | 57 ----- .../internal/WebViewPolicyDecidedEventArgs.cs | 40 +++ .../WebViewScrollEdgeReachedSignal.cs | 55 ---- .../Samples/WebViewNavigationPolicyTest.cs | 60 +++++ 11 files changed, 543 insertions(+), 262 deletions(-) create mode 100755 src/Tizen.NUI/src/internal/Interop/Interop.WebFrame.cs create mode 100755 src/Tizen.NUI/src/internal/Interop/Interop.WebPolicyDecisionMaker.cs create mode 100755 src/Tizen.NUI/src/internal/WebFrame.cs create mode 100755 src/Tizen.NUI/src/internal/WebPolicyDecisionMaker.cs delete mode 100755 src/Tizen.NUI/src/internal/WebViewPageLoadErrorSignal.cs delete mode 100755 src/Tizen.NUI/src/internal/WebViewPageLoadSignal.cs create mode 100755 src/Tizen.NUI/src/internal/WebViewPolicyDecidedEventArgs.cs delete mode 100755 src/Tizen.NUI/src/internal/WebViewScrollEdgeReachedSignal.cs create mode 100755 test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/WebViewNavigationPolicyTest.cs diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.WebFrame.cs b/src/Tizen.NUI/src/internal/Interop/Interop.WebFrame.cs new file mode 100755 index 000000000..a6129df02 --- /dev/null +++ b/src/Tizen.NUI/src/internal/Interop/Interop.WebFrame.cs @@ -0,0 +1,28 @@ +/* + * 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. + * + */ + +namespace Tizen.NUI +{ + internal static partial class Interop + { + internal static partial class WebFrame + { + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebFrame_IsMainFrame")] + public static extern bool IsMainFrame(global::System.Runtime.InteropServices.HandleRef jarg1); + } + } +} diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.WebPolicyDecisionMaker.cs b/src/Tizen.NUI/src/internal/Interop/Interop.WebPolicyDecisionMaker.cs new file mode 100755 index 000000000..6e9e7f8be --- /dev/null +++ b/src/Tizen.NUI/src/internal/Interop/Interop.WebPolicyDecisionMaker.cs @@ -0,0 +1,61 @@ +/* + * 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. + * + */ + +namespace Tizen.NUI +{ + internal static partial class Interop + { + internal static partial class WebPolicyDecisionMaker + { + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_delete_WebPolicyDecision")] + public static extern void DeleteWebPolicyDecision(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebPolicyDecision_GetUrl")] + public static extern string GetUrl(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebPolicyDecision_GetCookie")] + public static extern string GetCookie(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebPolicyDecision_GetDecisionType")] + public static extern int GetDecisionType(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebPolicyDecision_GetResponseMime")] + public static extern string GetResponseMime(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebPolicyDecision_GetResponseStatusCode")] + public static extern int GetResponseStatusCode(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebPolicyDecision_GetNavigationType")] + public static extern int GetNavigationType(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebPolicyDecision_GetFrame")] + public static extern System.IntPtr GetFrame(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebPolicyDecision_GetScheme")] + public static extern string GetScheme(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebPolicyDecision_Use")] + public static extern bool Use(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebPolicyDecision_Ignore")] + public static extern bool Ignore(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebPolicyDecision_Suspend")] + public static extern bool Suspend(global::System.Runtime.InteropServices.HandleRef jarg1); + } + } +} diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.WebView.cs b/src/Tizen.NUI/src/internal/Interop/Interop.WebView.cs index 1642a1307..088266c49 100755 --- a/src/Tizen.NUI/src/internal/Interop/Interop.WebView.cs +++ b/src/Tizen.NUI/src/internal/Interop/Interop.WebView.cs @@ -117,44 +117,20 @@ namespace Tizen.NUI [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_SWIGUpcast")] public static extern global::System.IntPtr WebView_SWIGUpcast(global::System.IntPtr jarg1); - [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_new_WebViewPageLoadSignal_PageLoadStarted")] - public static extern global::System.IntPtr new_WebViewPageLoadSignal_PageLoadStarted(global::System.Runtime.InteropServices.HandleRef jarg1); + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_RegisterPageLoadStartedCallback")] + public static extern void RegisterPageLoadStartedCallback(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2); - [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_new_WebViewPageLoadSignal_PageLoadFinished")] - public static extern global::System.IntPtr new_WebViewPageLoadSignal_PageLoadFinished(global::System.Runtime.InteropServices.HandleRef jarg1); + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_RegisterPageLoadFinishedCallback")] + public static extern void RegisterPageLoadFinishedCallback(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2); - [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_delete_WebViewPageLoadSignal")] - public static extern void delete_WebViewPageLoadSignal(global::System.Runtime.InteropServices.HandleRef jarg1); + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_RegisterPageLoadErrorCallback")] + public static extern void RegisterPageLoadErrorCallback(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2); - [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebViewPageLoadSignal_Connect")] - public static extern void WebViewPageLoadSignal_Connect(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_WebViewPageLoadSignal_Disconnect")] - public static extern void WebViewPageLoadSignal_Disconnect(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2); - - [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_new_WebViewPageLoadErrorSignal_PageLoadError")] - public static extern global::System.IntPtr new_WebViewPageLoadErrorSignal_PageLoadError(global::System.Runtime.InteropServices.HandleRef jarg1); - - [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_delete_WebViewPageLoadErrorSignal")] - public static extern void delete_WebViewPageLoadErrorSignal(global::System.Runtime.InteropServices.HandleRef jarg1); - - [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebViewPageLoadErrorSignal_Connect")] - public static extern void WebViewPageLoadErrorSignal_Connect(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2); - - [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebViewPageLoadErrorSignal_Disconnect")] - public static extern void WebViewPageLoadErrorSignal_Disconnect(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2); - - [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_new_WebViewScrollEdgeReachedSignal_ScrollEdgeReached")] - public static extern global::System.IntPtr NewWebViewScrollEdgeReachedSignalScrollEdgeReached(global::System.Runtime.InteropServices.HandleRef jarg1); - - [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_delete_WebViewScrollEdgeReachedSignal")] - public static extern void DeleteWebViewScrollEdgeReachedSignal(global::System.Runtime.InteropServices.HandleRef jarg1); - - [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebViewScrollEdgeReachedSignal_Connect")] - public static extern void WebViewScrollEdgeReachedSignalConnect(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2); - - [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebViewScrollEdgeReachedSignal_Disconnect")] - public static extern void WebViewScrollEdgeReachedSignalDisconnect(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_GetPlainTextAsynchronously")] public static extern void GetPlainTextAsynchronously(global::System.Runtime.InteropServices.HandleRef webViewRef, global::System.Runtime.InteropServices.HandleRef callbackRef); diff --git a/src/Tizen.NUI/src/internal/WebFrame.cs b/src/Tizen.NUI/src/internal/WebFrame.cs new file mode 100755 index 000000000..ada7c2e0b --- /dev/null +++ b/src/Tizen.NUI/src/internal/WebFrame.cs @@ -0,0 +1,44 @@ +/* + * 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.ComponentModel; + +namespace Tizen.NUI +{ + /// + /// It is a class for frame of web view. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public class WebFrame : Disposable + { + internal WebFrame(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) + { + } + + /// + /// Checks whether the frame is main frame or not. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public bool IsMainFrame + { + get + { + return Interop.WebFrame.IsMainFrame(SwigCPtr); + } + } + } +} diff --git a/src/Tizen.NUI/src/internal/WebPolicyDecisionMaker.cs b/src/Tizen.NUI/src/internal/WebPolicyDecisionMaker.cs new file mode 100755 index 000000000..5b682f953 --- /dev/null +++ b/src/Tizen.NUI/src/internal/WebPolicyDecisionMaker.cs @@ -0,0 +1,239 @@ +/* + * 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 +{ + /// + /// It is a class for policy decision maker of web view. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public class WebPolicyDecisionMaker : Disposable + { + internal WebPolicyDecisionMaker(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) + { + } + + /// This will not be public opened. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr) + { + Interop.WebPolicyDecisionMaker.DeleteWebPolicyDecision(swigCPtr); + } + + /// + /// Decision type + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public enum DecisionType + { + /// + /// Accepts the decision. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + Use, + + /// + /// Decides to download something. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + Download, + + /// + /// Ignores the decision. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + Ignore, + } + + /// + /// Policy navigation type + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public enum NavigationType + { + /// + /// Link clicked + /// + [EditorBrowsable(EditorBrowsableState.Never)] + LinkClicked, + + /// + /// Form submitted + /// + [EditorBrowsable(EditorBrowsableState.Never)] + FormSubmitted, + + /// + /// Back forward + /// + [EditorBrowsable(EditorBrowsableState.Never)] + BackForward, + + /// + /// Reload + /// + [EditorBrowsable(EditorBrowsableState.Never)] + Reload, + + /// + /// Form resubmitted + /// + [EditorBrowsable(EditorBrowsableState.Never)] + FormResubmitted, + + /// + /// Other + /// + [EditorBrowsable(EditorBrowsableState.Never)] + Other, + } + + /// + /// Gets the URL that request policy decision. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public string Url + { + get + { + return Interop.WebPolicyDecisionMaker.GetUrl(SwigCPtr); + } + } + + /// + /// Gets a cookie that web page has. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public string Cookie + { + get + { + return Interop.WebPolicyDecisionMaker.GetCookie(SwigCPtr); + } + } + + /// + /// Gets a decision type. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public DecisionType PolicyDecisionType + { + get + { + return (DecisionType)Interop.WebPolicyDecisionMaker.GetDecisionType(SwigCPtr); + } + } + + /// + /// Gets a MIME type for response data. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public string ResponseMime + { + get + { + return Interop.WebPolicyDecisionMaker.GetResponseMime(SwigCPtr); + } + } + + /// + /// Gets a HTTP status code. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public int ResponseStatusCode + { + get + { + return Interop.WebPolicyDecisionMaker.GetResponseStatusCode(SwigCPtr); + } + } + + /// + /// Gets a navigation type. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public NavigationType DecisionNavigationType + { + get + { + return (NavigationType)Interop.WebPolicyDecisionMaker.GetNavigationType(SwigCPtr); + } + } + + /// + /// Gets frame of web view. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public WebFrame Frame + { + get + { + IntPtr result = Interop.WebPolicyDecisionMaker.GetFrame(SwigCPtr); + return new WebFrame(result, false); + } + } + + /// + /// Gets a scheme. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public string Scheme + { + get + { + return Interop.WebPolicyDecisionMaker.GetScheme(SwigCPtr); + } + } + + /// + /// Accepts the action which triggers this decision. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public bool Use() + { + bool result = Interop.WebPolicyDecisionMaker.Use(SwigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return result; + } + + /// + /// Ignores the action which triggers this decision. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public bool Ignore() + { + bool result = Interop.WebPolicyDecisionMaker.Ignore(SwigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return result; + } + + /// + /// Suspends the operation for policy decision. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public bool Suspend() + { + bool result = Interop.WebPolicyDecisionMaker.Suspend(SwigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return result; + } + } +} diff --git a/src/Tizen.NUI/src/internal/WebView.cs b/src/Tizen.NUI/src/internal/WebView.cs index 53aad81df..236ffe3e3 100755 --- a/src/Tizen.NUI/src/internal/WebView.cs +++ b/src/Tizen.NUI/src/internal/WebView.cs @@ -31,28 +31,32 @@ namespace Tizen.NUI public class WebView : View { [UnmanagedFunctionPointer(CallingConvention.StdCall)] - private delegate void WebViewPageLoadCallbackDelegate(IntPtr data, string pageUrl); + private delegate void WebViewPageLoadCallback(string pageUrl); [UnmanagedFunctionPointer(CallingConvention.StdCall)] - private delegate void WebViewPageLoadErrorCallbackDelegate(IntPtr data, string pageUrl, int errorCode); + private delegate void WebViewPageLoadErrorCallback(string pageUrl, int errorCode); [UnmanagedFunctionPointer(CallingConvention.StdCall)] - private delegate void WebViewScrollEdgeReachedCallbackDelegate(IntPtr data, int edge); + private delegate void WebViewScrollEdgeReachedCallback(int edge); + + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + private delegate void WebViewPolicyDecidedCallback(IntPtr maker); - private readonly WebViewPageLoadSignal pageLoadStartedSignal; private EventHandler pageLoadStartedEventHandler; - private WebViewPageLoadCallbackDelegate pageLoadStartedCallback; + private WebViewPageLoadCallback pageLoadStartedCallback; - private readonly WebViewPageLoadSignal pageLoadFinishedSignal; private EventHandler pageLoadFinishedEventHandler; - private WebViewPageLoadCallbackDelegate pageLoadFinishedCallback; + private WebViewPageLoadCallback pageLoadFinishedCallback; - private readonly WebViewPageLoadErrorSignal pageLoadErrorSignal; private EventHandler pageLoadErrorEventHandler; - private WebViewPageLoadErrorCallbackDelegate pageLoadErrorCallback; - private readonly WebViewScrollEdgeReachedSignal scrollEdgeReachedSignal; + private WebViewPageLoadErrorCallback pageLoadErrorCallback; + private EventHandler scrollEdgeReachedEventHandler; - private WebViewScrollEdgeReachedCallbackDelegate scrollEdgeReachedCallback; + private WebViewScrollEdgeReachedCallback scrollEdgeReachedCallback; + + private EventHandler navigationPolicyDecidedEventHandler; + private WebViewPolicyDecidedCallback navigationPolicyDecidedCallback; + private PlainTextReceivedCallback plainTextReceivedCallback; /// @@ -64,11 +68,6 @@ namespace Tizen.NUI internal WebView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.WebView.WebView_SWIGUpcast(cPtr), cMemoryOwn) { - pageLoadStartedSignal = new WebViewPageLoadSignal(Interop.WebView.new_WebViewPageLoadSignal_PageLoadStarted(swigCPtr)); - pageLoadFinishedSignal = new WebViewPageLoadSignal(Interop.WebView.new_WebViewPageLoadSignal_PageLoadFinished(swigCPtr)); - pageLoadErrorSignal = new WebViewPageLoadErrorSignal(Interop.WebView.new_WebViewPageLoadErrorSignal_PageLoadError(swigCPtr)); - scrollEdgeReachedSignal = new WebViewScrollEdgeReachedSignal(Interop.WebView.NewWebViewScrollEdgeReachedSignalScrollEdgeReached(swigCPtr)); - BackForwardList = new WebBackForwardList(Interop.WebView.GetWebBackForwardList(SwigCPtr), false); Context = new WebContext(Interop.WebView.GetWebContext(SwigCPtr), false); CookieManager = new WebCookieManager(Interop.WebView.GetWebCookieManager(SwigCPtr), false); @@ -110,10 +109,6 @@ namespace Tizen.NUI //Called by User //Release your own managed resources here. //You should release all of your own disposable objects here. - pageLoadStartedSignal.Dispose(); - pageLoadFinishedSignal.Dispose(); - pageLoadErrorSignal.Dispose(); - BackForwardList.Dispose(); Context.Dispose(); CookieManager.Dispose(); @@ -131,41 +126,45 @@ namespace Tizen.NUI Interop.WebView.delete_WebView(swigCPtr); } - private void OnPageLoadStarted(IntPtr data, string pageUrl) + private void OnPageLoadStarted(string pageUrl) { WebViewPageLoadEventArgs e = new WebViewPageLoadEventArgs(); - e.WebView = Registry.GetManagedBaseHandleFromNativePtr(data) as WebView; + e.WebView = this; e.PageUrl = pageUrl; pageLoadStartedEventHandler?.Invoke(this, e); } - private void OnPageLoadFinished(IntPtr data, string pageUrl) + private void OnPageLoadFinished(string pageUrl) { WebViewPageLoadEventArgs e = new WebViewPageLoadEventArgs(); - e.WebView = Registry.GetManagedBaseHandleFromNativePtr(data) as WebView; + e.WebView = this; e.PageUrl = pageUrl; pageLoadFinishedEventHandler?.Invoke(this, e); } - private void OnPageLoadError(IntPtr data, string pageUrl, int errorCode) + private void OnPageLoadError(string pageUrl, int errorCode) { WebViewPageLoadErrorEventArgs e = new WebViewPageLoadErrorEventArgs(); - e.WebView = Registry.GetManagedBaseHandleFromNativePtr(data) as WebView; + e.WebView = this; e.PageUrl = pageUrl; e.ErrorCode = (WebViewPageLoadErrorEventArgs.LoadErrorCode)errorCode; pageLoadErrorEventHandler?.Invoke(this, e); } - private void OnScrollEdgeReached(IntPtr data, int edge) + private void OnScrollEdgeReached(int edge) + { + scrollEdgeReachedEventHandler?.Invoke(this, new WebViewScrollEdgeReachedEventArgs((WebViewScrollEdgeReachedEventArgs.Edge)edge)); + } + + private void OnNavigationPolicyDecided(IntPtr maker) { - WebViewScrollEdgeReachedEventArgs arg = new WebViewScrollEdgeReachedEventArgs((WebViewScrollEdgeReachedEventArgs.Edge)edge); - scrollEdgeReachedEventHandler?.Invoke(this, arg); + navigationPolicyDecidedEventHandler?.Invoke(this, new WebViewPolicyDecidedEventArgs(new WebPolicyDecisionMaker(maker, true))); } internal static new class Property @@ -539,18 +538,15 @@ namespace Tizen.NUI { if (pageLoadStartedEventHandler == null) { - pageLoadStartedCallback = (OnPageLoadStarted); - pageLoadStartedSignal.Connect(pageLoadStartedCallback); + pageLoadStartedCallback = OnPageLoadStarted; + IntPtr ip = Marshal.GetFunctionPointerForDelegate(pageLoadStartedCallback); + Interop.WebView.RegisterPageLoadStartedCallback(SwigCPtr, new HandleRef(this, ip)); } pageLoadStartedEventHandler += value; } remove { pageLoadStartedEventHandler -= value; - if (pageLoadStartedEventHandler == null && pageLoadStartedCallback != null) - { - pageLoadStartedSignal.Disconnect(pageLoadStartedCallback); - } } } @@ -565,18 +561,15 @@ namespace Tizen.NUI { if (pageLoadFinishedEventHandler == null) { - pageLoadFinishedCallback = (OnPageLoadFinished); - pageLoadFinishedSignal.Connect(pageLoadFinishedCallback); + pageLoadFinishedCallback = OnPageLoadFinished; + IntPtr ip = Marshal.GetFunctionPointerForDelegate(pageLoadFinishedCallback); + Interop.WebView.RegisterPageLoadFinishedCallback(SwigCPtr, new HandleRef(this, ip)); } pageLoadFinishedEventHandler += value; } remove { pageLoadFinishedEventHandler -= value; - if (pageLoadFinishedEventHandler == null && pageLoadFinishedCallback != null) - { - pageLoadFinishedSignal.Disconnect(pageLoadFinishedCallback); - } } } @@ -589,20 +582,13 @@ namespace Tizen.NUI { add { - if (pageLoadErrorEventHandler == null) - { - pageLoadErrorCallback = (OnPageLoadError); - pageLoadErrorSignal.Connect(pageLoadErrorCallback); - } - pageLoadErrorEventHandler += value; + pageLoadErrorCallback = OnPageLoadError; + IntPtr ip = Marshal.GetFunctionPointerForDelegate(pageLoadErrorCallback); + Interop.WebView.RegisterPageLoadErrorCallback(SwigCPtr, new HandleRef(this, ip)); } remove { pageLoadErrorEventHandler -= value; - if (pageLoadErrorEventHandler == null && pageLoadErrorCallback != null) - { - pageLoadErrorSignal.Disconnect(pageLoadErrorCallback); - } } } @@ -615,20 +601,36 @@ namespace Tizen.NUI { add { - if (scrollEdgeReachedEventHandler == null) - { - scrollEdgeReachedCallback = OnScrollEdgeReached; - scrollEdgeReachedSignal.Connect(scrollEdgeReachedCallback); - } - scrollEdgeReachedEventHandler += value; + scrollEdgeReachedCallback = OnScrollEdgeReached; + IntPtr ip = Marshal.GetFunctionPointerForDelegate(scrollEdgeReachedCallback); + Interop.WebView.RegisterScrollEdgeReachedCallback(SwigCPtr, new HandleRef(this, ip)); } remove { scrollEdgeReachedEventHandler -= value; - if (scrollEdgeReachedEventHandler == null && scrollEdgeReachedCallback != null) + } + } + + /// + /// Event for the NavigationPolicyDecided signal which can be used to subscribe or unsubscribe the event handler.
+ /// This signal is emitted when response policy would be decided.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler NavigationPolicyDecided + { + add + { + if (navigationPolicyDecidedEventHandler == null) { - scrollEdgeReachedSignal.Disconnect(scrollEdgeReachedCallback); + navigationPolicyDecidedCallback = OnNavigationPolicyDecided; + IntPtr ip = Marshal.GetFunctionPointerForDelegate(navigationPolicyDecidedCallback); + Interop.WebView.RegisterNavigationPolicyDecidedCallback(SwigCPtr, new HandleRef(this, ip)); } + navigationPolicyDecidedEventHandler += value; + } + remove + { + navigationPolicyDecidedEventHandler -= value; } } diff --git a/src/Tizen.NUI/src/internal/WebViewPageLoadErrorSignal.cs b/src/Tizen.NUI/src/internal/WebViewPageLoadErrorSignal.cs deleted file mode 100755 index 8ace6d5f9..000000000 --- a/src/Tizen.NUI/src/internal/WebViewPageLoadErrorSignal.cs +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright(c) 2019 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. - * - */ - -namespace Tizen.NUI -{ - internal class WebViewPageLoadErrorSignal : Disposable - { - - - protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr) - { - Interop.WebView.delete_WebViewPageLoadErrorSignal(swigCPtr); - } - - public void Connect(System.Delegate func) - { - System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(func); - { - Interop.WebView.WebViewPageLoadErrorSignal_Connect(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip)); - if (NDalicPINVOKE.SWIGPendingException.Pending) - { - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - } - } - } - - public void Disconnect(System.Delegate func) - { - System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(func); - { - Interop.WebView.WebViewPageLoadErrorSignal_Disconnect(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip)); - if (NDalicPINVOKE.SWIGPendingException.Pending) - { - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - } - } - } - - public WebViewPageLoadErrorSignal(global::System.IntPtr cPtr) : base(cPtr, true) - { - } - } -} diff --git a/src/Tizen.NUI/src/internal/WebViewPageLoadSignal.cs b/src/Tizen.NUI/src/internal/WebViewPageLoadSignal.cs deleted file mode 100755 index 63875e51d..000000000 --- a/src/Tizen.NUI/src/internal/WebViewPageLoadSignal.cs +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright(c) 2019 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. - * - */ - -namespace Tizen.NUI -{ - internal class WebViewPageLoadSignal : Disposable - { - - - protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr) - { - Interop.WebView.delete_WebViewPageLoadSignal(swigCPtr); - } - - public void Connect(System.Delegate func) - { - System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(func); - { - Interop.WebView.WebViewPageLoadSignal_Connect(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip)); - if (NDalicPINVOKE.SWIGPendingException.Pending) - { - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - } - } - } - - public void Disconnect(System.Delegate func) - { - System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(func); - { - Interop.WebView.WebViewPageLoadSignal_Disconnect(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip)); - if (NDalicPINVOKE.SWIGPendingException.Pending) - { - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - } - } - } - - public WebViewPageLoadSignal(global::System.IntPtr cPtr) : base(cPtr, true) - { - } - } -} diff --git a/src/Tizen.NUI/src/internal/WebViewPolicyDecidedEventArgs.cs b/src/Tizen.NUI/src/internal/WebViewPolicyDecidedEventArgs.cs new file mode 100755 index 000000000..43e719b69 --- /dev/null +++ b/src/Tizen.NUI/src/internal/WebViewPolicyDecidedEventArgs.cs @@ -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 +{ + /// + /// Event arguments that passed via the WebView.ResponsePolicyDecided. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public class WebViewPolicyDecidedEventArgs : EventArgs + { + internal WebViewPolicyDecidedEventArgs(WebPolicyDecisionMaker maker) + { + ResponsePolicyDecisionMaker = maker; + } + + /// + /// The response policy decision maker. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public WebPolicyDecisionMaker ResponsePolicyDecisionMaker { get; } + } +} diff --git a/src/Tizen.NUI/src/internal/WebViewScrollEdgeReachedSignal.cs b/src/Tizen.NUI/src/internal/WebViewScrollEdgeReachedSignal.cs deleted file mode 100755 index d04c921bf..000000000 --- a/src/Tizen.NUI/src/internal/WebViewScrollEdgeReachedSignal.cs +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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. - * - */ - -namespace Tizen.NUI -{ - internal class WebViewScrollEdgeReachedSignal : Disposable - { - public WebViewScrollEdgeReachedSignal(global::System.IntPtr cPtr) : base(cPtr, true) - { - } - - public void Connect(System.Delegate func) - { - System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(func); - { - Interop.WebView.WebViewScrollEdgeReachedSignalConnect(SwigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip)); - if (NDalicPINVOKE.SWIGPendingException.Pending) - { - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - } - } - } - - public void Disconnect(System.Delegate func) - { - System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(func); - { - Interop.WebView.WebViewScrollEdgeReachedSignalDisconnect(SwigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip)); - if (NDalicPINVOKE.SWIGPendingException.Pending) - { - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - } - } - } - - protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr) - { - Interop.WebView.DeleteWebViewScrollEdgeReachedSignal(swigCPtr); - } - } -} diff --git a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/WebViewNavigationPolicyTest.cs b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/WebViewNavigationPolicyTest.cs new file mode 100755 index 000000000..6e55f0370 --- /dev/null +++ b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/WebViewNavigationPolicyTest.cs @@ -0,0 +1,60 @@ + +using System; +using Tizen.NUI; +using Tizen.NUI.BaseComponents; +using Tizen.NUI.Components; +using System.IO; +using System.Text; + +namespace Tizen.NUI.Samples +{ + using tlog = Tizen.Log; + + public class WebViewInterceptTest : IExample + { + const string tag = "NUITEST"; + private View root; + private Window win; + private WebView webView; + + public void Activate() + { + win = NUIApplication.GetDefaultWindow(); + + root = new View() + { + Size = new Size(win.Size.Width, win.Size.Height, 0), + BackgroundColor = Color.Green, + Layout = new LinearLayout() + { + LinearOrientation = LinearLayout.Orientation.Vertical, + Padding = new Extents(3, 3, 3, 3), + }, + }; + win.Add(root); + + webView = new WebView(); + webView.Url = "https://www.google.com/"; + webView.WidthSpecification = LayoutParamPolicies.MatchParent; + webView.HeightSpecification = LayoutParamPolicies.MatchParent; + root.Add(webView); + + webView.NavigationPolicyDecided += OnCallback; + } + + private void OnCallback(object sender, WebViewPolicyDecidedEventArgs e) + { + tlog.Debug(tag, $"callback: navigation policy decided, Url: {e.ResponsePolicyDecisionMaker.Url}"); + e.ResponsePolicyDecisionMaker.Ignore(); + } + + public void Deactivate() + { + webView.Unparent(); + root.Unparent(); + + webView.Dispose(); + root.Dispose(); + } + } +} -- 2.34.1