1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2025-04-17 06:57:13 +02:00

Fix Lazarus build issue in Windows

Fix Delphi build issue in MacOS
Added TCefApplicationCore.CheckCEFResources
Added TCefApplicationCore.CheckCEFDLL
Set TCefApplicationCore.CheckCEFFiles to false by default in MacOS
This commit is contained in:
Salvador Diaz Fau 2021-02-21 18:41:25 +01:00
parent 51d8c20f63
commit 92da537bf7
9 changed files with 176 additions and 111 deletions

View File

@ -352,6 +352,10 @@ type
function MultiExeProcessing : boolean; function MultiExeProcessing : boolean;
function SingleExeProcessing : boolean; function SingleExeProcessing : boolean;
procedure BeforeInitSubProcess; virtual; procedure BeforeInitSubProcess; virtual;
function CheckCEFResources : boolean;
{$IFDEF MSWINDOWS}
function CheckCEFDLL : boolean;
{$ENDIF}
function CheckCEFLibrary : boolean; function CheckCEFLibrary : boolean;
procedure RegisterWidevineCDM; procedure RegisterWidevineCDM;
procedure ShowErrorMessageDlg(const aError : string); virtual; procedure ShowErrorMessageDlg(const aError : string); virtual;
@ -637,6 +641,7 @@ uses
System.Math, System.IOUtils, System.SysUtils, System.Math, System.IOUtils, System.SysUtils,
{$IFDEF MSWINDOWS}WinApi.TlHelp32, WinApi.PSAPI,{$ENDIF} {$IFDEF MSWINDOWS}WinApi.TlHelp32, WinApi.PSAPI,{$ENDIF}
{$IFDEF LINUX}{$IFDEF FMX}Posix.Unistd, Posix.Stdio,{$ENDIF}{$ENDIF} {$IFDEF LINUX}{$IFDEF FMX}Posix.Unistd, Posix.Stdio,{$ENDIF}{$ENDIF}
{$IFDEF MACOS}Posix.Stdio,{$ENDIF}
{$ELSE} {$ELSE}
Math, {$IFDEF DELPHI14_UP}IOUtils,{$ENDIF} SysUtils, Math, {$IFDEF DELPHI14_UP}IOUtils,{$ENDIF} SysUtils,
{$IFDEF FPC} {$IFDEF FPC}
@ -708,7 +713,11 @@ begin
FEnableGPU := False; FEnableGPU := False;
FCustomCommandLines := nil; FCustomCommandLines := nil;
FCustomCommandLineValues := nil; FCustomCommandLineValues := nil;
{$IFDEF MACOSX}
FCheckCEFFiles := False;
{$ELSE}
FCheckCEFFiles := True; FCheckCEFFiles := True;
{$ENDIF}
FSmoothScrolling := STATE_DEFAULT; FSmoothScrolling := STATE_DEFAULT;
FFastUnload := False; FFastUnload := False;
FDisableSafeBrowsing := False; FDisableSafeBrowsing := False;
@ -872,6 +881,7 @@ begin
end; end;
{$IFDEF MACOSX} {$IFDEF MACOSX}
{$WARN SYMBOL_PLATFORM OFF}
// This function checks if argv contains // This function checks if argv contains
// --framework-dir-path= // --framework-dir-path=
// --main-bundle-path= // --main-bundle-path=
@ -882,25 +892,42 @@ procedure TCefApplicationCore.InitLibLocationFromArgs;
const const
PARAM_FRAME_PATH = '--framework-dir-path'; PARAM_FRAME_PATH = '--framework-dir-path';
PARAM_BUNDLE_PATH = '--main-bundle-path'; PARAM_BUNDLE_PATH = '--main-bundle-path';
type
PCharArray = Array of PAnsiChar;
var var
i, l : Integer; i, l : Integer;
p : PChar;
MBPath : ustring; MBPath : ustring;
{$IFDEF FPC}
p : PChar;
TempArgCount : longint;
TempArgValues : PPChar;
{$ELSE}
p : PAnsiChar;
TempArgCount : integer;
TempArgValues : PCharArray;
{$ENDIF}
begin begin
for i := 0 to argc - 1 do {$IFDEF FPC}
TempArgCount := argc;
TempArgValues := argv;
{$ELSE}
TempArgCount := ArgCount;
TempArgValues := PCharArray(ArgValues^);
{$ENDIF}
for i := 0 to TempArgCount - 1 do
begin begin
p := strscan(argv[i], '='); p := strscan(TempArgValues[i], '=');
if p = nil then continue; if p = nil then continue;
l := p - argv[i]; l := p - TempArgValues[i];
if (l = Length(PARAM_FRAME_PATH)) and if (l = Length(PARAM_FRAME_PATH)) and
(strlcomp(argv[i], PChar(PARAM_FRAME_PATH), Length(PARAM_FRAME_PATH)) = 0) then (strlcomp(TempArgValues[i], PAnsiChar(PARAM_FRAME_PATH), Length(PARAM_FRAME_PATH)) = 0) then
FrameworkDirPath := PChar(argv[i] + Length(PARAM_FRAME_PATH) + 1); FrameworkDirPath := PChar(TempArgValues[i] + Length(PARAM_FRAME_PATH) + 1);
if (l = Length(PARAM_BUNDLE_PATH)) and if (l = Length(PARAM_BUNDLE_PATH)) and
(strlcomp(argv[i], PChar(PARAM_BUNDLE_PATH), Length(PARAM_BUNDLE_PATH)) = 0) then (strlcomp(TempArgValues[i], PAnsiChar(PARAM_BUNDLE_PATH), Length(PARAM_BUNDLE_PATH)) = 0) then
begin begin
MBPath := PChar(argv[i] + Length(PARAM_BUNDLE_PATH) + 1); MBPath := PChar(TempArgValues[i] + Length(PARAM_BUNDLE_PATH) + 1);
MainBundlePath := MBPath; MainBundlePath := MBPath;
end; end;
end; end;
@ -913,6 +940,7 @@ begin
FrameworkDirPath := MBPath; FrameworkDirPath := MBPath;
end; end;
end; end;
{$WARN SYMBOL_PLATFORM ON}
{$ENDIF} {$ENDIF}
// This function must only be called by the main executable when the application // This function must only be called by the main executable when the application
@ -1088,123 +1116,131 @@ begin
FLocalesDirPath := CustomAbsolutePath(aValue, True); FLocalesDirPath := CustomAbsolutePath(aValue, True);
end; end;
function TCefApplicationCore.CheckCEFLibrary : boolean; function TCefApplicationCore.CheckCEFResources : boolean;
var var
TempString, TempOldDir : string; TempString : string;
TempMissingFrm, TempMissingRsc, TempMissingLoc, TempMissingSubProc : boolean; TempMissingFrm, TempMissingRsc, TempMissingLoc, TempMissingSubProc : boolean;
{$IFDEF MSWINDOWS}
TempMachine : integer;
TempVersionInfo : TFileVersionInfo;
{$ENDIF}
begin begin
{$IFDEF MACOSX}
exit(true);
{$ENDIF}
Result := False; Result := False;
if not(FCheckCEFFiles) or (FProcessType <> ptBrowser) then TempMissingSubProc := not(CheckSubprocessPath(FBrowserSubprocessPath, FMissingLibFiles));
Result := True TempMissingFrm := not(CheckDLLs(FFrameworkDirPath, FMissingLibFiles));
else TempMissingRsc := not(CheckResources(ResourcesDirPath, FMissingLibFiles, FCheckDevToolsResources, not(FDisableExtensions)));
TempMissingLoc := not(CheckLocales(LocalesDirPath, FMissingLibFiles, FLocalesRequired));
if TempMissingFrm or TempMissingRsc or TempMissingLoc or TempMissingSubProc then
begin begin
if FSetCurrentDir then FStatus := asErrorMissingFiles;
begin TempString := 'CEF binaries missing !';
TempOldDir := GetCurrentDir;
chdir(GetModulePath);
end;
try
TempMissingSubProc := not(CheckSubprocessPath(FBrowserSubprocessPath, FMissingLibFiles));
TempMissingFrm := not(CheckDLLs(FFrameworkDirPath, FMissingLibFiles));
TempMissingRsc := not(CheckResources(ResourcesDirPath, FMissingLibFiles, FCheckDevToolsResources, not(FDisableExtensions)));
TempMissingLoc := not(CheckLocales(LocalesDirPath, FMissingLibFiles, FLocalesRequired));
if TempMissingFrm or TempMissingRsc or TempMissingLoc or TempMissingSubProc then if (length(FMissingLibFiles) > 0) then
begin TempString := TempString + CRLF + CRLF +
FStatus := asErrorMissingFiles; 'The missing files are :' + CRLF +
TempString := 'CEF binaries missing !'; trim(FMissingLibFiles);
if (length(FMissingLibFiles) > 0) then ShowErrorMessageDlg(TempString);
TempString := TempString + CRLF + CRLF + end
'The missing files are :' + CRLF + else
trim(FMissingLibFiles); Result := True;
end;
ShowErrorMessageDlg(TempString); {$IFDEF MSWINDOWS}
end function TCefApplicationCore.CheckCEFDLL : boolean;
else var
{$IFDEF MSWINDOWS} TempString : string;
if CheckDLLVersion(LibCefPath, TempMachine : integer;
CEF_SUPPORTED_VERSION_MAJOR, TempVersionInfo : TFileVersionInfo;
CEF_SUPPORTED_VERSION_MINOR, begin
CEF_SUPPORTED_VERSION_RELEASE, Result := False;
CEF_SUPPORTED_VERSION_BUILD) then
begin
if GetDLLHeaderMachine(LibCefPath, TempMachine) then
case TempMachine of
CEF_IMAGE_FILE_MACHINE_I386 :
if Is32BitProcess then
Result := True
else
begin
FStatus := asErrorDLLVersion;
TempString := 'Wrong CEF binaries !' +
CRLF + CRLF +
'Use the 32 bit CEF binaries with 32 bits applications only.';
ShowErrorMessageDlg(TempString); if CheckDLLVersion(LibCefPath,
end; CEF_SUPPORTED_VERSION_MAJOR,
CEF_SUPPORTED_VERSION_MINOR,
CEF_SUPPORTED_VERSION_RELEASE,
CEF_SUPPORTED_VERSION_BUILD) then
begin
if GetDLLHeaderMachine(LibCefPath, TempMachine) then
case TempMachine of
CEF_IMAGE_FILE_MACHINE_I386 :
if Is32BitProcess then
Result := True
else
begin
FStatus := asErrorDLLVersion;
TempString := 'Wrong CEF binaries !' +
CRLF + CRLF +
'Use the 32 bit CEF binaries with 32 bits applications only.';
CEF_IMAGE_FILE_MACHINE_AMD64 : ShowErrorMessageDlg(TempString);
if not(Is32BitProcess) then end;
Result := True
else
begin CEF_IMAGE_FILE_MACHINE_AMD64 :
FStatus := asErrorDLLVersion; if not(Is32BitProcess) then
TempString := 'Wrong CEF binaries !' + Result := True
CRLF + CRLF + else
'Use the 64 bit CEF binaries with 64 bits applications only.';
ShowErrorMessageDlg(TempString); begin
end; FStatus := asErrorDLLVersion;
TempString := 'Wrong CEF binaries !' +
CRLF + CRLF +
'Use the 64 bit CEF binaries with 64 bits applications only.';
else ShowErrorMessageDlg(TempString);
begin end;
FStatus := asErrorDLLVersion;
TempString := 'Unknown CEF binaries !' +
CRLF + CRLF +
'Use only the CEF binaries specified in the CEF4Delphi Readme.md file at ' +
CEF4DELPHI_URL;
ShowErrorMessageDlg(TempString); else
end;
end
else
Result := True;
end
else
begin begin
FStatus := asErrorDLLVersion; FStatus := asErrorDLLVersion;
TempString := 'Unsupported CEF version !' + TempString := 'Unknown CEF binaries !' +
CRLF + CRLF + CRLF + CRLF +
'Use only the CEF binaries specified in the CEF4Delphi Readme.md file at ' + 'Use only the CEF binaries specified in the CEF4Delphi Readme.md file at ' +
CEF4DELPHI_URL; CEF4DELPHI_URL;
if GetDLLVersion(LibCefPath, TempVersionInfo) then
TempString := TempString + CRLF + CRLF +
'Expected ' + LIBCEF_DLL + ' version : ' + LibCefVersion + CRLF +
'Found ' + LIBCEF_DLL + ' version : ' + FileVersionInfoToString(TempVersionInfo);
ShowErrorMessageDlg(TempString); ShowErrorMessageDlg(TempString);
end; end;
{$ELSE} end
begin else
Result := True; Result := True;
end; end
{$ENDIF} else
finally begin
if FSetCurrentDir then chdir(TempOldDir); FStatus := asErrorDLLVersion;
end; TempString := 'Unsupported CEF version !' +
CRLF + CRLF +
'Use only the CEF binaries specified in the CEF4Delphi Readme.md file at ' +
CEF4DELPHI_URL;
if GetDLLVersion(LibCefPath, TempVersionInfo) then
TempString := TempString + CRLF + CRLF +
'Expected ' + LIBCEF_DLL + ' version : ' + LibCefVersion + CRLF +
'Found ' + LIBCEF_DLL + ' version : ' + FileVersionInfoToString(TempVersionInfo);
ShowErrorMessageDlg(TempString);
end; end;
end; end;
{$ENDIF}
function TCefApplicationCore.CheckCEFLibrary : boolean;
var
TempOldDir : string;
begin
if not(FCheckCEFFiles) or (FProcessType <> ptBrowser) then
begin
Result := True;
exit;
end;
if FSetCurrentDir then
begin
TempOldDir := GetCurrentDir;
chdir(GetModulePath);
end;
Result := CheckCEFResources
{$IFDEF MSWINDOWS}and CheckCEFDLL{$ENDIF};
if FSetCurrentDir then chdir(TempOldDir);
end;
function TCefApplicationCore.StartMainProcess : boolean; function TCefApplicationCore.StartMainProcess : boolean;
begin begin

