CefApp.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. namespace Xilium.CefGlue
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. using Xilium.CefGlue.Interop;
  7. public abstract unsafe partial class CefApp
  8. {
  9. private void on_before_command_line_processing(cef_app_t* self, cef_string_t* process_type, cef_command_line_t* command_line)
  10. {
  11. CheckSelf(self);
  12. var processType = cef_string_t.ToString(process_type);
  13. using (var m_commandLine = CefCommandLine.FromNative(command_line))
  14. {
  15. OnBeforeCommandLineProcessing(processType, m_commandLine);
  16. }
  17. }
  18. /// <summary>
  19. /// Provides an opportunity to view and/or modify command-line arguments before
  20. /// processing by CEF and Chromium. The |process_type| value will be empty for
  21. /// the browser process. Do not keep a reference to the CefCommandLine object
  22. /// passed to this method. The CefSettings.command_line_args_disabled value
  23. /// can be used to start with an empty command-line object. Any values
  24. /// specified in CefSettings that equate to command-line arguments will be set
  25. /// before this method is called. Be cautious when using this method to modify
  26. /// command-line arguments for non-browser processes as this may result in
  27. /// undefined behavior including crashes.
  28. /// </summary>
  29. protected virtual void OnBeforeCommandLineProcessing(string processType, CefCommandLine commandLine)
  30. {
  31. }
  32. private void on_register_custom_schemes(cef_app_t* self, cef_scheme_registrar_t* registrar)
  33. {
  34. CheckSelf(self);
  35. var m_registrar = CefSchemeRegistrar.FromNative(registrar);
  36. try
  37. {
  38. OnRegisterCustomSchemes(m_registrar);
  39. }
  40. finally
  41. {
  42. m_registrar.ReleaseObject();
  43. }
  44. }
  45. /// <summary>
  46. /// Provides an opportunity to register custom schemes. Do not keep a reference
  47. /// to the |registrar| object. This method is called on the main thread for
  48. /// each process and the registered schemes should be the same across all
  49. /// processes.
  50. /// </summary>
  51. protected virtual void OnRegisterCustomSchemes(CefSchemeRegistrar registrar)
  52. {
  53. }
  54. private cef_resource_bundle_handler_t* get_resource_bundle_handler(cef_app_t* self)
  55. {
  56. CheckSelf(self);
  57. var result = GetResourceBundleHandler();
  58. return result != null ? result.ToNative() : null;
  59. }
  60. /// <summary>
  61. /// Return the handler for resource bundle events. If
  62. /// CefSettings.pack_loading_disabled is true a handler must be returned. If no
  63. /// handler is returned resources will be loaded from pack files. This method
  64. /// is called by the browser and renderer processes on multiple threads.
  65. /// </summary>
  66. protected virtual CefResourceBundleHandler GetResourceBundleHandler()
  67. {
  68. return null;
  69. }
  70. private cef_browser_process_handler_t* get_browser_process_handler(cef_app_t* self)
  71. {
  72. CheckSelf(self);
  73. var result = GetBrowserProcessHandler();
  74. return result != null ? result.ToNative() : null;
  75. }
  76. /// <summary>
  77. /// Return the handler for functionality specific to the browser process. This
  78. /// method is called on multiple threads in the browser process.
  79. /// </summary>
  80. protected virtual CefBrowserProcessHandler GetBrowserProcessHandler()
  81. {
  82. return null;
  83. }
  84. private cef_render_process_handler_t* get_render_process_handler(cef_app_t* self)
  85. {
  86. CheckSelf(self);
  87. var result = GetRenderProcessHandler();
  88. return result != null ? result.ToNative() : null;
  89. }
  90. /// <summary>
  91. /// Return the handler for render process events. This method is called by the
  92. /// render process main thread.
  93. /// </summary>
  94. /// <returns></returns>
  95. protected virtual CefRenderProcessHandler GetRenderProcessHandler()
  96. {
  97. return null;
  98. }
  99. }
  100. }