CommonCefClient.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using System;
  2. using Xilium.CefGlue.Common.Helpers;
  3. using Xilium.CefGlue.Common.Helpers.Logger;
  4. using Xilium.CefGlue.Common.InternalHandlers;
  5. using Xilium.CefGlue.Common.Shared.Helpers;
  6. namespace Xilium.CefGlue.Common
  7. {
  8. internal sealed class CommonCefClient : CefClient
  9. {
  10. private readonly CefLifeSpanHandler _lifeSpanHandler;
  11. private readonly CefDisplayHandler _displayHandler;
  12. private readonly CefRenderHandler _renderHandler;
  13. private readonly CefLoadHandler _loadHandler;
  14. private readonly CefContextMenuHandler _contextMenuHandler;
  15. private readonly ICefBrowserHost _owner;
  16. private readonly MessageDispatcher _messageDispatcher = new MessageDispatcher();
  17. public CommonCefClient(ICefBrowserHost owner, CefRenderHandler renderHandler, ILogger logger)
  18. {
  19. if (owner == null)
  20. {
  21. throw new ArgumentNullException("owner");
  22. }
  23. _owner = owner;
  24. _renderHandler = renderHandler;
  25. _lifeSpanHandler = new CommonCefLifeSpanHandler(owner);
  26. _displayHandler = new CommonCefDisplayHandler(owner);
  27. _loadHandler = new CommonCefLoadHandler(owner);
  28. _contextMenuHandler = new CommonCefContextMenuHandler(owner);
  29. }
  30. protected override CefContextMenuHandler GetContextMenuHandler()
  31. {
  32. return _contextMenuHandler;
  33. }
  34. protected override CefDialogHandler GetDialogHandler()
  35. {
  36. return _owner.DialogHandler;
  37. }
  38. protected override CefDownloadHandler GetDownloadHandler()
  39. {
  40. return _owner.DownloadHandler;
  41. }
  42. protected override CefDragHandler GetDragHandler()
  43. {
  44. return _owner.DragHandler;
  45. }
  46. protected override CefFindHandler GetFindHandler()
  47. {
  48. return _owner.FindHandler;
  49. }
  50. protected override CefFocusHandler GetFocusHandler()
  51. {
  52. return _owner.FocusHandler;
  53. }
  54. protected override CefKeyboardHandler GetKeyboardHandler()
  55. {
  56. return _owner.KeyboardHandler;
  57. }
  58. protected override CefRequestHandler GetRequestHandler()
  59. {
  60. return _owner.RequestHandler;
  61. }
  62. protected override CefJSDialogHandler GetJSDialogHandler()
  63. {
  64. return _owner.JSDialogHandler;
  65. }
  66. protected override CefLifeSpanHandler GetLifeSpanHandler()
  67. {
  68. return _lifeSpanHandler;
  69. }
  70. protected override CefDisplayHandler GetDisplayHandler()
  71. {
  72. return _displayHandler;
  73. }
  74. protected override CefRenderHandler GetRenderHandler()
  75. {
  76. return _renderHandler;
  77. }
  78. protected override CefLoadHandler GetLoadHandler()
  79. {
  80. return _loadHandler;
  81. }
  82. protected override bool OnProcessMessageReceived(CefBrowser browser, CefFrame frame, CefProcessId sourceProcess, CefProcessMessage message)
  83. {
  84. try
  85. {
  86. _messageDispatcher.DispatchMessage(browser, frame, sourceProcess, message);
  87. return base.OnProcessMessageReceived(browser, frame, sourceProcess, message);
  88. }
  89. catch (Exception e)
  90. {
  91. _owner.HandleException(e);
  92. return false;
  93. }
  94. }
  95. public MessageDispatcher Dispatcher => _messageDispatcher;
  96. }
  97. }