I've asked this question on the Awesomium forms but I haven't received any response yet and figured I could speed things up by asking here too.
I am unable to reach any break point within my callback_UI() when I push the corresponding html button. The links work fine to travel between pages but the callback does not get triggered.
Here is my simple C side code:
#define BUFFER_LEN_CALLBACKS 100
#define NAME_UIOBJ_INDEX "object_index"
#define NAME_UICALL_INDEX "callback_index"
void callback_UI(awe_webview* view, awe_string const* object_name, awe_string const* callback_name, awe_jsarray const* args){
char buff_object_name[BUFFER_LEN_CALLBACKS] = {0};
char buff_callback_name[BUFFER_LEN_CALLBACKS] = {0};
//char buff_args[BUFFER_LEN_CALLBACKS] = {0};
// Get the strings.
awe_string_to_utf8(object_name, buff_object_name, BUFFER_LEN_CALLBACKS);
awe_string_to_utf8(callback_name, buff_callback_name, BUFFER_LEN_CALLBACKS);
string s_obj_name(buff_object_name);
string s_call_name(buff_callback_name);
HandleCallback( s_obj_name, s_obj_name );
}
void create_uiobject(awe_webview* view, char* name){
awe_string* awes_name = awe_string_create_from_ascii(name, sizeof(name));
awe_webview_create_object(view, awes_name);
awe_string_destroy(awes_name);
}
void create_uicallback(awe_webview* view, char* name, char* callback){
awe_string* awes_name = awe_string_create_from_ascii(name, sizeof(name));
awe_string* awes_callback = awe_string_create_from_ascii(
callback,sizeof(callback));
awe_webview_set_object_callback(view, awes_name, awes_callback);
awe_string_destroy(awes_name);
awe_string_destroy(awes_callback);
// Set our UI callback to let the javascript talk to our program.
awe_webview_set_callback_js_callback(view, callback_UI);
}
void setup_javascript_objects(awe_webview* view){
// Create our object names.
create_uiobject(view,NAME_UIOBJ_INDEX);
// Create our object callbacks.
create_uicallback(view, NAME_UIOBJ_INDEX, NAME_UICALL_INDEX);
}
And here is my html side javascript code:
<input type="button" value="Click Me!"onclick="object_index.callback_index('hello!')" />
Everything else works fine. awe_webview_set_callback_js_console_message() is telling me that the "object_index" is not defined. I'm using awe_webview_create_object() to do so, but maybe I'm using it wrong. Idk.
Does anyone have any ideas?
The problem was my calls:
awe_string_create_from_ascii(name, sizeof(name));
needed to be:
awe_string_create_from_ascii(name, strlen(name));
This was a subtle but crushing error. I hope this post is able to help others who find themselves in a similar situation.