2017-11-22 17:43:48 +01:00
|
|
|
unit uTestExtensionHandler;
|
2017-07-25 22:50:34 +02:00
|
|
|
|
2023-11-26 19:28:28 +01:00
|
|
|
{$I ..\..\..\..\source\cef.inc}
|
2017-07-25 22:50:34 +02:00
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
{$IFDEF DELPHI16_UP}
|
|
|
|
Winapi.Windows,
|
|
|
|
{$ELSE}
|
|
|
|
Windows,
|
|
|
|
{$ENDIF}
|
|
|
|
uCEFRenderProcessHandler, uCEFBrowserProcessHandler, uCEFInterfaces, uCEFProcessMessage,
|
|
|
|
uCEFv8Context, uCEFTypes, uCEFv8Handler;
|
|
|
|
|
|
|
|
type
|
2017-11-22 17:43:48 +01:00
|
|
|
TTestExtensionHandler = class(TCefv8HandlerOwn)
|
|
|
|
protected
|
2019-11-24 18:19:49 +01:00
|
|
|
function Execute(const name: ustring; const object_: ICefv8Value; const arguments: TCefv8ValueArray; var retval: ICefv8Value; var exception: ustring): Boolean; override;
|
2017-07-25 22:50:34 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
2017-09-07 10:58:09 +02:00
|
|
|
uCEFMiscFunctions, uCEFConstants, uJSExtension;
|
2017-07-25 22:50:34 +02:00
|
|
|
|
2017-11-22 17:43:48 +01:00
|
|
|
function TTestExtensionHandler.Execute(const name : ustring;
|
2019-11-24 18:19:49 +01:00
|
|
|
const object_ : ICefv8Value;
|
2017-11-22 17:43:48 +01:00
|
|
|
const arguments : TCefv8ValueArray;
|
|
|
|
var retval : ICefv8Value;
|
|
|
|
var exception : ustring): Boolean;
|
2017-07-25 22:50:34 +02:00
|
|
|
var
|
2019-10-13 18:50:23 +02:00
|
|
|
TempMessage : ICefProcessMessage;
|
|
|
|
TempFrame : ICefFrame;
|
2017-07-25 22:50:34 +02:00
|
|
|
begin
|
2019-10-13 18:50:23 +02:00
|
|
|
Result := False;
|
2017-07-25 22:50:34 +02:00
|
|
|
|
2019-10-13 18:50:23 +02:00
|
|
|
try
|
|
|
|
if (name = 'mouseover') then
|
2017-11-22 17:43:48 +01:00
|
|
|
begin
|
2019-10-13 18:50:23 +02:00
|
|
|
if (length(arguments) > 0) and arguments[0].IsString then
|
2017-11-22 17:43:48 +01:00
|
|
|
begin
|
2019-10-13 18:50:23 +02:00
|
|
|
TempMessage := TCefProcessMessageRef.New(MOUSEOVER_MESSAGE_NAME);
|
|
|
|
TempMessage.ArgumentList.SetString(0, arguments[0].GetStringValue);
|
2017-11-22 17:43:48 +01:00
|
|
|
|
2019-10-13 18:50:23 +02:00
|
|
|
TempFrame := TCefv8ContextRef.Current.Browser.MainFrame;
|
|
|
|
|
|
|
|
if (TempFrame <> nil) and TempFrame.IsValid then
|
|
|
|
TempFrame.SendProcessMessage(PID_BROWSER, TempMessage);
|
2017-11-22 17:43:48 +01:00
|
|
|
end;
|
2017-07-25 22:50:34 +02:00
|
|
|
|
2017-11-22 17:43:48 +01:00
|
|
|
Result := True;
|
|
|
|
end
|
|
|
|
else
|
2019-10-13 18:50:23 +02:00
|
|
|
if (name = 'sendresulttobrowser') then
|
|
|
|
begin
|
|
|
|
if (length(arguments) > 1) and arguments[0].IsString and arguments[1].IsString then
|
|
|
|
begin
|
|
|
|
TempMessage := TCefProcessMessageRef.New(arguments[1].GetStringValue);
|
|
|
|
TempMessage.ArgumentList.SetString(0, arguments[0].GetStringValue);
|
|
|
|
|
|
|
|
TempFrame := TCefv8ContextRef.Current.Browser.MainFrame;
|
|
|
|
|
|
|
|
if (TempFrame <> nil) and TempFrame.IsValid then
|
|
|
|
TempFrame.SendProcessMessage(PID_BROWSER, TempMessage);
|
|
|
|
end;
|
|
|
|
|
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
TempMessage := nil;
|
|
|
|
end;
|
2017-07-25 22:50:34 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|