Merge pull request #341 from User4martin/fpc-mac-2

Thank you so much Martin! :-D
This commit is contained in:
Salvador Díaz Fau 2021-02-08 09:58:16 +01:00 committed by GitHub
commit a1f3e133ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 156 additions and 14 deletions

View File

Before

Width:  |  Height:  |  Size: 64 KiB

After

Width:  |  Height:  |  Size: 64 KiB

View File

@ -10,7 +10,7 @@
<MainUnitHasScaledStatement Value="False"/> <MainUnitHasScaledStatement Value="False"/>
</Flags> </Flags>
<SessionStorage Value="InProjectDir"/> <SessionStorage Value="InProjectDir"/>
<Title Value="cef_subprocess"/> <Title Value="AppHelper"/>
<ResourceType Value="res"/> <ResourceType Value="res"/>
<UseXPManifest Value="True"/> <UseXPManifest Value="True"/>
<XPManifest> <XPManifest>
@ -40,7 +40,7 @@
</RequiredPackages> </RequiredPackages>
<Units> <Units>
<Unit> <Unit>
<Filename Value="cef_subprocess.lpr"/> <Filename Value="AppHelper.lpr"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
</Unit> </Unit>
</Units> </Units>
@ -49,7 +49,7 @@
<Version Value="11"/> <Version Value="11"/>
<PathDelim Value="\"/> <PathDelim Value="\"/>
<Target> <Target>
<Filename Value="cef_subprocess"/> <Filename Value="..\..\..\bin\AppHelper"/>
</Target> </Target>
<SearchPaths> <SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/> <IncludeFiles Value="$(ProjOutDir)"/>

View File

