]> git.sesse.net Git - nageru/blob - nageru/nageru_cef_app.cpp
A hack to make Kaeru overlay CEF scores on a transcoded file. Probably not useful...
[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("disable-software-rasterizer");
19         command_line->AppendSwitch("enable-begin-frame-scheduling");
20
21         // https://bitbucket.org/chromiumembedded/cef/issues/2717/xmlhttprequest-empty-responsetext
22         command_line->AppendSwitch("disable-web-security");
23 }
24
25 void NageruCefApp::initialize_cef()
26 {
27         unique_lock<mutex> lock(cef_mutex);
28         if (cef_thread_refcount++ == 0) {
29                 cef_thread = thread(&NageruCefApp::cef_thread_func, this);
30         }
31         cef_initialized_cond.wait(lock, [this]{ return cef_initialized; });
32 }
33
34 void NageruCefApp::close_browser(CefRefPtr<CefBrowser> browser)
35 {
36         lock_guard<mutex> lock(cef_mutex);
37         browser->GetHost()->CloseBrowser(/*force_close=*/true);
38 }
39
40 void NageruCefApp::unref_cef()
41 {
42         unique_lock<mutex> lock(cef_mutex);
43         if (--cef_thread_refcount == 0) {
44                 CefPostTask(TID_UI, new CEFTaskAdapter(&CefQuitMessageLoop));
45                 lock.unlock();
46                 cef_thread.join();
47         }
48 }
49
50 void NageruCefApp::cef_thread_func()
51 {
52         CefMainArgs main_args;
53         CefSettings settings;
54         //settings.log_severity = LOGSEVERITY_VERBOSE;
55         settings.windowless_rendering_enabled = true;
56         settings.no_sandbox = true;
57         settings.command_line_args_disabled = false;
58         CefInitialize(main_args, settings, this, nullptr);
59
60         {
61                 lock_guard<mutex> lock(cef_mutex);
62                 cef_initialized = true;
63         }
64         cef_initialized_cond.notify_all();
65
66         CefRunMessageLoop();
67
68         CefShutdown();
69 }
70