WebBrowserHost.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include <ThirdParty/CEF/include/cef_app.h>
  2. #include <ThirdParty/CEF/include/cef_client.h>
  3. #include <ThirdParty/CEF/include/cef_render_handler.h>
  4. #include <ThirdParty/CEF/include/wrapper/cef_helpers.h>
  5. #include <Atomic/Core/ProcessUtils.h>
  6. #include <Atomic/IO/Log.h>
  7. #include "WebClient.h"
  8. #include "WebBrowserHost.h"
  9. class SimpleApp : public CefApp,
  10. public CefBrowserProcessHandler {
  11. public:
  12. SimpleApp();
  13. // CefApp methods:
  14. virtual CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler()
  15. OVERRIDE { return this; }
  16. // CefBrowserProcessHandler methods:
  17. virtual void OnContextInitialized() OVERRIDE;
  18. private:
  19. // Include the default reference counting implementation.
  20. IMPLEMENT_REFCOUNTING(SimpleApp);
  21. };
  22. SimpleApp::SimpleApp() {
  23. }
  24. void SimpleApp::OnContextInitialized() {
  25. CEF_REQUIRE_UI_THREAD();
  26. }
  27. namespace Atomic
  28. {
  29. WebBrowserHost::WebBrowserHost(Context* context) : Object (context)
  30. {
  31. const Vector<String>& arguments = GetArguments();
  32. const char** _argv { 0 };
  33. PODVector<const char*> argv;
  34. for (unsigned i = 0; i < arguments.Size(); i++)
  35. argv.Push(arguments[i].CString());
  36. CefMainArgs args(arguments.Size(), arguments.Size() ? (char**) &argv[0] : (char **) _argv);
  37. int result = CefExecuteProcess(args, nullptr, nullptr);
  38. if (result >= 0)
  39. {
  40. LOGERROR("CEFExecuteProcess - Error");
  41. }
  42. CefSettings settings;
  43. settings.windowless_rendering_enabled = true;
  44. // If losing OSX system menu, it means we're calling this
  45. // before initializing graphics subsystem
  46. if (!CefInitialize(args, settings, nullptr, nullptr))
  47. {
  48. LOGERROR("CefInitialize - Error");
  49. }
  50. }
  51. WebBrowserHost::~WebBrowserHost()
  52. {
  53. }
  54. bool WebBrowserHost::CreateBrowser(WebClient* webClient)
  55. {
  56. CefWindowInfo windowInfo;
  57. CefBrowserSettings browserSettings;
  58. CefBrowserHost::CreateBrowser(windowInfo, (CefClient*) webClient->d_,
  59. "http://www.atomicgameengine.com", browserSettings, nullptr);
  60. return true;
  61. }
  62. }