[WebView] [TCSACR-219] Adds WebView.BackForwardList (#620)
authorBasavarajPS <45586075+BasavarajPS@users.noreply.github.com>
Mon, 15 Apr 2019 23:27:49 +0000 (04:57 +0530)
committeryounghajung <35090305+younghajung@users.noreply.github.com>
Mon, 15 Apr 2019 23:27:49 +0000 (08:27 +0900)
Signed-off-by: basavarajps <basavaraj.ps@samsung.com>
src/Tizen.WebView/Interop/Interop.ChromiumEwk.BackForwardList.cs [new file with mode: 0644]
src/Tizen.WebView/Interop/Interop.ChromiumEwk.View.cs
src/Tizen.WebView/Interop/Interop.Eina.cs [new file with mode: 0644]
src/Tizen.WebView/Interop/Interop.Libraries.cs
src/Tizen.WebView/Tizen.WebView/BackForwardList.cs [new file with mode: 0644]
src/Tizen.WebView/Tizen.WebView/WebView.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 (file)
index 0000000..4735929
--- /dev/null
@@ -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);
+    }
+}
index 75a50cc..8ff9607 100644 (file)
@@ -31,6 +31,12 @@ internal static partial class Interop
         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 (file)
index 0000000..4c49d47
--- /dev/null
@@ -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);
+    }
+}
index 7dab1c4..e4e8417 100644 (file)
@@ -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 (file)
index 0000000..49dda74
--- /dev/null
@@ -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
+{
+    /// <summary>
+    /// This class provides the properties of Back Forward list item of a specific WebView.
+    /// </summary>
+    /// <since_tizen> 6 </since_tizen>
+    public class BackForwardListItem
+    {
+        private IntPtr _item_handle;
+
+        /// <summary>
+        /// Creates a Back Forward List Item object.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        internal BackForwardListItem(IntPtr handle)
+        {
+            _item_handle = handle;
+        }
+
+        /// <summary>
+        /// Url of the back forward list item.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public string Url
+        {
+            get
+            {
+                return Interop.ChromiumEwk.ewk_back_forward_list_item_url_get(_item_handle);
+            }
+        }
+
+        /// <summary>
+        /// Title of the back forward list item.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public string Title
+        {
+            get
+            {
+                return Interop.ChromiumEwk.ewk_back_forward_list_item_title_get(_item_handle);
+            }
+        }
+
+        /// <summary>
+        /// Original Url of the back forward list item.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public string OriginalUrl
+        {
+            get
+            {
+                return Interop.ChromiumEwk.ewk_back_forward_list_item_original_url_get(_item_handle);
+            }
+        }
+    }
+
+    /// <summary>
+    /// This class provides the properties of Back Forward list of a specific WebView.
+    /// </summary>
+    /// <since_tizen> 6 </since_tizen>
+    public class BackForwardList
+    {
+        private IntPtr _list_handle;
+
+        /// <summary>
+        /// Creates a Back Forward List object.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        internal BackForwardList(IntPtr handle)
+        {
+            _list_handle = handle;
+        }
+
+        /// <summary>
+        /// Current item of the back forward list.
+        /// </summary>
+        /// <remarks>
+        /// BackForward List can be null if there is no current item.
+        /// </remarks>
+        /// <since_tizen> 6 </since_tizen>
+        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;
+                }
+            }
+        }
+
+        /// <summary>
+        /// Previous item of the back forward list and null if no previous item.
+        /// </summary>
+        /// <remarks>
+        /// BackForward List can be null if there is no previous item.
+        /// </remarks>
+        /// <since_tizen> 6 </since_tizen>
+        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;
+                }
+            }
+        }
+
+        /// <summary>
+        /// Gets the back forward list count.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public uint Count
+        {
+            get
+            {
+                return Interop.ChromiumEwk.ewk_back_forward_list_count(_list_handle);
+            }
+        }
+        /// <summary>
+        /// Gets the list containing the items preceding the current item
+        /// limited by limit.
+        /// </summary>
+        /// <param name="limit"> limit The number of items to retrieve, if limit -1 all items preceding current item are returned.</param>
+        /// <returns>The list of the BackForwardListItem of back items.</returns>
+        /// <since_tizen> 6 </since_tizen>
+        public IList<BackForwardListItem> BackItems(int limit)
+        {
+            IntPtr backList = Interop.ChromiumEwk.ewk_back_forward_list_n_back_items_copy(_list_handle, limit);
+            List<BackForwardListItem> backItemsList = new List<BackForwardListItem>();
+
+            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;
+        }
+
+        /// <summary>
+        /// Gets the list containing the items following the current item
+        /// limited by limit.
+        /// </summary>
+        /// <param name="limit"> limit The number of items to retrieve, if limit is -1 all items following current item are returned.</param>
+        /// <returns>The list of the BackForwardListItem of forward items.</returns>
+        /// <since_tizen> 6 </since_tizen>
+        public IList<BackForwardListItem> ForwardItems(int limit)
+        {
+            IntPtr forwardList = Interop.ChromiumEwk.ewk_back_forward_list_n_forward_items_copy(_list_handle, limit);
+            List<BackForwardListItem> forwardItemsList = new List<BackForwardListItem>();
+
+            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;
+        }
+    }
+}
index 80de63b..5a11337 100644 (file)
@@ -179,6 +179,30 @@ namespace Tizen.WebView
         }
 
         /// <summary>
+        /// Gets the back/forward list object of this view.
+        /// </summary>
+        /// <returns>The BackForward List object of this view.</returns>
+        /// <since_tizen> 6 </since_tizen>
+        public BackForwardList GetBackForwardList()
+        {
+            IntPtr backforwardlistHandle = Interop.ChromiumEwk.ewk_view_back_forward_list_get(_realHandle);
+            if (backforwardlistHandle == IntPtr.Zero)
+            {
+                return null;
+            }
+            return new BackForwardList(backforwardlistHandle);
+        }
+
+        /// <summary>
+        /// Clear the back/forward list object of this view.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public void ClearBackForwardList()
+        {
+            Interop.ChromiumEwk.ewk_view_back_forward_list_clear(_realHandle);
+        }
+
+        /// <summary>
         /// Asks the object to load the given URL.
         /// </summary>
         /// <remarks>