CefRequestContextHandler.g.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 CefRequestContextHandler
  14. {
  15. private static Dictionary<IntPtr, CefRequestContextHandler> _roots = new Dictionary<IntPtr, CefRequestContextHandler>();
  16. private int _refct;
  17. private cef_request_context_handler_t* _self;
  18. internal static CefRequestContextHandler FromNativeOrNull(cef_request_context_handler_t* ptr)
  19. {
  20. CefRequestContextHandler 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 CefRequestContextHandler FromNative(cef_request_context_handler_t* ptr)
  31. {
  32. var value = FromNativeOrNull(ptr);
  33. if (value == null) throw ExceptionBuilder.ObjectNotFound();
  34. return value;
  35. }
  36. private cef_request_context_handler_t.add_ref_delegate _ds0;
  37. private cef_request_context_handler_t.release_delegate _ds1;
  38. private cef_request_context_handler_t.has_one_ref_delegate _ds2;
  39. private cef_request_context_handler_t.has_at_least_one_ref_delegate _ds3;
  40. private cef_request_context_handler_t.on_request_context_initialized_delegate _ds4;
  41. private cef_request_context_handler_t.on_before_plugin_load_delegate _ds5;
  42. private cef_request_context_handler_t.get_resource_request_handler_delegate _ds6;
  43. protected CefRequestContextHandler()
  44. {
  45. _self = cef_request_context_handler_t.Alloc();
  46. _ds0 = new cef_request_context_handler_t.add_ref_delegate(add_ref);
  47. _self->_base._add_ref = Marshal.GetFunctionPointerForDelegate(_ds0);
  48. _ds1 = new cef_request_context_handler_t.release_delegate(release);
  49. _self->_base._release = Marshal.GetFunctionPointerForDelegate(_ds1);
  50. _ds2 = new cef_request_context_handler_t.has_one_ref_delegate(has_one_ref);
  51. _self->_base._has_one_ref = Marshal.GetFunctionPointerForDelegate(_ds2);
  52. _ds3 = new cef_request_context_handler_t.has_at_least_one_ref_delegate(has_at_least_one_ref);
  53. _self->_base._has_at_least_one_ref = Marshal.GetFunctionPointerForDelegate(_ds3);
  54. _ds4 = new cef_request_context_handler_t.on_request_context_initialized_delegate(on_request_context_initialized);
  55. _self->_on_request_context_initialized = Marshal.GetFunctionPointerForDelegate(_ds4);
  56. _ds5 = new cef_request_context_handler_t.on_before_plugin_load_delegate(on_before_plugin_load);
  57. _self->_on_before_plugin_load = Marshal.GetFunctionPointerForDelegate(_ds5);
  58. _ds6 = new cef_request_context_handler_t.get_resource_request_handler_delegate(get_resource_request_handler);
  59. _self->_get_resource_request_handler = Marshal.GetFunctionPointerForDelegate(_ds6);
  60. }
  61. ~CefRequestContextHandler()
  62. {
  63. Dispose(false);
  64. }
  65. protected virtual void Dispose(bool disposing)
  66. {
  67. if (_self != null)
  68. {
  69. cef_request_context_handler_t.Free(_self);
  70. _self = null;
  71. }
  72. }
  73. private void add_ref(cef_request_context_handler_t* self)
  74. {
  75. if (Interlocked.Increment(ref _refct) == 1)
  76. {
  77. lock (_roots) { _roots.Add((IntPtr)_self, this); }
  78. }
  79. }
  80. private int release(cef_request_context_handler_t* self)
  81. {
  82. if (Interlocked.Decrement(ref _refct) == 0)
  83. {
  84. lock (_roots) { _roots.Remove((IntPtr)_self); }
  85. return 1;
  86. }
  87. return 0;
  88. }
  89. private int has_one_ref(cef_request_context_handler_t* self)
  90. {
  91. return _refct == 1 ? 1 : 0;
  92. }
  93. private int has_at_least_one_ref(cef_request_context_handler_t* self)
  94. {
  95. return _refct != 0 ? 1 : 0;
  96. }
  97. internal cef_request_context_handler_t* ToNative()
  98. {
  99. add_ref(_self);
  100. return _self;
  101. }
  102. [Conditional("DEBUG")]
  103. private void CheckSelf(cef_request_context_handler_t* self)
  104. {
  105. if (_self != self) throw ExceptionBuilder.InvalidSelfReference();
  106. }
  107. }
  108. }