1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2025-06-12 22:07:39 +02:00

Added GlobalCEFApp.DisablePDFExtension property

- Bug fix #89
- New SimpleLazOSRBrowser demo
This commit is contained in:
Salvador Díaz Fau
2018-06-17 14:18:11 +02:00
parent 8519c9b5d5
commit bf402109bf
61 changed files with 2141 additions and 583 deletions

View File

@ -57,8 +57,9 @@ uses
{$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.OnProcessMessageReceived := JSEvalFrm.RenderProcessHandler_OnProcessMessageReceivedEvent;
// GlobalCEFApp creation and initialization moved to a different unit to fix the memory leak described in the bug #89
// https://github.com/salvadordf/CEF4Delphi/issues/89
CreateGlobalCEFApp;
if GlobalCEFApp.StartMainProcess then
begin
@ -71,6 +72,5 @@ begin
Application.Run;
end;
GlobalCEFApp.Free;
GlobalCEFApp := nil;
DestroyGlobalCEFApp;
end.

View File

@ -117,17 +117,13 @@ type
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
procedure WMEnterMenuLoop(var aMessage: TMessage); message WM_ENTERMENULOOP;
procedure WMExitMenuLoop(var aMessage: TMessage); message WM_EXITMENULOOP;
procedure ParseEvalJsAnswer(const pMessage: ICefProcessMessage; pBrowser: ICefBrowser; pReturnValue : ICefv8Value; pException : ICefV8Exception);
procedure ParseBinaryValue(const pBrowser : ICefBrowser; const aBinaryValue : ICefBinaryValue);
public
procedure RenderProcessHandler_OnProcessMessageReceivedEvent(const pBrowser: ICefBrowser; uSourceProcess: TCefProcessId; const pMessage: ICefProcessMessage; var aHandled : boolean);
end;
var
JSEvalFrm: TJSEvalFrm;
procedure CreateGlobalCEFApp;
implementation
{$R *.dfm}
@ -139,7 +135,7 @@ uses
// Steps to evaluate some JavaScript code using the V8Context
// ----------------------------------------------------------
// 1. Set GlobalCEFApp.OnProcessMessageReceived to JSEvalFrm.RenderProcessHandler_OnProcessMessageReceivedEvent in the DPR file.
// 1. Set GlobalCEFApp.OnProcessMessageReceived to RenderProcessHandler_OnProcessMessageReceivedEvent.
// 2. To get the Javascript code in this demo we use a context menu that sends a MINIBROWSER_EVALJSCODE to the form.
// 3. The EvalJSCodeMsg asks for the Javascript code and sends it to the renderer using a process message.
// 4. RenderProcessHandler_OnProcessMessageReceivedEvent receives the process message and calls ParseEvalJsAnswer
@ -153,7 +149,7 @@ uses
// This demo also has an example of binary parameters in process messages
// ----------------------------------------------------------------------
// 1. Set GlobalCEFApp.OnProcessMessageReceived to JSEvalFrm.RenderProcessHandler_OnProcessMessageReceivedEvent in the DPR file.
// 1. Set GlobalCEFApp.OnProcessMessageReceived to RenderProcessHandler_OnProcessMessageReceivedEvent.
// 2. The context menu has a 'Send JPEG image' option that sends a MINIBROWSER_JSBINPARAM message to the form.
// 3. EvalJSBinParamMsg asks for a JPEG image and sends a process message with a ICefBinaryValue parameter to the
// renderer process.
@ -380,52 +376,10 @@ begin
end;
end;
procedure TJSEvalFrm.RenderProcessHandler_OnProcessMessageReceivedEvent(const pBrowser : ICefBrowser;
uSourceProcess : TCefProcessId;
const pMessage : ICefProcessMessage;
var aHandled : boolean);
var
pV8Context : ICefv8Context;
pReturnValue : ICefv8Value;
pException : ICefV8Exception;
TempScript : string;
TempBinValue : ICefBinaryValue;
begin
aHandled := False;
if (pMessage = nil) or (pMessage.ArgumentList = nil) then exit;
if (pMessage.Name = EVAL_JS) then
begin
TempScript := pMessage.ArgumentList.GetString(0);
if (length(TempScript) > 0) then
begin
pV8Context := pBrowser.MainFrame.GetV8Context;
if pV8Context.Enter then
begin
pV8Context.Eval(TempScript, '', 1, pReturnValue, pException);
ParseEvalJsAnswer(pMessage, pBrowser, pReturnValue, pException);
pV8Context.Exit;
end;
end;
aHandled := True;
end
else
if (pMessage.Name = BINARY_PARAM_JS) then
begin
TempBinValue := pMessage.ArgumentList.GetBinary(0);
ParseBinaryValue(pBrowser, TempBinValue);
aHandled := True;
end;
end;
procedure TJSEvalFrm.ParseEvalJsAnswer(const pMessage : ICefProcessMessage;
pBrowser : ICefBrowser;
pReturnValue : ICefv8Value;
pException : ICefV8Exception);
procedure ParseEvalJsAnswer(const pMessage : ICefProcessMessage;
pBrowser : ICefBrowser;
pReturnValue : ICefv8Value;
pException : ICefV8Exception);
var
pAnswer : ICefProcessMessage;
strResult : String;
@ -464,7 +418,7 @@ begin
pBrowser.SendProcessMessage(PID_BROWSER, pAnswer);
end;
procedure TJSEvalFrm.ParseBinaryValue(const pBrowser : ICefBrowser; const aBinaryValue : ICefBinaryValue);
procedure ParseBinaryValue(const pBrowser : ICefBrowser; const aBinaryValue : ICefBinaryValue);
var
pAnswer : ICefProcessMessage;
TempBuffer : TBytes;
@ -496,13 +450,61 @@ begin
end;
except
on e : exception do
if CustomExceptionHandler('TJSEvalFrm.ParseBinaryValue', e) then raise;
if CustomExceptionHandler('ParseBinaryValue', e) then raise;
end;
finally
SetLength(TempBuffer, 0);
end;
end;
procedure RenderProcessHandler_OnProcessMessageReceivedEvent(const pBrowser : ICefBrowser;
uSourceProcess : TCefProcessId;
const pMessage : ICefProcessMessage;
var aHandled : boolean);
var
pV8Context : ICefv8Context;
pReturnValue : ICefv8Value;
pException : ICefV8Exception;
TempScript : string;
TempBinValue : ICefBinaryValue;
begin
aHandled := False;
if (pMessage = nil) or (pMessage.ArgumentList = nil) then exit;
if (pMessage.Name = EVAL_JS) then
begin
TempScript := pMessage.ArgumentList.GetString(0);
if (length(TempScript) > 0) then
begin
pV8Context := pBrowser.MainFrame.GetV8Context;
if pV8Context.Enter then
begin
pV8Context.Eval(TempScript, '', 1, pReturnValue, pException);
ParseEvalJsAnswer(pMessage, pBrowser, pReturnValue, pException);
pV8Context.Exit;
end;
end;
aHandled := True;
end
else
if (pMessage.Name = BINARY_PARAM_JS) then
begin
TempBinValue := pMessage.ArgumentList.GetBinary(0);
ParseBinaryValue(pBrowser, TempBinValue);
aHandled := True;
end;
end;
procedure CreateGlobalCEFApp;
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.OnProcessMessageReceived := RenderProcessHandler_OnProcessMessageReceivedEvent;
end;
procedure TJSEvalFrm.Chromium1ProcessMessageReceived(Sender : TObject;
const browser : ICefBrowser;
sourceProcess : TCefProcessId;

View File

@ -57,9 +57,9 @@ uses
{$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.OnContextCreated := GlobalCEFApp_OnContextCreated;
GlobalCEFApp.OnProcessMessageReceived := GlobalCEFApp_OnProcessMessageReceived;
// GlobalCEFApp creation and initialization moved to a different unit to fix the memory leak described in the bug #89
// https://github.com/salvadordf/CEF4Delphi/issues/89
CreateGlobalCEFApp;
if GlobalCEFApp.StartMainProcess then
begin
@ -71,6 +71,5 @@ begin
Application.Run;
end;
GlobalCEFApp.Free;
GlobalCEFApp := nil;
DestroyGlobalCEFApp;
end.

View File

@ -110,11 +110,7 @@ var
GlobalCallbackFunc : ICefv8Value = nil;
GlobalCallbackContext : ICefv8Context = nil;
procedure GlobalCEFApp_OnContextCreated(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context);
procedure GlobalCEFApp_OnProcessMessageReceived(const browser : ICefBrowser;
sourceProcess : TCefProcessId;
const aMessage : ICefProcessMessage;
var aHandled : boolean);
procedure CreateGlobalCEFApp;
implementation
@ -171,6 +167,13 @@ begin
aHandled := False;
end;
procedure CreateGlobalCEFApp;
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.OnContextCreated := GlobalCEFApp_OnContextCreated;
GlobalCEFApp.OnProcessMessageReceived := GlobalCEFApp_OnProcessMessageReceived;
end;
procedure TJSExecutingFunctionsFrm.GoBtnClick(Sender: TObject);
begin
Chromium1.LoadURL(Edit1.Text);

View File

@ -58,8 +58,9 @@ uses
{$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.OnWebKitInitialized := GlobalCEFApp_OnWebKitInitialized;
// GlobalCEFApp creation and initialization moved to a different unit to fix the memory leak described in the bug #89
// https://github.com/salvadordf/CEF4Delphi/issues/89
CreateGlobalCEFApp;
if GlobalCEFApp.StartMainProcess then
begin
@ -72,6 +73,5 @@ begin
Application.Run;
end;
GlobalCEFApp.Free;
GlobalCEFApp := nil;
DestroyGlobalCEFApp;
end.

View File

@ -116,7 +116,7 @@ type
var
JSExtensionFrm: TJSExtensionFrm;
procedure GlobalCEFApp_OnWebKitInitialized;
procedure CreateGlobalCEFApp;
implementation
@ -177,6 +177,12 @@ begin
CefRegisterExtension('myextension', TempExtensionCode, TempHandler);
end;
procedure CreateGlobalCEFApp;
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.OnWebKitInitialized := GlobalCEFApp_OnWebKitInitialized;
end;
procedure TJSExtensionFrm.GoBtnClick(Sender: TObject);
begin
Chromium1.LoadURL(Edit1.Text);

View File

@ -57,8 +57,9 @@ uses
{$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.OnWebKitInitialized := GlobalCEFApp_OnWebKitInitializedEvent;
// GlobalCEFApp creation and initialization moved to a different unit to fix the memory leak described in the bug #89
// https://github.com/salvadordf/CEF4Delphi/issues/89
CreateGlobalCEFApp;
if GlobalCEFApp.StartMainProcess then
begin
@ -70,6 +71,5 @@ begin
Application.Run;
end;
GlobalCEFApp.Free;
GlobalCEFApp := nil;
DestroyGlobalCEFApp;
end.

View File

@ -98,7 +98,7 @@ type
var
JSExtensionWithFunctionFrm: TJSExtensionWithFunctionFrm;
procedure GlobalCEFApp_OnWebKitInitializedEvent;
procedure CreateGlobalCEFApp;
implementation
@ -142,6 +142,12 @@ begin
CefRegisterExtension('v8/test', TempExtensionCode, TempHandler);
end;
procedure CreateGlobalCEFApp;
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.OnWebKitInitialized := GlobalCEFApp_OnWebKitInitializedEvent;
end;
procedure TJSExtensionWithFunctionFrm.GoBtnClick(Sender: TObject);
begin
Chromium1.LoadURL(Edit1.Text);

View File

@ -57,8 +57,9 @@ uses
{$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.OnWebKitInitialized := GlobalCEFApp_OnWebKitInitializedEvent;
// GlobalCEFApp creation and initialization moved to a different unit to fix the memory leak described in the bug #89
// https://github.com/salvadordf/CEF4Delphi/issues/89
CreateGlobalCEFApp;
if GlobalCEFApp.StartMainProcess then
begin
@ -70,6 +71,5 @@ begin
Application.Run;
end;
GlobalCEFApp.Free;
GlobalCEFApp := nil;
DestroyGlobalCEFApp;
end.

View File

@ -137,13 +137,13 @@
</Excluded_Packages>
</Delphi.Personality>
<Deployment Version="3">
<DeployFile LocalName="JSExtension.exe" Configuration="Debug" Class="ProjectOutput"/>
<DeployFile LocalName="..\..\..\bin\JSExtensionWithObjectParameter.exe" Configuration="Debug" Class="ProjectOutput">
<Platform Name="Win32">
<RemoteName>JSExtensionWithObjectParameter.exe</RemoteName>
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="JSExtension.exe" Configuration="Debug" Class="ProjectOutput"/>
<DeployClass Name="AdditionalDebugSymbols">
<Platform Name="iOSSimulator">
<Operation>1</Operation>

View File

@ -94,7 +94,7 @@ type
var
JSExtensionWithObjectParameterFrm: TJSExtensionWithObjectParameterFrm;
procedure GlobalCEFApp_OnWebKitInitializedEvent;
procedure CreateGlobalCEFApp;
implementation
@ -145,6 +145,12 @@ begin
CefRegisterExtension('v8/test', TempExtensionCode, TempHandler);
end;
procedure CreateGlobalCEFApp;
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.OnWebKitInitialized := GlobalCEFApp_OnWebKitInitializedEvent;
end;
procedure TJSExtensionWithObjectParameterFrm.GoBtnClick(Sender: TObject);
begin
Chromium1.LoadURL(Edit1.Text);

View File

@ -58,9 +58,9 @@ uses
{$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.OnWebKitInitialized := GlobalCEFApp_OnWebKitInitialized;
// GlobalCEFApp creation and initialization moved to a different unit to fix the memory leak described in the bug #89
// https://github.com/salvadordf/CEF4Delphi/issues/89
CreateGlobalCEFApp;
if GlobalCEFApp.StartMainProcess then
begin
@ -73,6 +73,5 @@ begin
Application.Run;
end;
GlobalCEFApp.Free;
GlobalCEFApp := nil;
DestroyGlobalCEFApp;
end.

View File

@ -139,13 +139,13 @@
</Excluded_Packages>
</Delphi.Personality>
<Deployment Version="3">
<DeployFile LocalName="JSExtension.exe" Configuration="Debug" Class="ProjectOutput"/>
<DeployFile LocalName="..\..\bin\JSRTTIExtension.exe" Configuration="Debug" Class="ProjectOutput">
<Platform Name="Win32">
<RemoteName>JSRTTIExtension.exe</RemoteName>
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="JSExtension.exe" Configuration="Debug" Class="ProjectOutput"/>
<DeployClass Name="AdditionalDebugSymbols">
<Platform Name="iOSSimulator">
<Operation>1</Operation>

View File

@ -114,7 +114,7 @@ type
var
JSRTTIExtensionFrm: TJSRTTIExtensionFrm;
procedure GlobalCEFApp_OnWebKitInitialized;
procedure CreateGlobalCEFApp;
implementation
@ -156,6 +156,12 @@ begin
{$ENDIF}
end;
procedure CreateGlobalCEFApp;
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.OnWebKitInitialized := GlobalCEFApp_OnWebKitInitialized;
end;
procedure TJSRTTIExtensionFrm.GoBtnClick(Sender: TObject);
begin
Chromium1.LoadURL(Edit1.Text);

View File

@ -56,8 +56,9 @@ uses
{$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.OnWebKitInitialized := GlobalCEFApp_OnWebKitInitializedEvent;
// GlobalCEFApp creation and initialization moved to a different unit to fix the memory leak described in the bug #89
// https://github.com/salvadordf/CEF4Delphi/issues/89
CreateGlobalCEFApp;
if GlobalCEFApp.StartMainProcess then
begin
@ -69,6 +70,5 @@ begin
Application.Run;
end;
GlobalCEFApp.Free;
GlobalCEFApp := nil;
DestroyGlobalCEFApp;
end.

View File

@ -94,7 +94,7 @@ type
var
JSSimpleExtensionFrm: TJSSimpleExtensionFrm;
procedure GlobalCEFApp_OnWebKitInitializedEvent;
procedure CreateGlobalCEFApp;
implementation
@ -132,6 +132,12 @@ begin
CefRegisterExtension('v8/test', TempExtensionCode, nil);
end;
procedure CreateGlobalCEFApp;
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.OnWebKitInitialized := GlobalCEFApp_OnWebKitInitializedEvent;
end;
procedure TJSSimpleExtensionFrm.GoBtnClick(Sender: TObject);
begin
Chromium1.LoadURL(Edit1.Text);

View File

@ -56,8 +56,9 @@ uses
{$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.OnContextCreated := GlobalCEFApp_OnContextCreated;
// GlobalCEFApp creation and initialization moved to a different unit to fix the memory leak described in the bug #89
// https://github.com/salvadordf/CEF4Delphi/issues/89
CreateGlobalCEFApp;
if GlobalCEFApp.StartMainProcess then
begin
@ -69,6 +70,5 @@ begin
Application.Run;
end;
GlobalCEFApp.Free;
GlobalCEFApp := nil;
DestroyGlobalCEFApp;
end.

View File

@ -95,7 +95,7 @@ type
var
JSSimpleWindowBindingFrm: TJSSimpleWindowBindingFrm;
procedure GlobalCEFApp_OnContextCreated(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context);
procedure CreateGlobalCEFApp;
implementation
@ -125,6 +125,12 @@ begin
context.Global.SetValueByKey('myval', TempValue, V8_PROPERTY_ATTRIBUTE_NONE);
end;
procedure CreateGlobalCEFApp;
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.OnContextCreated := GlobalCEFApp_OnContextCreated;
end;
procedure TJSSimpleWindowBindingFrm.GoBtnClick(Sender: TObject);
begin
Chromium1.LoadURL(Edit1.Text);

View File

@ -57,8 +57,9 @@ uses
{$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.OnContextCreated := GlobalCEFApp_OnContextCreated;
// GlobalCEFApp creation and initialization moved to a different unit to fix the memory leak described in the bug #89
// https://github.com/salvadordf/CEF4Delphi/issues/89
CreateGlobalCEFApp;
if GlobalCEFApp.StartMainProcess then
begin
@ -70,6 +71,5 @@ begin
Application.Run;
end;
GlobalCEFApp.Free;
GlobalCEFApp := nil;
DestroyGlobalCEFApp;
end.

View File

@ -94,7 +94,7 @@ type
var
JSWindowBindingWithFunctionFrm: TJSWindowBindingWithFunctionFrm;
procedure GlobalCEFApp_OnContextCreated(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context);
procedure CreateGlobalCEFApp;
implementation
@ -129,6 +129,12 @@ begin
context.Global.SetValueByKey('myfunc', TempFunction, V8_PROPERTY_ATTRIBUTE_NONE);
end;
procedure CreateGlobalCEFApp;
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.OnContextCreated := GlobalCEFApp_OnContextCreated;
end;
procedure TJSWindowBindingWithFunctionFrm.GoBtnClick(Sender: TObject);
begin
Chromium1.LoadURL(Edit1.Text);

View File

@ -57,8 +57,9 @@ uses
{$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.OnContextCreated := GlobalCEFApp_OnContextCreated;
// GlobalCEFApp creation and initialization moved to a different unit to fix the memory leak described in the bug #89
// https://github.com/salvadordf/CEF4Delphi/issues/89
CreateGlobalCEFApp;
if GlobalCEFApp.StartMainProcess then
begin
@ -70,6 +71,5 @@ begin
Application.Run;
end;
GlobalCEFApp.Free;
GlobalCEFApp := nil;
DestroyGlobalCEFApp;
end.

View File

@ -94,7 +94,7 @@ type
var
JSWindowBindingWithObjectFrm: TJSWindowBindingWithObjectFrm;
procedure GlobalCEFApp_OnContextCreated(const browser: ICefBrowser; const frame: ICefFrame; const context: ICefv8Context);
procedure CreateGlobalCEFApp;
implementation
@ -130,6 +130,12 @@ begin
context.Global.SetValueByKey('myobj', TempObject, V8_PROPERTY_ATTRIBUTE_NONE);
end;
procedure CreateGlobalCEFApp;
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.OnContextCreated := GlobalCEFApp_OnContextCreated;
end;
procedure TJSWindowBindingWithObjectFrm.GoBtnClick(Sender: TObject);
begin
Chromium1.LoadURL(Edit1.Text);