[NUI] Replace XXXList with IList<XXX>. (#3468)
authorhuayongxu <49056704+huayongxu@users.noreply.github.com>
Tue, 31 Aug 2021 05:57:06 +0000 (13:57 +0800)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Wed, 1 Sep 2021 08:20:01 +0000 (17:20 +0900)
src/Tizen.NUI/src/internal/WebView/WebBackForwardList.cs
src/Tizen.NUI/src/internal/WebView/WebContext.cs
src/Tizen.NUI/src/internal/WebView/WebPasswordDataList.cs
src/Tizen.NUI/src/internal/WebView/WebSecurityOriginList.cs
src/Tizen.NUI/src/internal/WebView/WebView.cs

index f799c7e..1bfcb83 100755 (executable)
@@ -15,7 +15,7 @@
  *
  */
 
-using System;
+using System.Collections.Generic;
 using System.ComponentModel;
 
 namespace Tizen.NUI
@@ -73,54 +73,45 @@ namespace Tizen.NUI
     }
 
     /// <summary>
-    /// WebBackForwardSubList is a class for back-forward copied list item of web view.
+    /// WebBackForwardList is a class for back-forward list of web view.
     /// </summary>
     [EditorBrowsable(EditorBrowsableState.Never)]
-    public class WebBackForwardSubList : Disposable
+    public class WebBackForwardList : Disposable
     {
-        internal WebBackForwardSubList(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
-        {
-        }
+        private WebBackForwardSubList backwardItemList = null;
+        private WebBackForwardSubList forwardItemList = null;
 
-        protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
+        internal WebBackForwardList(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
         {
-            Interop.WebBackForwardSubList.DeleteCopiedItems(swigCPtr);
         }
 
         /// <summary>
-        /// Get item count.
+        /// Dispose for IDisposable pattern
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public uint ItemCount
+        protected override void Dispose(DisposeTypes type)
         {
-            get
+            if (Disposed)
             {
-                return Interop.WebBackForwardSubList.GetItemCount(SwigCPtr);
+                return;
             }
-        }
 
-        /// <summary>
-        /// Get item with index.
-        /// </summary>
-        /// <param name="index">The index of list item.</param>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public WebBackForwardListItem GetItemAtIndex(uint index)
-        {
-            System.IntPtr itemPtr = Interop.WebBackForwardSubList.GetItemAtIndex(SwigCPtr, index);
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            WebBackForwardListItem ret = new WebBackForwardListItem(itemPtr, false);
-            return ret;
-        }
-    }
+            if (type == DisposeTypes.Explicit)
+            {
+                //Called by User
+                //Release your own managed resources here.
+                //You should release all of your own disposable objects here.
+                if (backwardItemList != null)
+                {
+                    backwardItemList.Dispose();
+                }
+                if (forwardItemList != null)
+                {
+                    forwardItemList.Dispose();
+                }
+            }
 
-    /// <summary>
-    /// WebBackForwardList is a class for back-forward list of web view.
-    /// </summary>
-    [EditorBrowsable(EditorBrowsableState.Never)]
-    public class WebBackForwardList : Disposable
-    {
-        internal WebBackForwardList(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
-        {
+            base.Dispose(type);
         }
 
         /// <summary>
@@ -143,8 +134,7 @@ namespace Tizen.NUI
         {
             System.IntPtr itemPtr = Interop.WebBackForwardList.GetCurrentItem(SwigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            WebBackForwardListItem ret = new WebBackForwardListItem(itemPtr, true);
-            return ret;
+            return new WebBackForwardListItem(itemPtr, true);
         }
 
         /// <summary>
@@ -155,8 +145,7 @@ namespace Tizen.NUI
         {
             System.IntPtr itemPtr = Interop.WebBackForwardList.GetPreviousItem(SwigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            WebBackForwardListItem ret = new WebBackForwardListItem(itemPtr, true);
-            return ret;
+            return new WebBackForwardListItem(itemPtr, true);
         }
 
         /// <summary>
@@ -167,8 +156,7 @@ namespace Tizen.NUI
         {
             System.IntPtr itemPtr = Interop.WebBackForwardList.GetNextItem(SwigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            WebBackForwardListItem ret = new WebBackForwardListItem(itemPtr, true);
-            return ret;
+            return new WebBackForwardListItem(itemPtr, true);
         }
 
         /// <summary>
@@ -180,35 +168,96 @@ namespace Tizen.NUI
         {
             System.IntPtr itemPtr = Interop.WebBackForwardList.GetItemAtIndex(SwigCPtr, index);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            WebBackForwardListItem ret = new WebBackForwardListItem(itemPtr, true);
-            return ret;
+            return new WebBackForwardListItem(itemPtr, true);
         }
 
         /// <summary>
-        /// Get copied backward items.
+        /// Get copied backward items preceding the current item and limited by limit.
+        /// Item in returned list starts with the oldest one.
+        /// If limit is equal to ItemCount - 1, all the items preceding the current item are returned.
         /// </summary>
-        /// <param name="index">limit The number of items to retrieve.</param>
+        /// <param name="limit">The number of items to retrieve.</param>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public WebBackForwardSubList GetBackwardItems(int index)
+        public IList<WebBackForwardListItem> GetBackwardItems(int limit)
         {
-            System.IntPtr itemPtr = Interop.WebBackForwardList.GetBackwardItems(SwigCPtr, index);
+            System.IntPtr itemPtr = Interop.WebBackForwardList.GetBackwardItems(SwigCPtr, limit);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            WebBackForwardSubList ret = new WebBackForwardSubList(itemPtr, true);
-            return ret;
+
+            if (backwardItemList != null)
+            {
+                backwardItemList.Dispose();
+            }
+            backwardItemList = new WebBackForwardSubList(itemPtr, true);
+
+            List<WebBackForwardListItem> list = new List<WebBackForwardListItem>();
+            for (uint i = 0; i < backwardItemList.ItemCount; i++)
+            {
+                list.Add(backwardItemList.GetItemAtIndex(i));
+            }
+            return list;
         }
 
         /// <summary>
-        /// Get copied forward items.
+        /// Get copied forward items following the current item and limited by limit.
+        /// Item in returned list starts with the oldest one.
+        /// If limit is equal to ItemCount - 1, all the items preceding the current item are returned.
         /// </summary>
-        /// <param name="index">limit The number of items to retrieve.</param>
+        /// <param name="limit">The number of items to retrieve.</param>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public WebBackForwardSubList GetForwardItems(int index)
+        public IList<WebBackForwardListItem> GetForwardItems(int limit)
         {
-            System.IntPtr itemPtr = Interop.WebBackForwardList.GetBackwardItems(SwigCPtr, index);
+            System.IntPtr itemPtr = Interop.WebBackForwardList.GetBackwardItems(SwigCPtr, limit);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            WebBackForwardSubList ret = new WebBackForwardSubList(itemPtr, true);
-            return ret;
+
+            if (forwardItemList != null)
+            {
+                forwardItemList.Dispose();
+            }
+            forwardItemList = new WebBackForwardSubList(itemPtr, true);
+
+            List<WebBackForwardListItem> list = new List<WebBackForwardListItem>();
+            for (uint i = 0; i < forwardItemList.ItemCount; i++)
+            {
+                list.Add(forwardItemList.GetItemAtIndex(i));
+            }
+            return list;
         }
     }
-}
 
+    /// <summary>
+    /// WebBackForwardSubList is an internal class for back-forward copied list item of web view.
+    /// </summary>
+    internal class WebBackForwardSubList : Disposable
+    {
+        internal WebBackForwardSubList(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
+        {
+        }
+
+        protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
+        {
+            Interop.WebBackForwardSubList.DeleteCopiedItems(swigCPtr);
+        }
+
+        /// <summary>
+        /// Get item count.
+        /// </summary>
+        internal uint ItemCount
+        {
+            get
+            {
+                return Interop.WebBackForwardSubList.GetItemCount(SwigCPtr);
+            }
+        }
+
+        /// <summary>
+        /// Get item with index.
+        /// </summary>
+        /// <param name="index">The index of list item.</param>
+        internal WebBackForwardListItem GetItemAtIndex(uint index)
+        {
+            System.IntPtr itemPtr = Interop.WebBackForwardSubList.GetItemAtIndex(SwigCPtr, index);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return new WebBackForwardListItem(itemPtr, false);
+        }
+    }
+}
index 68df524..0f4b942 100755 (executable)
@@ -16,6 +16,7 @@
  */
 
 using System;
+using System.Collections.Generic;
 using System.ComponentModel;
 using System.Runtime.InteropServices;
 
@@ -31,8 +32,10 @@ namespace Tizen.NUI
         private string appVersion;
         private float timeOffset;
         private ApplicationType applicationType;
-        private SecurityOriginListAcquiredCallback securityOriginListAcquiredCallback;
+        private WebSecurityOriginList securityOriginList;
+        private SecurityOriginListAcquiredCallback securityOriginsAcquiredCallback;
         private readonly WebContextSecurityOriginListAcquiredProxyCallback securityOriginListAcquiredProxyCallback;
+        private WebPasswordDataList passwordList;
         private PasswordDataListAcquiredCallback passwordDataListAcquiredCallback;
         private readonly WebContextPasswordDataListAcquiredProxyCallback passwordDataListAcquiredProxyCallback;
 
@@ -43,11 +46,40 @@ namespace Tizen.NUI
         }
 
         /// <summary>
+        /// Dispose for IDisposable pattern
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected override void Dispose(DisposeTypes type)
+        {
+            if (Disposed)
+            {
+                return;
+            }
+
+            if (type == DisposeTypes.Explicit)
+            {
+                //Called by User
+                //Release your own managed resources here.
+                //You should release all of your own disposable objects here.
+                if (passwordList != null)
+                {
+                    passwordList.Dispose();
+                }
+                if (securityOriginList != null)
+                {
+                    securityOriginList.Dispose();
+                }
+            }
+
+            base.Dispose(type);
+        }
+
+        /// <summary>
         /// The callback function that is invoked when security origin list is acquired.
         /// </summary>
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public delegate void SecurityOriginListAcquiredCallback(WebSecurityOriginList list);
+        public delegate void SecurityOriginListAcquiredCallback(IList<WebSecurityOrigin> list);
 
         /// <summary>
         /// The callback function that is invoked when storage usage is acquired.
@@ -57,11 +89,11 @@ namespace Tizen.NUI
         public delegate void StorageUsageAcquiredCallback(ulong usage);
 
         /// <summary>
-        /// The callback function that is invoked when security origin list is acquired.
+        /// The callback function that is invoked when password data list is acquired.
         /// </summary>
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public delegate void PasswordDataListAcquiredCallback(WebPasswordDataList list);
+        public delegate void PasswordDataListAcquiredCallback(IList<WebPasswordData> list);
 
         /// <summary>
         /// The callback function that is invoked when download is started.
@@ -350,7 +382,7 @@ namespace Tizen.NUI
         [EditorBrowsable(EditorBrowsableState.Never)]
         public bool GetWebDatabaseOrigins(SecurityOriginListAcquiredCallback callback)
         {
-            securityOriginListAcquiredCallback = callback;
+            securityOriginsAcquiredCallback = callback;
             IntPtr ip = Marshal.GetFunctionPointerForDelegate(securityOriginListAcquiredProxyCallback);
             bool result = Interop.WebContext.GetWebDatabaseOrigins(SwigCPtr, new HandleRef(this, ip));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
@@ -376,7 +408,7 @@ namespace Tizen.NUI
         [EditorBrowsable(EditorBrowsableState.Never)]
         public bool GetWebStorageOrigins(SecurityOriginListAcquiredCallback callback)
         {
-            securityOriginListAcquiredCallback = callback;
+            securityOriginsAcquiredCallback = callback;
             IntPtr ip = Marshal.GetFunctionPointerForDelegate(securityOriginListAcquiredProxyCallback);
             bool result = Interop.WebContext.GetWebStorageOrigins(SwigCPtr, new HandleRef(this, ip));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
@@ -629,18 +661,34 @@ namespace Tizen.NUI
             return ret;
         }
 
-        private void OnSecurityOriginListAcquired(IntPtr list)
+        private void OnSecurityOriginListAcquired(IntPtr alist)
         {
-            WebSecurityOriginList originList = new WebSecurityOriginList(list, true);
-            securityOriginListAcquiredCallback?.Invoke(originList);
-            originList.Dispose();
+            if (securityOriginList != null)
+            {
+                securityOriginList.Dispose();
+            }
+            securityOriginList = new WebSecurityOriginList(alist, true);
+            List<WebSecurityOrigin> originList = new List<WebSecurityOrigin>();
+            for (uint i = 0; i < securityOriginList.ItemCount; i++)
+            {
+                originList.Add(securityOriginList.GetItemAtIndex(i));
+            }
+            securityOriginsAcquiredCallback?.Invoke(originList);
         }
 
-        private void OnPasswordDataListAcquired(IntPtr list)
+        private void OnPasswordDataListAcquired(IntPtr alist)
         {
-            WebPasswordDataList passwordList = new WebPasswordDataList(list, true);
-            passwordDataListAcquiredCallback?.Invoke(passwordList);
-            passwordList.Dispose();
+            if (passwordList != null)
+            {
+                passwordList.Dispose();
+            }
+            passwordList = new WebPasswordDataList(alist, true);
+            List<WebPasswordData> passwordDataList = new List<WebPasswordData>();
+            for(uint i = 0; i < passwordList.ItemCount; i++)
+            {
+                passwordDataList.Add(passwordList.GetItemAtIndex(i));
+            }
+            passwordDataListAcquiredCallback?.Invoke(passwordDataList);
         }
     }
 }
index e05cac1..40c24a1 100755 (executable)
@@ -21,10 +21,9 @@ using System.ComponentModel;
 namespace Tizen.NUI
 {
     /// <summary>
-    /// It is a class for password data list of web view.
+    /// It is an internal class for password data list of web view.
     /// </summary>
-    [EditorBrowsable(EditorBrowsableState.Never)]
-    public class WebPasswordDataList : Disposable
+    internal class WebPasswordDataList : Disposable
     {
         internal WebPasswordDataList(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
         {
@@ -32,7 +31,6 @@ namespace Tizen.NUI
 
         /// This will not be public opened.
         /// <param name="swigCPtr"></param>
-        [EditorBrowsable(EditorBrowsableState.Never)]
         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
         {
             Interop.WebPasswordDataList.DeleteWebPasswordDataList(swigCPtr);
@@ -41,8 +39,7 @@ namespace Tizen.NUI
         /// <summary>
         /// Count of password data list.
         /// </summary>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public uint ItemCount
+        internal uint ItemCount
         {
             get
             {
@@ -54,11 +51,10 @@ namespace Tizen.NUI
         /// Gets password data by index.
         /// <param name="index">index of list</param>
         /// </summary>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public WebPasswordData GetItemAtIndex(uint index)
+        internal WebPasswordData GetItemAtIndex(uint index)
         {
             System.IntPtr dataIntPtr = Interop.WebPasswordDataList.ValueOfIndex(SwigCPtr, index);
-            if (NDalicPINVOKE.SWIGPendingException.Pending) return null;
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return new WebPasswordData(dataIntPtr, false);
         }
     }
index 6aacd67..447eacf 100755 (executable)
@@ -21,10 +21,9 @@ using System.ComponentModel;
 namespace Tizen.NUI
 {
     /// <summary>
-    /// It is a class for security origin list of web view.
+    /// It is an internal class for security origin list of web view.
     /// </summary>
-    [EditorBrowsable(EditorBrowsableState.Never)]
-    public class WebSecurityOriginList : Disposable
+    internal class WebSecurityOriginList : Disposable
     {
         internal WebSecurityOriginList(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
         {
@@ -32,7 +31,6 @@ namespace Tizen.NUI
 
         /// This will not be public opened.
         /// <param name="swigCPtr"></param>
-        [EditorBrowsable(EditorBrowsableState.Never)]
         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
         {
             Interop.WebSecurityOriginList.DeleteWebSecurityOriginList(swigCPtr);
@@ -41,8 +39,7 @@ namespace Tizen.NUI
         /// <summary>
         /// Count of security origin list.
         /// </summary>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public uint ItemCount
+        internal uint ItemCount
         {
             get
             {
@@ -54,11 +51,10 @@ namespace Tizen.NUI
         /// Gets security origin by index.
         /// <param name="index">index of list</param>
         /// </summary>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public WebSecurityOrigin GetItemAtIndex(uint index)
+        internal WebSecurityOrigin GetItemAtIndex(uint index)
         {
             System.IntPtr dataIntPtr = Interop.WebSecurityOriginList.ValueOfIndex(SwigCPtr, index);
-            if (NDalicPINVOKE.SWIGPendingException.Pending) return null;
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return new WebSecurityOrigin(dataIntPtr, false);
         }
     }
index 7e511d1..f2506ae 100755 (executable)
@@ -147,7 +147,7 @@ namespace Tizen.NUI.BaseComponents
         [EditorBrowsable(EditorBrowsableState.Never)]
         protected override void Dispose(DisposeTypes type)
         {
-            if (disposed)
+            if (Disposed)
             {
                 return;
             }