WebAppRenderer.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #pragma once
  2. #include <Atomic/Container/List.h>
  3. #include "WebApp.h"
  4. namespace Atomic
  5. {
  6. // Web app implementation for the renderer process.
  7. class WebAppRenderer : public WebApp, public CefRenderProcessHandler
  8. {
  9. public:
  10. // Interface for renderer delegates. All Delegates must be returned via
  11. // CreateDelegates. Do not perform work in the Delegate
  12. // constructor. See CefRenderProcessHandler for documentation.
  13. class Delegate : public virtual CefBase
  14. {
  15. public:
  16. virtual void OnRenderThreadCreated(CefRefPtr<WebAppRenderer> app,
  17. CefRefPtr<CefListValue> extra_info) {}
  18. virtual void OnWebKitInitialized(CefRefPtr<WebAppRenderer> app) {}
  19. virtual void OnBrowserCreated(CefRefPtr<WebAppRenderer> app,
  20. CefRefPtr<CefBrowser> browser) {}
  21. virtual void OnBrowserDestroyed(CefRefPtr<WebAppRenderer> app,
  22. CefRefPtr<CefBrowser> browser) {}
  23. virtual CefRefPtr<CefLoadHandler> GetLoadHandler(CefRefPtr<WebAppRenderer> app)
  24. {
  25. return NULL;
  26. }
  27. virtual bool OnBeforeNavigation(CefRefPtr<WebAppRenderer> app,
  28. CefRefPtr<CefBrowser> browser,
  29. CefRefPtr<CefFrame> frame,
  30. CefRefPtr<CefRequest> request,
  31. cef_navigation_type_t navigation_type,
  32. bool is_redirect)
  33. {
  34. return false;
  35. }
  36. virtual void OnContextCreated(CefRefPtr<WebAppRenderer> app,
  37. CefRefPtr<CefBrowser> browser,
  38. CefRefPtr<CefFrame> frame,
  39. CefRefPtr<CefV8Context> context) {}
  40. virtual void OnContextReleased(CefRefPtr<WebAppRenderer> app,
  41. CefRefPtr<CefBrowser> browser,
  42. CefRefPtr<CefFrame> frame,
  43. CefRefPtr<CefV8Context> context) {}
  44. virtual void OnUncaughtException(CefRefPtr<WebAppRenderer> app,
  45. CefRefPtr<CefBrowser> browser,
  46. CefRefPtr<CefFrame> frame,
  47. CefRefPtr<CefV8Context> context,
  48. CefRefPtr<CefV8Exception> exception,
  49. CefRefPtr<CefV8StackTrace> stackTrace) {}
  50. virtual void OnFocusedNodeChanged(CefRefPtr<WebAppRenderer> app,
  51. CefRefPtr<CefBrowser> browser,
  52. CefRefPtr<CefFrame> frame,
  53. CefRefPtr<CefDOMNode> node) {}
  54. // Called when a process message is received. Return true if the message was
  55. // handled and should not be passed on to other handlers. Delegates
  56. // should check for unique message names to avoid interfering with each
  57. // other.
  58. virtual bool OnProcessMessageReceived(
  59. CefRefPtr<WebAppRenderer> app,
  60. CefRefPtr<CefBrowser> browser,
  61. CefProcessId source_process,
  62. CefRefPtr<CefProcessMessage> message)
  63. {
  64. return false;
  65. }
  66. };
  67. typedef List<CefRefPtr<Delegate>> DelegateSet;
  68. WebAppRenderer();
  69. private:
  70. // Creates all of the Delegate objects. Implemented by cefclient in
  71. // client_app_delegates_renderer.cc
  72. static void CreateDelegates(DelegateSet& delegates);
  73. // CefApp methods.
  74. CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() OVERRIDE {
  75. return this;
  76. }
  77. // CefRenderProcessHandler methods.
  78. void OnRenderThreadCreated(CefRefPtr<CefListValue> extra_info) OVERRIDE;
  79. void OnWebKitInitialized() OVERRIDE;
  80. void OnBrowserCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
  81. void OnBrowserDestroyed(CefRefPtr<CefBrowser> browser) OVERRIDE;
  82. CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE;
  83. bool OnBeforeNavigation(CefRefPtr<CefBrowser> browser,
  84. CefRefPtr<CefFrame> frame,
  85. CefRefPtr<CefRequest> request,
  86. NavigationType navigation_type,
  87. bool is_redirect) OVERRIDE;
  88. void OnContextCreated(CefRefPtr<CefBrowser> browser,
  89. CefRefPtr<CefFrame> frame,
  90. CefRefPtr<CefV8Context> context) OVERRIDE;
  91. void OnContextReleased(CefRefPtr<CefBrowser> browser,
  92. CefRefPtr<CefFrame> frame,
  93. CefRefPtr<CefV8Context> context) OVERRIDE;
  94. void OnUncaughtException(CefRefPtr<CefBrowser> browser,
  95. CefRefPtr<CefFrame> frame,
  96. CefRefPtr<CefV8Context> context,
  97. CefRefPtr<CefV8Exception> exception,
  98. CefRefPtr<CefV8StackTrace> stackTrace) OVERRIDE;
  99. void OnFocusedNodeChanged(CefRefPtr<CefBrowser> browser,
  100. CefRefPtr<CefFrame> frame,
  101. CefRefPtr<CefDOMNode> node) OVERRIDE;
  102. bool OnProcessMessageReceived(
  103. CefRefPtr<CefBrowser> browser,
  104. CefProcessId source_process,
  105. CefRefPtr<CefProcessMessage> message) OVERRIDE;
  106. private:
  107. // Set of supported Delegates.
  108. DelegateSet delegates_;
  109. IMPLEMENT_REFCOUNTING(WebAppRenderer);
  110. DISALLOW_COPY_AND_ASSIGN(WebAppRenderer);
  111. };
  112. }