Skip to content

Commit

Permalink
Fixed app/client handlers on Windows. The calling convention
Browse files Browse the repository at this point in the history
for CEF callbacks needs to be __stdcall (cef_export.h).

The CEF_CALLBACK was misplaced in cef_app/cef_client header
files.
  • Loading branch information
cztomczak committed Feb 18, 2014
1 parent 9eca185 commit f789834
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 52 deletions.
12 changes: 6 additions & 6 deletions handlers/cef_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ void CEF_CALLBACK on_register_custom_schemes(
// 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.
///
struct CEF_CALLBACK _cef_resource_bundle_handler_t*
get_resource_bundle_handler(struct _cef_app_t* self) {
struct _cef_resource_bundle_handler_t*
CEF_CALLBACK get_resource_bundle_handler(struct _cef_app_t* self) {
DEBUG_CALLBACK("get_resource_bundle_handler\n");
return NULL;
}
Expand All @@ -61,8 +61,8 @@ struct CEF_CALLBACK _cef_resource_bundle_handler_t*
// Return the handler for functionality specific to the browser process. This
// function is called on multiple threads in the browser process.
///
struct CEF_CALLBACK _cef_browser_process_handler_t*
get_browser_process_handler(struct _cef_app_t* self) {
struct _cef_browser_process_handler_t*
CEF_CALLBACK get_browser_process_handler(struct _cef_app_t* self) {
DEBUG_CALLBACK("get_browser_process_handler\n");
return NULL;
}
Expand All @@ -71,8 +71,8 @@ struct CEF_CALLBACK _cef_browser_process_handler_t*
// Return the handler for functionality specific to the render process. This
// function is called on the render process main thread.
///
struct CEF_CALLBACK _cef_render_process_handler_t* get_render_process_handler(
struct _cef_app_t* self) {
struct _cef_render_process_handler_t*
CEF_CALLBACK get_render_process_handler(struct _cef_app_t* self) {
DEBUG_CALLBACK("get_render_process_handler\n");
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion handlers/cef_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void initialize_cef_base(cef_base_t* base) {
// 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.
printf("cef_base_t.size = %lu\n", size);
printf("cef_base_t.size = %lu\n", (unsigned long)size);
if (size <= 0) {
printf("FATAL: initialize_cef_base failed, size member not set\n");
_exit(1);
Expand Down
26 changes: 13 additions & 13 deletions handlers/cef_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// implementation will be used.
///

struct CEF_CALLBACK _cef_context_menu_handler_t* get_context_menu_handler(
struct _cef_context_menu_handler_t* CEF_CALLBACK get_context_menu_handler(
struct _cef_client_t* self) {
DEBUG_CALLBACK("get_context_menu_handler\n");
return NULL;
Expand All @@ -30,7 +30,7 @@ struct CEF_CALLBACK _cef_context_menu_handler_t* get_context_menu_handler(
// Return the handler for dialogs. If no handler is provided the default
// implementation will be used.
///
struct CEF_CALLBACK _cef_dialog_handler_t* get_dialog_handler(
struct _cef_dialog_handler_t* CEF_CALLBACK get_dialog_handler(
struct _cef_client_t* self) {
DEBUG_CALLBACK("get_dialog_handler\n");
return NULL;
Expand All @@ -39,7 +39,7 @@ struct CEF_CALLBACK _cef_dialog_handler_t* get_dialog_handler(
///
// Return the handler for browser display state events.
///
struct CEF_CALLBACK _cef_display_handler_t* get_display_handler(
struct _cef_display_handler_t* CEF_CALLBACK get_display_handler(
struct _cef_client_t* self) {
DEBUG_CALLBACK("get_display_handler\n");
return NULL;
Expand All @@ -49,7 +49,7 @@ struct CEF_CALLBACK _cef_display_handler_t* get_display_handler(
// Return the handler for download events. If no handler is returned downloads
// will not be allowed.
///
struct CEF_CALLBACK _cef_download_handler_t* get_download_handler(
struct _cef_download_handler_t* CEF_CALLBACK get_download_handler(
struct _cef_client_t* self) {
DEBUG_CALLBACK("get_download_handler\n");
return NULL;
Expand All @@ -58,7 +58,7 @@ struct CEF_CALLBACK _cef_download_handler_t* get_download_handler(
///
// Return the handler for drag events.
///
struct CEF_CALLBACK _cef_drag_handler_t* get_drag_handler(
struct _cef_drag_handler_t* CEF_CALLBACK get_drag_handler(
struct _cef_client_t* self) {
DEBUG_CALLBACK("get_drag_handler\n");
return NULL;
Expand All @@ -67,7 +67,7 @@ struct CEF_CALLBACK _cef_drag_handler_t* get_drag_handler(
///
// Return the handler for focus events.
///
struct CEF_CALLBACK _cef_focus_handler_t* get_focus_handler(
struct _cef_focus_handler_t* CEF_CALLBACK get_focus_handler(
struct _cef_client_t* self) {
DEBUG_CALLBACK("get_focus_handler\n");
return NULL;
Expand All @@ -77,7 +77,7 @@ struct CEF_CALLBACK _cef_focus_handler_t* get_focus_handler(
// Return the handler for geolocation permissions requests. If no handler is
// provided geolocation access will be denied by default.
///
struct CEF_CALLBACK _cef_geolocation_handler_t* get_geolocation_handler(
struct _cef_geolocation_handler_t* CEF_CALLBACK get_geolocation_handler(
struct _cef_client_t* self) {
DEBUG_CALLBACK("get_geolocation_handler\n");
return NULL;
Expand All @@ -87,7 +87,7 @@ struct CEF_CALLBACK _cef_geolocation_handler_t* get_geolocation_handler(
// Return the handler for JavaScript dialogs. If no handler is provided the
// default implementation will be used.
///
struct CEF_CALLBACK _cef_jsdialog_handler_t* get_jsdialog_handler(
struct _cef_jsdialog_handler_t* CEF_CALLBACK get_jsdialog_handler(
struct _cef_client_t* self) {
DEBUG_CALLBACK("get_jsdialog_handler\n");
return NULL;
Expand All @@ -96,7 +96,7 @@ struct CEF_CALLBACK _cef_jsdialog_handler_t* get_jsdialog_handler(
///
// Return the handler for keyboard events.
///
struct CEF_CALLBACK _cef_keyboard_handler_t* get_keyboard_handler(
struct _cef_keyboard_handler_t* CEF_CALLBACK get_keyboard_handler(
struct _cef_client_t* self) {
DEBUG_CALLBACK("get_keyboard_handler\n");
return NULL;
Expand All @@ -105,7 +105,7 @@ struct CEF_CALLBACK _cef_keyboard_handler_t* get_keyboard_handler(
///
// Return the handler for browser life span events.
///
struct CEF_CALLBACK _cef_life_span_handler_t* get_life_span_handler(
struct _cef_life_span_handler_t* CEF_CALLBACK get_life_span_handler(
struct _cef_client_t* self) {
DEBUG_CALLBACK("get_life_span_handler\n");
return NULL;
Expand All @@ -114,7 +114,7 @@ struct CEF_CALLBACK _cef_life_span_handler_t* get_life_span_handler(
///
// Return the handler for browser load status events.
///
struct CEF_CALLBACK _cef_load_handler_t* get_load_handler(
struct _cef_load_handler_t* CEF_CALLBACK get_load_handler(
struct _cef_client_t* self) {
DEBUG_CALLBACK("get_load_handler\n");
return NULL;
Expand All @@ -123,7 +123,7 @@ struct CEF_CALLBACK _cef_load_handler_t* get_load_handler(
///
// Return the handler for off-screen rendering events.
///
struct CEF_CALLBACK _cef_render_handler_t* get_render_handler(
struct _cef_render_handler_t* CEF_CALLBACK get_render_handler(
struct _cef_client_t* self) {
DEBUG_CALLBACK("get_render_handler\n");
return NULL;
Expand All @@ -132,7 +132,7 @@ struct CEF_CALLBACK _cef_render_handler_t* get_render_handler(
///
// Return the handler for browser request events.
///
struct CEF_CALLBACK _cef_request_handler_t* get_request_handler(
struct _cef_request_handler_t* CEF_CALLBACK get_request_handler(
struct _cef_client_t* self) {
DEBUG_CALLBACK("get_request_handler\n");
return NULL;
Expand Down
5 changes: 5 additions & 0 deletions include/internal/cef_export.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@
#elif defined(COMPILER_GCC)

#define CEF_EXPORT __attribute__ ((visibility("default")))

#ifdef OS_WIN
#define CEF_CALLBACK __stdcall
#else
#define CEF_CALLBACK
#endif

#endif // COMPILER_GCC

Expand Down
45 changes: 13 additions & 32 deletions src/cef/cef.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ package cef
/*
CEF capi fixes
--------------
In cef_string.h:
this => typedef cef_string_utf16_t cef_string_t;
to => #define cef_string_t cef_string_utf16_t
1. In cef_string.h:
this => typedef cef_string_utf16_t cef_string_t;
to => #define cef_string_t cef_string_utf16_t
2. In cef_export.h:
#elif defined(COMPILER_GCC)
#define CEF_EXPORT __attribute__ ((visibility("default")))
#ifdef OS_WIN
#define CEF_CALLBACK __stdcall
#else
#define CEF_CALLBACK
#endif
*/

/*
Expand Down Expand Up @@ -75,38 +81,13 @@ func _InitializeGlobalCStructures() {
_MainArgs = (*C.struct__cef_main_args_t)(
C.calloc(1, C.sizeof_struct__cef_main_args_t))

// Some bug in Go on Windows: "unexpected fault address 0xffffffff".
// Happens in cef_execute_process() when initialize_app_handler()
// or initialize_client_handler() are called here. This same code
// works perfectly fine on Linux and OS X. From the logs:
// [cef] cef.go:88: ExecuteProcess, args= [cef2go.exe]
// initialize_app_handler
// initialize_cef_base
// cef_base_t.size = 36
// initialize_client_handler
// initialize_cef_base
// cef_base_t.size = 72
// [cef] cef_windows.go:19: FillMainArgs
// cef_base_t.add_ref
// unexpected fault address 0xffffffff
// fatal error: fault
// So it looks like the problem occurs after the first call to
// add_ref made by CEF.
// Maybe that's the bug - some problem during linking:
// "cmd/ld: order of files in archives matters on Windows"
// https://code.google.com/p/go/issues/detail?id=2601

_AppHandler = (*C.cef_app_t)(
C.calloc(1, C.sizeof_cef_app_t))
if runtime.GOOS != "windows" {
C.initialize_app_handler(_AppHandler)
}
C.initialize_app_handler(_AppHandler)

_ClientHandler = (*C.struct__cef_client_t)(
C.calloc(1, C.sizeof_struct__cef_client_t))
if runtime.GOOS != "windows" {
C.initialize_client_handler(_ClientHandler)
}
C.initialize_client_handler(_ClientHandler)
}

func ExecuteProcess(appHandle unsafe.Pointer) int {
Expand Down

0 comments on commit f789834

Please sign in to comment.