Skip to content
This repository has been archived by the owner on Oct 12, 2021. It is now read-only.

Generic Message Routing

[email protected] edited this page Nov 29, 2019 · 1 revision

Applies Only to CefGlue apps

This is info about registering handlers for Cef Generic Message Router

Cef/CefGlue IPC provides a generic implementation for routing asynchronous messages between Javascript running in the renderer process and .NET C# running in the browser process. These implementations are done internally by registering Javascript functions on the current window browser. These functions are cefQuery and cefQueryCancel.

The generic message router functions in UI are in the following formats:

 // Create and send a new query.
 var request_id = window.cefQuery({
        request: 'my_request',
        persistent: false,
        onSuccess: function(response) {},
        onFailure: function(error_code, error_message) {}
     });
 
// Optionally cancel the query.
window.cefQueryCancel(request_id)

For Chromely CefGlue message routing, the following must be done:

  • Use default message router handler or register a new one.
  • Add appropriate cefQuery Javascript function in the UI.

Register Message Router Handler

To use the default handler nothing needs to be done. To register a new handler please check Configuration.

Chromely default message route handling only implements cefQuery. To implement cefQueryCancel a new handler must be implemented and registered.

The default handler expects the request to be in the following format:

var request = {
      "method": method,
      "url": url
      "parameters": parameters,
      "postData": postData,
 };

Where:
   method: Restful methods "GET" or "POST". Only "Get" and "POST" are allowed.
   url: route path - "controller/action".
   parameters: Dictionary of parameters, where keys are in string, and values can be any primitive object.
   postData: Posted/input data object.

cefQuery Javascript function in the UI

A sample CefQuery GET request in the UI will be:

function messageRouterResult(response) {
            var jsonData = JSON.parse(response);
            if (jsonData.ReadyState == 4 && jsonData.Status == 200) {
                   .... process response
            }
        }

 function messageRouterRun() {
            var request = {
                "method": "GET",
                "url": "/democontroller/movies",
                "parameters": null,
                "postData": null,
            };
            window.cefQuery({
                request: JSON.stringify(request),
                onSuccess: function (response) {
                    messageRouterResult(response);
                }, onFailure: function (err, msg) {
                    console.log(err, msg);
                }
            });
        }
Where:
   On success callback function: messageRouterResult 
Clone this wiki locally