@ -1,4 +1,4 @@
program cef_subprocess; program AppHelper;
(* (*
* The compiled exe should be copied into * The compiled exe should be copied into
@ -21,9 +21,8 @@ begin
// The main process and the subprocess *MUST* have the same GlobalCEFApp // The main process and the subprocess *MUST* have the same GlobalCEFApp
// properties and events, specially FrameworkDirPath, ResourcesDirPath, // properties and events, specially FrameworkDirPath, ResourcesDirPath,
// LocalesDirPath, cache and UserDataPath paths. // LocalesDirPath, cache and UserDataPath paths.
GlobalCEFApp.InitLibLocationFromArgs;
GlobalCEFApp.MultiThreadedMessageLoop:=false;
GlobalCEFApp.StartSubProcess; GlobalCEFApp.StartSubProcess;
GlobalCEFApp.Free; GlobalCEFApp.Free;
GlobalCEFApp := nil; GlobalCEFApp := nil;

View File

@ -0,0 +1,57 @@
#!/bin/sh
BASEDIR=$(dirname "$0")
DEST=$1
SRC=$2
if [ "$SRC" = "" ];
then
SRC=$BASEDIR/../../../bin/AppHelper.app
fi
if [ "$1" = "" ] || [ ! -e "$DEST" ] || [ ! -e "$SRC" ];
then
echo "Usage"
echo " $0 destpath/project.app"
echo " $0 destpath/project.app sourcedir/AppHelper.app"
echo
if [ ! -e "$DEST" ];
then
echo "Error: Target app bundle not found. (Did you compile AND create the bundle?)"
fi
if [ ! -e "$SRC" ];
then
echo "Error: Source (AppHelper) app bundle not found. (Did you compile AND create the bundle?)"
fi
exit;
fi
SRCAPP=$(basename "$SRC")
SRCAPP="${SRCAPP%\.app}"
DESTAPP=$(basename "$DEST")
DESTAPP="${DESTAPP%\.app}"
SUB=""
rm -rf "$DEST/Contents/Frameworks/$DESTAPP Helper$SUB.app"
cp -r "$SRC" "$DEST/Contents/Frameworks/$DESTAPP Helper$SUB.app"
mv "$DEST/Contents/Frameworks/$DESTAPP Helper$SUB.app/Contents/MacOS/$SRCAPP" "$DEST/Contents/Frameworks/$DESTAPP Helper$SUB.app/Contents/MacOS/$DESTAPP Helper$SUB"
sed -i '' "s/$SRCAPP/$DESTAPP Helper$SUB/g" "$DEST/Contents/Frameworks/$DESTAPP Helper$SUB.app/Contents/Info.plist"
SUB=" (GPU)"
rm -rf "$DEST/Contents/Frameworks/$DESTAPP Helper$SUB.app"
cp -r "$SRC" "$DEST/Contents/Frameworks/$DESTAPP Helper$SUB.app"
mv "$DEST/Contents/Frameworks/$DESTAPP Helper$SUB.app/Contents/MacOS/$SRCAPP" "$DEST/Contents/Frameworks/$DESTAPP Helper$SUB.app/Contents/MacOS/$DESTAPP Helper$SUB"
sed -i '' "s/$SRCAPP/$DESTAPP Helper$SUB/g" "$DEST/Contents/Frameworks/$DESTAPP Helper$SUB.app/Contents/Info.plist"
SUB=" (Renderer)"
rm -rf "$DEST/Contents/Frameworks/$DESTAPP Helper$SUB.app"
cp -r "$SRC" "$DEST/Contents/Frameworks/$DESTAPP Helper$SUB.app"
mv "$DEST/Contents/Frameworks/$DESTAPP Helper$SUB.app/Contents/MacOS/$SRCAPP" "$DEST/Contents/Frameworks/$DESTAPP Helper$SUB.app/Contents/MacOS/$DESTAPP Helper$SUB"
sed -i '' "s/$SRCAPP/$DESTAPP Helper$SUB/g" "$DEST/Contents/Frameworks/$DESTAPP Helper$SUB.app/Contents/Info.plist"
SUB=" (Plugin)"
rm -rf "$DEST/Contents/Frameworks/$DESTAPP Helper$SUB.app"
cp -r "$SRC" "$DEST/Contents/Frameworks/$DESTAPP Helper$SUB.app"
mv "$DEST/Contents/Frameworks/$DESTAPP Helper$SUB.app/Contents/MacOS/$SRCAPP" "$DEST/Contents/Frameworks/$DESTAPP Helper$SUB.app/Contents/MacOS/$DESTAPP Helper$SUB"
sed -i '' "s/$SRCAPP/$DESTAPP Helper$SUB/g" "$DEST/Contents/Frameworks/$DESTAPP Helper$SUB.app/Contents/Info.plist"

View File

@ -0,0 +1,8 @@
#!/bin/sh
CDIR=$(pwd)
cd "$(dirname "$0")"
../AppHelper/create_mac_helper_apps.sh ../../../bin/SimpleBrowser2.app
cd "$CDIR"

View File

@ -90,6 +90,11 @@ const
CHROMEELF_DLL = ''; CHROMEELF_DLL = '';
{$ENDIF} {$ENDIF}
// for InitLibLocationFromArgs
LIBCEF_PAK = 'cef.pak';
LIBCEF_LOCALE_DIR = 'locales';
LIBCEF_LOCALE_ENUS = 'en-US.pak';
type type
TCefApplicationCore = class TCefApplicationCore = class
protected protected
@ -265,6 +270,8 @@ type
function GetLibCefVersion : ustring; function GetLibCefVersion : ustring;
function GetLibCefPath : ustring; function GetLibCefPath : ustring;
function GetChromeElfPath : ustring; function GetChromeElfPath : ustring;
function GetLocalesDirPath: ustring;
function GetResourcesDirPath: ustring;
function GetMustCreateResourceBundleHandler : boolean; virtual; function GetMustCreateResourceBundleHandler : boolean; virtual;
function GetMustCreateBrowserProcessHandler : boolean; virtual; function GetMustCreateBrowserProcessHandler : boolean; virtual;
function GetMustCreateRenderProcessHandler : boolean; virtual; function GetMustCreateRenderProcessHandler : boolean; virtual;
@ -359,6 +366,7 @@ type
destructor Destroy; override; destructor Destroy; override;
procedure AfterConstruction; override; procedure AfterConstruction; override;
procedure AddCustomCommandLine(const aCommandLine : string; const aValue : string = ''); procedure AddCustomCommandLine(const aCommandLine : string; const aValue : string = '');
procedure InitLibLocationFromArgs;
function StartMainProcess : boolean; function StartMainProcess : boolean;
function StartSubProcess : boolean; function StartSubProcess : boolean;
@ -421,8 +429,8 @@ type
property LogFile : ustring read FLogFile write FLogFile; property LogFile : ustring read FLogFile write FLogFile;
property LogSeverity : TCefLogSeverity read FLogSeverity write FLogSeverity; property LogSeverity : TCefLogSeverity read FLogSeverity write FLogSeverity;
property JavaScriptFlags : ustring read FJavaScriptFlags write FJavaScriptFlags; property JavaScriptFlags : ustring read FJavaScriptFlags write FJavaScriptFlags;
property ResourcesDirPath : ustring read FResourcesDirPath write SetResourcesDirPath; property ResourcesDirPath : ustring read GetResourcesDirPath write SetResourcesDirPath;
property LocalesDirPath : ustring read FLocalesDirPath write SetLocalesDirPath; property LocalesDirPath : ustring read GetLocalesDirPath write SetLocalesDirPath;
property PackLoadingDisabled : Boolean read FPackLoadingDisabled write FPackLoadingDisabled; property PackLoadingDisabled : Boolean read FPackLoadingDisabled write FPackLoadingDisabled;
property RemoteDebuggingPort : Integer read FRemoteDebuggingPort write FRemoteDebuggingPort; property RemoteDebuggingPort : Integer read FRemoteDebuggingPort write FRemoteDebuggingPort;
property UncaughtExceptionStackSize : Integer read FUncaughtExceptionStackSize write FUncaughtExceptionStackSize; property UncaughtExceptionStackSize : Integer read FUncaughtExceptionStackSize write FUncaughtExceptionStackSize;
@ -859,6 +867,50 @@ begin
if (FCustomCommandLineValues <> nil) then FCustomCommandLineValues.Add(aValue); if (FCustomCommandLineValues <> nil) then FCustomCommandLineValues.Add(aValue);
end; end;
// This function checks if argv contains
// --framework-dir-path=
// --main-bundle-path=
// It sets the corresponding fields in the config
// This params are passed on Mac.
// The values can also be calculated, instead of calling this procedure
var
PARAM_FRAME_PATH : string = '--framework-dir-path';
PARAM_BUNDLE_PATH : string = '--main-bundle-path';
procedure TCefApplicationCore.InitLibLocationFromArgs;
var
i, l : Integer;
p : PChar;
MBPath : ustring;
begin
for i := 0 to argc - 1 do
begin
p := strscan(argv[i], '=');
if p = nil then continue;
l := p - argv[i];
if (l = Length(PARAM_FRAME_PATH)) and
(strlcomp(argv[i], PChar(PARAM_FRAME_PATH), Length(PARAM_FRAME_PATH)) = 0) then
begin
FrameworkDirPath := PChar(argv[i] + Length(PARAM_FRAME_PATH) + 1);
end;
if (l = Length(PARAM_BUNDLE_PATH)) and
(strlcomp(argv[i], PChar(PARAM_BUNDLE_PATH), Length(PARAM_BUNDLE_PATH)) = 0) then
begin
MBPath := PChar(argv[i] + Length(PARAM_BUNDLE_PATH) + 1);
MainBundlePath := MBPath;
end;
end;
if (MBPath <> '') and (FrameworkDirPath = '') then
begin
MBPath := IncludeTrailingPathDelimiter(MBPath);
{$IFDEF MACOSX}
MBPath := MBPath + LIBCEF_PREFIX;
{$ENDIF}
if FileExists(MBPath + LIBCEF_DLL) then begin
FrameworkDirPath := MBPath;
end;
end;
end;
// 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
// is configured to use a different executable for the subprocesses. // is configured to use a different executable for the subprocesses.
// The process calling ths function must be the browser process. // The process calling ths function must be the browser process.
@ -968,6 +1020,28 @@ begin
Result := CHROMEELF_DLL; Result := CHROMEELF_DLL;
end; end;
function TCefApplicationCore.GetLocalesDirPath: ustring;
begin
Result := FLocalesDirPath;
{$IFNDEF MACOSX}
if (Result = '') and (FrameworkDirPath <> '') then
begin
if FileExists(IncludeTrailingPathDelimiter(FrameworkDirPath + LIBCEF_LOCALE_DIR) + LIBCEF_LOCALE_ENUS) then
Result := FrameworkDirPath + LIBCEF_LOCALE_DIR;
end;
{$ENDIF}
end;
function TCefApplicationCore.GetResourcesDirPath: ustring;
begin
Result := FResourcesDirPath;
if (Result = '') and (FrameworkDirPath <> '') then
begin
if FileExists(IncludeTrailingPathDelimiter(FrameworkDirPath) + LIBCEF_PAK) then
Result := FrameworkDirPath;
end;
end;
procedure TCefApplicationCore.SetCache(const aValue : ustring); procedure TCefApplicationCore.SetCache(const aValue : ustring);
begin begin
FCache := CustomAbsolutePath(aValue); FCache := CustomAbsolutePath(aValue);
@ -1583,7 +1657,8 @@ begin
FOnScheduleMessagePumpWork(delayMs); FOnScheduleMessagePumpWork(delayMs);
end; end;
function TCefApplicationCore.Internal_GetLocalizedString(stringid: Integer; var stringVal: ustring) : boolean; function TCefApplicationCore.Internal_GetLocalizedString(stringId: Integer;
var stringVal: ustring): boolean;
begin begin
Result := False; Result := False;
@ -1744,7 +1819,8 @@ begin
FOnGetPDFPaperSize(deviceUnitsPerInch, aResult); FOnGetPDFPaperSize(deviceUnitsPerInch, aResult);
end; end;
procedure TCefApplicationCore.AppendSwitch(var aKeys, aValues : TStringList; const aNewKey, aNewValue : ustring); procedure TCefApplicationCore.AppendSwitch(var aKeys, aValues: TStringList;
const aNewKey: ustring; const aNewValue: ustring);
var var
TempKey, TempHyphenatedKey : ustring; TempKey, TempHyphenatedKey : ustring;
i : integer; i : integer;
@ -1848,7 +1924,8 @@ begin
FreeAndNil(TempDisabledValues); FreeAndNil(TempDisabledValues);
end; end;
procedure TCefApplicationCore.ReplaceSwitch(var aKeys, aValues : TStringList; const aNewKey, aNewValue : ustring); procedure TCefApplicationCore.ReplaceSwitch(var aKeys, aValues: TStringList;
const aNewKey: ustring; const aNewValue: ustring);
var var
TempKey, TempHyphenatedKey : ustring; TempKey, TempHyphenatedKey : ustring;
i : integer; i : integer;

View File

@ -871,14 +871,15 @@ begin
end; end;
function TBufferPanel.GetRealScreenScale(var aResultScale : single) : boolean; function TBufferPanel.GetRealScreenScale(var aResultScale : single) : boolean;
var
{$IFDEF MSWINDOWS} {$IFDEF MSWINDOWS}
var
TempHandle : TCefWindowHandle; TempHandle : TCefWindowHandle;
TempDC : HDC; TempDC : HDC;
TempDPI : UINT; TempDPI : UINT;
{$ELSE} {$ELSE}
{$IFDEF LINUX} {$IFDEF LINUX}
{$IFDEF FPC} {$IFDEF FPC}
var
TempForm : TCustomForm; TempForm : TCustomForm;
TempMonitor : TMonitor; TempMonitor : TMonitor;
{$ENDIF} {$ENDIF}

View File

@ -2334,7 +2334,7 @@ end;
function ValidCefWindowHandle(aHandle : TCefWindowHandle) : boolean; function ValidCefWindowHandle(aHandle : TCefWindowHandle) : boolean;
begin begin
{$IFDEF MACOSX} {$IFDEF MACOS}
Result := (aHandle <> nil); Result := (aHandle <> nil);
{$ELSE} {$ELSE}
Result := (aHandle <> 0); Result := (aHandle <> 0);
@ -2343,7 +2343,7 @@ end;
procedure InitializeWindowHandle(var aHandle : TCefWindowHandle); procedure InitializeWindowHandle(var aHandle : TCefWindowHandle);
begin begin
{$IFDEF MACOSX} {$IFDEF MACOS}
aHandle := nil; aHandle := nil;
{$ELSE} {$ELSE}
aHandle := 0; aHandle := 0;