You've already forked CEF4Delphi
mirror of
https://github.com/salvadordf/CEF4Delphi.git
synced 2025-06-12 22:07:39 +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:
@ -1,4 +1,4 @@
|
||||
// ************************************************************************
|
||||
// ************************************************************************
|
||||
// ***************************** CEF4Delphi *******************************
|
||||
// ************************************************************************
|
||||
//
|
||||
@ -432,7 +432,8 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
pFrame.SendProcessMessage(PID_BROWSER, pAnswer);
|
||||
if (pFrame <> nil) and pFrame.IsValid then
|
||||
pFrame.SendProcessMessage(PID_BROWSER, pAnswer);
|
||||
end;
|
||||
|
||||
procedure ParseBinaryValue(const pBrowser : ICefBrowser; const pFrame: ICefFrame; const aBinaryValue : ICefBinaryValue);
|
||||
@ -476,7 +477,7 @@ begin
|
||||
TempString := 'Image size : ' + inttostr(TempSize) + #13 + #10 +
|
||||
'Encoded image : ' + TempEncodedStream.DataString;
|
||||
|
||||
if pAnswer.ArgumentList.SetString(0, TempString) then
|
||||
if (pFrame <> nil) and pFrame.IsValid and pAnswer.ArgumentList.SetString(0, TempString) then
|
||||
pFrame.SendProcessMessage(PID_BROWSER, pAnswer);
|
||||
end;
|
||||
end;
|
||||
@ -512,9 +513,9 @@ begin
|
||||
begin
|
||||
TempScript := pMessage.ArgumentList.GetString(0);
|
||||
|
||||
if (length(TempScript) > 0) then
|
||||
if (length(TempScript) > 0) and (pFrame <> nil) and pFrame.IsValid then
|
||||
begin
|
||||
pV8Context := pBrowser.MainFrame.GetV8Context;
|
||||
pV8Context := pFrame.GetV8Context;
|
||||
|
||||
if pV8Context.Enter then
|
||||
begin
|
||||
|
@ -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 :
|
||||
|
@ -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.
|
||||
|
@ -1,4 +1,4 @@
|
||||
// ************************************************************************
|
||||
// ************************************************************************
|
||||
// ***************************** CEF4Delphi *******************************
|
||||
// ************************************************************************
|
||||
//
|
||||
@ -63,19 +63,28 @@ function TMyV8Handler.Execute(const name : ustring;
|
||||
var retval : ICefv8Value;
|
||||
var exception : ustring): Boolean;
|
||||
var
|
||||
msg: ICefProcessMessage;
|
||||
TempMessage : ICefProcessMessage;
|
||||
TempFrame : ICefFrame;
|
||||
begin
|
||||
if (name = 'myfunc') then
|
||||
begin
|
||||
msg := TCefProcessMessageRef.New(TEST_MESSAGE_NAME);
|
||||
msg.ArgumentList.SetString(0, 'Message received!');
|
||||
TCefv8ContextRef.Current.Browser.MainFrame.SendProcessMessage(PID_BROWSER, msg);
|
||||
Result := False;
|
||||
|
||||
retval := TCefv8ValueRef.NewString('My Value!');
|
||||
Result := True;
|
||||
end
|
||||
else
|
||||
Result := False;
|
||||
try
|
||||
if (name = 'myfunc') then
|
||||
begin
|
||||
TempMessage := TCefProcessMessageRef.New(TEST_MESSAGE_NAME);
|
||||
TempMessage.ArgumentList.SetString(0, 'Message received!');
|
||||
|
||||
TempFrame := TCefv8ContextRef.Current.Browser.MainFrame;
|
||||
|
||||
if (TempFrame <> nil) and TempFrame.IsValid then
|
||||
TempFrame.SendProcessMessage(PID_BROWSER, TempMessage);
|
||||
|
||||
retval := TCefv8ValueRef.NewString('My Value!');
|
||||
Result := True;
|
||||
end;
|
||||
finally
|
||||
TempMessage := nil;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user