View File

@ -4922,6 +4922,7 @@ var
TempPoint : TCefPoint; TempPoint : TCefPoint;
TempClient : ICefClient; TempClient : ICefClient;
TempPPoint : PCefPoint; TempPPoint : PCefPoint;
TempHandle : TCefWindowHandle;
begin begin
try try
try try
@ -4929,7 +4930,10 @@ begin
begin begin
InitializeSettings(FDevBrowserSettings); InitializeSettings(FDevBrowserSettings);
if aWindowInfo = nil then if aWindowInfo = nil then
DefaultInitializeDevToolsWindowInfo(0, Rect(0, 0, 0, 0), '') begin
InitializeWindowHandle(TempHandle);
DefaultInitializeDevToolsWindowInfo(TempHandle, Rect(0, 0, 0, 0), '');
end
else else
if aWindowInfo <> @FDevWindowInfo then if aWindowInfo <> @FDevWindowInfo then
FDevWindowInfo := aWindowInfo^; FDevWindowInfo := aWindowInfo^;

View File

@ -75,7 +75,7 @@ type
procedure SetVisible(Value: Boolean); override; procedure SetVisible(Value: Boolean); override;
{$ENDIF} {$ENDIF}
function GetBrowserInitialized : boolean; function GetBrowserInitialized : boolean;
function GetChildWindowHandle : {$IFDEF FPC}LclType.{$ENDIF}THandle; override; function GetChildWindowHandle : {$IFNDEF MSWINDOWS}{$IFDEF FPC}LclType.{$ENDIF}{$ENDIF}THandle; override;
{$IFDEF MSWINDOWS} {$IFDEF MSWINDOWS}
procedure WndProc(var aMessage: TMessage); override; procedure WndProc(var aMessage: TMessage); override;
@ -186,7 +186,7 @@ begin
end; end;
end; end;
function TChromiumWindow.GetChildWindowHandle : {$IFDEF FPC}LclType.{$ENDIF}THandle; function TChromiumWindow.GetChildWindowHandle : {$IFNDEF MSWINDOWS}{$IFDEF FPC}LclType.{$ENDIF}{$ENDIF}THandle;
begin begin
Result := 0; Result := 0;

