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
31 private string appVersion;
32 private float timeOffset;
33 private ApplicationType applicationType;
34 private SecurityOriginListAcquiredCallback securityOriginListAcquiredCallback;
35 private readonly WebContextSecurityOriginListAcquiredProxyCallback securityOriginListAcquiredProxyCallback;
36 private PasswordDataListAcquiredCallback passwordDataListAcquiredCallback;
37 private readonly WebContextPasswordDataListAcquiredProxyCallback passwordDataListAcquiredProxyCallback;
39 internal WebContext(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
41 securityOriginListAcquiredProxyCallback = OnSecurityOriginListAcquired;
42 passwordDataListAcquiredProxyCallback = OnPasswordDataListAcquired;
46 /// The callback function that is invoked when security origin list is acquired.
48 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
49 [EditorBrowsable(EditorBrowsableState.Never)]
50 public delegate void SecurityOriginListAcquiredCallback(WebSecurityOriginList list);
53 /// The callback function that is invoked when storage usage is acquired.
55 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
56 [EditorBrowsable(EditorBrowsableState.Never)]
57 public delegate void StorageUsageAcquiredCallback(ulong usage);
60 /// The callback function that is invoked when security origin list is acquired.
62 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
63 [EditorBrowsable(EditorBrowsableState.Never)]
64 public delegate void PasswordDataListAcquiredCallback(WebPasswordDataList list);
67 /// The callback function that is invoked when download is started.
69 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
70 [EditorBrowsable(EditorBrowsableState.Never)]
71 public delegate void DownloadStartedCallback(string url);
74 /// The callback function that is invoked when current mime type need be overridden.
76 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
77 [EditorBrowsable(EditorBrowsableState.Never)]
78 public delegate bool MimeOverriddenCallback(string url, string currentMime, string newMime);
80 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
81 private delegate void WebContextSecurityOriginListAcquiredProxyCallback(IntPtr list);
83 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
84 private delegate void WebContextPasswordDataListAcquiredProxyCallback(IntPtr list);
89 [EditorBrowsable(EditorBrowsableState.Never)]
90 public enum CacheModelType
93 /// The smallest cache capacity
95 [EditorBrowsable(EditorBrowsableState.Never)]
99 /// The bigger cache capacity than DocumentBrowser
101 [EditorBrowsable(EditorBrowsableState.Never)]
105 /// The biggest cache capacity.
107 [EditorBrowsable(EditorBrowsableState.Never)]
114 [EditorBrowsable(EditorBrowsableState.Never)]
115 public enum ApplicationType
120 [EditorBrowsable(EditorBrowsableState.Never)]
126 [EditorBrowsable(EditorBrowsableState.Never)]
132 [EditorBrowsable(EditorBrowsableState.Never)]
138 [EditorBrowsable(EditorBrowsableState.Never)]
145 [EditorBrowsable(EditorBrowsableState.Never)]
146 public CacheModelType CacheModel
150 return (CacheModelType)Interop.WebContext.GetCacheModel(SwigCPtr);
154 Interop.WebContext.SetCacheModel(SwigCPtr, (int)value);
155 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
162 [EditorBrowsable(EditorBrowsableState.Never)]
163 public string ProxyUrl
167 return Interop.WebContext.GetProxyUri(SwigCPtr);
173 Interop.WebContext.SetProxyUri(SwigCPtr, value);
174 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
180 /// Certificate file path.
182 [EditorBrowsable(EditorBrowsableState.Never)]
183 public string CertificateFilePath
187 return Interop.WebContext.GetCertificateFilePath(SwigCPtr);
191 Interop.WebContext.SetCertificateFilePath(SwigCPtr, value);
192 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
197 /// Enables cache or not.
199 [EditorBrowsable(EditorBrowsableState.Never)]
200 public bool CacheEnabled
204 return Interop.WebContext.IsCacheEnabled(SwigCPtr);
208 Interop.WebContext.EnableCache(SwigCPtr, value);
209 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
216 [EditorBrowsable(EditorBrowsableState.Never)]
225 Interop.WebContext.SetAppId(SwigCPtr, value);
226 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
234 [EditorBrowsable(EditorBrowsableState.Never)]
235 public string AppVersion
243 Interop.WebContext.SetAppVersion(SwigCPtr, value);
244 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
252 [EditorBrowsable(EditorBrowsableState.Never)]
253 public ApplicationType AppType
257 return applicationType;
261 Interop.WebContext.SetApplicationType(SwigCPtr, (int)value);
262 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
263 applicationType = value;
270 [EditorBrowsable(EditorBrowsableState.Never)]
271 public float TimeOffset
279 Interop.WebContext.SetTimeOffset(SwigCPtr, value);
280 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
286 /// Default zoom factor.
288 [EditorBrowsable(EditorBrowsableState.Never)]
289 public float DefaultZoomFactor
293 return Interop.WebContext.GetDefaultZoomFactor(SwigCPtr);
297 Interop.WebContext.SetDefaultZoomFactor(SwigCPtr, value);
298 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
303 /// Deprecated. Gets context proxy.
305 [EditorBrowsable(EditorBrowsableState.Never)]
306 public string ContextProxy
310 return Interop.WebContext.GetProxyUri(SwigCPtr);
315 /// Gets proxy bypass rule.
317 [EditorBrowsable(EditorBrowsableState.Never)]
318 public string ProxyBypassRule
322 return Interop.WebContext.GetProxyBypassRule(SwigCPtr);
327 /// Sets default proxy auth.
329 [EditorBrowsable(EditorBrowsableState.Never)]
330 public void SetDefaultProxyAuth(string username, string password)
332 Interop.WebContext.SetDefaultProxyAuth(SwigCPtr, username, password);
333 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
337 /// Deletes all web database.
339 [EditorBrowsable(EditorBrowsableState.Never)]
340 public void DeleteAllWebDatabase()
342 Interop.WebContext.DeleteAllWebDatabase(SwigCPtr);
343 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
347 /// Gets security origins of web database asynchronously.
348 /// <param name="callback">callback for acquiring security origins</param>
350 [EditorBrowsable(EditorBrowsableState.Never)]
351 public bool GetWebDatabaseOrigins(SecurityOriginListAcquiredCallback callback)
353 securityOriginListAcquiredCallback = callback;
354 IntPtr ip = Marshal.GetFunctionPointerForDelegate(securityOriginListAcquiredProxyCallback);
355 bool result = Interop.WebContext.GetWebDatabaseOrigins(SwigCPtr, new HandleRef(this, ip));
356 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
361 /// Deletes web databases by origin.
362 /// <param name="origin">security origin of web database</param>
364 [EditorBrowsable(EditorBrowsableState.Never)]
365 public bool DeleteWebDatabase(WebSecurityOrigin origin)
367 bool result = Interop.WebContext.DeleteWebDatabase(SwigCPtr, WebSecurityOrigin.getCPtr(origin));
368 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
373 /// Gets a list of security origins of web storage asynchronously.
374 /// <param name="callback">callback for acquiring security origins</param>
376 [EditorBrowsable(EditorBrowsableState.Never)]
377 public bool GetWebStorageOrigins(SecurityOriginListAcquiredCallback callback)
379 securityOriginListAcquiredCallback = callback;
380 IntPtr ip = Marshal.GetFunctionPointerForDelegate(securityOriginListAcquiredProxyCallback);
381 bool result = Interop.WebContext.GetWebStorageOrigins(SwigCPtr, new HandleRef(this, ip));
382 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
387 /// Gets a list of security origins of web storage asynchronously.
388 /// <param name="origin">security origin of web storage</param>
389 /// <param name="callback">callback for acquiring storage usage</param>
391 [EditorBrowsable(EditorBrowsableState.Never)]
392 public bool GetWebStorageUsageForOrigin(WebSecurityOrigin origin, StorageUsageAcquiredCallback callback)
394 IntPtr ip = Marshal.GetFunctionPointerForDelegate(callback);
395 bool result = Interop.WebContext.GetWebStorageUsageForOrigin(SwigCPtr, WebSecurityOrigin.getCPtr(origin), new HandleRef(this, ip));
396 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
401 /// Deletes all web storage.
403 [EditorBrowsable(EditorBrowsableState.Never)]
404 public void DeleteAllWebStorage()
406 Interop.WebContext.DeleteAllWebStorage(SwigCPtr);
407 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
411 /// Deletes web storage by origin.
412 /// <param name="origin">security origin of web storage</param>
414 [EditorBrowsable(EditorBrowsableState.Never)]
415 public bool DeleteWebStorage(WebSecurityOrigin origin)
417 bool result = Interop.WebContext.DeleteWebStorage(SwigCPtr, WebSecurityOrigin.getCPtr(origin));
418 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
423 /// Deletes local fileSystem.
425 [EditorBrowsable(EditorBrowsableState.Never)]
426 public void DeleteLocalFileSystem()
428 Interop.WebContext.DeleteLocalFileSystem(SwigCPtr);
429 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
435 [EditorBrowsable(EditorBrowsableState.Never)]
436 public void ClearCache()
438 Interop.WebContext.ClearCache(SwigCPtr);
439 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
443 /// Deletes web application cache by origin.
444 /// <param name="origin">security origin of web application</param>
446 [EditorBrowsable(EditorBrowsableState.Never)]
447 public bool DeleteApplicationCache(WebSecurityOrigin origin)
449 bool result = Interop.WebContext.DeleteApplicationCache(SwigCPtr, WebSecurityOrigin.getCPtr(origin));
450 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
455 /// Gets a list of all password data asynchronously.
456 /// <param name="callback">callback for acquiring password data list</param>
458 [EditorBrowsable(EditorBrowsableState.Never)]
459 public void GetFormPasswordList(PasswordDataListAcquiredCallback callback)
461 passwordDataListAcquiredCallback = callback;
462 IntPtr ip = Marshal.GetFunctionPointerForDelegate(passwordDataListAcquiredProxyCallback);
463 Interop.WebContext.GetFormPasswordList(SwigCPtr, new HandleRef(this, ip));
464 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
468 /// Registers callback for download started.
469 /// <param name="callback">callback for download started</param>
471 [EditorBrowsable(EditorBrowsableState.Never)]
472 public void RegisterDownloadStartedCallback(DownloadStartedCallback callback)
474 IntPtr ip = Marshal.GetFunctionPointerForDelegate(callback);
475 Interop.WebContext.RegisterDownloadStartedCallback(SwigCPtr, new HandleRef(this, ip));
476 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
480 /// Registers callback for overriding mime type.
481 /// <param name="callback">callback for overriding mime type</param>
483 [EditorBrowsable(EditorBrowsableState.Never)]
484 public void RegisterMimeOverriddenCallback(MimeOverriddenCallback callback)
486 IntPtr ip = Marshal.GetFunctionPointerForDelegate(callback);
487 Interop.WebContext.RegisterMimeOverriddenCallback(SwigCPtr, new HandleRef(this, ip));
488 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
492 /// Sets context time zone offset.
493 /// <param name="offset">Time offset</param>
494 /// <param name="time">Daylight saving time</param>
496 [EditorBrowsable(EditorBrowsableState.Never)]
497 public void SetTimeZoneOffset(float offset, float time)
499 Interop.WebContext.SetTimeZoneOffset(SwigCPtr, offset, time);
500 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
504 /// Deprecated. Sets context time zone offset.
505 /// <param name="offset">Time offset</param>
506 /// <param name="time">Daylight saving time</param>
508 [EditorBrowsable(EditorBrowsableState.Never)]
509 public void SetContextTimeZoneOffset(float offset, float time)
511 SetTimeZoneOffset(offset, time);
515 /// Registers url schemes enabled.
516 /// <param name="schemes">The string array of schemes</param>
518 [EditorBrowsable(EditorBrowsableState.Never)]
519 public void RegisterUrlSchemesAsCorsEnabled(string[] schemes)
523 Interop.WebContext.RegisterUrlSchemesAsCorsEnabled(SwigCPtr, schemes, (uint)schemes.Length);
524 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
529 /// Registers js plugin mime types.
530 /// <param name="mimes">The string array of types</param>
532 [EditorBrowsable(EditorBrowsableState.Never)]
533 public void RegisterJsPluginMimeTypes(string[] mimes)
537 Interop.WebContext.RegisterJsPluginMimeTypes(SwigCPtr, mimes, (uint)mimes.Length);
538 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
543 /// Deletes all application cache.
545 [EditorBrowsable(EditorBrowsableState.Never)]
546 public bool DeleteAllApplicationCache()
548 bool ret = Interop.WebContext.DeleteAllApplicationCache(SwigCPtr);
549 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
554 /// Deletes all web indexed database.
556 [EditorBrowsable(EditorBrowsableState.Never)]
557 public bool DeleteAllWebIndexedDatabase()
559 bool ret = Interop.WebContext.DeleteAllWebIndexedDatabase(SwigCPtr);
560 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
565 /// Deletes password dataList.
566 /// <param name="passwords">The string array of data list</param>
568 [EditorBrowsable(EditorBrowsableState.Never)]
569 public void DeleteFormPasswordDataList(string[] passwords)
571 if (passwords != null)
573 Interop.WebContext.DeleteFormPasswordDataList(SwigCPtr, passwords, (uint)passwords.Length);
574 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
579 /// Deletes all password data.
581 [EditorBrowsable(EditorBrowsableState.Never)]
582 public void DeleteAllFormPasswordData()
584 Interop.WebContext.DeleteAllFormPasswordData(SwigCPtr);
585 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
589 /// Deletes all candidate data.
591 [EditorBrowsable(EditorBrowsableState.Never)]
592 public void DeleteAllFormCandidateData()
594 Interop.WebContext.DeleteAllFormCandidateData(SwigCPtr);
595 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
599 /// Sets proxy bypass rule.
600 /// <param name="proxy">The proxy string</param>
601 /// <param name="rule">Bypass rule</param>
603 [EditorBrowsable(EditorBrowsableState.Never)]
604 public void SetProxyBypassRule(string proxy, string rule)
606 Interop.WebContext.SetProxyBypassRule(SwigCPtr, proxy, rule);
607 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
611 /// Deprecated. Sets proxy bypass rule.
612 /// <param name="proxy">The proxy string</param>
613 /// <param name="rule">Bypass rule</param>
615 [EditorBrowsable(EditorBrowsableState.Never)]
616 public void SetContextProxy(string proxy, string rule)
618 SetProxyBypassRule(proxy, rule);
622 /// Frees unused memory.
624 [EditorBrowsable(EditorBrowsableState.Never)]
625 public bool FreeUnusedMemory()
627 bool ret = Interop.WebContext.FreeUnusedMemory(SwigCPtr);
628 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
632 private void OnSecurityOriginListAcquired(IntPtr list)
634 WebSecurityOriginList originList = new WebSecurityOriginList(list, true);
635 securityOriginListAcquiredCallback?.Invoke(originList);
636 originList.Dispose();
639 private void OnPasswordDataListAcquired(IntPtr list)
641 WebPasswordDataList passwordList = new WebPasswordDataList(list, true);
642 passwordDataListAcquiredCallback?.Invoke(passwordList);
643 passwordList.Dispose();