I'm trying to send some data from the renderer process to the browser process. The other way around seems to be working fine. However, when I try to send some back, the message never gets received.
Here is the relevant code that is trying to send the message:
- Code: Select all
CefRefPtr<CefProcessMessage> msg = CefProcessMessage::Create("eval-js-result");
CefRefPtr<CefListValue> msg_args = msg->GetArgumentList();
if ( !result ) {fprintf(stderr, "error\n");
CefString error_msg = "error";//bw_cef_v8exc_to_string( exception );
// The first parameter specifies the ID of the script that has executed
msg_args->SetInt( 0, script_id );
// The second parameter specifies whether or not an error has resulted
msg_args->SetBool( 1, false );
// The third parameter specifies the error message
msg_args->SetString( 2, error_msg );
}
else {
CefString result_string = ret_val->GetStringValue();
// The first parameter specifies the ID of the script that has executed
msg_args->SetInt( 0, script_id );
// The second parameter specifies whether or not an error has resulted
msg_args->SetBool( 1, true );
// The third parameter specifies the result formatted as a string
msg_args->SetString( 2, result_string );
}
// Send the message back to the browser process
browser->GetMainFrame()->SendProcessMessage( PID_BROWSER, msg );
and here is my OnProcessMessageReceived function, that doesn't get called after sending this particular message unfortunately.
- Code: Select all
virtual bool OnProcessMessageReceived(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message
) override {
// The message to execute some javascript, and return its output
if ( message->GetName() == "eval-js" ) {
int script_id = message->GetArgumentList()->GetInt( 0 );
CefString js = message->GetArgumentList()->GetString( 1 );
this->eval_js( browser, frame, js, script_id );
return true;
}
// The message to reveal the result of some javascript code
else if ( message->GetName() == "eval-js-result" ) {
fprintf(stderr, "eval-js-result\n");
int script_id = message->GetArgumentList()->GetInt( 0 );
bool success = message->GetArgumentList()->GetBool( 1 );
CefString result = message->GetArgumentList()->GetString( 2 );
fprintf(stderr, "Test: %s\n", result.ToString().c_str());
return true;
}
else
fprintf(stderr, "Unknown process message received: %s\n", message->GetName() );
return false;
}
Got any ideas?
Thank you.