/
NUIApp.cpp
118 lines (98 loc) · 3.58 KB
/
NUIApp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* This file is part of the CitizenFX project - http://citizen.re/
*
* See LICENSE and MENTIONS in the root of the source tree for information
* regarding licensing.
*/
#include "StdInc.h"
#include "NUIApp.h"
#include "memdbgon.h"
void NUIApp::OnRegisterCustomSchemes(CefRawPtr<CefSchemeRegistrar> registrar)
{
// add the 'nui://' internal scheme
registrar->AddCustomScheme("nui", true, false, false, true, false, true);
}
// null data resource functions
bool NUIApp::GetDataResource(int resourceID, void*& data, size_t& data_size)
{
return false;
}
bool NUIApp::GetDataResourceForScale(int resource_id, ScaleFactor scale_factor, void*& data, size_t& data_size)
{
return false;
}
bool NUIApp::GetLocalizedString(int messageID, CefString& string)
{
string = "";
return true;
}
void NUIApp::OnContextInitialized()
{
auto manager = CefCookieManager::GetGlobalManager(nullptr);
manager->SetSupportedSchemes({ "nui" }, nullptr);
}
void NUIApp::OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context)
{
CefRefPtr<CefV8Value> window = context->GetGlobal();
window->SetValue("registerPollFunction", CefV8Value::CreateFunction("registerPollFunction", this), V8_PROPERTY_ATTRIBUTE_READONLY);
window->SetValue("registerFrameFunction", CefV8Value::CreateFunction("registerFrameFunction", this), V8_PROPERTY_ATTRIBUTE_READONLY);
window->SetValue("invokeNative", CefV8Value::CreateFunction("invokeNative", this), V8_PROPERTY_ATTRIBUTE_READONLY);
}
void NUIApp::OnBeforeCommandLineProcessing(const CefString& process_type, CefRefPtr<CefCommandLine> command_line)
{
command_line->AppendSwitch("enable-experimental-web-platform-features");
command_line->AppendSwitch("enable-media-stream");
command_line->AppendSwitch("use-fake-ui-for-media-stream");
command_line->AppendSwitch("enable-speech-input");
command_line->AppendSwitch("ignore-gpu-blacklist");
command_line->AppendSwitch("enable-usermedia-screen-capture");
command_line->AppendSwitch("disable-direct-composition");
command_line->AppendSwitchWithValue("default-encoding", "utf-8");
command_line->AppendSwitch("disable-gpu-vsync");
command_line->AppendSwitchWithValue("autoplay-policy", "no-user-gesture-required");
if (IsWindows10OrGreater())
{
command_line->AppendSwitch("force-gpu-rasterization");
}
}
bool NUIApp::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefProcessId source_process, CefRefPtr<CefProcessMessage> message)
{
auto handler = m_processMessageHandlers.find(message->GetName());
bool success = false;
if (handler != m_processMessageHandlers.end())
{
success = handler->second(browser, message);
}
else
{
trace("Unknown NUI process message: %s\n", message->GetName().ToString().c_str());
}
return success;
}
CefRefPtr<CefRenderProcessHandler> NUIApp::GetRenderProcessHandler()
{
return this;
}
bool NUIApp::Execute(const CefString& name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception)
{
auto handler = m_v8Handlers.find(name);
bool success = false;
if (handler != m_v8Handlers.end())
{
retval = handler->second(arguments, exception);
success = true;
}
else
{
trace("Unknown NUI function: %s\n", name.ToString().c_str());
}
return success;
}
void NUIApp::AddProcessMessageHandler(std::string key, TProcessMessageHandler handler)
{
m_processMessageHandlers[key] = handler;
}
void NUIApp::AddV8Handler(std::string key, TV8Handler handler)
{
m_v8Handlers[key] = handler;
}