Skip to content

Commit

Permalink
Add callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmcwatters committed Feb 18, 2018
1 parent 7039a60 commit 714e5df
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 3 deletions.
80 changes: 80 additions & 0 deletions test/cef_app.lua
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion test/cef_client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/cef_life_span_handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion test/main_win.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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" )

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 714e5df

Please sign in to comment.