So, CefExecuteProcess doesn't spawn a new process?
Yes, I am in the main application entry point... so it's good that it's returning -1?
Our render handler code is inside "RendererApp", which we are passing into CefExecuteProcess and CefInitialize ... isn't this how to attach it to CEFWorker.exe (the exe name in the main entry point)? Or is something missing?
Yes, there were other people who did the initial implementation, I am new and inherited that code, not sure if the other people are still around or available but I could look into that. In any case, the code I shared is our entire application entry point, so it all should be in there. There was no CefExecuteProcess - that is me attempting to add that in order to hit our RenderProcessHandler javascript binding code. I will reshare the code here for convenience.
- Code: Select all
CEFManager(int port)
{
char pathStr[MAX_PATH];
#ifdef _WIN32
::GetModuleFileName(NULL, pathStr, MAX_PATH);
#else
auto pathStrLen = readlink("/proc/self/exe", pathStr, MAX_PATH);
pathStr[pathStrLen] = '\0'; // readlink returns non-null-terminating strings, so terminate.
#endif
#ifndef _WIN64
char** args = new char*[1];
args[0] = pathStr;
CefMainArgs mainArgs(1, args);
#else
CefMainArgs mainArgs(GetModuleHandle(NULL));
#endif
CefRefPtr<RendererApp> app = new RendererApp();
int exit_code = CefExecuteProcess(mainArgs, app.get(), nullptr);
CefSettings settings;
std::string path = pathStr;
auto loc = path.find_last_of('/');
if (loc == std::string::npos)
{
loc = path.find_last_of('\\');
}
auto const WORKER_PATH = path.substr(0, loc + 1) +
#ifndef _WIN64
"CEFWorker";
#else
"CEFWorker.exe";
#endif
if (!boost::filesystem::exists(WORKER_PATH))
{
Logger::getInstance().logMessage(Severity::FATAL_LEVEL, "CEF", __FUNCTION__, __FILE__, __LINE__, "CEF Worker executable not found at %s", WORKER_PATH.c_str());
}
CefString(&settings.browser_subprocess_path).FromASCII(WORKER_PATH.c_str());
settings.no_sandbox = true;
settings.log_severity = LOGSEVERITY_VERBOSE;
CefString(&settings.log_file) = path.substr(0, loc + 1) + "cef_debug.log";
settings.windowless_rendering_enabled = true;
settings.multi_threaded_message_loop = true;
settings.remote_debugging_port = port;
Logger::getInstance().logMessage(Severity::INFO_LEVEL, "CEF", __FUNCTION__, __FILE__, __LINE__, "HeadlessBrowser Runnig on Port %d", port);
// If not in Windows, take locales and resources from PATH
#ifndef _WIN64
const std::string RESOURCES_DIR_PATH = "/opt/cef/resources";
CefString(&settings.resources_dir_path).FromASCII(RESOURCES_DIR_PATH.c_str());
CefString(&settings.locales_dir_path).FromASCII(RESOURCES_DIR_PATH.c_str());
Logger::getInstance().logMessage(Severity::INFO_LEVEL, "CEF", __FUNCTION__, __FILE__, __LINE__,
"CEF Headless browser looking for resources in %s", RESOURCES_DIR_PATH.c_str());
#else
bool success = false;
const std::string RESOURCES_DIR_PATH = Utils::getVenueInstalledDirectory() + "\\Bin";
CefString(&settings.resources_dir_path).FromASCII(RESOURCES_DIR_PATH.c_str());
CefString(&settings.locales_dir_path).FromASCII(RESOURCES_DIR_PATH.c_str());
Logger::getInstance().logMessage(Severity::INFO_LEVEL, "CEF", __FUNCTION__, __FILE__, __LINE__,
"CEF Headless browser looking for resources in %s", RESOURCES_DIR_PATH.c_str());
#endif
// Initialize CEF.
_initializedCorrectly = CefInitialize(mainArgs, settings, app, nullptr);
}
bool _initializedCorrectly = false;
};