[NUI] Implement some new APIs of webcontext.
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / WebView / WebContext.cs
index 97d6708..5ee9ddc 100755 (executable)
@@ -17,6 +17,7 @@
 
 using System;
 using System.ComponentModel;
+using System.Runtime.InteropServices;
 
 namespace Tizen.NUI
 {
@@ -26,6 +27,61 @@ namespace Tizen.NUI
     [EditorBrowsable(EditorBrowsableState.Never)]
     public class WebContext : Disposable
     {
+        private string proxyUri;
+        private string certificateFilePath;
+        private bool disableCache;
+        private SecurityOriginListAcquiredCallback securityOriginListAcquiredCallback;
+        private readonly WebContextSecurityOriginListAcquiredProxyCallback securityOriginListAcquiredProxyCallback;
+        private PasswordDataListAcquiredCallback passwordDataListAcquiredCallback;
+        private readonly WebContextPasswordDataListAcquiredProxyCallback passwordDataListAcquiredProxyCallback;
+
+        internal WebContext(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
+        {
+            securityOriginListAcquiredProxyCallback = OnSecurityOriginListAcquired;
+            passwordDataListAcquiredProxyCallback = OnPasswordDataListAcquired;
+        }
+
+        /// <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);
+
+        /// <summary>
+        /// The callback function that is invoked when storage usage is acquired.
+        /// </summary>
+        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public delegate void StorageUsageAcquiredCallback(ulong usage);
+
+        /// <summary>
+        /// The callback function that is invoked when security origin list is acquired.
+        /// </summary>
+        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public delegate void PasswordDataListAcquiredCallback(WebPasswordDataList list);
+
+        /// <summary>
+        /// The callback function that is invoked when download is started.
+        /// </summary>
+        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public delegate void DownloadStartedCallback(string url);
+
+        /// <summary>
+        /// The callback function that is invoked when current mime type need be overridden.
+        /// </summary>
+        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public delegate bool MimeOverriddenCallback(string url, string currentMime, string newMime);
+
+        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+        private delegate void WebContextSecurityOriginListAcquiredProxyCallback(IntPtr list);
+
+        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+        private delegate void WebContextPasswordDataListAcquiredProxyCallback(IntPtr list);
+
         /// <summary>
         /// Cache model
         /// </summary>
@@ -132,27 +188,93 @@ namespace Tizen.NUI
         }
 
         /// <summary>
-        /// Delete Web Database.
+        /// Delete all web database.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void DeleteAllWebDatabase()
+        {
+            Interop.WebContext.DeleteAllWebDatabase(SwigCPtr);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        /// <summary>
+        /// Gets security origins of web database asynchronously.
+        /// <param name="callback">callback for acquiring security origins</param>
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public bool GetWebDatabaseOrigins(SecurityOriginListAcquiredCallback callback)
+        {
+            securityOriginListAcquiredCallback = callback;
+            IntPtr ip = Marshal.GetFunctionPointerForDelegate(securityOriginListAcquiredProxyCallback);
+            bool result = Interop.WebContext.GetWebDatabaseOrigins(SwigCPtr, new HandleRef(this, ip));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return result;
+        }
+
+        /// <summary>
+        /// Deletes web databases by origin.
+        /// <param name="origin">security origin of web database</param>
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public bool DeleteWebDatabase(WebSecurityOrigin origin)
+        {
+            bool result = Interop.WebContext.DeleteWebDatabase(SwigCPtr, WebSecurityOrigin.getCPtr(origin));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return result;
+        }
+
+        /// <summary>
+        /// Gets a list of security origins of web storage asynchronously.
+        /// <param name="callback">callback for acquiring security origins</param>
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public bool GetWebStorageOrigins(SecurityOriginListAcquiredCallback callback)
+        {
+            securityOriginListAcquiredCallback = callback;
+            IntPtr ip = Marshal.GetFunctionPointerForDelegate(securityOriginListAcquiredProxyCallback);
+            bool result = Interop.WebContext.GetWebStorageOrigins(SwigCPtr, new HandleRef(this, ip));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return result;
+        }
+
+        /// <summary>
+        /// Gets a list of security origins of web storage asynchronously.
+        /// <param name="origin">security origin of web storage</param>
+        /// <param name="callback">callback for acquiring storage usage</param>
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public void DeleteWebDatabase()
+        public bool GetWebStorageUsageForOrigin(WebSecurityOrigin origin, StorageUsageAcquiredCallback callback)
         {
-            Interop.WebContext.DeleteWebDatabase(SwigCPtr);
+            IntPtr ip = Marshal.GetFunctionPointerForDelegate(callback);
+            bool result = Interop.WebContext.GetWebStorageUsageForOrigin(SwigCPtr, WebSecurityOrigin.getCPtr(origin), new HandleRef(this, ip));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return result;
         }
 
         /// <summary>
-        /// Delete Web Storage.
+        /// Delete all web storage.
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public void DeleteWebStorage()
+        public void DeleteAllWebStorage()
         {
-            Interop.WebContext.DeleteWebStorage(SwigCPtr);
+            Interop.WebContext.DeleteAllWebStorage(SwigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         /// <summary>
-        /// Delete Local FileSystem.
+        /// Deletes web storage by origin.
+        /// <param name="origin">security origin of web storage</param>
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public bool DeleteWebStorage(WebSecurityOrigin origin)
+        {
+            bool result = Interop.WebContext.DeleteWebStorageOrigin(SwigCPtr, WebSecurityOrigin.getCPtr(origin));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return result;
+        }
+
+        /// <summary>
+        /// Delete local fileSystem.
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
         public void DeleteLocalFileSystem()
@@ -171,39 +293,67 @@ namespace Tizen.NUI
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
-        internal WebContext(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
+        /// <summary>
+        /// Deletes web application cache by origin.
+        /// <param name="origin">security origin of web application</param>
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public bool DeleteApplicationCache(WebSecurityOrigin origin)
         {
+            bool result = Interop.WebContext.DeleteApplicationCache(SwigCPtr, WebSecurityOrigin.getCPtr(origin));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return result;
         }
 
-        internal static global::System.Runtime.InteropServices.HandleRef getCPtr(WebContext obj)
+        /// <summary>
+        /// Gets a list of all password data asynchronously.
+        /// <param name="callback">callback for acquiring password data list</param>
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void GetFormPasswordList(PasswordDataListAcquiredCallback callback)
         {
-            return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
+            passwordDataListAcquiredCallback = callback;
+            IntPtr ip = Marshal.GetFunctionPointerForDelegate(passwordDataListAcquiredProxyCallback);
+            Interop.WebContext.GetFormPasswordList(SwigCPtr, new HandleRef(this, ip));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         /// <summary>
-        /// Dispose for IDisposable pattern
+        /// Registers callback for download started.
+        /// <param name="callback">callback for download started</param>
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        protected override void Dispose(DisposeTypes type)
+        public void RegisterDownloadStartedCallback(DownloadStartedCallback callback)
         {
-            if (disposed)
-            {
-                return;
-            }
+            IntPtr ip = Marshal.GetFunctionPointerForDelegate(callback);
+            Interop.WebContext.RegisterDownloadStartedCallback(SwigCPtr, new HandleRef(this, ip));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
 
-            if (type == DisposeTypes.Explicit)
-            {
-                //Called by User
-                //Release your own managed resources here.
-                //You should release all of your own disposable objects here.
-            }
+        /// <summary>
+        /// Registers callback for overriding mime type.
+        /// <param name="callback">callback for overriding mime type</param>
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void RegisterMimeOverriddenCallback(MimeOverriddenCallback callback)
+        {
+            IntPtr ip = Marshal.GetFunctionPointerForDelegate(callback);
+            Interop.WebContext.RegisterMimeOverriddenCallback(SwigCPtr, new HandleRef(this, ip));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
 
-            base.Dispose(type);
+        private void OnSecurityOriginListAcquired(IntPtr list)
+        {
+            WebSecurityOriginList originList = new WebSecurityOriginList(list, true);
+            securityOriginListAcquiredCallback?.Invoke(originList);
+            originList.Dispose();
         }
 
-        // private
-        private string proxyUri;
-        private string certificateFilePath;
-        private bool disableCache;
+        private void OnPasswordDataListAcquired(IntPtr list)
+        {
+            WebPasswordDataList passwordList = new WebPasswordDataList(list, true);
+            passwordDataListAcquiredCallback?.Invoke(passwordList);
+            passwordList.Dispose();
+        }
     }
 }