[NUI] Change all CallingConvention to `Cdecl`
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / WebView / WebCookieManager.cs
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 using System;
19 using System.ComponentModel;
20 using System.Runtime.InteropServices;
21
22 namespace Tizen.NUI
23 {
24     /// <summary>
25     /// WebCookieManager is a class for cookie manager of web view.
26     /// </summary>
27     [EditorBrowsable(EditorBrowsableState.Never)]
28     public class WebCookieManager : Disposable
29     {
30         private EventHandler<EventArgs> cookieChangedEventHandler;
31         private CookieChangedCallback cookieChangedCallback;
32
33         internal WebCookieManager(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
34         {
35         }
36
37         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
38         private delegate void CookieChangedCallback();
39
40         /// <summary>
41         /// Event for cookie changed when cookies are added, removed or modified.
42         /// </summary>
43         [EditorBrowsable(EditorBrowsableState.Never)]
44         public event EventHandler<EventArgs> CookieChanged
45         {
46             add
47             {
48                 if (cookieChangedEventHandler == null)
49                 {
50                     cookieChangedCallback = OnCookieChanged;
51                     IntPtr ip = Marshal.GetFunctionPointerForDelegate(cookieChangedCallback);
52                     Interop.WebCookieManager.CookieChangedCallback(SwigCPtr, new HandleRef(this, ip));
53                 }
54                 cookieChangedEventHandler += value;
55             }
56             remove
57             {
58                 cookieChangedEventHandler -= value;
59                 if (cookieChangedEventHandler == null)
60                 {
61                     IntPtr ip = IntPtr.Zero;
62                     Interop.WebCookieManager.CookieChangedCallback(SwigCPtr, new HandleRef(this, ip));
63                 }
64             }
65         }
66
67         /// <summary>
68         /// Enumeration for cookie accept policy
69         /// </summary>
70         [EditorBrowsable(EditorBrowsableState.Never)]
71         public enum CookieAcceptPolicyType
72         {
73             /// <summary>
74             /// Always
75             /// </summary>
76             [EditorBrowsable(EditorBrowsableState.Never)]
77             Always,
78
79             /// <summary>
80             /// Never
81             /// </summary>
82             [EditorBrowsable(EditorBrowsableState.Never)]
83             Never,
84
85             /// <summary>
86             /// No third party.
87             /// </summary>
88             [EditorBrowsable(EditorBrowsableState.Never)]
89             NoThirdParty,
90         }
91
92         /// <summary>
93         /// Enumeration for cookie persistent storage type.
94         /// </summary>
95         [EditorBrowsable(EditorBrowsableState.Never)]
96         public enum CookiePersistentStorageType
97         {
98             /// <summary>
99             /// Deprecated. Cookies are stored in a text file.
100             /// </summary>
101             [EditorBrowsable(EditorBrowsableState.Never)]
102             Text,
103
104             /// <summary>
105             /// Cookies are stored in a SQLite file.
106             /// </summary>
107             [EditorBrowsable(EditorBrowsableState.Never)]
108             SqlLite,
109         }
110
111         /// <summary>
112         /// Cookie accept policy
113         /// </summary>
114         [EditorBrowsable(EditorBrowsableState.Never)]
115         public CookieAcceptPolicyType CookieAcceptPolicy
116         {
117             get
118             {
119                 return (CookieAcceptPolicyType)Interop.WebCookieManager.GetCookieAcceptPolicy(SwigCPtr);
120             }
121             set
122             {
123                 Interop.WebCookieManager.SetCookieAcceptPolicy(SwigCPtr, (int)value);
124             }
125         }
126
127         /// <summary>
128         /// Sets the persistent storage.
129         /// </summary>
130         /// <param name="path">The path for persistent storage</param>
131         /// <param name="storageType">The type of storage</param>
132         [EditorBrowsable(EditorBrowsableState.Never)]
133         public void SetPersistentStorage(string path, CookiePersistentStorageType storageType)
134         {
135             Interop.WebCookieManager.SetPersistentStorage(SwigCPtr, path, (int)storageType);
136             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
137         }
138
139         /// <summary>
140         /// Clears cookies.
141         /// </summary>
142         [EditorBrowsable(EditorBrowsableState.Never)]
143         public void ClearCookies()
144         {
145             Interop.WebCookieManager.ClearCookies(SwigCPtr);
146             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
147         }
148
149         private void OnCookieChanged()
150         {
151             cookieChangedEventHandler?.Invoke(this, new EventArgs());
152         }
153     }
154 }