2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 using System.ComponentModel;
20 using System.Runtime.InteropServices;
25 /// WebCookieManager is a class for cookie manager of web view.
27 [EditorBrowsable(EditorBrowsableState.Never)]
28 public class WebCookieManager : Disposable
30 private EventHandler<EventArgs> cookieChangedEventHandler;
31 private CookieChangedCallback cookieChangedCallback;
33 internal WebCookieManager(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
37 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
38 private delegate void CookieChangedCallback();
41 /// Event for cookie changed when cookies are added, removed or modified.
43 [EditorBrowsable(EditorBrowsableState.Never)]
44 public event EventHandler<EventArgs> CookieChanged
48 if (cookieChangedEventHandler == null)
50 cookieChangedCallback = OnCookieChanged;
51 IntPtr ip = Marshal.GetFunctionPointerForDelegate(cookieChangedCallback);
52 Interop.WebCookieManager.CookieChangedCallback(SwigCPtr, new HandleRef(this, ip));
54 cookieChangedEventHandler += value;
58 cookieChangedEventHandler -= value;
59 if (cookieChangedEventHandler == null)
61 IntPtr ip = IntPtr.Zero;
62 Interop.WebCookieManager.CookieChangedCallback(SwigCPtr, new HandleRef(this, ip));
68 /// Enumeration for cookie accept policy
70 [EditorBrowsable(EditorBrowsableState.Never)]
71 public enum CookieAcceptPolicyType
76 [EditorBrowsable(EditorBrowsableState.Never)]
82 [EditorBrowsable(EditorBrowsableState.Never)]
88 [EditorBrowsable(EditorBrowsableState.Never)]
93 /// Enumeration for cookie persistent storage type.
95 [EditorBrowsable(EditorBrowsableState.Never)]
96 public enum CookiePersistentStorageType
99 /// Deprecated. Cookies are stored in a text file.
101 [EditorBrowsable(EditorBrowsableState.Never)]
105 /// Cookies are stored in a SQLite file.
107 [EditorBrowsable(EditorBrowsableState.Never)]
112 /// Cookie accept policy
114 [EditorBrowsable(EditorBrowsableState.Never)]
115 public CookieAcceptPolicyType CookieAcceptPolicy
119 return (CookieAcceptPolicyType)Interop.WebCookieManager.GetCookieAcceptPolicy(SwigCPtr);
123 Interop.WebCookieManager.SetCookieAcceptPolicy(SwigCPtr, (int)value);
128 /// Sets the persistent storage.
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)
135 Interop.WebCookieManager.SetPersistentStorage(SwigCPtr, path, (int)storageType);
136 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
142 [EditorBrowsable(EditorBrowsableState.Never)]
143 public void ClearCookies()
145 Interop.WebCookieManager.ClearCookies(SwigCPtr);
146 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
149 private void OnCookieChanged()
151 cookieChangedEventHandler?.Invoke(this, new EventArgs());