View File

@ -370,7 +370,7 @@ var
TempForm : TCustomForm; TempForm : TCustomForm;
{$ENDIF} {$ENDIF}
begin begin
Result := 0; InitializeWindowHandle(Result);
{$IFDEF MSWINDOWS} {$IFDEF MSWINDOWS}
TempForm := GetParentForm; TempForm := GetParentForm;

View File

@ -119,7 +119,7 @@ function TFMXChromium.CreateBrowser(const aWindowName : ustring;
var var
TempHandle : TCefWindowHandle; TempHandle : TCefWindowHandle;
begin begin
{$IFDEF MACOSX} {$IFDEF MACOS}
TempHandle := nil; TempHandle := nil;
{$ELSE} {$ELSE}
TempHandle := 0; TempHandle := 0;
@ -128,8 +128,15 @@ begin
end; end;
procedure TFMXChromium.InitializeDevToolsWindowInfo; procedure TFMXChromium.InitializeDevToolsWindowInfo;
var
TempHandle : TCefWindowHandle;
begin begin
DefaultInitializeDevToolsWindowInfo(0, Rect(0, 0, 0, 0), ''); {$IFDEF MACOS}
TempHandle := nil;
{$ELSE}
TempHandle := 0;
{$ENDIF}
DefaultInitializeDevToolsWindowInfo(TempHandle, Rect(0, 0, 0, 0), '');
end; end;
procedure TFMXChromium.ShowDevTools(inspectElementAt: TPoint); procedure TFMXChromium.ShowDevTools(inspectElementAt: TPoint);

View File

@ -73,7 +73,7 @@ type
{$ENDIF} {$ENDIF}
procedure SetChromium(aValue : TChromium); procedure SetChromium(aValue : TChromium);
function GetChildWindowHandle : {$IFDEF FPC}LclType.{$ENDIF}THandle; override; function GetChildWindowHandle : {$IFNDEF MSWINDOWS}{$IFDEF FPC}{LclType.}{$ENDIF}{$ENDIF}THandle; override;
{$IFDEF MSWINDOWS} {$IFDEF MSWINDOWS}
procedure WndProc(var aMessage: TMessage); override; procedure WndProc(var aMessage: TMessage); override;
{$ENDIF} {$ENDIF}
@ -105,7 +105,7 @@ begin
FChromium := nil; FChromium := nil;
end; end;
function TCEFLinkedWindowParent.GetChildWindowHandle : {$IFDEF FPC}LclType.{$ENDIF}THandle; function TCEFLinkedWindowParent.GetChildWindowHandle : {$IFNDEF MSWINDOWS}{$IFDEF FPC}{LclType.}{$ENDIF}{$ENDIF}THandle;
begin begin
Result := 0; Result := 0;

View File

@ -291,6 +291,7 @@ implementation
uses uses
{$IFDEF LINUX}{$IFDEF FMX}Posix.Unistd, Posix.Stdio,{$ENDIF}{$ENDIF} {$IFDEF LINUX}{$IFDEF FMX}Posix.Unistd, Posix.Stdio,{$ENDIF}{$ENDIF}
{$IFDEF MACOS}Posix.Unistd, Posix.Stdio,{$ENDIF}
uCEFApplicationCore, uCEFSchemeHandlerFactory, uCEFValue, uCEFApplicationCore, uCEFSchemeHandlerFactory, uCEFValue,
uCEFBinaryValue, uCEFStringList; uCEFBinaryValue, uCEFStringList;
@ -677,7 +678,11 @@ begin
aWindowInfo.windowless_rendering_enabled := ord(False); aWindowInfo.windowless_rendering_enabled := ord(False);
aWindowInfo.shared_texture_enabled := ord(False); aWindowInfo.shared_texture_enabled := ord(False);
aWindowInfo.external_begin_frame_enabled := ord(False); aWindowInfo.external_begin_frame_enabled := ord(False);
{$IFDEF FPC}
aWindowInfo.view := 0; aWindowInfo.view := 0;
{$ELSE}
aWindowInfo.view := nil;
{$ENDIF}
end; end;
procedure WindowInfoAsPopUp(var aWindowInfo : TCefWindowInfo; aParent : TCefWindowHandle; const aWindowName : ustring; aHidden : boolean); procedure WindowInfoAsPopUp(var aWindowInfo : TCefWindowInfo; aParent : TCefWindowHandle; const aWindowName : ustring; aHidden : boolean);
@ -692,7 +697,11 @@ begin
aWindowInfo.windowless_rendering_enabled := ord(False); aWindowInfo.windowless_rendering_enabled := ord(False);
aWindowInfo.shared_texture_enabled := ord(False); aWindowInfo.shared_texture_enabled := ord(False);
aWindowInfo.external_begin_frame_enabled := ord(False); aWindowInfo.external_begin_frame_enabled := ord(False);
{$IFDEF FPC}
aWindowInfo.view := 0; aWindowInfo.view := 0;
{$ELSE}
aWindowInfo.view := nil;
{$ENDIF}
end; end;
procedure WindowInfoAsWindowless(var aWindowInfo : TCefWindowInfo; aParent : TCefWindowHandle; const aWindowName : ustring; aHidden : boolean); procedure WindowInfoAsWindowless(var aWindowInfo : TCefWindowInfo; aParent : TCefWindowHandle; const aWindowName : ustring; aHidden : boolean);
@ -707,7 +716,11 @@ begin
aWindowInfo.windowless_rendering_enabled := ord(True); aWindowInfo.windowless_rendering_enabled := ord(True);
aWindowInfo.shared_texture_enabled := ord(False); aWindowInfo.shared_texture_enabled := ord(False);
aWindowInfo.external_begin_frame_enabled := ord(False); aWindowInfo.external_begin_frame_enabled := ord(False);
{$IFDEF FPC}
aWindowInfo.view := 0; aWindowInfo.view := 0;
{$ELSE}
aWindowInfo.view := nil;
{$ENDIF}
end; end;
{$ENDIF} {$ENDIF}
@ -1528,10 +1541,15 @@ begin
{$IFDEF MACOSX} {$IFDEF MACOSX}
Result := IncludeTrailingPathDelimiter(ExtractFileDir(ParamStr(0))); Result := IncludeTrailingPathDelimiter(ExtractFileDir(ParamStr(0)));
{$IFDEF FPC}
if copy(Result, Length(Result) + 1 - Length(MAC_APP_POSTFIX) - Length(MAC_APP_SUBPATH)) = MAC_APP_POSTFIX + MAC_APP_SUBPATH then if copy(Result, Length(Result) + 1 - Length(MAC_APP_POSTFIX) - Length(MAC_APP_SUBPATH)) = MAC_APP_POSTFIX + MAC_APP_SUBPATH then
SetLength(Result, Length(Result) - Length(MAC_APP_SUBPATH)); SetLength(Result, Length(Result) - Length(MAC_APP_SUBPATH));
Result := CreateAbsolutePath(Result, GetCurrentDirUTF8); Result := CreateAbsolutePath(Result, GetCurrentDirUTF8);
{$ELSE}
if Result.Contains(MAC_APP_POSTFIX + MAC_APP_SUBPATH) then
Result := Result.Remove(Result.LastIndexOf(MAC_APP_SUBPATH));
{$ENDIF}
{$ENDIF} {$ENDIF}
end; end;

View File

@ -62,7 +62,7 @@ uses
type type
TCEFWinControl = class(TWinControl) TCEFWinControl = class(TWinControl)
protected protected
function GetChildWindowHandle : {$IFDEF FPC}LclType.{$ENDIF}THandle; virtual; function GetChildWindowHandle : {$IFNDEF MSWINDOWS}{$IFDEF FPC}{LclType.}{$ENDIF}{$ENDIF}THandle; virtual;
procedure Resize; override; procedure Resize; override;
public public
@ -110,7 +110,7 @@ implementation
uses uses
uCEFMiscFunctions, uCEFClient, uCEFConstants; uCEFMiscFunctions, uCEFClient, uCEFConstants;
function TCEFWinControl.GetChildWindowHandle : {$IFDEF FPC}LclType.{$ENDIF}THandle; function TCEFWinControl.GetChildWindowHandle : {$IFNDEF MSWINDOWS}{$IFDEF FPC}{LclType.}{$ENDIF}{$ENDIF}THandle;
begin begin
{$IFDEF MSWINDOWS} {$IFDEF MSWINDOWS}
if not(csDesigning in ComponentState) and HandleAllocated then if not(csDesigning in ComponentState) and HandleAllocated then

View File

@ -2,7 +2,7 @@
"UpdateLazPackages" : [ "UpdateLazPackages" : [
{ {
"ForceNotify" : true, "ForceNotify" : true,
"InternalVersion" : 261, "InternalVersion" : 262,
"Name" : "cef4delphi_lazarus.lpk", "Name" : "cef4delphi_lazarus.lpk",
"Version" : "88.2.9.0" "Version" : "88.2.9.0"
} }