- Code: Select all
CefSettings settings = CefSettings();
settings.size = sizeof(CefSettings);
settings.log_severity = LOGSEVERITY_DEBUG;
settings.multi_threaded_message_loop = true;
//we need to get the filepath.
LPWSTR wPath = new WCHAR[MAX_PATH + 1];
GetModuleFileName(GetModuleHandle(NULL), wPath, MAX_PATH + 1);
//currently this looks like the full path of this exe, we need to change it to the other one.
std::wstring wP(wPath);
auto point = wP.find_last_of(L"\\");
std::wstring realPath = wP.substr(0, point + 1) + L"VPHTMLManagerSubProcess.exe";
cef_string_set(realPath.c_str(), std::wcslen(realPath.c_str()), &(settings.browser_subprocess_path), true);
delete[] wPath;
settings.windowless_rendering_enabled = true;
settings.no_sandbox = true;
// Initialize CEF - other modules will conflict
CefInitialize(main_args, settings, NULL, NULL);
and initializing a browser with:
- Code: Select all
CefWindowInfo window_info;
window_info.SetAsWindowless(nullptr);
CefBrowserSettings browser_settings = CefBrowserSettings();
browser_settings.size = sizeof(CefBrowserSettings);
browser_settings.webgl = STATE_DISABLED;
browser_settings.windowless_frame_rate = 24;
browser_settings.background_color = 0x50505050;
CefBrowserHost::CreateBrowser(window_info, this, CefString("https://www.bing.com/"), browser_settings, NULL, NULL);
I'm using the multi_threaded_thread_loop on windows. For a while I couldn't figure out why the first couple browsers I created wouldn't render anything. Eventually I figured out that there's no queue that Browser creation is put on after CefInitialize is called, so browsers constructed too soon won't render. Currently, I have this fixed by having my main thread sleep for a bit, before constructing a browser. Is there a better way of doing this, like a callback I can subscribe to which would notify me when it's safe to create a browser?
Also, currently, after a browser has had OnAfterCreated called, I allow it to receive LoadURL requests. Is this the only requirement to start sending LoadURL requests, or are there other callbacks I should listen to? Also, after a LoadURL request is sent, is it safe to send LoadURL requests immediately after that, or should I wait for the Loading State to change. Finally, when the dimensions of the browser are changed, are there any requirements I should be aware of, other than OnAfterCreate being called for making an WasResized call into the browser?
That's a lot of questions, but making sure that everything is properly sequenced when switching from the main threaded approach to this multi threaded approach has been kind of frustrating due to the number of mistakes I've made. Also, in the past I've had rare errors that I could never reproduce due to race conditions with the browser, and this time around I want to avoid that type of issue.
Thank you.