2 #include <cef_browser.h>
3 #include <cef_command_line.h>
10 #include "nageru_cef_app.h"
14 void NageruCefApp::OnBeforeCommandLineProcessing(
15 const CefString& process_type,
16 CefRefPtr<CefCommandLine> command_line)
18 command_line->AppendSwitch("disable-gpu");
19 command_line->AppendSwitch("disable-gpu-compositing");
20 command_line->AppendSwitch("enable-begin-frame-scheduling");
21 command_line->AppendSwitchWithValue("autoplay-policy", "no-user-gesture-required");
23 // https://bitbucket.org/chromiumembedded/cef/issues/2717/xmlhttprequest-empty-responsetext
24 command_line->AppendSwitch("disable-web-security");
27 void NageruCefApp::initialize_cef()
29 unique_lock<mutex> lock(cef_mutex);
30 if (cef_thread_refcount++ == 0) {
31 cef_thread = thread(&NageruCefApp::cef_thread_func, this);
33 cef_initialized_cond.wait(lock, [this]{ return cef_initialized; });
36 void NageruCefApp::close_browser(CefRefPtr<CefBrowser> browser)
38 lock_guard<mutex> lock(cef_mutex);
39 browser->GetHost()->CloseBrowser(/*force_close=*/true);
42 void NageruCefApp::unref_cef()
44 unique_lock<mutex> lock(cef_mutex);
45 if (--cef_thread_refcount == 0) {
46 CefPostTask(TID_UI, new CEFTaskAdapter(&CefQuitMessageLoop));
52 void NageruCefApp::cef_thread_func()
54 CefMainArgs main_args;
56 //settings.log_severity = LOGSEVERITY_VERBOSE;
57 settings.windowless_rendering_enabled = true;
58 settings.no_sandbox = true;
59 settings.command_line_args_disabled = false;
60 CefInitialize(main_args, settings, this, nullptr);
63 lock_guard<mutex> lock(cef_mutex);
64 cef_initialized = true;
66 cef_initialized_cond.notify_all();