]> git.sesse.net Git - nageru/blob - nageru/nageru_cef_app.cpp
Fix some leftovers in warning messages.
[nageru] / nageru / nageru_cef_app.cpp
1 #include <cef_app.h>
2 #include <cef_browser.h>
3 #include <cef_client.h>
4 #include <cef_version.h>
5 #include <QTimer>
6 #include <QWidget>
7
8 #include "nageru_cef_app.h"
9
10 using namespace std;
11
12 void NageruCefApp::OnBeforeCommandLineProcessing(
13         const CefString& process_type,
14         CefRefPtr<CefCommandLine> command_line)
15 {
16         command_line->AppendSwitch("disable-gpu");
17         command_line->AppendSwitch("disable-gpu-compositing");
18         command_line->AppendSwitch("enable-begin-frame-scheduling");
19
20         // https://bitbucket.org/chromiumembedded/cef/issues/2717/xmlhttprequest-empty-responsetext
21         command_line->AppendSwitch("disable-web-security");
22 }
23
24 void NageruCefApp::initialize_cef()
25 {
26         unique_lock<mutex> lock(cef_mutex);
27         if (cef_thread_refcount++ == 0) {
28                 cef_thread = thread(&NageruCefApp::cef_thread_func, this);
29         }
30         cef_initialized_cond.wait(lock, [this]{ return cef_initialized; });
31 }
32
33 void NageruCefApp::close_browser(CefRefPtr<CefBrowser> browser)
34 {
35         lock_guard<mutex> lock(cef_mutex);
36         browser->GetHost()->CloseBrowser(/*force_close=*/true);
37 }
38
39 void NageruCefApp::unref_cef()
40 {
41         unique_lock<mutex> lock(cef_mutex);
42         if (--cef_thread_refcount == 0) {
43                 CefPostTask(TID_UI, new CEFTaskAdapter(&CefQuitMessageLoop));
44                 lock.unlock();
45                 cef_thread.join();
46         }
47 }
48
49 void NageruCefApp::cef_thread_func()
50 {
51         CefMainArgs main_args;
52         CefSettings settings;
53         //settings.log_severity = LOGSEVERITY_VERBOSE;
54         settings.windowless_rendering_enabled = true;
55         settings.no_sandbox = true;
56         settings.command_line_args_disabled = false;
57         CefInitialize(main_args, settings, this, nullptr);
58
59         {
60                 lock_guard<mutex> lock(cef_mutex);
61                 cef_initialized = true;
62         }
63         cef_initialized_cond.notify_all();
64
65         CefRunMessageLoop();
66
67         CefShutdown();
68 }
69