CefExtensionHandler.g.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. //
  2. // DO NOT MODIFY! THIS IS AUTOGENERATED FILE!
  3. //
  4. namespace Xilium.CefGlue
  5. {
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Diagnostics;
  9. using System.Runtime.InteropServices;
  10. using System.Threading;
  11. using Xilium.CefGlue.Interop;
  12. // Role: HANDLER
  13. public abstract unsafe partial class CefExtensionHandler
  14. {
  15. private static Dictionary<IntPtr, CefExtensionHandler> _roots = new Dictionary<IntPtr, CefExtensionHandler>();
  16. private int _refct;
  17. private cef_extension_handler_t* _self;
  18. internal static CefExtensionHandler FromNativeOrNull(cef_extension_handler_t* ptr)
  19. {
  20. CefExtensionHandler value = null;
  21. bool found;
  22. lock (_roots)
  23. {
  24. found = _roots.TryGetValue((IntPtr)ptr, out value);
  25. // as we're getting the ref from the outside, it's our responsibility to decrement it
  26. value.release(ptr);
  27. }
  28. return found ? value : null;
  29. }
  30. internal static CefExtensionHandler FromNative(cef_extension_handler_t* ptr)
  31. {
  32. var value = FromNativeOrNull(ptr);
  33. if (value == null) throw ExceptionBuilder.ObjectNotFound();
  34. return value;
  35. }
  36. private cef_extension_handler_t.add_ref_delegate _ds0;
  37. private cef_extension_handler_t.release_delegate _ds1;
  38. private cef_extension_handler_t.has_one_ref_delegate _ds2;
  39. private cef_extension_handler_t.has_at_least_one_ref_delegate _ds3;
  40. private cef_extension_handler_t.on_extension_load_failed_delegate _ds4;
  41. private cef_extension_handler_t.on_extension_loaded_delegate _ds5;
  42. private cef_extension_handler_t.on_extension_unloaded_delegate _ds6;
  43. private cef_extension_handler_t.on_before_background_browser_delegate _ds7;
  44. private cef_extension_handler_t.on_before_browser_delegate _ds8;
  45. private cef_extension_handler_t.get_active_browser_delegate _ds9;
  46. private cef_extension_handler_t.can_access_browser_delegate _dsa;
  47. private cef_extension_handler_t.get_extension_resource_delegate _dsb;
  48. protected CefExtensionHandler()
  49. {
  50. _self = cef_extension_handler_t.Alloc();
  51. _ds0 = new cef_extension_handler_t.add_ref_delegate(add_ref);
  52. _self->_base._add_ref = Marshal.GetFunctionPointerForDelegate(_ds0);
  53. _ds1 = new cef_extension_handler_t.release_delegate(release);
  54. _self->_base._release = Marshal.GetFunctionPointerForDelegate(_ds1);
  55. _ds2 = new cef_extension_handler_t.has_one_ref_delegate(has_one_ref);
  56. _self->_base._has_one_ref = Marshal.GetFunctionPointerForDelegate(_ds2);
  57. _ds3 = new cef_extension_handler_t.has_at_least_one_ref_delegate(has_at_least_one_ref);
  58. _self->_base._has_at_least_one_ref = Marshal.GetFunctionPointerForDelegate(_ds3);
  59. _ds4 = new cef_extension_handler_t.on_extension_load_failed_delegate(on_extension_load_failed);
  60. _self->_on_extension_load_failed = Marshal.GetFunctionPointerForDelegate(_ds4);
  61. _ds5 = new cef_extension_handler_t.on_extension_loaded_delegate(on_extension_loaded);
  62. _self->_on_extension_loaded = Marshal.GetFunctionPointerForDelegate(_ds5);
  63. _ds6 = new cef_extension_handler_t.on_extension_unloaded_delegate(on_extension_unloaded);
  64. _self->_on_extension_unloaded = Marshal.GetFunctionPointerForDelegate(_ds6);
  65. _ds7 = new cef_extension_handler_t.on_before_background_browser_delegate(on_before_background_browser);
  66. _self->_on_before_background_browser = Marshal.GetFunctionPointerForDelegate(_ds7);
  67. _ds8 = new cef_extension_handler_t.on_before_browser_delegate(on_before_browser);
  68. _self->_on_before_browser = Marshal.GetFunctionPointerForDelegate(_ds8);
  69. _ds9 = new cef_extension_handler_t.get_active_browser_delegate(get_active_browser);
  70. _self->_get_active_browser = Marshal.GetFunctionPointerForDelegate(_ds9);
  71. _dsa = new cef_extension_handler_t.can_access_browser_delegate(can_access_browser);
  72. _self->_can_access_browser = Marshal.GetFunctionPointerForDelegate(_dsa);
  73. _dsb = new cef_extension_handler_t.get_extension_resource_delegate(get_extension_resource);
  74. _self->_get_extension_resource = Marshal.GetFunctionPointerForDelegate(_dsb);
  75. }
  76. ~CefExtensionHandler()
  77. {
  78. Dispose(false);
  79. }
  80. protected virtual void Dispose(bool disposing)
  81. {
  82. if (_self != null)
  83. {
  84. cef_extension_handler_t.Free(_self);
  85. _self = null;
  86. }
  87. }
  88. private void add_ref(cef_extension_handler_t* self)
  89. {
  90. if (Interlocked.Increment(ref _refct) == 1)
  91. {
  92. lock (_roots) { _roots.Add((IntPtr)_self, this); }
  93. }
  94. }
  95. private int release(cef_extension_handler_t* self)
  96. {
  97. if (Interlocked.Decrement(ref _refct) == 0)
  98. {
  99. lock (_roots) { _roots.Remove((IntPtr)_self); }
  100. return 1;
  101. }
  102. return 0;
  103. }
  104. private int has_one_ref(cef_extension_handler_t* self)
  105. {
  106. return _refct == 1 ? 1 : 0;
  107. }
  108. private int has_at_least_one_ref(cef_extension_handler_t* self)
  109. {
  110. return _refct != 0 ? 1 : 0;
  111. }
  112. internal cef_extension_handler_t* ToNative()
  113. {
  114. add_ref(_self);
  115. return _self;
  116. }
  117. [Conditional("DEBUG")]
  118. private void CheckSelf(cef_extension_handler_t* self)
  119. {
  120. if (_self != self) throw ExceptionBuilder.InvalidSelfReference();
  121. }
  122. }
  123. }