CefResourceBundleHandler.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. namespace Xilium.CefGlue
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Runtime.InteropServices;
  7. using Xilium.CefGlue.Interop;
  8. /// <summary>
  9. /// Class used to implement a custom resource bundle interface. See CefSettings
  10. /// for additional options related to resource bundle loading. The methods of
  11. /// this class may be called on multiple threads.
  12. /// </summary>
  13. public abstract unsafe partial class CefResourceBundleHandler
  14. {
  15. private int get_localized_string(cef_resource_bundle_handler_t* self, int string_id, cef_string_t* @string)
  16. {
  17. CheckSelf(self);
  18. string mValue;
  19. var result = GetLocalizedString(string_id, out mValue);
  20. if (result)
  21. {
  22. cef_string_t.Copy(mValue, @string);
  23. return 1;
  24. }
  25. else return 0;
  26. }
  27. /// <summary>
  28. /// Called to retrieve a localized translation for the specified |string_id|.
  29. /// To provide the translation set |string| to the translation string and
  30. /// return true. To use the default translation return false. Include
  31. /// cef_pack_strings.h for a listing of valid string ID values.
  32. /// </summary>
  33. protected virtual bool GetLocalizedString(int stringId, out string value)
  34. {
  35. value = null;
  36. return false;
  37. }
  38. private int get_data_resource(cef_resource_bundle_handler_t* self, int resource_id, void** data, UIntPtr* data_size)
  39. {
  40. CheckSelf(self);
  41. void* mData;
  42. UIntPtr mDataSize;
  43. var result = GetDataResource(resource_id, out mData, out mDataSize);
  44. if (result)
  45. {
  46. *data = mData;
  47. *data_size = mDataSize;
  48. return 1;
  49. }
  50. else return 0;
  51. }
  52. /// <summary>
  53. /// Called to retrieve data for the specified scale independent |resource_id|.
  54. /// To provide the resource data set |data| and |data_size| to the data pointer
  55. /// and size respectively and return true. To use the default resource data
  56. /// return false. The resource data will not be copied and must remain resident
  57. /// in memory. Include cef_pack_resources.h for a listing of valid resource ID
  58. /// values.
  59. /// </summary>
  60. protected virtual bool GetDataResource(int resourceId, out void* data, out UIntPtr dataSize)
  61. {
  62. data = null;
  63. dataSize = UIntPtr.Zero;
  64. return false;
  65. }
  66. private int get_data_resource_for_scale(cef_resource_bundle_handler_t* self, int resource_id, CefScaleFactor scale_factor, void** data, UIntPtr* data_size)
  67. {
  68. CheckSelf(self);
  69. void* mData;
  70. UIntPtr mDataSize;
  71. var result = GetDataResourceForScale(resource_id, scale_factor, out mData, out mDataSize);
  72. if (result)
  73. {
  74. *data = mData;
  75. *data_size = mDataSize;
  76. return 1;
  77. }
  78. else return 0;
  79. }
  80. /// <summary>
  81. /// Called to retrieve data for the specified |resource_id| nearest the scale
  82. /// factor |scale_factor|. To provide the resource data set |data| and
  83. /// |data_size| to the data pointer and size respectively and return true. To
  84. /// use the default resource data return false. The resource data will not be
  85. /// copied and must remain resident in memory. Include cef_pack_resources.h for
  86. /// a listing of valid resource ID values.
  87. /// </summary>
  88. protected virtual bool GetDataResourceForScale(int resourceId, CefScaleFactor scaleFactor, out void* data, out UIntPtr dataSize)
  89. {
  90. data = null;
  91. dataSize = UIntPtr.Zero;
  92. return false;
  93. }
  94. }
  95. }