The answer to both is:
yesPlease see
the Javascript example:
1. See
TCustomRenderProcessHandler.OnWebKitInitialized:
There is
native function GetTestParam()
which registers a Pascal function in Javascript.
Every time you call a
native function the registered handler
is called.
There you have every information needed to handle the call:
// Structure that should be implemented to handle V8 function calls. The
// functions of this structure will be called on the thread associated with the
// V8 function.
TCefV8Handler = record
[..]
// Handle execution of the function identified by |name|. |object| is the
// receiver ('this' object) of the function. |arguments| is the list of
// arguments passed to the function. If execution succeeds set |retval| to the
// function return value. If execution fails set |exception| to the exception
// that will be thrown. Return true (1) if execution was handled.
execute: function(self: PCefv8Handler; const name: PCefString; object_: PCefv8Value;
argumentsCount: csize_t; arguments: PCefV8ValueArray; out retval: PCefV8Value;
exception: PCefString): Integer; cconv;
end;
This also is the bridge between Pascal and Javascript: You can pass data to Pascal by calling a native function, you can pass data to Javascript by calling a Javascript function, which in turn calls a native function:
retval can be a
ICefDictionaryValue, so it is not limited to a single value.
If you have a lot of data to pass to Javascript, you could also register a custom scheme with a custom scheme handler (think of it as a custom protocol, e.g. cefinternal://). Javascript then could load data from this scheme (e.g. JSON files).
Any thoughts please,
Code has already been posted
here.
The relevant parts are:
1. A custom render process handler for the render process:
type
TCustomRenderProcessHandler = class(TCefRenderProcessHandlerOwn)
protected
function OnProcessMessageReceived(const browser: ICefBrowser; sourceProcess: TCefProcessId;
const message: ICefProcessMessage): Boolean; override;
end;
2. Implement messages, the example defines the message
visitdom.
You can pass data via
ICefProcessMessage.ArgumentList.
function TCustomRenderProcessHandler.OnProcessMessageReceived
(const browser: ICefBrowser; sourceProcess: TCefProcessId;
const message: ICefProcessMessage): Boolean;
begin
case message.Name of
'visitdom':
begin
browser.MainFrame.VisitDomProc(@VisitDOM);
Result := True;
end;
else
Result := inherited;
end;
end;
This part is for communicating UI process to render process
3. The counterpart for the UI process is
OnProcessMessageReceived in
TChromium. There you can handle messages for communicating render process to UI process.
4. Send messages:
browser.SendProcessMessage(PID_RENDERER, TCefProcessMessageRef.New('visitdom'));
For also passing data you only need to set
TCefProcessMessageRef.ArgumentList.
I really hope this helps you to get started finally.