-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d7c844
commit 80be67e
Showing
4 changed files
with
288 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ) | ||
|
||
-- Set to 1 to check if add_ref() and release() | ||
-- are called and to track the total number of calls. | ||
-- add_ref will be printed as "+", release as "-". | ||
DEBUG_REFERENCE_COUNTING = false | ||
|
||
-- Print only the first execution of the callback, | ||
-- ignore the subsequent. | ||
function DEBUG_CALLBACK(x) | ||
first_call = first_call or {} | ||
if (first_call[x] == nil) then | ||
first_call[x] = 1; | ||
ffi.C.printf(x); | ||
end | ||
end | ||
|
||
-- ---------------------------------------------------------------------------- | ||
-- cef_base_ref_counted_t | ||
-- ---------------------------------------------------------------------------- | ||
|
||
--- | ||
-- Structure defining the reference count implementation functions. | ||
-- All framework structures must include the cef_base_ref_counted_t | ||
-- structure first. | ||
--- | ||
|
||
--- | ||
-- Increment the reference count. | ||
--- | ||
function add_ref(self) | ||
DEBUG_CALLBACK("cef_base_ref_counted_t.add_ref\n"); | ||
if (DEBUG_REFERENCE_COUNTING) then | ||
ffi.C.printf("+"); | ||
end | ||
end | ||
|
||
--- | ||
-- Decrement the reference count. Delete this object when no references | ||
-- remain. | ||
--- | ||
function release(self) | ||
DEBUG_CALLBACK("cef_base_ref_counted_t.release\n"); | ||
if (DEBUG_REFERENCE_COUNTING) then | ||
ffi.C.printf("-"); | ||
end | ||
return 1; | ||
end | ||
|
||
--- | ||
-- Returns the current number of references. | ||
--- | ||
function has_one_ref(self) | ||
DEBUG_CALLBACK("cef_base_ref_counted_t.has_one_ref\n"); | ||
if (DEBUG_REFERENCE_COUNTING) then | ||
ffi.C.printf("="); | ||
end | ||
return 1; | ||
end | ||
|
||
function initialize_cef_base_ref_counted(base) | ||
ffi.C.printf("initialize_cef_base_ref_counted\n"); | ||
-- Check if "size" member was set. | ||
local size = base.size; | ||
-- Let's print the size in case sizeof was used | ||
-- on a pointer instead of a structure. In such | ||
-- case the number will be very high. | ||
ffi.C.printf("cef_base_ref_counted_t.size = %lu\n", size); | ||
if (size <= 0) then | ||
ffi.C.printf("FATAL: initialize_cef_base failed, size member not set\n"); | ||
os.exit(1); | ||
end | ||
base.add_ref = add_ref; | ||
base.release = release; | ||
base.has_one_ref = has_one_ref; | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
-- CEF C API example | ||
-- Project website: https://github.com/cztomczak/cefcapi | ||
|
||
local ffi = require( "ffi" ) | ||
local cef = require( "../cef" ) | ||
|
||
|
||
-- ---------------------------------------------------------------------------- | ||
-- struct cef_client_t | ||
-- ---------------------------------------------------------------------------- | ||
|
||
--- | ||
-- Implement this structure to provide handler implementations. | ||
--- | ||
|
||
--- | ||
-- Return the handler for context menus. If no handler is | ||
-- provided the default implementation will be used. | ||
--- | ||
|
||
function get_context_menu_handler(self) | ||
DEBUG_CALLBACK("get_context_menu_handler\n"); | ||
return nil; | ||
end | ||
|
||
--- | ||
-- Return the handler for dialogs. If no handler is provided the default | ||
-- implementation will be used. | ||
--- | ||
function get_dialog_handler(self) | ||
DEBUG_CALLBACK("get_dialog_handler\n"); | ||
return nil; | ||
end | ||
|
||
--- | ||
-- Return the handler for browser display state events. | ||
--- | ||
function get_display_handler(self) | ||
DEBUG_CALLBACK("get_display_handler\n"); | ||
return nil; | ||
end | ||
|
||
--- | ||
-- Return the handler for download events. If no handler is returned downloads | ||
-- will not be allowed. | ||
--- | ||
function get_download_handler(self) | ||
DEBUG_CALLBACK("get_download_handler\n"); | ||
return nil; | ||
end | ||
|
||
--- | ||
-- Return the handler for drag events. | ||
--- | ||
function get_drag_handler(self) | ||
DEBUG_CALLBACK("get_drag_handler\n"); | ||
return nil; | ||
end | ||
|
||
--- | ||
-- Return the handler for focus events. | ||
--- | ||
function get_focus_handler(self) | ||
DEBUG_CALLBACK("get_focus_handler\n"); | ||
return nil; | ||
end | ||
|
||
--- | ||
-- Return the handler for geolocation permissions requests. If no handler is | ||
-- provided geolocation access will be denied by default. | ||
--- | ||
function get_geolocation_handler(self) | ||
DEBUG_CALLBACK("get_geolocation_handler\n"); | ||
return nil; | ||
end | ||
|
||
--- | ||
-- Return the handler for JavaScript dialogs. If no handler is provided the | ||
-- default implementation will be used. | ||
--- | ||
function get_jsdialog_handler(self) | ||
DEBUG_CALLBACK("get_jsdialog_handler\n"); | ||
return nil; | ||
end | ||
|
||
--- | ||
-- Return the handler for keyboard events. | ||
--- | ||
function get_keyboard_handler(self) | ||
DEBUG_CALLBACK("get_keyboard_handler\n"); | ||
return nil; | ||
end | ||
|
||
--- | ||
-- Return the handler for browser life span events. | ||
--- | ||
function get_life_span_handler(self) | ||
DEBUG_CALLBACK("get_life_span_handler\n"); | ||
-- Implemented! | ||
return g_life_span_handler; | ||
end | ||
|
||
--- | ||
-- Return the handler for browser load status events. | ||
--- | ||
function get_load_handler(self) | ||
DEBUG_CALLBACK("get_load_handler\n"); | ||
return nil; | ||
end | ||
|
||
--- | ||
-- Return the handler for off-screen rendering events. | ||
--- | ||
function get_render_handler(self) | ||
DEBUG_CALLBACK("get_render_handler\n"); | ||
return nil; | ||
end | ||
|
||
--- | ||
-- Return the handler for browser request events. | ||
--- | ||
function get_request_handler(self) | ||
DEBUG_CALLBACK("get_request_handler\n"); | ||
return nil; | ||
end | ||
|
||
--- | ||
-- Called when a new message is received from a different process. Return true | ||
-- (1) if the message was handled or false (0) otherwise. Do not keep a | ||
-- reference to or attempt to access the message outside of this callback. | ||
--- | ||
function on_process_message_received(self, browser, source_process, message) | ||
DEBUG_CALLBACK("on_process_message_received\n"); | ||
return 0; | ||
end | ||
|
||
function initialize_cef_client(client) | ||
DEBUG_CALLBACK("initialize_client_handler\n"); | ||
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; | ||
client.get_dialog_handler = get_dialog_handler; | ||
client.get_display_handler = get_display_handler; | ||
client.get_download_handler = get_download_handler; | ||
client.get_drag_handler = get_drag_handler; | ||
client.get_focus_handler = get_focus_handler; | ||
client.get_geolocation_handler = get_geolocation_handler; | ||
client.get_jsdialog_handler = get_jsdialog_handler; | ||
client.get_keyboard_handler = get_keyboard_handler; | ||
client.get_life_span_handler = get_life_span_handler; -- Implemented! | ||
client.get_load_handler = get_load_handler; | ||
client.get_render_handler = get_render_handler; | ||
client.get_request_handler = get_request_handler; | ||
client.on_process_message_received = on_process_message_received; | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
-- CEF C API example | ||
-- Project website: https://github.com/cztomczak/cefcapi | ||
|
||
local ffi = require( "ffi" ) | ||
local cef = require( "../cef" ) | ||
|
||
-- ---------------------------------------------------------------------------- | ||
-- struct cef_life_span_handler_t | ||
-- ---------------------------------------------------------------------------- | ||
|
||
--- | ||
-- Implement this structure to handle events related to browser life span. The | ||
-- functions of this structure will be called on the UI thread unless otherwise | ||
-- indicated. | ||
--- | ||
|
||
-- NOTE: There are many more callbacks in cef_life_span_handler, | ||
-- but only on_before_close is implemented here. | ||
|
||
--- | ||
-- Called just before a browser is destroyed. Release all references to the | ||
-- browser object and do not attempt to execute any functions on the browser | ||
-- object after this callback returns. This callback will be the last | ||
-- notification that references |browser|. See do_close() documentation for | ||
-- additional usage information. | ||
--- | ||
function on_before_close(self, browser) | ||
DEBUG_CALLBACK("on_before_close\n"); | ||
-- TODO: Check how many browsers do exist and quit message | ||
-- loop only when last browser is closed. Otherwise | ||
-- closing a popup window will exit app while main | ||
-- window shouldn't be closed. | ||
cef.cef_quit_message_loop(); | ||
end | ||
|
||
function initialize_cef_life_span_handler(handler) | ||
DEBUG_CALLBACK("initialize_cef_life_span_handler\n"); | ||
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; | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters