WebAppRenderer.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //
  2. // Copyright (c) 2014-2016, THUNDERBEAST GAMES LLC All rights reserved
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include <Atomic/Container/List.h>
  24. #include "WebApp.h"
  25. namespace Atomic
  26. {
  27. // Web app implementation for the renderer process.
  28. class WebAppRenderer : public WebApp, public CefRenderProcessHandler
  29. {
  30. public:
  31. // Interface for renderer delegates. All Delegates must be returned via
  32. // CreateDelegates. Do not perform work in the Delegate
  33. // constructor. See CefRenderProcessHandler for documentation.
  34. class Delegate : public virtual CefBase
  35. {
  36. public:
  37. virtual void OnRenderThreadCreated(CefRefPtr<WebAppRenderer> app,
  38. CefRefPtr<CefListValue> extra_info) {}
  39. virtual void OnWebKitInitialized(CefRefPtr<WebAppRenderer> app) {}
  40. virtual void OnBrowserCreated(CefRefPtr<WebAppRenderer> app,
  41. CefRefPtr<CefBrowser> browser) {}
  42. virtual void OnBrowserDestroyed(CefRefPtr<WebAppRenderer> app,
  43. CefRefPtr<CefBrowser> browser) {}
  44. virtual CefRefPtr<CefLoadHandler> GetLoadHandler(CefRefPtr<WebAppRenderer> app)
  45. {
  46. return NULL;
  47. }
  48. virtual bool OnBeforeNavigation(CefRefPtr<WebAppRenderer> app,
  49. CefRefPtr<CefBrowser> browser,
  50. CefRefPtr<CefFrame> frame,
  51. CefRefPtr<CefRequest> request,
  52. cef_navigation_type_t navigation_type,
  53. bool is_redirect)
  54. {
  55. return false;
  56. }
  57. virtual void OnContextCreated(CefRefPtr<WebAppRenderer> app,
  58. CefRefPtr<CefBrowser> browser,
  59. CefRefPtr<CefFrame> frame,
  60. CefRefPtr<CefV8Context> context) {}
  61. virtual void OnContextReleased(CefRefPtr<WebAppRenderer> app,
  62. CefRefPtr<CefBrowser> browser,
  63. CefRefPtr<CefFrame> frame,
  64. CefRefPtr<CefV8Context> context) {}
  65. virtual void OnUncaughtException(CefRefPtr<WebAppRenderer> app,
  66. CefRefPtr<CefBrowser> browser,
  67. CefRefPtr<CefFrame> frame,
  68. CefRefPtr<CefV8Context> context,
  69. CefRefPtr<CefV8Exception> exception,
  70. CefRefPtr<CefV8StackTrace> stackTrace) {}
  71. virtual void OnFocusedNodeChanged(CefRefPtr<WebAppRenderer> app,
  72. CefRefPtr<CefBrowser> browser,
  73. CefRefPtr<CefFrame> frame,
  74. CefRefPtr<CefDOMNode> node) {}
  75. // Called when a process message is received. Return true if the message was
  76. // handled and should not be passed on to other handlers. Delegates
  77. // should check for unique message names to avoid interfering with each
  78. // other.
  79. virtual bool OnProcessMessageReceived(
  80. CefRefPtr<WebAppRenderer> app,
  81. CefRefPtr<CefBrowser> browser,
  82. CefProcessId source_process,
  83. CefRefPtr<CefProcessMessage> message)
  84. {
  85. return false;
  86. }
  87. };
  88. typedef List<CefRefPtr<Delegate>> DelegateSet;
  89. WebAppRenderer();
  90. private:
  91. // Creates all of the Delegate objects. Implemented by cefclient in
  92. // client_app_delegates_renderer.cc
  93. static void CreateDelegates(DelegateSet& delegates);
  94. // CefApp methods.
  95. CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() OVERRIDE {
  96. return this;
  97. }
  98. // CefRenderProcessHandler methods.
  99. void OnRenderThreadCreated(CefRefPtr<CefListValue> extra_info) OVERRIDE;
  100. void OnWebKitInitialized() OVERRIDE;
  101. void OnBrowserCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
  102. void OnBrowserDestroyed(CefRefPtr<CefBrowser> browser) OVERRIDE;
  103. CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE;
  104. bool OnBeforeNavigation(CefRefPtr<CefBrowser> browser,
  105. CefRefPtr<CefFrame> frame,
  106. CefRefPtr<CefRequest> request,
  107. NavigationType navigation_type,
  108. bool is_redirect) OVERRIDE;
  109. void OnContextCreated(CefRefPtr<CefBrowser> browser,
  110. CefRefPtr<CefFrame> frame,
  111. CefRefPtr<CefV8Context> context) OVERRIDE;
  112. void OnContextReleased(CefRefPtr<CefBrowser> browser,
  113. CefRefPtr<CefFrame> frame,
  114. CefRefPtr<CefV8Context> context) OVERRIDE;
  115. void OnUncaughtException(CefRefPtr<CefBrowser> browser,
  116. CefRefPtr<CefFrame> frame,
  117. CefRefPtr<CefV8Context> context,
  118. CefRefPtr<CefV8Exception> exception,
  119. CefRefPtr<CefV8StackTrace> stackTrace) OVERRIDE;
  120. void OnFocusedNodeChanged(CefRefPtr<CefBrowser> browser,
  121. CefRefPtr<CefFrame> frame,
  122. CefRefPtr<CefDOMNode> node) OVERRIDE;
  123. bool OnProcessMessageReceived(
  124. CefRefPtr<CefBrowser> browser,
  125. CefProcessId source_process,
  126. CefRefPtr<CefProcessMessage> message) OVERRIDE;
  127. private:
  128. // Set of supported Delegates.
  129. DelegateSet delegates_;
  130. IMPLEMENT_REFCOUNTING(WebAppRenderer);
  131. DISALLOW_COPY_AND_ASSIGN(WebAppRenderer);
  132. };
  133. }