From cc804636757e534df2cf653d4e8e8bac8ed042d9 Mon Sep 17 00:00:00 2001 From: BasavarajPS <45586075+BasavarajPS@users.noreply.github.com> Date: Tue, 16 Apr 2019 04:57:49 +0530 Subject: [PATCH] [WebView] [TCSACR-219] Adds WebView.BackForwardList (#620) Signed-off-by: basavarajps --- .../Interop.ChromiumEwk.BackForwardList.cs | 63 ++++++ .../Interop/Interop.ChromiumEwk.View.cs | 6 + src/Tizen.WebView/Interop/Interop.Eina.cs | 30 +++ .../Interop/Interop.Libraries.cs | 1 + .../Tizen.WebView/BackForwardList.cs | 192 ++++++++++++++++++ src/Tizen.WebView/Tizen.WebView/WebView.cs | 24 +++ 6 files changed, 316 insertions(+) create mode 100644 src/Tizen.WebView/Interop/Interop.ChromiumEwk.BackForwardList.cs create mode 100644 src/Tizen.WebView/Interop/Interop.Eina.cs create mode 100644 src/Tizen.WebView/Tizen.WebView/BackForwardList.cs diff --git a/src/Tizen.WebView/Interop/Interop.ChromiumEwk.BackForwardList.cs b/src/Tizen.WebView/Interop/Interop.ChromiumEwk.BackForwardList.cs new file mode 100644 index 000000000..4735929b3 --- /dev/null +++ b/src/Tizen.WebView/Interop/Interop.ChromiumEwk.BackForwardList.cs @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2018 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; + +internal static partial class Interop +{ + internal static partial class ChromiumEwk + { + [DllImport(Libraries.ChromiumEwk, EntryPoint = "ewk_back_forward_list_item_url_get", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)] + internal static extern IntPtr _ewk_back_forward_list_item_url_get(IntPtr obj); + internal static string ewk_back_forward_list_item_url_get(IntPtr obj) + { + IntPtr ptr = _ewk_back_forward_list_item_url_get(obj); + return Marshal.PtrToStringAnsi(ptr); + } + + [DllImport(Libraries.ChromiumEwk, EntryPoint = "ewk_back_forward_list_item_title_get", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)] + internal static extern IntPtr _ewk_back_forward_list_item_title_get(IntPtr obj); + internal static string ewk_back_forward_list_item_title_get(IntPtr obj) + { + IntPtr ptr = _ewk_back_forward_list_item_title_get(obj); + return Marshal.PtrToStringAnsi(ptr); + } + + [DllImport(Libraries.ChromiumEwk, EntryPoint = "ewk_back_forward_list_item_original_url_get", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)] + internal static extern IntPtr _ewk_back_forward_list_item_original_url_get(IntPtr obj); + internal static string ewk_back_forward_list_item_original_url_get(IntPtr obj) + { + IntPtr ptr = _ewk_back_forward_list_item_original_url_get(obj); + return Marshal.PtrToStringAnsi(ptr); + } + + [DllImport(Libraries.ChromiumEwk)] + internal static extern IntPtr ewk_back_forward_list_current_item_get(IntPtr backforwardlist); + + [DllImport(Libraries.ChromiumEwk)] + internal static extern IntPtr ewk_back_forward_list_previous_item_get(IntPtr backforwardlist); + + [DllImport(Libraries.ChromiumEwk)] + internal static extern uint ewk_back_forward_list_count(IntPtr backforwardlist); + + [DllImport(Libraries.ChromiumEwk)] + internal static extern IntPtr ewk_back_forward_list_n_back_items_copy(IntPtr backforwardlist, int limit); + + [DllImport(Libraries.ChromiumEwk)] + internal static extern IntPtr ewk_back_forward_list_n_forward_items_copy(IntPtr backforwardlist, int limit); + } +} diff --git a/src/Tizen.WebView/Interop/Interop.ChromiumEwk.View.cs b/src/Tizen.WebView/Interop/Interop.ChromiumEwk.View.cs index 75a50ccc8..8ff960777 100644 --- a/src/Tizen.WebView/Interop/Interop.ChromiumEwk.View.cs +++ b/src/Tizen.WebView/Interop/Interop.ChromiumEwk.View.cs @@ -30,6 +30,12 @@ internal static partial class Interop [DllImport(Libraries.ChromiumEwk)] internal static extern IntPtr ewk_view_settings_get(IntPtr obj); + [DllImport(Libraries.ChromiumEwk)] + internal static extern IntPtr ewk_view_back_forward_list_get(IntPtr obj); + + [DllImport(Libraries.ChromiumEwk)] + internal static extern void ewk_view_back_forward_list_clear(IntPtr obj); + [DllImport(Libraries.ChromiumEwk)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool ewk_view_url_set(IntPtr obj, string url); diff --git a/src/Tizen.WebView/Interop/Interop.Eina.cs b/src/Tizen.WebView/Interop/Interop.Eina.cs new file mode 100644 index 000000000..4c49d4701 --- /dev/null +++ b/src/Tizen.WebView/Interop/Interop.Eina.cs @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2018 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; + +internal static partial class Interop +{ + internal static partial class Eina + { + [DllImport(Libraries.Eina)] + internal static extern uint eina_list_count(IntPtr list); + + [DllImport(Libraries.Eina)] + internal static extern IntPtr eina_list_nth(IntPtr list, uint n); + } +} diff --git a/src/Tizen.WebView/Interop/Interop.Libraries.cs b/src/Tizen.WebView/Interop/Interop.Libraries.cs index 7dab1c45a..e4e8417e9 100644 --- a/src/Tizen.WebView/Interop/Interop.Libraries.cs +++ b/src/Tizen.WebView/Interop/Interop.Libraries.cs @@ -20,5 +20,6 @@ internal static partial class Interop internal const string ChromiumEwk = "libchromium-ewk.so"; internal const string Elementary = "libelementary.so.1"; internal const string Evas = "libevas.so.1"; + internal const string Eina = "libeina.so.1"; } } diff --git a/src/Tizen.WebView/Tizen.WebView/BackForwardList.cs b/src/Tizen.WebView/Tizen.WebView/BackForwardList.cs new file mode 100644 index 000000000..49dda74f6 --- /dev/null +++ b/src/Tizen.WebView/Tizen.WebView/BackForwardList.cs @@ -0,0 +1,192 @@ +/* + * Copyright (c) 2018 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.Collections; +using System.ComponentModel; +using System.Collections.Generic; + +namespace Tizen.WebView +{ + /// + /// This class provides the properties of Back Forward list item of a specific WebView. + /// + /// 6 + public class BackForwardListItem + { + private IntPtr _item_handle; + + /// + /// Creates a Back Forward List Item object. + /// + /// 6 + internal BackForwardListItem(IntPtr handle) + { + _item_handle = handle; + } + + /// + /// Url of the back forward list item. + /// + /// 6 + public string Url + { + get + { + return Interop.ChromiumEwk.ewk_back_forward_list_item_url_get(_item_handle); + } + } + + /// + /// Title of the back forward list item. + /// + /// 6 + public string Title + { + get + { + return Interop.ChromiumEwk.ewk_back_forward_list_item_title_get(_item_handle); + } + } + + /// + /// Original Url of the back forward list item. + /// + /// 6 + public string OriginalUrl + { + get + { + return Interop.ChromiumEwk.ewk_back_forward_list_item_original_url_get(_item_handle); + } + } + } + + /// + /// This class provides the properties of Back Forward list of a specific WebView. + /// + /// 6 + public class BackForwardList + { + private IntPtr _list_handle; + + /// + /// Creates a Back Forward List object. + /// + /// 6 + internal BackForwardList(IntPtr handle) + { + _list_handle = handle; + } + + /// + /// Current item of the back forward list. + /// + /// + /// BackForward List can be null if there is no current item. + /// + /// 6 + public BackForwardListItem CurrentItem + { + get + { + IntPtr itemPtr = Interop.ChromiumEwk.ewk_back_forward_list_current_item_get(_list_handle); + if(itemPtr != null) { + BackForwardListItem item = new BackForwardListItem(itemPtr); + return item; + } + else { + return null; + } + } + } + + /// + /// Previous item of the back forward list and null if no previous item. + /// + /// + /// BackForward List can be null if there is no previous item. + /// + /// 6 + public BackForwardListItem PreviousItem + { + get + { + IntPtr itemPtr = Interop.ChromiumEwk.ewk_back_forward_list_previous_item_get(_list_handle); + if(itemPtr != null) { + BackForwardListItem item = new BackForwardListItem(itemPtr); + return item; + } + else { + return null; + } + } + } + + /// + /// Gets the back forward list count. + /// + /// 6 + public uint Count + { + get + { + return Interop.ChromiumEwk.ewk_back_forward_list_count(_list_handle); + } + } + /// + /// Gets the list containing the items preceding the current item + /// limited by limit. + /// + /// limit The number of items to retrieve, if limit -1 all items preceding current item are returned. + /// The list of the BackForwardListItem of back items. + /// 6 + public IList BackItems(int limit) + { + IntPtr backList = Interop.ChromiumEwk.ewk_back_forward_list_n_back_items_copy(_list_handle, limit); + List backItemsList = new List(); + + uint count = Interop.Eina.eina_list_count(backList); + + for(uint i=0; i < count; i++) { + IntPtr data = Interop.Eina.eina_list_nth(backList, i); + backItemsList.Add(new BackForwardListItem(data)); + } + return backItemsList; + } + + /// + /// Gets the list containing the items following the current item + /// limited by limit. + /// + /// limit The number of items to retrieve, if limit is -1 all items following current item are returned. + /// The list of the BackForwardListItem of forward items. + /// 6 + public IList ForwardItems(int limit) + { + IntPtr forwardList = Interop.ChromiumEwk.ewk_back_forward_list_n_forward_items_copy(_list_handle, limit); + List forwardItemsList = new List(); + + uint count = Interop.Eina.eina_list_count(forwardList); + + for(uint i = 0; i < count; i++) { + IntPtr data = Interop.Eina.eina_list_nth(forwardList, i); + forwardItemsList.Add(new BackForwardListItem(data)); + } + return forwardItemsList; + } + } +} diff --git a/src/Tizen.WebView/Tizen.WebView/WebView.cs b/src/Tizen.WebView/Tizen.WebView/WebView.cs index 80de63b23..5a11337ab 100644 --- a/src/Tizen.WebView/Tizen.WebView/WebView.cs +++ b/src/Tizen.WebView/Tizen.WebView/WebView.cs @@ -178,6 +178,30 @@ namespace Tizen.WebView return _settings; } + /// + /// Gets the back/forward list object of this view. + /// + /// The BackForward List object of this view. + /// 6 + public BackForwardList GetBackForwardList() + { + IntPtr backforwardlistHandle = Interop.ChromiumEwk.ewk_view_back_forward_list_get(_realHandle); + if (backforwardlistHandle == IntPtr.Zero) + { + return null; + } + return new BackForwardList(backforwardlistHandle); + } + + /// + /// Clear the back/forward list object of this view. + /// + /// 6 + public void ClearBackForwardList() + { + Interop.ChromiumEwk.ewk_view_back_forward_list_clear(_realHandle); + } + /// /// Asks the object to load the given URL. /// -- 2.34.1