From 4bbf59fbb334ef99630e8e438fac2aba2e7ea26b Mon Sep 17 00:00:00 2001 From: martin Date: Sat, 6 Feb 2021 23:16:02 +0100 Subject: [PATCH 1/6] Rename SubProcess to AppHelper --- .../{SubProcess => AppHelper}/00-Delete.bat | 0 .../cef_subprocess.ico => AppHelper/AppHelper.ico} | Bin .../cef_subprocess.lpi => AppHelper/AppHelper.lpi} | 6 +++--- .../cef_subprocess.lpr => AppHelper/AppHelper.lpr} | 3 +-- .../cef_subprocess.res => AppHelper/AppHelper.res} | Bin demos/Lazarus_Mac/{SubProcess => AppHelper}/cef.inc | 0 6 files changed, 4 insertions(+), 5 deletions(-) rename demos/Lazarus_Mac/{SubProcess => AppHelper}/00-Delete.bat (100%) rename demos/Lazarus_Mac/{SubProcess/cef_subprocess.ico => AppHelper/AppHelper.ico} (100%) rename demos/Lazarus_Mac/{SubProcess/cef_subprocess.lpi => AppHelper/AppHelper.lpi} (93%) rename demos/Lazarus_Mac/{SubProcess/cef_subprocess.lpr => AppHelper/AppHelper.lpr} (91%) rename demos/Lazarus_Mac/{SubProcess/cef_subprocess.res => AppHelper/AppHelper.res} (100%) rename demos/Lazarus_Mac/{SubProcess => AppHelper}/cef.inc (100%) diff --git a/demos/Lazarus_Mac/SubProcess/00-Delete.bat b/demos/Lazarus_Mac/AppHelper/00-Delete.bat similarity index 100% rename from demos/Lazarus_Mac/SubProcess/00-Delete.bat rename to demos/Lazarus_Mac/AppHelper/00-Delete.bat diff --git a/demos/Lazarus_Mac/SubProcess/cef_subprocess.ico b/demos/Lazarus_Mac/AppHelper/AppHelper.ico similarity index 100% rename from demos/Lazarus_Mac/SubProcess/cef_subprocess.ico rename to demos/Lazarus_Mac/AppHelper/AppHelper.ico diff --git a/demos/Lazarus_Mac/SubProcess/cef_subprocess.lpi b/demos/Lazarus_Mac/AppHelper/AppHelper.lpi similarity index 93% rename from demos/Lazarus_Mac/SubProcess/cef_subprocess.lpi rename to demos/Lazarus_Mac/AppHelper/AppHelper.lpi index 55968a1e..7a12e328 100644 --- a/demos/Lazarus_Mac/SubProcess/cef_subprocess.lpi +++ b/demos/Lazarus_Mac/AppHelper/AppHelper.lpi @@ -10,7 +10,7 @@ - + <Title Value="AppHelper"/> <ResourceType Value="res"/> <UseXPManifest Value="True"/> <XPManifest> @@ -40,7 +40,7 @@ </RequiredPackages> <Units> <Unit> - <Filename Value="cef_subprocess.lpr"/> + <Filename Value="AppHelper.lpr"/> <IsPartOfProject Value="True"/> </Unit> </Units> @@ -49,7 +49,7 @@ <Version Value="11"/> <PathDelim Value="\"/> <Target> - <Filename Value="cef_subprocess"/> + <Filename Value="..\..\..\bin\AppHelper"/> </Target> <SearchPaths> <IncludeFiles Value="$(ProjOutDir)"/> diff --git a/demos/Lazarus_Mac/SubProcess/cef_subprocess.lpr b/demos/Lazarus_Mac/AppHelper/AppHelper.lpr similarity index 91% rename from demos/Lazarus_Mac/SubProcess/cef_subprocess.lpr rename to demos/Lazarus_Mac/AppHelper/AppHelper.lpr index 1da714f8..517f7f7a 100644 --- a/demos/Lazarus_Mac/SubProcess/cef_subprocess.lpr +++ b/demos/Lazarus_Mac/AppHelper/AppHelper.lpr @@ -1,4 +1,4 @@ -program cef_subprocess; +program AppHelper; (* * The compiled exe should be copied into @@ -23,7 +23,6 @@ begin // LocalesDirPath, cache and UserDataPath paths. - GlobalCEFApp.MultiThreadedMessageLoop:=false; GlobalCEFApp.StartSubProcess; GlobalCEFApp.Free; GlobalCEFApp := nil; diff --git a/demos/Lazarus_Mac/SubProcess/cef_subprocess.res b/demos/Lazarus_Mac/AppHelper/AppHelper.res similarity index 100% rename from demos/Lazarus_Mac/SubProcess/cef_subprocess.res rename to demos/Lazarus_Mac/AppHelper/AppHelper.res diff --git a/demos/Lazarus_Mac/SubProcess/cef.inc b/demos/Lazarus_Mac/AppHelper/cef.inc similarity index 100% rename from demos/Lazarus_Mac/SubProcess/cef.inc rename to demos/Lazarus_Mac/AppHelper/cef.inc From 06bcf00dd7927ce2ea5acfe84b79ca191cdb5b0f Mon Sep 17 00:00:00 2001 From: martin <martin@m> Date: Sun, 7 Feb 2021 16:45:55 +0100 Subject: [PATCH 2/6] Allow AppHelper to read FrameworkDirPath from argv --- demos/Lazarus_Mac/AppHelper/AppHelper.lpr | 2 +- source/uCEFApplicationCore.pas | 66 +++++++++++++++++++++-- 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/demos/Lazarus_Mac/AppHelper/AppHelper.lpr b/demos/Lazarus_Mac/AppHelper/AppHelper.lpr index 517f7f7a..94707950 100644 --- a/demos/Lazarus_Mac/AppHelper/AppHelper.lpr +++ b/demos/Lazarus_Mac/AppHelper/AppHelper.lpr @@ -21,7 +21,7 @@ begin // The main process and the subprocess *MUST* have the same GlobalCEFApp // properties and events, specially FrameworkDirPath, ResourcesDirPath, // LocalesDirPath, cache and UserDataPath paths. - + GlobalCEFApp.InitLibLocationFromArgs; GlobalCEFApp.StartSubProcess; GlobalCEFApp.Free; diff --git a/source/uCEFApplicationCore.pas b/source/uCEFApplicationCore.pas index f36072d2..2c9db943 100644 --- a/source/uCEFApplicationCore.pas +++ b/source/uCEFApplicationCore.pas @@ -90,6 +90,11 @@ const CHROMEELF_DLL = ''; {$ENDIF} + // for InitLibLocationFromArgs + LIBCEF_PAK = 'cef.pak'; + LIBCEF_LOCALE_DIR = 'locales'; + LIBCEF_LOCALE_ENUS = 'en-US.pak'; + type TCefApplicationCore = class protected @@ -359,6 +364,7 @@ type destructor Destroy; override; procedure AfterConstruction; override; procedure AddCustomCommandLine(const aCommandLine : string; const aValue : string = ''); + procedure InitLibLocationFromArgs; function StartMainProcess : boolean; function StartSubProcess : boolean; @@ -859,6 +865,57 @@ begin if (FCustomCommandLineValues <> nil) then FCustomCommandLineValues.Add(aValue); 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; + if FileExists(MBPath + LIBCEF_PAK) then begin + ResourcesDirPath := MBPath; + {$IFNDEF MACOSX} + if FileExists(IncludeTrailingPathDelimiter(MBPath + LIBCEF_LOCALE_DIR) + LIBCEF_LOCALE_ENUS) then + LocalesDirPath := MBPath + LIBCEF_LOCALE_DIR; + {$ENDIF} + end; + end; + end; +end; + // This function must only be called by the main executable when the application // is configured to use a different executable for the subprocesses. // The process calling ths function must be the browser process. @@ -1583,7 +1640,8 @@ begin FOnScheduleMessagePumpWork(delayMs); end; -function TCefApplicationCore.Internal_GetLocalizedString(stringid: Integer; var stringVal: ustring) : boolean; +function TCefApplicationCore.Internal_GetLocalizedString(stringId: Integer; + var stringVal: ustring): boolean; begin Result := False; @@ -1744,7 +1802,8 @@ begin FOnGetPDFPaperSize(deviceUnitsPerInch, aResult); 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 TempKey, TempHyphenatedKey : ustring; i : integer; @@ -1848,7 +1907,8 @@ begin FreeAndNil(TempDisabledValues); 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 TempKey, TempHyphenatedKey : ustring; i : integer; From 7c94142d25cdb4806cddbf749a8be4400f8d8b8c Mon Sep 17 00:00:00 2001 From: martin <martin@local> Date: Sun, 7 Feb 2021 19:44:43 +0300 Subject: [PATCH 3/6] fix compile on Fpc/Mac. Handle is PtrUInt. IFDEF MACOS only matches Delphi --- source/uCEFMiscFunctions.pas | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/uCEFMiscFunctions.pas b/source/uCEFMiscFunctions.pas index b05c9bcd..a04c53e2 100644 --- a/source/uCEFMiscFunctions.pas +++ b/source/uCEFMiscFunctions.pas @@ -2334,7 +2334,7 @@ end; function ValidCefWindowHandle(aHandle : TCefWindowHandle) : boolean; begin - {$IFDEF MACOSX} + {$IFDEF MACOS} Result := (aHandle <> nil); {$ELSE} Result := (aHandle <> 0); @@ -2343,7 +2343,7 @@ end; procedure InitializeWindowHandle(var aHandle : TCefWindowHandle); begin - {$IFDEF MACOSX} + {$IFDEF MACOS} aHandle := nil; {$ELSE} aHandle := 0; From bfff18e7b554afde574f5029d58024849118e2df Mon Sep 17 00:00:00 2001 From: martin <martin@local> Date: Sun, 7 Feb 2021 19:46:58 +0300 Subject: [PATCH 4/6] fix compile. If IFDEF does not apply, an empty var block causes a compile error on fpc --- source/uCEFBufferPanel.pas | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/uCEFBufferPanel.pas b/source/uCEFBufferPanel.pas index aa2ff2d2..c5893688 100644 --- a/source/uCEFBufferPanel.pas +++ b/source/uCEFBufferPanel.pas @@ -871,14 +871,15 @@ begin end; function TBufferPanel.GetRealScreenScale(var aResultScale : single) : boolean; -var {$IFDEF MSWINDOWS} +var TempHandle : TCefWindowHandle; TempDC : HDC; TempDPI : UINT; {$ELSE} {$IFDEF LINUX} {$IFDEF FPC} +var TempForm : TCustomForm; TempMonitor : TMonitor; {$ENDIF} From 03e917f85cef42b1bc4ed43d381b3b5688201b96 Mon Sep 17 00:00:00 2001 From: martin <martin@m> Date: Sun, 7 Feb 2021 16:59:04 +0100 Subject: [PATCH 5/6] Set LocalesDirPath and ResourcesDirPath from FrameworkDirPath, if not set explicitly --- source/uCEFApplicationCore.pas | 35 +++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/source/uCEFApplicationCore.pas b/source/uCEFApplicationCore.pas index 2c9db943..32718257 100644 --- a/source/uCEFApplicationCore.pas +++ b/source/uCEFApplicationCore.pas @@ -270,6 +270,8 @@ type function GetLibCefVersion : ustring; function GetLibCefPath : ustring; function GetChromeElfPath : ustring; + function GetLocalesDirPath: ustring; + function GetResourcesDirPath: ustring; function GetMustCreateResourceBundleHandler : boolean; virtual; function GetMustCreateBrowserProcessHandler : boolean; virtual; function GetMustCreateRenderProcessHandler : boolean; virtual; @@ -427,8 +429,8 @@ type property LogFile : ustring read FLogFile write FLogFile; property LogSeverity : TCefLogSeverity read FLogSeverity write FLogSeverity; property JavaScriptFlags : ustring read FJavaScriptFlags write FJavaScriptFlags; - property ResourcesDirPath : ustring read FResourcesDirPath write SetResourcesDirPath; - property LocalesDirPath : ustring read FLocalesDirPath write SetLocalesDirPath; + property ResourcesDirPath : ustring read GetResourcesDirPath write SetResourcesDirPath; + property LocalesDirPath : ustring read GetLocalesDirPath write SetLocalesDirPath; property PackLoadingDisabled : Boolean read FPackLoadingDisabled write FPackLoadingDisabled; property RemoteDebuggingPort : Integer read FRemoteDebuggingPort write FRemoteDebuggingPort; property UncaughtExceptionStackSize : Integer read FUncaughtExceptionStackSize write FUncaughtExceptionStackSize; @@ -905,15 +907,8 @@ begin {$ENDIF} if FileExists(MBPath + LIBCEF_DLL) then begin FrameworkDirPath := MBPath; - if FileExists(MBPath + LIBCEF_PAK) then begin - ResourcesDirPath := MBPath; - {$IFNDEF MACOSX} - if FileExists(IncludeTrailingPathDelimiter(MBPath + LIBCEF_LOCALE_DIR) + LIBCEF_LOCALE_ENUS) then - LocalesDirPath := MBPath + LIBCEF_LOCALE_DIR; - {$ENDIF} end; end; - end; end; // This function must only be called by the main executable when the application @@ -1025,6 +1020,28 @@ begin Result := CHROMEELF_DLL; 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); begin FCache := CustomAbsolutePath(aValue); From 30bda87db47f9eee9646b5e73b70039d95bb7113 Mon Sep 17 00:00:00 2001 From: martin <martin@local> Date: Sun, 7 Feb 2021 22:49:15 +0300 Subject: [PATCH 6/6] helper scripts for mac app helpers --- .../AppHelper/create_mac_helper_apps.sh | 57 +++++++++++++++++++ .../SimpleBrowser2/create_mac_helper.sh | 8 +++ 2 files changed, 65 insertions(+) create mode 100755 demos/Lazarus_Mac/AppHelper/create_mac_helper_apps.sh create mode 100755 demos/Lazarus_Mac/SimpleBrowser2/create_mac_helper.sh diff --git a/demos/Lazarus_Mac/AppHelper/create_mac_helper_apps.sh b/demos/Lazarus_Mac/AppHelper/create_mac_helper_apps.sh new file mode 100755 index 00000000..4050723f --- /dev/null +++ b/demos/Lazarus_Mac/AppHelper/create_mac_helper_apps.sh @@ -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" + diff --git a/demos/Lazarus_Mac/SimpleBrowser2/create_mac_helper.sh b/demos/Lazarus_Mac/SimpleBrowser2/create_mac_helper.sh new file mode 100755 index 00000000..43b6334b --- /dev/null +++ b/demos/Lazarus_Mac/SimpleBrowser2/create_mac_helper.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +CDIR=$(pwd) +cd "$(dirname "$0")" + +../AppHelper/create_mac_helper_apps.sh ../../../bin/SimpleBrowser2.app + +cd "$CDIR"