Leviathan  0.8.0.0
Leviathan game engine
GlobalCEFHandler.h
Go to the documentation of this file.
1 // Leviathan Game Engine
2 // Copyright (c) 2012-2018 Henri Hyyryläinen
3 #pragma once
4 #include "Define.h"
5 // ------------------------------------ //
8 
9 #include "include/cef_task.h"
10 #include "include/internal/cef_ptr.h"
11 
12 // Forward declare some things //
13 class CefScopedSandboxInfo;
14 
15 #define REQUIRE_UI_THREAD() assert(CefCurrentlyOn(TID_UI));
16 #define REQUIRE_IO_THREAD() assert(CefCurrentlyOn(TID_IO));
17 #define REQUIRE_FILE_THREAD() assert(CefCurrentlyOn(TID_FILE));
18 
19 namespace Leviathan {
20 
23  friend GlobalCEFHandler;
24 
25 public:
28 
30  DLLEXPORT CefRefPtr<GUI::CefApplication> GetCEFApp() const;
31 
32 protected:
33  CefRefPtr<GUI::CefApplication> CEFApp;
34 };
35 
38 public:
45  int argcount, char* args[], int& returnvalue,
46  std::shared_ptr<CEFApplicationKeeper>& keeper, const std::string& logname
47 #ifdef _WIN32
48 #ifdef CEF_ENABLE_SANDBOX
49  ,
50  CefScopedSandboxInfo& sandbox
51 #endif
52  ,
53  HINSTANCE hInstance
54 #endif // _WIN32
55  );
56 
57  DLLEXPORT static void CEFLastThingInProgram();
59 
60  DLLEXPORT static void DoCEFMessageLoopWork();
61 
66  std::shared_ptr<GUI::JSAsyncCustom> ptr);
70 
72  DLLEXPORT static const std::vector<std::shared_ptr<GUI::JSAsyncCustom>>&
74 
78  std::shared_ptr<GUI::CustomExtension> extension);
79 
80 
87 
89  DLLEXPORT static bool HandleCustomExtensionProcessMessage(CefRefPtr<CefBrowser> browser,
90  CefProcessId source_process, CefRefPtr<CefProcessMessage> message);
91 
92 private:
93  GlobalCEFHandler() = delete;
94  ~GlobalCEFHandler() = delete;
95 
96 protected:
98  static bool CEFInitialized;
100 
102  static std::vector<std::shared_ptr<GUI::JSAsyncCustom>> CustomJSHandlers;
103 
105  static std::vector<GUI::LeviathanJavaScriptAsync*> JSAsynToNotify;
106 
107  static std::recursive_mutex JSCustomMutex;
108 
110  static std::vector<std::shared_ptr<GUI::CustomExtension>> CustomExtensions;
111 };
112 
113 } // namespace Leviathan
Provides client applications and modules (not done) support for defining custom request responses.
static std::vector< std::shared_ptr< GUI::CustomExtension > > CustomExtensions
Custom extension storage here to allow routing messages to the right one.
static DLLEXPORT const std::vector< std::shared_ptr< GUI::JSAsyncCustom > > & GetRegisteredCustomHandlers()
Mainly allows LeviathanJavaScriptAsync to access the list of handlers.
static DLLEXPORT void RegisterCustomJavaScriptQueryHandler(std::shared_ptr< GUI::JSAsyncCustom > ptr)
Registers a new JavaScript query handler.
static std::vector< GUI::LeviathanJavaScriptAsync * > JSAsynToNotify
Stored to be able to notify all LeviathanJavaScriptAsync objects.
static DLLEXPORT bool CEFFirstCheckChildProcess(int argcount, char *args[], int &returnvalue, std::shared_ptr< CEFApplicationKeeper > &keeper, const std::string &logname)
This is the first function called in the Engine to handle CEF child processes.
static DLLEXPORT void RegisterCustomExtension(std::shared_ptr< GUI::CustomExtension > extension)
Registers a custom extension for all render processes to load as a V8 extension.
static DLLEXPORT void UnRegisterCustomJavaScriptQueryHandler(GUI::JSAsyncCustom *toremove)
Unregisters a registered query handler.
DLLEXPORT CefRefPtr< GUI::CefApplication > GetCEFApp() const
Gets the corresponding Gui::CefApplication.
Handles asynchronous javascript requests.
static std::recursive_mutex JSCustomMutex
static DLLEXPORT void UnRegisterJSAsync(GUI::LeviathanJavaScriptAsync *ptr)
Unregisters a registered LeviathanJavaScriptAsync.
Keeps certain CEF objects allocated for long enough.
static DLLEXPORT void RegisterJSAsync(GUI::LeviathanJavaScriptAsync *ptr)
Registers a LeviathanJavaScriptAsync to receive notifications about JSAsyncCustom changes.
Singleton class for handling CEF initialization that needs to be done right away.
static DLLEXPORT void CEFLastThingInProgram()
static bool CEFInitialized
A flag for making sure that functions are only ran if CEF is actually used.
static DLLEXPORT bool HandleCustomExtensionProcessMessage(CefRefPtr< CefBrowser > browser, CefProcessId source_process, CefRefPtr< CefProcessMessage > message)
Handles passing a custom process message.
CefRefPtr< GUI::CefApplication > CEFApp
#define DLLEXPORT
Definition: Include.h:84
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
static CEFApplicationKeeper * AccessToThese
static DLLEXPORT CEFApplicationKeeper * GetCEFObjects()
static std::vector< std::shared_ptr< GUI::JSAsyncCustom > > CustomJSHandlers
Stores all the custom handlers.
static DLLEXPORT void DoCEFMessageLoopWork()