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 /// WebContext is a class for context of web view.
27 [EditorBrowsable(EditorBrowsableState.Never)]
28 public class WebContext : Disposable
30 private string proxyUri;
31 private string certificateFilePath;
32 private bool disableCache;
33 private SecurityOriginListAcquiredCallback securityOriginListAcquiredCallback;
34 private readonly WebContextSecurityOriginListAcquiredProxyCallback securityOriginListAcquiredProxyCallback;
35 private PasswordDataListAcquiredCallback passwordDataListAcquiredCallback;
36 private readonly WebContextPasswordDataListAcquiredProxyCallback passwordDataListAcquiredProxyCallback;
38 internal WebContext(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
40 securityOriginListAcquiredProxyCallback = OnSecurityOriginListAcquired;
41 passwordDataListAcquiredProxyCallback = OnPasswordDataListAcquired;
45 /// The callback function that is invoked when security origin list is acquired.
47 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
48 [EditorBrowsable(EditorBrowsableState.Never)]
49 public delegate void SecurityOriginListAcquiredCallback(WebSecurityOriginList list);
52 /// The callback function that is invoked when storage usage is acquired.
54 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
55 [EditorBrowsable(EditorBrowsableState.Never)]
56 public delegate void StorageUsageAcquiredCallback(ulong usage);
59 /// The callback function that is invoked when security origin list is acquired.
61 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
62 [EditorBrowsable(EditorBrowsableState.Never)]
63 public delegate void PasswordDataListAcquiredCallback(WebPasswordDataList list);
66 /// The callback function that is invoked when download is started.
68 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
69 [EditorBrowsable(EditorBrowsableState.Never)]
70 public delegate void DownloadStartedCallback(string url);
73 /// The callback function that is invoked when current mime type need be overridden.
75 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
76 [EditorBrowsable(EditorBrowsableState.Never)]
77 public delegate bool MimeOverriddenCallback(string url, string currentMime, string newMime);
79 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
80 private delegate void WebContextSecurityOriginListAcquiredProxyCallback(IntPtr list);
82 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
83 private delegate void WebContextPasswordDataListAcquiredProxyCallback(IntPtr list);
88 [EditorBrowsable(EditorBrowsableState.Never)]
89 public enum CacheModelType
92 /// The smallest cache capacity
94 [EditorBrowsable(EditorBrowsableState.Never)]
98 /// The bigger cache capacity than DocumentBrowser
100 [EditorBrowsable(EditorBrowsableState.Never)]
104 /// The biggest cache capacity.
106 [EditorBrowsable(EditorBrowsableState.Never)]
113 [EditorBrowsable(EditorBrowsableState.Never)]
114 public CacheModelType CacheModel
118 return (CacheModelType)Interop.WebContext.GetCacheModel(SwigCPtr);
122 Interop.WebContext.SetCacheModel(SwigCPtr, (int)value);
127 /// Set the proxy uri.
129 [EditorBrowsable(EditorBrowsableState.Never)]
134 return new Uri(proxyUri);
140 proxyUri = value.AbsoluteUri;
141 Interop.WebContext.SetProxyUri(SwigCPtr, proxyUri);
147 /// Set the Certificate File Path.
149 [EditorBrowsable(EditorBrowsableState.Never)]
150 public string CertificateFilePath
154 return certificateFilePath;
158 certificateFilePath = value;
159 Interop.WebContext.SetCertificateFilePath(SwigCPtr, value);
164 /// Disable cache or not.
166 [EditorBrowsable(EditorBrowsableState.Never)]
167 public bool DisableCache
175 disableCache = value;
176 Interop.WebContext.DisableCache(SwigCPtr, value);
181 /// Set Default Proxy Auth.
183 [EditorBrowsable(EditorBrowsableState.Never)]
184 public void SetDefaultProxyAuth(string username, string password)
186 Interop.WebContext.SetDefaultProxyAuth(SwigCPtr, username, password);
187 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
191 /// Delete all web database.
193 [EditorBrowsable(EditorBrowsableState.Never)]
194 public void DeleteAllWebDatabase()
196 Interop.WebContext.DeleteAllWebDatabase(SwigCPtr);
197 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
201 /// Gets security origins of web database asynchronously.
202 /// <param name="callback">callback for acquiring security origins</param>
204 [EditorBrowsable(EditorBrowsableState.Never)]
205 public bool GetWebDatabaseOrigins(SecurityOriginListAcquiredCallback callback)
207 securityOriginListAcquiredCallback = callback;
208 IntPtr ip = Marshal.GetFunctionPointerForDelegate(securityOriginListAcquiredProxyCallback);
209 bool result = Interop.WebContext.GetWebDatabaseOrigins(SwigCPtr, new HandleRef(this, ip));
210 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
215 /// Deletes web databases by origin.
216 /// <param name="origin">security origin of web database</param>
218 [EditorBrowsable(EditorBrowsableState.Never)]
219 public bool DeleteWebDatabase(WebSecurityOrigin origin)
221 bool result = Interop.WebContext.DeleteWebDatabase(SwigCPtr, WebSecurityOrigin.getCPtr(origin));
222 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
227 /// Gets a list of security origins of web storage asynchronously.
228 /// <param name="callback">callback for acquiring security origins</param>
230 [EditorBrowsable(EditorBrowsableState.Never)]
231 public bool GetWebStorageOrigins(SecurityOriginListAcquiredCallback callback)
233 securityOriginListAcquiredCallback = callback;
234 IntPtr ip = Marshal.GetFunctionPointerForDelegate(securityOriginListAcquiredProxyCallback);
235 bool result = Interop.WebContext.GetWebStorageOrigins(SwigCPtr, new HandleRef(this, ip));
236 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
241 /// Gets a list of security origins of web storage asynchronously.
242 /// <param name="origin">security origin of web storage</param>
243 /// <param name="callback">callback for acquiring storage usage</param>
245 [EditorBrowsable(EditorBrowsableState.Never)]
246 public bool GetWebStorageUsageForOrigin(WebSecurityOrigin origin, StorageUsageAcquiredCallback callback)
248 IntPtr ip = Marshal.GetFunctionPointerForDelegate(callback);
249 bool result = Interop.WebContext.GetWebStorageUsageForOrigin(SwigCPtr, WebSecurityOrigin.getCPtr(origin), new HandleRef(this, ip));
250 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
255 /// Delete all web storage.
257 [EditorBrowsable(EditorBrowsableState.Never)]
258 public void DeleteAllWebStorage()
260 Interop.WebContext.DeleteAllWebStorage(SwigCPtr);
261 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
265 /// Deletes web storage by origin.
266 /// <param name="origin">security origin of web storage</param>
268 [EditorBrowsable(EditorBrowsableState.Never)]
269 public bool DeleteWebStorage(WebSecurityOrigin origin)
271 bool result = Interop.WebContext.DeleteWebStorageOrigin(SwigCPtr, WebSecurityOrigin.getCPtr(origin));
272 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
277 /// Delete local fileSystem.
279 [EditorBrowsable(EditorBrowsableState.Never)]
280 public void DeleteLocalFileSystem()
282 Interop.WebContext.DeleteLocalFileSystem(SwigCPtr);
283 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
289 [EditorBrowsable(EditorBrowsableState.Never)]
290 public void ClearCache()
292 Interop.WebContext.ClearCache(SwigCPtr);
293 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
297 /// Deletes web application cache by origin.
298 /// <param name="origin">security origin of web application</param>
300 [EditorBrowsable(EditorBrowsableState.Never)]
301 public bool DeleteApplicationCache(WebSecurityOrigin origin)
303 bool result = Interop.WebContext.DeleteApplicationCache(SwigCPtr, WebSecurityOrigin.getCPtr(origin));
304 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
309 /// Gets a list of all password data asynchronously.
310 /// <param name="callback">callback for acquiring password data list</param>
312 [EditorBrowsable(EditorBrowsableState.Never)]
313 public void GetFormPasswordList(PasswordDataListAcquiredCallback callback)
315 passwordDataListAcquiredCallback = callback;
316 IntPtr ip = Marshal.GetFunctionPointerForDelegate(passwordDataListAcquiredProxyCallback);
317 Interop.WebContext.GetFormPasswordList(SwigCPtr, new HandleRef(this, ip));
318 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
322 /// Registers callback for download started.
323 /// <param name="callback">callback for download started</param>
325 [EditorBrowsable(EditorBrowsableState.Never)]
326 public void RegisterDownloadStartedCallback(DownloadStartedCallback callback)
328 IntPtr ip = Marshal.GetFunctionPointerForDelegate(callback);
329 Interop.WebContext.RegisterDownloadStartedCallback(SwigCPtr, new HandleRef(this, ip));
330 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
334 /// Registers callback for overriding mime type.
335 /// <param name="callback">callback for overriding mime type</param>
337 [EditorBrowsable(EditorBrowsableState.Never)]
338 public void RegisterMimeOverriddenCallback(MimeOverriddenCallback callback)
340 IntPtr ip = Marshal.GetFunctionPointerForDelegate(callback);
341 Interop.WebContext.RegisterMimeOverriddenCallback(SwigCPtr, new HandleRef(this, ip));
342 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
345 private void OnSecurityOriginListAcquired(IntPtr list)
347 WebSecurityOriginList originList = new WebSecurityOriginList(list, true);
348 securityOriginListAcquiredCallback?.Invoke(originList);
349 originList.Dispose();
352 private void OnPasswordDataListAcquired(IntPtr list)
354 WebPasswordDataList passwordList = new WebPasswordDataList(list, true);
355 passwordDataListAcquiredCallback?.Invoke(passwordList);
356 passwordList.Dispose();