diff --git a/meson.build b/meson.build index e483862..d1a54ae 100644 --- a/meson.build +++ b/meson.build @@ -3,7 +3,7 @@ libcef = custom_target('libcef', output: 'libcef.so', command: ['./cef/install.s meson.add_install_script('cef/install.sh') executable( 'bolt', - 'src/main.cxx', 'src/cef/app.cxx', + 'src/main.cxx', 'src/browser/app.cxx', dependencies: [dependency('fmt'), dependency('tesseract'), dependency('x11')], include_directories: 'cef/dist', install: true, diff --git a/src/browser/app.cxx b/src/browser/app.cxx new file mode 100644 index 0000000..87ce4ad --- /dev/null +++ b/src/browser/app.cxx @@ -0,0 +1,72 @@ +#include "app.hxx" + +Browser::App* resolve_app(cef_app_t* app) { + return reinterpret_cast(reinterpret_cast(app) - offsetof(Browser::App, cef_app)); +} + +Browser::App* resolve_base(cef_base_ref_counted_t* base) { + return reinterpret_cast(reinterpret_cast(base) - (offsetof(Browser::App, cef_app) + offsetof(cef_app_t, base))); +} + +Browser::App::App() { + this->cef_app.base.size = sizeof(cef_base_ref_counted_t); + this->cef_app.base.add_ref = Browser::AddRef; + this->cef_app.base.release = Browser::Release; + this->cef_app.base.has_one_ref = Browser::HasOneRef; + this->cef_app.base.has_at_least_one_ref = Browser::HasAnyRefs; + this->cef_app.on_before_command_line_processing = Browser::OnBeforeCommandLineProcessing; + this->cef_app.on_register_custom_schemes = Browser::OnRegisterCustomSchemes; + this->cef_app.get_resource_bundle_handler = Browser::ResourceBundleHandler; + this->cef_app.get_browser_process_handler = Browser::BrowserProcessHandler; + this->cef_app.get_render_process_handler = Browser::RenderProcessHandler; + this->refcount = 0; +} + +void Browser::App::Destroy() { + // Any self-cleanup should be done here +} + +cef_app_t* Browser::App::app() { + this->refcount += 1; + return &this->cef_app; +} + +void Browser::AddRef(cef_base_ref_counted_t* app) { + resolve_base(app)->refcount += 1; +} + +int Browser::Release(cef_base_ref_counted_t* app) { + Browser::App* _app = resolve_base(app); + _app->refcount -= 1; + + if (_app->refcount == 0) { + _app->Destroy(); + return 1; + } + + return 0; +} + +int Browser::HasOneRef(cef_base_ref_counted_t* app) { + return (resolve_base(app)->refcount == 1) ? 1 : 0; +} + +int Browser::HasAnyRefs(cef_base_ref_counted_t* app) { + return (resolve_base(app)->refcount >= 1) ? 1 : 0; +} + +void Browser::OnBeforeCommandLineProcessing(cef_app_t*, const cef_string_t*, cef_command_line_t*) { } + +void Browser::OnRegisterCustomSchemes(cef_app_t*, cef_scheme_registrar_t*) { } + +cef_resource_bundle_handler_t* Browser::ResourceBundleHandler(cef_app_t*) { + return nullptr; +} + +cef_browser_process_handler_t* Browser::BrowserProcessHandler(cef_app_t*) { + return nullptr; +} + +cef_render_process_handler_t* Browser::RenderProcessHandler(cef_app_t*) { + return nullptr; +} diff --git a/src/cef/app.hxx b/src/browser/app.hxx similarity index 97% rename from src/cef/app.hxx rename to src/browser/app.hxx index 1606d30..76b7200 100644 --- a/src/cef/app.hxx +++ b/src/browser/app.hxx @@ -3,7 +3,7 @@ #include "include/capi/cef_app_capi.h" -namespace Cef { +namespace Browser { struct App { cef_app_t cef_app; unsigned int refcount; diff --git a/src/cef/app.cxx b/src/cef/app.cxx deleted file mode 100644 index d7ca1ef..0000000 --- a/src/cef/app.cxx +++ /dev/null @@ -1,72 +0,0 @@ -#include "app.hxx" - -Cef::App* resolve_app(cef_app_t* app) { - return reinterpret_cast(reinterpret_cast(app) - offsetof(Cef::App, cef_app)); -} - -Cef::App* resolve_base(cef_base_ref_counted_t* base) { - return reinterpret_cast(reinterpret_cast(base) - (offsetof(Cef::App, cef_app) + offsetof(cef_app_t, base))); -} - -Cef::App::App() { - this->cef_app.base.size = sizeof(cef_base_ref_counted_t); - this->cef_app.base.add_ref = Cef::AddRef; - this->cef_app.base.release = Cef::Release; - this->cef_app.base.has_one_ref = Cef::HasOneRef; - this->cef_app.base.has_at_least_one_ref = Cef::HasAnyRefs; - this->cef_app.on_before_command_line_processing = Cef::OnBeforeCommandLineProcessing; - this->cef_app.on_register_custom_schemes = Cef::OnRegisterCustomSchemes; - this->cef_app.get_resource_bundle_handler = Cef::ResourceBundleHandler; - this->cef_app.get_browser_process_handler = Cef::BrowserProcessHandler; - this->cef_app.get_render_process_handler = Cef::RenderProcessHandler; - this->refcount = 0; -} - -void Cef::App::Destroy() { - // Any self-cleanup should be done here -} - -cef_app_t* Cef::App::app() { - this->refcount += 1; - return &this->cef_app; -} - -void Cef::AddRef(cef_base_ref_counted_t* app) { - resolve_base(app)->refcount += 1; -} - -int Cef::Release(cef_base_ref_counted_t* app) { - Cef::App* _app = resolve_base(app); - _app->refcount -= 1; - - if (_app->refcount == 0) { - _app->Destroy(); - return 1; - } - - return 0; -} - -int Cef::HasOneRef(cef_base_ref_counted_t* app) { - return (resolve_base(app)->refcount == 1) ? 1 : 0; -} - -int Cef::HasAnyRefs(cef_base_ref_counted_t* app) { - return (resolve_base(app)->refcount >= 1) ? 1 : 0; -} - -void Cef::OnBeforeCommandLineProcessing(cef_app_t*, const cef_string_t*, cef_command_line_t*) { } - -void Cef::OnRegisterCustomSchemes(cef_app_t*, cef_scheme_registrar_t*) { } - -cef_resource_bundle_handler_t* Cef::ResourceBundleHandler(cef_app_t*) { - return nullptr; -} - -cef_browser_process_handler_t* Cef::BrowserProcessHandler(cef_app_t*) { - return nullptr; -} - -cef_render_process_handler_t* Cef::RenderProcessHandler(cef_app_t*) { - return nullptr; -} diff --git a/src/main.cxx b/src/main.cxx index fbb8d1a..f357b1b 100644 --- a/src/main.cxx +++ b/src/main.cxx @@ -1,6 +1,6 @@ #include -#include "cef/app.hxx" +#include "browser/app.hxx" #ifdef WIN32 #include @@ -59,7 +59,7 @@ int main(int argc, char* argv[]) { settings.command_line_args_disabled = true; settings.uncaught_exception_stack_size = 16; - Cef::App cef_app; + Browser::App cef_app; // Initialize CEF exit_code = cef_initialize(&main_args, &settings, cef_app.app(), nullptr);