WebBrowserHost.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 "WebBrowserHost.h"
  8. class SimpleApp : public CefApp,
  9. public CefBrowserProcessHandler {
  10. public:
  11. SimpleApp();
  12. // CefApp methods:
  13. virtual CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler()
  14. OVERRIDE { return this; }
  15. // CefBrowserProcessHandler methods:
  16. virtual void OnContextInitialized() OVERRIDE;
  17. private:
  18. // Include the default reference counting implementation.
  19. IMPLEMENT_REFCOUNTING(SimpleApp);
  20. };
  21. SimpleApp::SimpleApp() {
  22. }
  23. void SimpleApp::OnContextInitialized() {
  24. CEF_REQUIRE_UI_THREAD();
  25. }
  26. namespace Atomic
  27. {
  28. WebBrowserHost::WebBrowserHost(Context* context) : Object (context)
  29. {
  30. const Vector<String>& arguments = GetArguments();
  31. const char** _argv { 0 };
  32. PODVector<const char*> argv;
  33. for (unsigned i = 0; i < arguments.Size(); i++)
  34. argv.Push(arguments[i].CString());
  35. CefMainArgs args(arguments.Size(), arguments.Size() ? (char**) &argv[0] : (char **) _argv);
  36. int result = CefExecuteProcess(args, nullptr, nullptr);
  37. if (result >= 0)
  38. {
  39. LOGERROR("CEFExecuteProcess - Error");
  40. }
  41. CefSettings settings;
  42. settings.windowless_rendering_enabled = true;
  43. // If losing OSX system menu, it means we're calling this
  44. // before initializing graphics subsystem
  45. if (!CefInitialize(args, settings, nullptr, nullptr))
  46. {
  47. LOGERROR("CefInitialize - Error");
  48. }
  49. }
  50. WebBrowserHost::~WebBrowserHost()
  51. {
  52. }
  53. }