Skip to content

Commit

Permalink
nui/resources: add secure origin support for NUI RPC scheme
Browse files Browse the repository at this point in the history
As posted on https://forum.fivem.net/t/788942 by a user.
  • Loading branch information
blattersturm committed Sep 14, 2019
1 parent a786c7e commit 09a151e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion code/components/nui-resources/src/RPCSchemeHandler.cpp
Expand Up @@ -210,7 +210,7 @@ static InitFunction initFunction([] ()
{
OnSchemeCreateRequest.Connect([] (const char* name, CefRefPtr<CefRequest> request, CefRefPtr<CefResourceHandler>& handler)
{
if (!strcmp(name, "http"))
if (!strcmp(name, "http") || !strcmp(name, "https"))
{
handler = new RPCResourceHandler();
}
Expand Down
2 changes: 2 additions & 0 deletions code/components/nui-resources/src/ResourceUI.cpp
Expand Up @@ -59,13 +59,15 @@ bool ResourceUI::Create()
auto resourceName = m_resource->GetName();
std::transform(resourceName.begin(), resourceName.end(), resourceName.begin(), ::ToLower);
CefRegisterSchemeHandlerFactory("http", resourceName, Instance<NUISchemeHandlerFactory>::Get());
CefRegisterSchemeHandlerFactory("https", resourceName, Instance<NUISchemeHandlerFactory>::Get());

// create the NUI frame
std::string path = "nui://" + m_resource->GetName() + "/" + pageName;
nui::CreateFrame(m_resource->GetName(), path);

// add a cross-origin entry to allow fetching the callback handler
CefAddCrossOriginWhitelistEntry(va("nui://%s", m_resource->GetName().c_str()), "http", m_resource->GetName(), true);
CefAddCrossOriginWhitelistEntry(va("nui://%s", m_resource->GetName().c_str()), "https", m_resource->GetName(), true);

return true;
}
Expand Down

0 comments on commit 09a151e

Please sign in to comment.