1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2025-04-07 06:50:04 +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

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

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

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

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

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

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

@ -291,6 +291,7 @@ implementation
uses
{$IFDEF LINUX}{$IFDEF FMX}Posix.Unistd, Posix.Stdio,{$ENDIF}{$ENDIF}
{$IFDEF MACOS}Posix.Unistd, Posix.Stdio,{$ENDIF}
uCEFApplicationCore, uCEFSchemeHandlerFactory, uCEFValue,
uCEFBinaryValue, uCEFStringList;
@ -677,7 +678,11 @@ begin
aWindowInfo.windowless_rendering_enabled := ord(False);
aWindowInfo.shared_texture_enabled := ord(False);
aWindowInfo.external_begin_frame_enabled := ord(False);
{$IFDEF FPC}
aWindowInfo.view := 0;
{$ELSE}
aWindowInfo.view := nil;
{$ENDIF}
end;
procedure WindowInfoAsPopUp(var aWindowInfo : TCefWindowInfo; aParent : TCefWindowHandle; const aWindowName : ustring; aHidden : boolean);
@ -692,7 +697,11 @@ begin
aWindowInfo.windowless_rendering_enabled := ord(False);
aWindowInfo.shared_texture_enabled := ord(False);
aWindowInfo.external_begin_frame_enabled := ord(False);
{$IFDEF FPC}
aWindowInfo.view := 0;
{$ELSE}
aWindowInfo.view := nil;
{$ENDIF}
end;
procedure WindowInfoAsWindowless(var aWindowInfo : TCefWindowInfo; aParent : TCefWindowHandle; const aWindowName : ustring; aHidden : boolean);
@ -707,7 +716,11 @@ begin
aWindowInfo.windowless_rendering_enabled := ord(True);
aWindowInfo.shared_texture_enabled := ord(False);
aWindowInfo.external_begin_frame_enabled := ord(False);
{$IFDEF FPC}
aWindowInfo.view := 0;
{$ELSE}
aWindowInfo.view := nil;
{$ENDIF}
end;
{$ENDIF}
@ -1528,10 +1541,15 @@ begin
{$IFDEF MACOSX}
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
SetLength(Result, Length(Result) - Length(MAC_APP_SUBPATH));
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}
end;

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

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