CefClient.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. public abstract unsafe partial class CefClient
  9. {
  10. private cef_audio_handler_t* get_audio_handler(cef_client_t* self)
  11. {
  12. CheckSelf(self);
  13. var result = GetAudioHandler();
  14. return result != null ? result.ToNative() : null;
  15. }
  16. /// <summary>
  17. /// Return the handler for audio rendering events.
  18. /// </summary>
  19. protected virtual CefAudioHandler GetAudioHandler()
  20. {
  21. return null;
  22. }
  23. private cef_context_menu_handler_t* get_context_menu_handler(cef_client_t* self)
  24. {
  25. CheckSelf(self);
  26. var result = GetContextMenuHandler();
  27. return result != null ? result.ToNative() : null;
  28. }
  29. /// <summary>
  30. /// Return the handler for context menus. If no handler is provided the default
  31. /// implementation will be used.
  32. /// </summary>
  33. protected virtual CefContextMenuHandler GetContextMenuHandler()
  34. {
  35. return null;
  36. }
  37. private cef_dialog_handler_t* get_dialog_handler(cef_client_t* self)
  38. {
  39. CheckSelf(self);
  40. var result = GetDialogHandler();
  41. return result != null ? result.ToNative() : null;
  42. }
  43. /// <summary>
  44. /// Return the handler for dialogs. If no handler is provided the default
  45. /// implementation will be used.
  46. /// </summary>
  47. protected virtual CefDialogHandler GetDialogHandler()
  48. {
  49. return null;
  50. }
  51. private cef_display_handler_t* get_display_handler(cef_client_t* self)
  52. {
  53. CheckSelf(self);
  54. var result = GetDisplayHandler();
  55. return result != null ? result.ToNative() : null;
  56. }
  57. /// <summary>
  58. /// Return the handler for browser display state events.
  59. /// </summary>
  60. protected virtual CefDisplayHandler GetDisplayHandler()
  61. {
  62. return null;
  63. }
  64. private cef_download_handler_t* get_download_handler(cef_client_t* self)
  65. {
  66. CheckSelf(self);
  67. var result = GetDownloadHandler();
  68. return result != null ? result.ToNative() : null;
  69. }
  70. /// <summary>
  71. /// Return the handler for download events. If no handler is returned downloads
  72. /// will not be allowed.
  73. /// </summary>
  74. protected virtual CefDownloadHandler GetDownloadHandler()
  75. {
  76. return null;
  77. }
  78. private cef_drag_handler_t* get_drag_handler(cef_client_t* self)
  79. {
  80. CheckSelf(self);
  81. var result = GetDragHandler();
  82. return result != null ? result.ToNative() : null;
  83. }
  84. /// <summary>
  85. /// Return the handler for drag events.
  86. /// </summary>
  87. protected virtual CefDragHandler GetDragHandler()
  88. {
  89. return null;
  90. }
  91. private cef_find_handler_t* get_find_handler(cef_client_t* self)
  92. {
  93. CheckSelf(self);
  94. var result = GetFindHandler();
  95. return result != null ? result.ToNative() : null;
  96. }
  97. /// <summary>
  98. /// Return the handler for find result events.
  99. /// </summary>
  100. protected virtual CefFindHandler GetFindHandler()
  101. {
  102. return null;
  103. }
  104. private cef_focus_handler_t* get_focus_handler(cef_client_t* self)
  105. {
  106. CheckSelf(self);
  107. var result = GetFocusHandler();
  108. return result != null ? result.ToNative() : null;
  109. }
  110. /// <summary>
  111. /// Return the handler for focus events.
  112. /// </summary>
  113. protected virtual CefFocusHandler GetFocusHandler()
  114. {
  115. return null;
  116. }
  117. private cef_jsdialog_handler_t* get_jsdialog_handler(cef_client_t* self)
  118. {
  119. CheckSelf(self);
  120. var result = GetJSDialogHandler();
  121. return result != null ? result.ToNative() : null;
  122. }
  123. /// <summary>
  124. /// Return the handler for JavaScript dialogs. If no handler is provided the
  125. /// default implementation will be used.
  126. /// </summary>
  127. protected virtual CefJSDialogHandler GetJSDialogHandler()
  128. {
  129. return null;
  130. }
  131. private cef_keyboard_handler_t* get_keyboard_handler(cef_client_t* self)
  132. {
  133. CheckSelf(self);
  134. var result = GetKeyboardHandler();
  135. return result != null ? result.ToNative() : null;
  136. }
  137. /// <summary>
  138. /// Return the handler for keyboard events.
  139. /// </summary>
  140. protected virtual CefKeyboardHandler GetKeyboardHandler()
  141. {
  142. return null;
  143. }
  144. private cef_life_span_handler_t* get_life_span_handler(cef_client_t* self)
  145. {
  146. CheckSelf(self);
  147. var result = GetLifeSpanHandler();
  148. return result != null ? result.ToNative() : null;
  149. }
  150. /// <summary>
  151. /// Return the handler for browser life span events.
  152. /// </summary>
  153. protected virtual CefLifeSpanHandler GetLifeSpanHandler()
  154. {
  155. return null;
  156. }
  157. private cef_load_handler_t* get_load_handler(cef_client_t* self)
  158. {
  159. CheckSelf(self);
  160. var result = GetLoadHandler();
  161. return result != null ? result.ToNative() : null;
  162. }
  163. /// <summary>
  164. /// Return the handler for browser load status events.
  165. /// </summary>
  166. protected virtual CefLoadHandler GetLoadHandler()
  167. {
  168. return null;
  169. }
  170. private cef_print_handler_t* get_print_handler(cef_client_t* self)
  171. {
  172. CheckSelf(self);
  173. var result = GetPrintHandler();
  174. return result != null ? result.ToNative() : null;
  175. }
  176. /// <summary>
  177. /// Return the handler for printing on Linux. If a print handler is not
  178. /// provided then printing will not be supported on the Linux platform.
  179. /// </summary>
  180. protected virtual CefPrintHandler GetPrintHandler()
  181. {
  182. return null;
  183. }
  184. private cef_render_handler_t* get_render_handler(cef_client_t* self)
  185. {
  186. CheckSelf(self);
  187. var result = GetRenderHandler();
  188. return result != null ? result.ToNative() : null;
  189. }
  190. /// <summary>
  191. /// Return the handler for off-screen rendering events.
  192. /// </summary>
  193. protected virtual CefRenderHandler GetRenderHandler()
  194. {
  195. return null;
  196. }
  197. private cef_request_handler_t* get_request_handler(cef_client_t* self)
  198. {
  199. CheckSelf(self);
  200. var result = GetRequestHandler();
  201. return result != null ? result.ToNative() : null;
  202. }
  203. /// <summary>
  204. /// Return the handler for browser request events.
  205. /// </summary>
  206. protected virtual CefRequestHandler GetRequestHandler()
  207. {
  208. return null;
  209. }
  210. private int on_process_message_received(cef_client_t* self, cef_browser_t* browser, cef_frame_t* frame, CefProcessId source_process, cef_process_message_t* message)
  211. {
  212. CheckSelf(self);
  213. var m_browser = CefBrowser.FromNative(browser);
  214. var m_frame = CefFrame.FromNative(frame);
  215. using (var m_message = CefProcessMessage.FromNative(message))
  216. {
  217. var result = OnProcessMessageReceived(m_browser, m_frame, source_process, m_message);
  218. return result ? 1 : 0;
  219. }
  220. }
  221. /// <summary>
  222. /// Called when a new message is received from a different process. Return true
  223. /// if the message was handled or false otherwise. Do not keep a reference to
  224. /// or attempt to access the message outside of this callback.
  225. /// </summary>
  226. protected virtual bool OnProcessMessageReceived(CefBrowser browser, CefFrame frame, CefProcessId sourceProcess, CefProcessMessage message)
  227. {
  228. return false;
  229. }
  230. }
  231. }