From 714e5dfb742b828bf559d0c88bb4d513048c0251 Mon Sep 17 00:00:00 2001 From: Andrew McWatters Date: Sat, 17 Feb 2018 19:28:53 -0700 Subject: [PATCH] Add callbacks --- test/cef_app.lua | 80 ++++++++++++++++++++++++++++++++++ test/cef_client.lua | 2 +- test/cef_life_span_handler.lua | 2 +- test/main_win.lua | 3 +- 4 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 test/cef_app.lua diff --git a/test/cef_app.lua b/test/cef_app.lua new file mode 100644 index 0000000..df5621d --- /dev/null +++ b/test/cef_app.lua @@ -0,0 +1,80 @@ +-- CEF C API example +-- Project website: https://github.com/cztomczak/cefcapi + +local ffi = require( "ffi" ) +local cef = require( "../cef" ) + +-- ---------------------------------------------------------------------------- +-- cef_app_t +-- ---------------------------------------------------------------------------- + +--- +-- Implement this structure to provide handler implementations. Methods will be +-- called by the process and/or thread indicated. +--- + +--- +-- Provides an opportunity to view and/or modify command-line arguments before +-- processing by CEF and Chromium. The |process_type| value will be NULL for +-- the browser process. Do not keep a reference to the cef_command_line_t +-- object passed to this function. The CefSettings.command_line_args_disabled +-- value can be used to start with an NULL command-line object. Any values +-- specified in CefSettings that equate to command-line arguments will be set +-- before this function is called. Be cautious when using this function to +-- modify command-line arguments for non-browser processes as this may result +-- in undefined behavior including crashes. +--- +function on_before_command_line_processing(self, process_type, command_line) + DEBUG_CALLBACK("on_before_command_line_processing\n"); +end + +--- +-- Provides an opportunity to register custom schemes. Do not keep a reference +-- to the |registrar| object. This function is called on the main thread for +-- each process and the registered schemes should be the same across all +-- processes. +--- +function on_register_custom_schemes(self, registrar) + DEBUG_CALLBACK("on_register_custom_schemes\n"); +end + +--- +-- Return the handler for resource bundle events. If +-- CefSettings.pack_loading_disabled is true (1) a handler must be returned. +-- If no handler is returned resources will be loaded from pack files. This +-- function is called by the browser and render processes on multiple threads. +--- +function get_resource_bundle_handler(self) + DEBUG_CALLBACK("get_resource_bundle_handler\n"); + return nil; +end + +--- +-- Return the handler for functionality specific to the browser process. This +-- function is called on multiple threads in the browser process. +--- +function get_browser_process_handler(self) + DEBUG_CALLBACK("get_browser_process_handler\n"); + return nil; +end + +--- +-- Return the handler for functionality specific to the render process. This +-- function is called on the render process main thread. +--- +function get_render_process_handler(self) + DEBUG_CALLBACK("get_render_process_handler\n"); + return nil; +end + +function initialize_cef_app(app) + ffi.C.printf("initialize_cef_app\n"); + -- app.base.size = ffi.sizeof( app ); + -- initialize_cef_base_ref_counted(ffi.cast( "cef_base_ref_counted_t*", app )); + -- callbacks + app.on_before_command_line_processing = on_before_command_line_processing; + app.on_register_custom_schemes = on_register_custom_schemes; + app.get_resource_bundle_handler = get_resource_bundle_handler; + app.get_browser_process_handler = get_browser_process_handler; + app.get_render_process_handler = get_render_process_handler; +end diff --git a/test/cef_client.lua b/test/cef_client.lua index 0b7444b..422e450 100644 --- a/test/cef_client.lua +++ b/test/cef_client.lua @@ -136,7 +136,7 @@ end function initialize_cef_client(client) DEBUG_CALLBACK("initialize_client_handler\n"); - client.base.size = ffi.sizeof(client); + client.base.size = ffi.sizeof( client ); initialize_cef_base_ref_counted(ffi.cast( "cef_base_ref_counted_t*", client )); -- callbacks client.get_context_menu_handler = get_context_menu_handler; diff --git a/test/cef_life_span_handler.lua b/test/cef_life_span_handler.lua index a99ca5f..1c21c73 100644 --- a/test/cef_life_span_handler.lua +++ b/test/cef_life_span_handler.lua @@ -35,7 +35,7 @@ end function initialize_cef_life_span_handler(handler) DEBUG_CALLBACK("initialize_cef_life_span_handler\n"); - handler.base.size = ffi.sizeof(handler); + handler.base.size = ffi.sizeof( handler ); initialize_cef_base_ref_counted(ffi.cast( "cef_base_ref_counted_t*", handler )); -- callbacks - there are many, but implementing only one handler.on_before_close = on_before_close; diff --git a/test/main_win.lua b/test/main_win.lua index eeaa356..b31662c 100644 --- a/test/main_win.lua +++ b/test/main_win.lua @@ -18,6 +18,7 @@ ffi.cdef [[ local cef = require( "../cef" ) require( "test.cef_base" ) +require( "test.cef_app" ) require( "test.cef_client" ) require( "test.cef_life_span_handler" ) @@ -59,7 +60,7 @@ main_args.instance = ffi.C.GetModuleHandleW(nil); -- Cef app local app = ffi.new( "cef_app_t" ); --- initialize_cef_app(app); +initialize_cef_app(app); -- Application settings. It is mandatory to set the -- "size" member.