1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2025-11-23 21:34:53 +02:00

Added TCEFSentinel to more demos

- Check that all frames are valid before using them
- Added an error page to MiniBrowser.
This commit is contained in:
Salvador Díaz Fau
2019-10-13 18:50:23 +02:00
parent 9391d68ee0
commit 77121dc510
89 changed files with 1097 additions and 522 deletions

View File

@@ -388,7 +388,7 @@ begin
case commandId of
MINIBROWSER_CONTEXTMENU_SETJSEVENT :
if (browser <> nil) and (browser.MainFrame <> nil) then
if (frame <> nil) and frame.IsValid then
begin
TempJSCode := 'document.body.addEventListener("mouseover", function(evt){'+
'function getpath(n){'+
@@ -399,16 +399,16 @@ begin
'myextension.mouseover(getpath(evt.target))}'+
')';
browser.MainFrame.ExecuteJavaScript(TempJSCode, 'about:blank', 0);
frame.ExecuteJavaScript(TempJSCode, 'about:blank', 0);
end;
MINIBROWSER_CONTEXTMENU_JSVISITDOM :
if (browser <> nil) and (browser.MainFrame <> nil) then
if (frame <> nil) and frame.IsValid then
begin
TempJSCode := 'var testhtml = document.body.innerHTML; ' +
'myextension.sendresulttobrowser(testhtml, ' + quotedstr(CUSTOMNAME_MESSAGE_NAME) + ');';
browser.MainFrame.ExecuteJavaScript(TempJSCode, 'about:blank', 0);
frame.ExecuteJavaScript(TempJSCode, 'about:blank', 0);
end;
MINIBROWSER_CONTEXTMENU_SHOWDEVTOOLS :

View File

@@ -1,4 +1,4 @@
// ************************************************************************
// ************************************************************************
// ***************************** CEF4Delphi *******************************
// ************************************************************************
//
@@ -69,35 +69,46 @@ function TTestExtensionHandler.Execute(const name : ustring;
var retval : ICefv8Value;
var exception : ustring): Boolean;
var
msg: ICefProcessMessage;
TempMessage : ICefProcessMessage;
TempFrame : ICefFrame;
begin
if (name = 'mouseover') then
begin
if (length(arguments) > 0) and arguments[0].IsString then
begin
msg := TCefProcessMessageRef.New(MOUSEOVER_MESSAGE_NAME);
msg.ArgumentList.SetString(0, arguments[0].GetStringValue);
Result := False;
TCefv8ContextRef.Current.Browser.MainFrame.SendProcessMessage(PID_BROWSER, msg);
end;
Result := True;
end
else
if (name = 'sendresulttobrowser') then
try
if (name = 'mouseover') then
begin
if (length(arguments) > 1) and arguments[0].IsString and arguments[1].IsString then
if (length(arguments) > 0) and arguments[0].IsString then
begin
msg := TCefProcessMessageRef.New(arguments[1].GetStringValue);
msg.ArgumentList.SetString(0, arguments[0].GetStringValue);
TempMessage := TCefProcessMessageRef.New(MOUSEOVER_MESSAGE_NAME);
TempMessage.ArgumentList.SetString(0, arguments[0].GetStringValue);
TCefv8ContextRef.Current.Browser.MainFrame.SendProcessMessage(PID_BROWSER, msg);
TempFrame := TCefv8ContextRef.Current.Browser.MainFrame;
if (TempFrame <> nil) and TempFrame.IsValid then
TempFrame.SendProcessMessage(PID_BROWSER, TempMessage);
end;
Result := True;
end
else
Result := False;
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;
end;
end.