CefExtension.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. /// Object representing an extension. Methods may be called on any thread unless
  10. /// otherwise indicated.
  11. /// </summary>
  12. public sealed unsafe partial class CefExtension
  13. {
  14. /// <summary>
  15. /// Returns the unique extension identifier. This is calculated based on the
  16. /// extension public key, if available, or on the extension path. See
  17. /// https://developer.chrome.com/extensions/manifest/key for details.
  18. /// </summary>
  19. public string Identifier
  20. {
  21. get
  22. {
  23. return cef_string_userfree.ToString(
  24. cef_extension_t.get_identifier(_self)
  25. );
  26. }
  27. }
  28. /// <summary>
  29. /// Returns the absolute path to the extension directory on disk. This value
  30. /// will be prefixed with PK_DIR_RESOURCES if a relative path was passed to
  31. /// CefRequestContext::LoadExtension.
  32. /// </summary>
  33. public string Path
  34. {
  35. get
  36. {
  37. return cef_string_userfree.ToString(
  38. cef_extension_t.get_path(_self)
  39. );
  40. }
  41. }
  42. /// <summary>
  43. /// Returns the extension manifest contents as a CefDictionaryValue object. See
  44. /// https://developer.chrome.com/extensions/manifest for details.
  45. /// </summary>
  46. public CefDictionaryValue GetManifest()
  47. {
  48. return CefDictionaryValue.FromNativeOrNull(
  49. cef_extension_t.get_manifest(_self)
  50. );
  51. }
  52. /// <summary>
  53. /// Returns true if this object is the same extension as |that| object.
  54. /// Extensions are considered the same if identifier, path and loader context
  55. /// match.
  56. /// </summary>
  57. public bool IsSame(CefExtension that)
  58. {
  59. var n_that = that != null ? that.ToNative() : null;
  60. return cef_extension_t.is_same(_self, n_that) != 0;
  61. }
  62. /// <summary>
  63. /// Returns the handler for this extension. Will return NULL for internal
  64. /// extensions or if no handler was passed to CefRequestContext::LoadExtension.
  65. /// </summary>
  66. public CefExtensionHandler GetHandler()
  67. {
  68. return CefExtensionHandler.FromNativeOrNull(
  69. cef_extension_t.get_handler(_self)
  70. );
  71. }
  72. /// <summary>
  73. /// Returns the request context that loaded this extension. Will return NULL
  74. /// for internal extensions or if the extension has been unloaded. See the
  75. /// CefRequestContext::LoadExtension documentation for more information about
  76. /// loader contexts. Must be called on the browser process UI thread.
  77. /// </summary>
  78. public CefRequestContext GetLoaderContext()
  79. {
  80. return CefRequestContext.FromNativeOrNull(
  81. cef_extension_t.get_loader_context(_self)
  82. );
  83. }
  84. /// <summary>
  85. /// Returns true if this extension is currently loaded. Must be called on the
  86. /// browser process UI thread.
  87. /// </summary>
  88. public bool IsLoaded
  89. {
  90. get
  91. {
  92. return cef_extension_t.is_loaded(_self) != 0;
  93. }
  94. }
  95. /// <summary>
  96. /// Unload this extension if it is not an internal extension and is currently
  97. /// loaded. Will result in a call to CefExtensionHandler::OnExtensionUnloaded
  98. /// on success.
  99. /// </summary>
  100. public void Unload()
  101. {
  102. cef_extension_t.unload(_self);
  103. }
  104. }
  105. }