2018-04-18 10:25:38 +02:00
|
|
|
// ************************************************************************
|
|
|
|
// ***************************** CEF4Delphi *******************************
|
|
|
|
// ************************************************************************
|
|
|
|
//
|
2019-10-19 10:58:34 +02:00
|
|
|
// CEF4Delphi is based on DCEF3 which uses CEF to embed a chromium-based
|
2018-04-18 10:25:38 +02:00
|
|
|
// browser in Delphi applications.
|
|
|
|
//
|
|
|
|
// The original license of DCEF3 still applies to CEF4Delphi.
|
|
|
|
//
|
|
|
|
// For more information about CEF4Delphi visit :
|
|
|
|
// https://www.briskbard.com/index.php?lang=en&pageid=cef
|
|
|
|
//
|
2020-01-01 13:48:10 +02:00
|
|
|
// Copyright � 2020 Salvador Diaz Fau. All rights reserved.
|
2018-04-18 10:25:38 +02:00
|
|
|
//
|
|
|
|
// ************************************************************************
|
|
|
|
// ************ vvvv Original license and comments below vvvv *************
|
|
|
|
// ************************************************************************
|
|
|
|
(*
|
|
|
|
* Delphi Chromium Embedded 3
|
|
|
|
*
|
|
|
|
* Usage allowed under the restrictions of the Lesser GNU General Public License
|
|
|
|
* or alternatively the restrictions of the Mozilla Public License 1.1
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
|
|
|
|
* the specific language governing rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* Unit owner : Henri Gourvest <hgourvest@gmail.com>
|
|
|
|
* Web site : http://www.progdigy.com
|
|
|
|
* Repository : http://code.google.com/p/delphichromiumembedded/
|
|
|
|
* Group : http://groups.google.com/group/delphichromiumembedded
|
|
|
|
*
|
|
|
|
* Embarcadero Technologies, Inc is not permitted to use or redistribute
|
|
|
|
* this source code without explicit permission.
|
|
|
|
*
|
|
|
|
*)
|
|
|
|
|
|
|
|
unit uCEFMiscFunctions;
|
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
{$IFDEF FPC}
|
|
|
|
{$MODE OBJFPC}{$H+}
|
|
|
|
{$ENDIF}
|
|
|
|
|
2018-11-22 16:02:21 +02:00
|
|
|
{$IFNDEF CPUX64}{$ALIGN ON}{$ENDIF}
|
|
|
|
{$MINENUMSIZE 4}
|
2018-04-18 10:25:38 +02:00
|
|
|
|
|
|
|
{$I cef.inc}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
{$IFDEF DELPHI16_UP}
|
2018-09-18 15:19:44 +02:00
|
|
|
{$IFDEF MSWINDOWS}WinApi.Windows, WinApi.ActiveX,{$ENDIF} System.IOUtils, System.Classes, System.SysUtils, System.UITypes, System.Math,
|
2018-04-18 10:25:38 +02:00
|
|
|
{$ELSE}
|
2019-11-09 00:15:53 +02:00
|
|
|
{$IFDEF MSWINDOWS}Windows, ActiveX,{$ENDIF} {$IFDEF DELPHI14_UP}IOUtils,{$ENDIF} Classes, SysUtils, Math,
|
2019-11-10 19:23:39 +02:00
|
|
|
{$IFDEF FPC}LCLType,{$IFNDEF MSWINDOWS}InterfaceBase, Forms,{$ENDIF}{$ENDIF}
|
2018-04-18 10:25:38 +02:00
|
|
|
{$ENDIF}
|
|
|
|
uCEFTypes, uCEFInterfaces, uCEFLibFunctions, uCEFResourceHandler,
|
2018-10-12 12:21:43 +02:00
|
|
|
uCEFRegisterCDMCallback, uCEFConstants;
|
2018-04-18 10:25:38 +02:00
|
|
|
|
|
|
|
const
|
|
|
|
Kernel32DLL = 'kernel32.dll';
|
|
|
|
SHLWAPIDLL = 'shlwapi.dll';
|
|
|
|
|
|
|
|
function CefColorGetA(color: TCefColor): Byte;
|
|
|
|
function CefColorGetR(color: TCefColor): byte;
|
|
|
|
function CefColorGetG(color: TCefColor): Byte;
|
|
|
|
function CefColorGetB(color: TCefColor): Byte;
|
|
|
|
|
|
|
|
function CefColorSetARGB(a, r, g, b: Byte): TCefColor;
|
|
|
|
|
|
|
|
function CefInt64Set(int32_low, int32_high: Integer): Int64;
|
|
|
|
|
|
|
|
function CefInt64GetLow(const int64_val: Int64): Integer;
|
|
|
|
function CefInt64GetHigh(const int64_val: Int64): Integer;
|
|
|
|
|
|
|
|
function CefGetObject(ptr: Pointer): TObject; {$IFDEF SUPPORTS_INLINE} inline; {$ENDIF}
|
|
|
|
function CefGetData(const i: ICefBaseRefCounted): Pointer; {$IFDEF SUPPORTS_INLINE} inline; {$ENDIF}
|
|
|
|
|
|
|
|
function CefStringAlloc(const str: ustring): TCefString;
|
2019-11-24 19:19:49 +02:00
|
|
|
function CefStringClearAndGet(str: PCefString): ustring;
|
2018-04-18 10:25:38 +02:00
|
|
|
|
|
|
|
function CefString(const str: ustring): TCefString; overload;
|
|
|
|
function CefString(const str: PCefString): ustring; overload;
|
|
|
|
function CefUserFreeString(const str: ustring): PCefStringUserFree;
|
|
|
|
procedure CefStringFree(const str: PCefString);
|
|
|
|
function CefStringFreeAndGet(const str: PCefStringUserFree): ustring;
|
|
|
|
procedure CefStringSet(const str: PCefString; const value: ustring);
|
2019-11-24 19:19:49 +02:00
|
|
|
procedure CefStringInitialize(const aCefString : PCefString); {$IFDEF SUPPORTS_INLINE} inline; {$ENDIF}
|
2018-04-18 10:25:38 +02:00
|
|
|
|
2019-10-19 10:58:34 +02:00
|
|
|
function CefRegisterExtension(const name, code: ustring; const Handler: ICefv8Handler): Boolean;
|
|
|
|
|
|
|
|
function CefPostTask(aThreadId : TCefThreadId; const aTask: ICefTask) : boolean;
|
|
|
|
function CefPostDelayedTask(aThreadId : TCefThreadId; const aTask : ICefTask; aDelayMs : Int64) : boolean;
|
|
|
|
function CefCurrentlyOn(aThreadId : TCefThreadId) : boolean;
|
2018-04-18 10:25:38 +02:00
|
|
|
|
|
|
|
function CefTimeToSystemTime(const dt: TCefTime): TSystemTime;
|
|
|
|
function SystemTimeToCefTime(const dt: TSystemTime): TCefTime;
|
|
|
|
function CefTimeToDateTime(const dt: TCefTime): TDateTime;
|
|
|
|
function DateTimeToCefTime(dt: TDateTime): TCefTime;
|
|
|
|
|
|
|
|
function cef_string_wide_copy(const src: PWideChar; src_len: NativeUInt; output: PCefStringWide): Integer;
|
|
|
|
function cef_string_utf8_copy(const src: PAnsiChar; src_len: NativeUInt; output: PCefStringUtf8): Integer;
|
|
|
|
function cef_string_utf16_copy(const src: PChar16; src_len: NativeUInt; output: PCefStringUtf16): Integer;
|
|
|
|
function cef_string_copy(const src: PCefChar; src_len: NativeUInt; output: PCefString): Integer;
|
|
|
|
|
2018-05-24 19:15:41 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2019-11-10 01:24:26 +02:00
|
|
|
procedure WindowInfoAsChild(var aWindowInfo : TCefWindowInfo; aParent : TCefWindowHandle; aRect : TRect; const aWindowName : ustring = ''; aExStyle : cardinal = 0);
|
|
|
|
procedure WindowInfoAsPopUp(var aWindowInfo : TCefWindowInfo; aParent : TCefWindowHandle; const aWindowName : ustring = ''; aExStyle : cardinal = 0);
|
|
|
|
procedure WindowInfoAsWindowless(var aWindowInfo : TCefWindowInfo; aParent : TCefWindowHandle; const aWindowName : ustring = ''; aExStyle : cardinal = 0);
|
2018-05-24 19:15:41 +02:00
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
{$IFDEF MACOS}
|
|
|
|
procedure WindowInfoAsChild(var aWindowInfo : TCefWindowInfo; aParent : TCefWindowHandle; aRect : TRect; aHidden : boolean = False; const aWindowName : ustring = '');
|
|
|
|
procedure WindowInfoAsPopUp(var aWindowInfo : TCefWindowInfo; aParent : TCefWindowHandle; aHidden : boolean = False; const aWindowName : ustring = '');
|
|
|
|
procedure WindowInfoAsWindowless(var aWindowInfo : TCefWindowInfo; aParent : TCefWindowHandle; aHidden : boolean = False; const aWindowName : ustring = '');
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
{$IFDEF LINUX}
|
2019-03-15 18:17:14 +02:00
|
|
|
procedure WindowInfoAsChild(var aWindowInfo : TCefWindowInfo; aParent : TCefWindowHandle; aRect : TRect; const aWindowName : ustring = '');
|
|
|
|
procedure WindowInfoAsPopUp(var aWindowInfo : TCefWindowInfo; aParent : TCefWindowHandle; const aWindowName : ustring = '');
|
|
|
|
procedure WindowInfoAsWindowless(var aWindowInfo : TCefWindowInfo; aParent : TCefWindowHandle; const aWindowName : ustring = '');
|
2018-05-24 19:15:41 +02:00
|
|
|
{$ENDIF}
|
2018-04-18 10:25:38 +02:00
|
|
|
|
2018-06-03 17:18:54 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2018-09-02 13:11:43 +02:00
|
|
|
function ProcessUnderWow64(hProcess: THandle; var Wow64Process: BOOL): BOOL; external Kernel32DLL name 'IsWow64Process';
|
2018-04-18 10:25:38 +02:00
|
|
|
function TzSpecificLocalTimeToSystemTime(lpTimeZoneInformation: PTimeZoneInformation; lpLocalTime, lpUniversalTime: PSystemTime): BOOL; stdcall; external Kernel32DLL;
|
|
|
|
function SystemTimeToTzSpecificLocalTime(lpTimeZoneInformation: PTimeZoneInformation; lpUniversalTime, lpLocalTime: PSystemTime): BOOL; stdcall; external Kernel32DLL;
|
|
|
|
function PathIsRelativeAnsi(pszPath: LPCSTR): BOOL; stdcall; external SHLWAPIDLL name 'PathIsRelativeA';
|
|
|
|
function PathIsRelativeUnicode(pszPath: LPCWSTR): BOOL; stdcall; external SHLWAPIDLL name 'PathIsRelativeW';
|
2018-10-25 12:50:01 +02:00
|
|
|
function GetGlobalMemoryStatusEx(var Buffer: TMyMemoryStatusEx): BOOL; stdcall; external Kernel32DLL name 'GlobalMemoryStatusEx';
|
2019-09-21 11:37:13 +02:00
|
|
|
function PathCanonicalizeAnsi(pszBuf: LPSTR; pszPath: LPCSTR): BOOL; stdcall; external SHLWAPIDLL name 'PathCanonicalizeA';
|
|
|
|
function PathCanonicalizeUnicode(pszBuf: LPWSTR; pszPath: LPCWSTR): BOOL; stdcall; external SHLWAPIDLL name 'PathCanonicalizeW';
|
2019-09-23 12:01:39 +02:00
|
|
|
function PathIsUNCAnsi(pszPath: LPCSTR): BOOL; stdcall; external SHLWAPIDLL name 'PathIsUNCA';
|
2019-09-23 11:42:20 +02:00
|
|
|
function PathIsUNCUnicode(pszPath: LPCWSTR): BOOL; stdcall; external SHLWAPIDLL name 'PathIsUNCW';
|
2019-09-23 12:01:39 +02:00
|
|
|
function PathIsURLAnsi(pszPath: LPCSTR): BOOL; stdcall; external SHLWAPIDLL name 'PathIsURLA';
|
2019-09-23 11:42:20 +02:00
|
|
|
function PathIsURLUnicode(pszPath: LPCWSTR): BOOL; stdcall; external SHLWAPIDLL name 'PathIsURLW';
|
2018-04-18 10:25:38 +02:00
|
|
|
|
|
|
|
{$IFNDEF DELPHI12_UP}
|
2019-11-10 19:23:39 +02:00
|
|
|
const
|
|
|
|
GWLP_WNDPROC = GWL_WNDPROC;
|
2019-11-11 22:21:14 +02:00
|
|
|
GWLP_HWNDPARENT = GWL_HWNDPARENT;
|
2018-06-03 17:18:54 +02:00
|
|
|
{$IFDEF WIN64}
|
|
|
|
function SetWindowLongPtr(hWnd: HWND; nIndex: Integer; dwNewLong: int64): int64; stdcall; external user32 name 'SetWindowLongPtrW';
|
|
|
|
{$ELSE}
|
|
|
|
function SetWindowLongPtr(hWnd: HWND; nIndex: Integer; dwNewLong: LongInt): LongInt; stdcall; external user32 name 'SetWindowLongW';
|
|
|
|
{$ENDIF}
|
2018-04-18 10:25:38 +02:00
|
|
|
{$ENDIF}
|
2018-06-03 17:18:54 +02:00
|
|
|
|
2018-04-18 10:25:38 +02:00
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
function CustomPathIsRelative(const aPath : string) : boolean;
|
2019-09-21 11:37:13 +02:00
|
|
|
function CustomPathCanonicalize(const aOriginalPath : string; var aCanonicalPath : string) : boolean;
|
|
|
|
function CustomAbsolutePath(const aPath : string; aMustExist : boolean = False) : string;
|
2019-09-23 11:42:20 +02:00
|
|
|
function CustomPathIsURL(const aPath : string) : boolean;
|
|
|
|
function CustomPathIsUNC(const aPath : string) : boolean;
|
2018-04-18 10:25:38 +02:00
|
|
|
function GetModulePath : string;
|
|
|
|
|
|
|
|
function CefIsCertStatusError(Status : TCefCertStatus) : boolean;
|
|
|
|
|
|
|
|
function CefCrashReportingEnabled : boolean;
|
|
|
|
procedure CefSetCrashKeyValue(const aKey, aValue : ustring);
|
|
|
|
|
|
|
|
procedure CefLog(const aFile : string; aLine, aSeverity : integer; const aMessage : string);
|
2018-10-12 12:21:43 +02:00
|
|
|
procedure CefDebugLog(const aMessage : string; aSeverity : integer = CEF_LOG_SEVERITY_ERROR);
|
2018-04-18 10:25:38 +02:00
|
|
|
procedure OutputDebugMessage(const aMessage : string);
|
|
|
|
function CustomExceptionHandler(const aFunctionName : string; const aException : exception) : boolean;
|
|
|
|
|
2018-06-11 18:38:51 +02:00
|
|
|
function CefRegisterSchemeHandlerFactory(const SchemeName, DomainName : ustring; const handler: TCefResourceHandlerClass = nil): Boolean;
|
2018-04-18 10:25:38 +02:00
|
|
|
function CefClearSchemeHandlerFactories : boolean;
|
|
|
|
|
|
|
|
function CefAddCrossOriginWhitelistEntry(const SourceOrigin, TargetProtocol, TargetDomain: ustring; AllowTargetSubdomains: Boolean): Boolean;
|
|
|
|
function CefRemoveCrossOriginWhitelistEntry(const SourceOrigin, TargetProtocol, TargetDomain: ustring; AllowTargetSubdomains: Boolean): Boolean;
|
|
|
|
function CefClearCrossOriginWhitelist: Boolean;
|
|
|
|
|
|
|
|
procedure UInt64ToFileVersionInfo(const aVersion : uint64; var aVersionInfo : TFileVersionInfo);
|
2019-01-08 20:15:25 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2018-04-18 10:25:38 +02:00
|
|
|
function GetExtendedFileVersion(const aFileName : string) : uint64;
|
|
|
|
function GetStringFileInfo(const aFileName, aField : string; var aValue : string) : boolean;
|
|
|
|
function GetDLLVersion(const aDLLFile : string; var aVersionInfo : TFileVersionInfo) : boolean;
|
2019-01-08 20:15:25 +02:00
|
|
|
{$ENDIF}
|
2018-04-18 10:25:38 +02:00
|
|
|
|
|
|
|
function SplitLongString(aSrcString : string) : string;
|
|
|
|
function GetAbsoluteDirPath(const aSrcPath : string; var aRsltPath : string) : boolean;
|
2018-10-12 12:21:43 +02:00
|
|
|
function CheckSubprocessPath(const aSubprocessPath : string; var aMissingFiles : string) : boolean;
|
2018-04-18 10:25:38 +02:00
|
|
|
function CheckLocales(const aLocalesDirPath : string; var aMissingFiles : string; const aLocalesRequired : string = '') : boolean;
|
2018-10-03 09:58:51 +02:00
|
|
|
function CheckResources(const aResourcesDirPath : string; var aMissingFiles : string; aCheckDevResources: boolean = True; aCheckExtensions: boolean = True) : boolean;
|
2018-04-18 10:25:38 +02:00
|
|
|
function CheckDLLs(const aFrameworkDirPath : string; var aMissingFiles : string) : boolean;
|
2019-01-08 20:15:25 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
function CheckDLLVersion(const aDLLFile : string; aMajor, aMinor, aRelease, aBuild : uint16) : boolean;
|
|
|
|
function GetDLLHeaderMachine(const aDLLFile : string; var aMachine : integer) : boolean;
|
|
|
|
{$ENDIF}
|
2018-04-18 10:25:38 +02:00
|
|
|
function FileVersionInfoToString(const aVersionInfo : TFileVersionInfo) : string;
|
|
|
|
function CheckFilesExist(var aList : TStringList; var aMissingFiles : string) : boolean;
|
2018-09-02 13:11:43 +02:00
|
|
|
function Is32BitProcess : boolean;
|
2018-04-18 10:25:38 +02:00
|
|
|
|
|
|
|
function CefParseUrl(const url: ustring; var parts: TUrlParts): Boolean;
|
|
|
|
function CefCreateUrl(var parts: TUrlParts): ustring;
|
|
|
|
function CefFormatUrlForSecurityDisplay(const originUrl: string): string;
|
|
|
|
function CefGetMimeType(const extension: ustring): ustring;
|
|
|
|
procedure CefGetExtensionsForMimeType(const mimeType: ustring; var extensions: TStringList);
|
|
|
|
|
|
|
|
function CefBase64Encode(const data: Pointer; dataSize: NativeUInt): ustring;
|
|
|
|
function CefBase64Decode(const data: ustring): ICefBinaryValue;
|
|
|
|
function CefUriEncode(const text: ustring; usePlus: Boolean): ustring;
|
|
|
|
function CefUriDecode(const text: ustring; convertToUtf8: Boolean; unescapeRule: TCefUriUnescapeRule): ustring;
|
|
|
|
|
2019-11-24 19:19:49 +02:00
|
|
|
function CefGetPath(const aPathKey : TCefPathKey) : ustring;
|
|
|
|
|
2018-04-18 10:25:38 +02:00
|
|
|
function CefParseJson(const jsonString: ustring; options: TCefJsonParserOptions): ICefValue;
|
|
|
|
function CefParseJsonAndReturnError(const jsonString : ustring;
|
|
|
|
options : TCefJsonParserOptions;
|
|
|
|
out errorCodeOut : TCefJsonParserError;
|
|
|
|
out errorMsgOut : ustring): ICefValue;
|
|
|
|
function CefWriteJson(const node: ICefValue; options: TCefJsonWriterOptions): ustring;
|
|
|
|
|
|
|
|
function CefCreateDirectory(const fullPath: ustring): Boolean;
|
|
|
|
function CefGetTempDirectory(out tempDir: ustring): Boolean;
|
|
|
|
function CefCreateNewTempDirectory(const prefix: ustring; out newTempPath: ustring): Boolean;
|
|
|
|
function CefCreateTempDirectoryInDirectory(const baseDir, prefix: ustring; out newDir: ustring): Boolean;
|
|
|
|
function CefDirectoryExists(const path: ustring): Boolean;
|
|
|
|
function CefDeleteFile(const path: ustring; recursive: Boolean): Boolean;
|
|
|
|
function CefZipDirectory(const srcDir, destFile: ustring; includeHiddenFiles: Boolean): Boolean;
|
|
|
|
procedure CefLoadCRLSetsFile(const path : ustring);
|
|
|
|
|
2019-01-08 20:15:25 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2018-04-18 10:25:38 +02:00
|
|
|
function CefIsKeyDown(aWparam : WPARAM) : boolean;
|
|
|
|
function CefIsKeyToggled(aWparam : WPARAM) : boolean;
|
2019-01-08 20:15:25 +02:00
|
|
|
function GetCefMouseModifiers : TCefEventFlags; overload;
|
2018-04-18 10:25:38 +02:00
|
|
|
function GetCefMouseModifiers(awparam : WPARAM) : TCefEventFlags; overload;
|
2019-01-08 20:15:25 +02:00
|
|
|
function GetCefKeyboardModifiers(aWparam : WPARAM; aLparam : LPARAM) : TCefEventFlags;
|
2018-04-18 10:25:38 +02:00
|
|
|
|
|
|
|
procedure DropEffectToDragOperation(aEffect : Longint; var aAllowedOps : TCefDragOperations);
|
|
|
|
procedure DragOperationToDropEffect(const aDragOperations : TCefDragOperations; var aEffect: Longint);
|
2019-01-08 20:15:25 +02:00
|
|
|
{$ENDIF}
|
2018-04-18 10:25:38 +02:00
|
|
|
|
|
|
|
function DeviceToLogical(aValue : integer; const aDeviceScaleFactor : double) : integer; overload;
|
|
|
|
procedure DeviceToLogical(var aEvent : TCEFMouseEvent; const aDeviceScaleFactor : double); overload;
|
|
|
|
procedure DeviceToLogical(var aPoint : TPoint; const aDeviceScaleFactor : double); overload;
|
|
|
|
function LogicalToDevice(aValue : integer; const aDeviceScaleFactor : double) : integer; overload;
|
|
|
|
procedure LogicalToDevice(var aRect : TCEFRect; const aDeviceScaleFactor : double); overload;
|
|
|
|
|
|
|
|
function GetScreenDPI : integer;
|
|
|
|
function GetDeviceScaleFactor : single;
|
|
|
|
|
2019-06-19 16:53:26 +02:00
|
|
|
function DeleteDirContents(const aDirectory : string; const aExcludeFiles : TStringList = nil) : boolean;
|
|
|
|
function DeleteFileList(const aFileList : TStringList) : boolean;
|
|
|
|
function MoveFileList(const aFileList : TStringList; const aSrcDirectory, aDstDirectory : string) : boolean;
|
2018-09-18 15:19:44 +02:00
|
|
|
|
2019-10-13 18:50:23 +02:00
|
|
|
function CefGetDataURI(const aString, aMimeType : ustring) : ustring; overload;
|
|
|
|
function CefGetDataURI(aData : pointer; aSize : integer; const aMimeType : ustring; const aCharset : ustring = '') : ustring; overload;
|
|
|
|
|
2018-04-18 10:25:38 +02:00
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
2019-11-09 00:15:53 +02:00
|
|
|
uCEFApplicationCore, uCEFSchemeHandlerFactory, uCEFValue,
|
2018-04-18 10:25:38 +02:00
|
|
|
uCEFBinaryValue, uCEFStringList;
|
|
|
|
|
|
|
|
function CefColorGetA(color: TCefColor): Byte;
|
|
|
|
begin
|
|
|
|
Result := (color shr 24) and $FF;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CefColorGetR(color: TCefColor): byte;
|
|
|
|
begin
|
|
|
|
Result := (color shr 16) and $FF;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CefColorGetG(color: TCefColor): Byte;
|
|
|
|
begin
|
|
|
|
Result := (color shr 8) and $FF;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CefColorGetB(color: TCefColor): Byte;
|
|
|
|
begin
|
|
|
|
Result := color and $FF;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CefColorSetARGB(a, r, g, b: Byte): TCefColor;
|
|
|
|
begin
|
|
|
|
Result := (a shl 24) or (r shl 16) or (g shl 8) or b;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CefInt64Set(int32_low, int32_high: Integer): Int64;
|
|
|
|
begin
|
|
|
|
Result := int32_low or (int32_high shl 32);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CefInt64GetLow(const int64_val: Int64): Integer;
|
|
|
|
begin
|
|
|
|
Result := Integer(int64_val);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CefInt64GetHigh(const int64_val: Int64): Integer;
|
|
|
|
begin
|
|
|
|
Result := (int64_val shr 32) and $FFFFFFFF;
|
|
|
|
end;
|
|
|
|
|
2019-11-24 19:19:49 +02:00
|
|
|
function CefStringClearAndGet(str: PCefString): ustring;
|
2018-04-18 10:25:38 +02:00
|
|
|
begin
|
2019-11-24 19:19:49 +02:00
|
|
|
if (str <> nil) and (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
2018-06-11 09:01:38 +02:00
|
|
|
begin
|
2019-11-24 19:19:49 +02:00
|
|
|
Result := CefString(str);
|
|
|
|
cef_string_utf16_clear(str);
|
2018-06-11 09:01:38 +02:00
|
|
|
end
|
|
|
|
else
|
|
|
|
Result := '';
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function CefGetObject(ptr: Pointer): TObject; {$IFDEF SUPPORTS_INLINE} inline; {$ENDIF}
|
|
|
|
begin
|
|
|
|
if (ptr <> nil) then
|
|
|
|
begin
|
|
|
|
Dec(PByte(ptr), SizeOf(Pointer));
|
|
|
|
Result := TObject(PPointer(ptr)^);
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Result := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CefGetData(const i: ICefBaseRefCounted): Pointer; {$IFDEF SUPPORTS_INLINE} inline; {$ENDIF}
|
|
|
|
begin
|
|
|
|
if (i <> nil) then
|
|
|
|
Result := i.Wrap
|
|
|
|
else
|
|
|
|
Result := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CefString(const str: PCefString): ustring;
|
|
|
|
begin
|
|
|
|
if (str <> nil) then
|
2018-05-12 14:50:54 +02:00
|
|
|
SetString(Result, str^.str, str^.length)
|
2018-04-18 10:25:38 +02:00
|
|
|
else
|
|
|
|
Result := '';
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CefString(const str: ustring): TCefString;
|
|
|
|
begin
|
|
|
|
Result.str := PChar16(PWideChar(str));
|
|
|
|
Result.length := Length(str);
|
|
|
|
Result.dtor := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure CefStringFree(const str: PCefString);
|
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (str <> nil) and (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
cef_string_utf16_clear(str);
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure CefStringSet(const str: PCefString; const value: ustring);
|
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (str <> nil) and (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
2019-11-24 19:19:49 +02:00
|
|
|
cef_string_utf16_set(PWideChar(value), Length(value), str, Ord(True));
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure CefStringInitialize(const aCefString : PCefString); {$IFDEF SUPPORTS_INLINE} inline; {$ENDIF}
|
|
|
|
begin
|
|
|
|
if (aCefString <> nil) then
|
|
|
|
begin
|
|
|
|
aCefString^.str := nil;
|
|
|
|
aCefString^.length := 0;
|
|
|
|
aCefString^.dtor := nil;
|
|
|
|
end;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function CefStringFreeAndGet(const str: PCefStringUserFree): ustring;
|
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (str <> nil) and (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
2018-04-18 10:25:38 +02:00
|
|
|
begin
|
|
|
|
Result := CefString(PCefString(str));
|
|
|
|
cef_string_userfree_utf16_free(str);
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Result := '';
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CefStringAlloc(const str: ustring): TCefString;
|
|
|
|
begin
|
2019-11-24 19:19:49 +02:00
|
|
|
CefStringInitialize(@Result);
|
|
|
|
|
2018-06-11 09:01:38 +02:00
|
|
|
if (str <> '') and (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
cef_string_wide_to_utf16(PWideChar(str), Length(str), @Result);
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure _free_string(str: PChar16); stdcall;
|
|
|
|
begin
|
|
|
|
if (str <> nil) then FreeMem(str);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CefUserFreeString(const str: ustring): PCefStringUserFree;
|
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
begin
|
|
|
|
Result := cef_string_userfree_utf16_alloc();
|
|
|
|
Result^.length := Length(str);
|
|
|
|
GetMem(Result^.str, Result^.length * SizeOf(TCefChar));
|
|
|
|
Move(PCefChar(str)^, Result^.str^, Result^.length * SizeOf(TCefChar));
|
|
|
|
Result^.dtor := @_free_string;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Result := nil;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function CefRegisterExtension(const name, code: ustring; const Handler: ICefv8Handler): Boolean;
|
|
|
|
var
|
2018-06-11 09:01:38 +02:00
|
|
|
TempName, TempCode : TCefString;
|
2018-04-18 10:25:38 +02:00
|
|
|
begin
|
2019-09-12 11:40:52 +02:00
|
|
|
if (GlobalCEFApp <> nil) and
|
2018-07-24 18:18:54 +02:00
|
|
|
GlobalCEFApp.LibLoaded and
|
2019-09-12 11:40:52 +02:00
|
|
|
(GlobalCEFApp.ProcessType = ptRenderer) and
|
|
|
|
(length(name) > 0) and
|
|
|
|
(length(code) > 0) then
|
2018-06-11 09:01:38 +02:00
|
|
|
begin
|
|
|
|
TempName := CefString(name);
|
|
|
|
TempCode := CefString(code);
|
|
|
|
Result := cef_register_extension(@TempName, @TempCode, CefGetData(handler)) <> 0;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Result := False;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
2019-10-19 10:58:34 +02:00
|
|
|
function CefPostTask(aThreadId : TCefThreadId; const aTask : ICefTask) : boolean;
|
2018-04-18 10:25:38 +02:00
|
|
|
begin
|
2019-10-19 10:58:34 +02:00
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded and (aTask <> nil) then
|
|
|
|
Result := cef_post_task(aThreadId, aTask.Wrap) <> 0
|
|
|
|
else
|
|
|
|
Result := False;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CefPostDelayedTask(aThreadId : TCefThreadId; const aTask : ICefTask; aDelayMs : Int64) : boolean;
|
|
|
|
begin
|
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded and (aTask <> nil) then
|
|
|
|
Result := cef_post_delayed_task(aThreadId, aTask.Wrap, aDelayMs) <> 0
|
|
|
|
else
|
|
|
|
Result := False;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
2019-10-19 10:58:34 +02:00
|
|
|
function CefCurrentlyOn(aThreadId : TCefThreadId) : boolean;
|
2018-04-18 10:25:38 +02:00
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
2019-10-19 10:58:34 +02:00
|
|
|
Result := cef_currently_on(aThreadId) <> 0
|
|
|
|
else
|
|
|
|
Result := False;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function CefTimeToSystemTime(const dt: TCefTime): TSystemTime;
|
|
|
|
begin
|
2019-01-08 20:15:25 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2018-04-18 10:25:38 +02:00
|
|
|
Result.wYear := dt.year;
|
|
|
|
Result.wMonth := dt.month;
|
|
|
|
Result.wDayOfWeek := dt.day_of_week;
|
|
|
|
Result.wDay := dt.day_of_month;
|
|
|
|
Result.wHour := dt.hour;
|
|
|
|
Result.wMinute := dt.minute;
|
|
|
|
Result.wSecond := dt.second;
|
|
|
|
Result.wMilliseconds := dt.millisecond;
|
2019-01-08 20:15:25 +02:00
|
|
|
{$ELSE}
|
|
|
|
Result.Year := dt.year;
|
|
|
|
Result.Month := dt.month;
|
|
|
|
Result.DayOfWeek := dt.day_of_week;
|
|
|
|
Result.Day := dt.day_of_month;
|
|
|
|
Result.Hour := dt.hour;
|
|
|
|
Result.Minute := dt.minute;
|
|
|
|
Result.Second := dt.second;
|
|
|
|
Result.Millisecond := dt.millisecond;
|
|
|
|
{$ENDIF}
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function SystemTimeToCefTime(const dt: TSystemTime): TCefTime;
|
|
|
|
begin
|
2019-01-08 20:15:25 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2018-04-18 10:25:38 +02:00
|
|
|
Result.year := dt.wYear;
|
|
|
|
Result.month := dt.wMonth;
|
|
|
|
Result.day_of_week := dt.wDayOfWeek;
|
|
|
|
Result.day_of_month := dt.wDay;
|
|
|
|
Result.hour := dt.wHour;
|
|
|
|
Result.minute := dt.wMinute;
|
|
|
|
Result.second := dt.wSecond;
|
|
|
|
Result.millisecond := dt.wMilliseconds;
|
2019-01-08 20:15:25 +02:00
|
|
|
{$ELSE}
|
|
|
|
Result.year := dt.Year;
|
|
|
|
Result.month := dt.Month;
|
|
|
|
Result.day_of_week := dt.DayOfWeek;
|
|
|
|
Result.day_of_month := dt.Day;
|
|
|
|
Result.hour := dt.Hour;
|
|
|
|
Result.minute := dt.Minute;
|
|
|
|
Result.second := dt.Second;
|
|
|
|
Result.millisecond := dt.Millisecond;
|
|
|
|
{$ENDIF}
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function CefTimeToDateTime(const dt: TCefTime): TDateTime;
|
2019-01-08 20:15:25 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2018-04-18 10:25:38 +02:00
|
|
|
var
|
2018-06-11 09:01:38 +02:00
|
|
|
TempTime : TSystemTime;
|
2019-01-08 20:15:25 +02:00
|
|
|
{$ENDIF}
|
2018-04-18 10:25:38 +02:00
|
|
|
begin
|
2019-01-08 20:15:25 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2018-09-18 16:19:21 +02:00
|
|
|
Result := 0;
|
2018-10-25 12:50:01 +02:00
|
|
|
|
|
|
|
try
|
|
|
|
TempTime := CefTimeToSystemTime(dt);
|
2018-09-18 16:19:21 +02:00
|
|
|
SystemTimeToTzSpecificLocalTime(nil, @TempTime, @TempTime);
|
2018-10-25 12:50:01 +02:00
|
|
|
Result := SystemTimeToDateTime(TempTime);
|
2018-09-18 16:19:21 +02:00
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('CefTimeToDateTime', e) then raise;
|
|
|
|
end;
|
2019-01-08 20:15:25 +02:00
|
|
|
{$ELSE}
|
|
|
|
Result := EncodeDate(dt.year, dt.month, dt.day_of_month) + EncodeTime(dt.hour, dt.minute, dt.second, dt.millisecond);
|
|
|
|
{$ENDIF}
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function DateTimeToCefTime(dt: TDateTime): TCefTime;
|
|
|
|
var
|
2019-01-08 20:15:25 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2018-06-11 09:01:38 +02:00
|
|
|
TempTime : TSystemTime;
|
2019-01-08 20:15:25 +02:00
|
|
|
{$ELSE}
|
|
|
|
TempYear, TempMonth, TempDay, TempHour, TempMin, TempSec, TempMSec : Word;
|
|
|
|
{$ENDIF}
|
2018-04-18 10:25:38 +02:00
|
|
|
begin
|
2019-01-08 20:15:25 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2018-09-18 16:19:21 +02:00
|
|
|
FillChar(Result, SizeOf(TCefTime), 0);
|
2018-10-25 12:50:01 +02:00
|
|
|
|
|
|
|
try
|
|
|
|
DateTimeToSystemTime(dt, TempTime);
|
2018-09-18 16:19:21 +02:00
|
|
|
TzSpecificLocalTimeToSystemTime(nil, @TempTime, @TempTime);
|
2018-10-25 12:50:01 +02:00
|
|
|
Result := SystemTimeToCefTime(TempTime);
|
2018-09-18 16:19:21 +02:00
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('DateTimeToCefTime', e) then raise;
|
|
|
|
end;
|
2019-01-08 20:15:25 +02:00
|
|
|
{$ELSE}
|
|
|
|
DecodeDate(dt, TempYear, TempMonth, TempDay);
|
|
|
|
DecodeTime(dt, TempHour, TempMin, TempSec, TempMSec);
|
|
|
|
|
|
|
|
Result.year := TempYear;
|
|
|
|
Result.month := TempMonth;
|
|
|
|
Result.day_of_week := DayOfWeek(dt);
|
|
|
|
Result.day_of_month := TempMonth;
|
|
|
|
Result.hour := TempHour;
|
|
|
|
Result.minute := TempMin;
|
|
|
|
Result.second := TempSec;
|
|
|
|
Result.millisecond := TempMSec;
|
|
|
|
{$ENDIF}
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function cef_string_wide_copy(const src: PWideChar; src_len: NativeUInt; output: PCefStringWide): Integer;
|
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
Result := cef_string_wide_set(src, src_len, output, ord(True))
|
|
|
|
else
|
|
|
|
Result := 0;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function cef_string_utf8_copy(const src: PAnsiChar; src_len: NativeUInt; output: PCefStringUtf8): Integer;
|
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
Result := cef_string_utf8_set(src, src_len, output, ord(True))
|
|
|
|
else
|
|
|
|
Result := 0;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function cef_string_utf16_copy(const src: PChar16; src_len: NativeUInt; output: PCefStringUtf16): Integer;
|
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
Result := cef_string_utf16_set(src, src_len, output, ord(True))
|
|
|
|
else
|
|
|
|
Result := 0;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function cef_string_copy(const src: PCefChar; src_len: NativeUInt; output: PCefString): Integer;
|
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
Result := cef_string_utf16_set(src, src_len, output, ord(True))
|
|
|
|
else
|
|
|
|
Result := 0;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
2018-05-24 19:15:41 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2019-11-10 01:24:26 +02:00
|
|
|
procedure WindowInfoAsChild(var aWindowInfo : TCefWindowInfo; aParent : TCefWindowHandle; aRect : TRect; const aWindowName : ustring; aExStyle : cardinal);
|
2018-04-18 10:25:38 +02:00
|
|
|
begin
|
2018-10-26 10:32:10 +02:00
|
|
|
aWindowInfo.ex_style := aExStyle;
|
2018-04-18 10:25:38 +02:00
|
|
|
aWindowInfo.window_name := CefString(aWindowName);
|
|
|
|
aWindowInfo.style := WS_CHILD or WS_VISIBLE or WS_CLIPCHILDREN or WS_CLIPSIBLINGS or WS_TABSTOP;
|
|
|
|
aWindowInfo.x := aRect.left;
|
|
|
|
aWindowInfo.y := aRect.top;
|
|
|
|
aWindowInfo.width := aRect.right - aRect.left;
|
|
|
|
aWindowInfo.height := aRect.bottom - aRect.top;
|
|
|
|
aWindowInfo.parent_window := aParent;
|
|
|
|
aWindowInfo.menu := 0;
|
|
|
|
aWindowInfo.windowless_rendering_enabled := ord(False);
|
2018-12-12 18:13:23 +02:00
|
|
|
aWindowInfo.shared_texture_enabled := ord(False);
|
|
|
|
aWindowInfo.external_begin_frame_enabled := ord(False);
|
2018-04-18 10:25:38 +02:00
|
|
|
aWindowInfo.window := 0;
|
|
|
|
end;
|
|
|
|
|
2019-11-10 01:24:26 +02:00
|
|
|
procedure WindowInfoAsPopUp(var aWindowInfo : TCefWindowInfo; aParent : TCefWindowHandle; const aWindowName : ustring; aExStyle : cardinal);
|
2018-04-18 10:25:38 +02:00
|
|
|
begin
|
2018-10-26 10:32:10 +02:00
|
|
|
aWindowInfo.ex_style := aExStyle;
|
2018-04-18 10:25:38 +02:00
|
|
|
aWindowInfo.window_name := CefString(aWindowName);
|
|
|
|
aWindowInfo.style := WS_OVERLAPPEDWINDOW or WS_CLIPCHILDREN or WS_CLIPSIBLINGS or WS_VISIBLE;
|
|
|
|
aWindowInfo.x := integer(CW_USEDEFAULT);
|
|
|
|
aWindowInfo.y := integer(CW_USEDEFAULT);
|
|
|
|
aWindowInfo.width := integer(CW_USEDEFAULT);
|
|
|
|
aWindowInfo.height := integer(CW_USEDEFAULT);
|
|
|
|
aWindowInfo.parent_window := aParent;
|
|
|
|
aWindowInfo.menu := 0;
|
|
|
|
aWindowInfo.windowless_rendering_enabled := ord(False);
|
2018-12-12 18:13:23 +02:00
|
|
|
aWindowInfo.shared_texture_enabled := ord(False);
|
|
|
|
aWindowInfo.external_begin_frame_enabled := ord(False);
|
2018-04-18 10:25:38 +02:00
|
|
|
aWindowInfo.window := 0;
|
|
|
|
end;
|
|
|
|
|
2019-11-10 01:24:26 +02:00
|
|
|
procedure WindowInfoAsWindowless(var aWindowInfo : TCefWindowInfo; aParent : TCefWindowHandle; const aWindowName : ustring; aExStyle : cardinal);
|
2018-04-18 10:25:38 +02:00
|
|
|
begin
|
2018-10-26 10:32:10 +02:00
|
|
|
aWindowInfo.ex_style := aExStyle;
|
2018-04-18 10:25:38 +02:00
|
|
|
aWindowInfo.window_name := CefString(aWindowName);
|
|
|
|
aWindowInfo.style := 0;
|
|
|
|
aWindowInfo.x := 0;
|
|
|
|
aWindowInfo.y := 0;
|
|
|
|
aWindowInfo.width := 0;
|
|
|
|
aWindowInfo.height := 0;
|
|
|
|
aWindowInfo.parent_window := aParent;
|
|
|
|
aWindowInfo.menu := 0;
|
|
|
|
aWindowInfo.windowless_rendering_enabled := ord(True);
|
2018-12-12 18:13:23 +02:00
|
|
|
aWindowInfo.shared_texture_enabled := ord(False);
|
|
|
|
aWindowInfo.external_begin_frame_enabled := ord(False);
|
2018-04-18 10:25:38 +02:00
|
|
|
aWindowInfo.window := 0;
|
|
|
|
end;
|
2018-05-24 19:15:41 +02:00
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
{$IFDEF MACOS}
|
|
|
|
procedure WindowInfoAsChild(var aWindowInfo : TCefWindowInfo; aParent : TCefWindowHandle; aRect : TRect; aHidden : boolean; const aWindowName : ustring);
|
|
|
|
begin
|
|
|
|
aWindowInfo.window_name := CefString(aWindowName);
|
|
|
|
aWindowInfo.x := aRect.left;
|
|
|
|
aWindowInfo.y := aRect.top;
|
|
|
|
aWindowInfo.width := aRect.right - aRect.left;
|
|
|
|
aWindowInfo.height := aRect.bottom - aRect.top;
|
|
|
|
aWindowInfo.hidden := Ord(aHidden);
|
|
|
|
aWindowInfo.parent_view := aParent;
|
|
|
|
aWindowInfo.windowless_rendering_enabled := ord(False);
|
2018-12-12 18:13:23 +02:00
|
|
|
aWindowInfo.shared_texture_enabled := ord(False);
|
|
|
|
aWindowInfo.external_begin_frame_enabled := ord(False);
|
2018-05-24 19:15:41 +02:00
|
|
|
aWindowInfo.view := 0;
|
|
|
|
end;
|
|
|
|
|
2019-11-10 01:24:26 +02:00
|
|
|
procedure WindowInfoAsPopUp(var aWindowInfo : TCefWindowInfo; aParent : TCefWindowHandle; aHidden : boolean; const aWindowName : ustring);
|
2018-05-24 19:15:41 +02:00
|
|
|
begin
|
|
|
|
aWindowInfo.window_name := CefString(aWindowName);
|
|
|
|
aWindowInfo.x := integer(CW_USEDEFAULT);
|
|
|
|
aWindowInfo.y := integer(CW_USEDEFAULT);
|
|
|
|
aWindowInfo.width := integer(CW_USEDEFAULT);
|
|
|
|
aWindowInfo.height := integer(CW_USEDEFAULT);
|
|
|
|
aWindowInfo.hidden := Ord(aHidden);
|
|
|
|
aWindowInfo.parent_view := aParent;
|
|
|
|
aWindowInfo.windowless_rendering_enabled := ord(False);
|
2018-12-12 18:13:23 +02:00
|
|
|
aWindowInfo.shared_texture_enabled := ord(False);
|
|
|
|
aWindowInfo.external_begin_frame_enabled := ord(False);
|
2018-05-24 19:15:41 +02:00
|
|
|
aWindowInfo.view := 0;
|
|
|
|
end;
|
|
|
|
|
2019-11-10 01:24:26 +02:00
|
|
|
procedure WindowInfoAsWindowless(var aWindowInfo : TCefWindowInfo; aParent : TCefWindowHandle; aHidden : boolean; const aWindowName : ustring);
|
2018-05-24 19:15:41 +02:00
|
|
|
begin
|
|
|
|
|
|
|
|
aWindowInfo.window_name := CefString(aWindowName);
|
|
|
|
aWindowInfo.x := 0;
|
|
|
|
aWindowInfo.y := 0;
|
|
|
|
aWindowInfo.width := 0;
|
|
|
|
aWindowInfo.height := 0;
|
|
|
|
aWindowInfo.hidden := Ord(aHidden);
|
|
|
|
aWindowInfo.parent_view := aParent;
|
|
|
|
aWindowInfo.windowless_rendering_enabled := ord(True);
|
2018-12-12 18:13:23 +02:00
|
|
|
aWindowInfo.shared_texture_enabled := ord(False);
|
|
|
|
aWindowInfo.external_begin_frame_enabled := ord(False);
|
2018-05-24 19:15:41 +02:00
|
|
|
aWindowInfo.view := 0;
|
|
|
|
end;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
{$IFDEF LINUX}
|
2019-03-15 18:17:14 +02:00
|
|
|
procedure WindowInfoAsChild(var aWindowInfo : TCefWindowInfo; aParent : TCefWindowHandle; aRect : TRect; const aWindowName : ustring = '');
|
2018-05-24 19:15:41 +02:00
|
|
|
begin
|
2019-05-04 09:53:50 +02:00
|
|
|
aWindowInfo.window_name := CefString(aWindowName);
|
2018-05-24 19:15:41 +02:00
|
|
|
aWindowInfo.x := aRect.left;
|
|
|
|
aWindowInfo.y := aRect.top;
|
|
|
|
aWindowInfo.width := aRect.right - aRect.left;
|
|
|
|
aWindowInfo.height := aRect.bottom - aRect.top;
|
|
|
|
aWindowInfo.parent_window := aParent;
|
|
|
|
aWindowInfo.windowless_rendering_enabled := ord(False);
|
2018-12-12 18:13:23 +02:00
|
|
|
aWindowInfo.shared_texture_enabled := ord(False);
|
|
|
|
aWindowInfo.external_begin_frame_enabled := ord(False);
|
2018-05-24 19:15:41 +02:00
|
|
|
aWindowInfo.window := 0;
|
|
|
|
end;
|
|
|
|
|
2019-03-15 18:17:14 +02:00
|
|
|
procedure WindowInfoAsPopUp(var aWindowInfo : TCefWindowInfo; aParent : TCefWindowHandle; const aWindowName : ustring = '');
|
2018-05-24 19:15:41 +02:00
|
|
|
begin
|
2019-05-04 09:53:50 +02:00
|
|
|
aWindowInfo.window_name := CefString(aWindowName);
|
2019-01-08 20:15:25 +02:00
|
|
|
aWindowInfo.x := 0;
|
|
|
|
aWindowInfo.y := 0;
|
|
|
|
aWindowInfo.width := 0;
|
|
|
|
aWindowInfo.height := 0;
|
2018-05-24 19:15:41 +02:00
|
|
|
aWindowInfo.parent_window := aParent;
|
|
|
|
aWindowInfo.windowless_rendering_enabled := ord(False);
|
2018-12-12 18:13:23 +02:00
|
|
|
aWindowInfo.shared_texture_enabled := ord(False);
|
|
|
|
aWindowInfo.external_begin_frame_enabled := ord(False);
|
2018-05-24 19:15:41 +02:00
|
|
|
aWindowInfo.window := 0;
|
|
|
|
end;
|
|
|
|
|
2019-03-15 18:17:14 +02:00
|
|
|
procedure WindowInfoAsWindowless(var aWindowInfo : TCefWindowInfo; aParent : TCefWindowHandle; const aWindowName : ustring = '');
|
2018-05-24 19:15:41 +02:00
|
|
|
begin
|
2019-05-04 09:53:50 +02:00
|
|
|
aWindowInfo.window_name := CefString(aWindowName);
|
2018-05-24 19:15:41 +02:00
|
|
|
aWindowInfo.x := 0;
|
|
|
|
aWindowInfo.y := 0;
|
|
|
|
aWindowInfo.width := 0;
|
|
|
|
aWindowInfo.height := 0;
|
|
|
|
aWindowInfo.parent_window := aParent;
|
2019-12-18 16:10:30 +02:00
|
|
|
aWindowInfo.windowless_rendering_enabled := ord(True);
|
2018-12-12 18:13:23 +02:00
|
|
|
aWindowInfo.shared_texture_enabled := ord(False);
|
|
|
|
aWindowInfo.external_begin_frame_enabled := ord(False);
|
2018-05-24 19:15:41 +02:00
|
|
|
aWindowInfo.window := 0;
|
|
|
|
end;
|
|
|
|
{$ENDIF}
|
2018-04-18 10:25:38 +02:00
|
|
|
|
|
|
|
function CefIsCertStatusError(Status : TCefCertStatus) : boolean;
|
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
Result := (GlobalCEFApp <> nil) and
|
|
|
|
GlobalCEFApp.LibLoaded and
|
|
|
|
(cef_is_cert_status_error(Status) <> 0);
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function CefCrashReportingEnabled : boolean;
|
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
Result := (GlobalCEFApp <> nil) and
|
|
|
|
GlobalCEFApp.LibLoaded and
|
|
|
|
(cef_crash_reporting_enabled() <> 0);
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure CefSetCrashKeyValue(const aKey, aValue : ustring);
|
|
|
|
var
|
|
|
|
TempKey, TempValue : TCefString;
|
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
begin
|
|
|
|
TempKey := CefString(aKey);
|
|
|
|
TempValue := CefString(aValue);
|
|
|
|
cef_set_crash_key_value(@TempKey, @TempValue);
|
|
|
|
end;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure CefLog(const aFile : string; aLine, aSeverity : integer; const aMessage : string);
|
|
|
|
var
|
|
|
|
TempFile, TempMessage : AnsiString;
|
|
|
|
begin
|
|
|
|
if (length(aFile) > 0) and (length(aMessage) > 0) then
|
|
|
|
begin
|
|
|
|
TempFile := AnsiString(aFile);
|
|
|
|
TempMessage := AnsiString(aMessage);
|
|
|
|
|
|
|
|
cef_log(@TempFile[1], aLine, aSeverity, @TempMessage[1]);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2018-10-12 12:21:43 +02:00
|
|
|
procedure CefDebugLog(const aMessage : string; aSeverity : integer);
|
2018-04-18 10:25:38 +02:00
|
|
|
const
|
|
|
|
DEFAULT_LINE = 1;
|
|
|
|
var
|
|
|
|
TempString : string;
|
|
|
|
begin
|
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
begin
|
2019-01-08 20:15:25 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2018-04-18 10:25:38 +02:00
|
|
|
TempString := 'PID: ' + IntToStr(GetCurrentProcessID) + ', TID: ' + IntToStr(GetCurrentThreadID);
|
2019-01-08 20:15:25 +02:00
|
|
|
{$ELSE}
|
|
|
|
TempString := 'PID: ' + IntToStr(GetProcessID()) + ', TID: ' + IntToStr(GetCurrentThreadID());
|
|
|
|
{$ENDIF}
|
2018-04-18 10:25:38 +02:00
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
case GlobalCEFApp.ProcessType of
|
|
|
|
ptBrowser : TempString := TempString + ', PT: Browser';
|
|
|
|
ptRenderer : TempString := TempString + ', PT: Renderer';
|
|
|
|
ptZygote : TempString := TempString + ', PT: Zygote';
|
|
|
|
ptGPU : TempString := TempString + ', PT: GPU';
|
|
|
|
else TempString := TempString + ', PT: Other';
|
|
|
|
end;
|
|
|
|
|
2018-10-12 12:21:43 +02:00
|
|
|
CefLog('CEF4Delphi', DEFAULT_LINE, aSeverity, TempString + ' - ' + aMessage);
|
2018-03-29 20:02:04 +02:00
|
|
|
end;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure OutputDebugMessage(const aMessage : string);
|
|
|
|
const
|
|
|
|
DEFAULT_LINE = 1;
|
|
|
|
begin
|
|
|
|
{$IFDEF DEBUG}
|
2019-12-18 16:10:30 +02:00
|
|
|
{$IFNDEF FPC}
|
2018-04-18 10:25:38 +02:00
|
|
|
OutputDebugString({$IFDEF DELPHI12_UP}PWideChar{$ELSE}PAnsiChar{$ENDIF}(aMessage + chr(0)));
|
2019-12-18 16:10:30 +02:00
|
|
|
{$ENDIF}
|
2018-04-18 10:25:38 +02:00
|
|
|
|
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
CefLog('CEF4Delphi', DEFAULT_LINE, CEF_LOG_SEVERITY_ERROR, aMessage);
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CustomExceptionHandler(const aFunctionName : string; const aException : exception) : boolean;
|
|
|
|
begin
|
|
|
|
OutputDebugMessage(aFunctionName + ' error : ' + aException.message);
|
|
|
|
|
|
|
|
Result := (GlobalCEFApp <> nil) and GlobalCEFApp.ReRaiseExceptions;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CefRegisterSchemeHandlerFactory(const SchemeName : ustring;
|
2018-06-11 18:38:51 +02:00
|
|
|
const DomainName : ustring;
|
2018-04-18 10:25:38 +02:00
|
|
|
const handler : TCefResourceHandlerClass) : boolean;
|
|
|
|
var
|
2018-06-11 18:38:51 +02:00
|
|
|
TempScheme, TempDomainName : TCefString;
|
2018-04-18 10:25:38 +02:00
|
|
|
TempFactory : ICefSchemeHandlerFactory;
|
2018-06-11 18:38:51 +02:00
|
|
|
TempDomainNamePtr : PCefString;
|
2018-04-18 10:25:38 +02:00
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
Result := False;
|
|
|
|
|
|
|
|
try
|
2018-06-11 18:38:51 +02:00
|
|
|
if (GlobalCEFApp <> nil) and
|
|
|
|
GlobalCEFApp.LibLoaded and
|
|
|
|
(length(SchemeName) > 0) then
|
2018-06-11 09:01:38 +02:00
|
|
|
begin
|
2018-06-11 18:38:51 +02:00
|
|
|
if (length(DomainName) > 0) then
|
|
|
|
begin
|
|
|
|
TempDomainName := CefString(DomainName);
|
|
|
|
TempDomainNamePtr := @TempDomainName;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
TempDomainNamePtr := nil;
|
|
|
|
|
|
|
|
TempScheme := CefString(SchemeName);
|
|
|
|
TempFactory := TCefSchemeHandlerFactoryOwn.Create(handler);
|
|
|
|
Result := cef_register_scheme_handler_factory(@TempScheme, TempDomainNamePtr, TempFactory.Wrap) <> 0;
|
2018-06-11 09:01:38 +02:00
|
|
|
end;
|
|
|
|
finally
|
|
|
|
TempFactory := nil;
|
|
|
|
end;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function CefClearSchemeHandlerFactories : boolean;
|
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
Result := (GlobalCEFApp <> nil) and
|
|
|
|
GlobalCEFApp.LibLoaded and
|
|
|
|
(cef_clear_scheme_handler_factories() <> 0);
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function CefAddCrossOriginWhitelistEntry(const SourceOrigin : ustring;
|
|
|
|
const TargetProtocol : ustring;
|
|
|
|
const TargetDomain : ustring;
|
|
|
|
AllowTargetSubdomains : Boolean): Boolean;
|
|
|
|
var
|
|
|
|
TempSourceOrigin, TempTargetProtocol, TempTargetDomain : TCefString;
|
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
begin
|
|
|
|
TempSourceOrigin := CefString(SourceOrigin);
|
|
|
|
TempTargetProtocol := CefString(TargetProtocol);
|
|
|
|
TempTargetDomain := CefString(TargetDomain);
|
|
|
|
Result := cef_add_cross_origin_whitelist_entry(@TempSourceOrigin,
|
|
|
|
@TempTargetProtocol,
|
|
|
|
@TempTargetDomain,
|
|
|
|
Ord(AllowTargetSubdomains)) <> 0;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Result := False;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function CefRemoveCrossOriginWhitelistEntry(const SourceOrigin : ustring;
|
|
|
|
const TargetProtocol : ustring;
|
|
|
|
const TargetDomain : ustring;
|
|
|
|
AllowTargetSubdomains : Boolean): Boolean;
|
|
|
|
var
|
|
|
|
TempSourceOrigin, TempTargetProtocol, TempTargetDomain : TCefString;
|
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
begin
|
|
|
|
TempSourceOrigin := CefString(SourceOrigin);
|
|
|
|
TempTargetProtocol := CefString(TargetProtocol);
|
|
|
|
TempTargetDomain := CefString(TargetDomain);
|
|
|
|
Result := cef_remove_cross_origin_whitelist_entry(@TempSourceOrigin,
|
|
|
|
@TempTargetProtocol,
|
|
|
|
@TempTargetDomain,
|
|
|
|
Ord(AllowTargetSubdomains)) <> 0;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Result := False;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function CefClearCrossOriginWhitelist: Boolean;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := cef_clear_cross_origin_whitelist() <> 0;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function SplitLongString(aSrcString : string) : string;
|
|
|
|
const
|
|
|
|
MAXLINELENGTH = 50;
|
|
|
|
begin
|
2019-11-10 19:23:39 +02:00
|
|
|
Result := '';
|
2018-04-18 10:25:38 +02:00
|
|
|
while (length(aSrcString) > 0) do
|
|
|
|
begin
|
2019-11-10 19:23:39 +02:00
|
|
|
if (Result <> '') then
|
2018-04-18 10:25:38 +02:00
|
|
|
Result := Result + CRLF + copy(aSrcString, 1, MAXLINELENGTH)
|
|
|
|
else
|
|
|
|
Result := Result + copy(aSrcString, 1, MAXLINELENGTH);
|
|
|
|
|
|
|
|
aSrcString := copy(aSrcString, succ(MAXLINELENGTH), length(aSrcString));
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function GetAbsoluteDirPath(const aSrcPath : string; var aRsltPath : string) : boolean;
|
|
|
|
begin
|
|
|
|
Result := True;
|
|
|
|
|
|
|
|
if (length(aSrcPath) > 0) then
|
|
|
|
begin
|
2019-09-21 11:37:13 +02:00
|
|
|
aRsltPath := IncludeTrailingPathDelimiter(CustomAbsolutePath(aSrcPath));
|
|
|
|
Result := DirectoryExists(aRsltPath);
|
2018-04-18 10:25:38 +02:00
|
|
|
end
|
|
|
|
else
|
|
|
|
aRsltPath := '';
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CheckLocales(const aLocalesDirPath : string; var aMissingFiles : string; const aLocalesRequired : string) : boolean;
|
|
|
|
const
|
|
|
|
LOCALES_REQUIRED_DEFAULT =
|
|
|
|
'am,' +
|
|
|
|
'ar,' +
|
|
|
|
'bg,' +
|
|
|
|
'bn,' +
|
|
|
|
'ca,' +
|
|
|
|
'cs,' +
|
|
|
|
'da,' +
|
|
|
|
'de,' +
|
|
|
|
'el,' +
|
|
|
|
'en-GB,' +
|
|
|
|
'en-US,' +
|
|
|
|
'es,' +
|
|
|
|
'es-419,' +
|
|
|
|
'et,' +
|
|
|
|
'fa,' +
|
|
|
|
'fi,' +
|
|
|
|
'fil,' +
|
|
|
|
'fr,' +
|
|
|
|
'gu,' +
|
|
|
|
'he,' +
|
|
|
|
'hi,' +
|
|
|
|
'hr,' +
|
|
|
|
'hu,' +
|
|
|
|
'id,' +
|
|
|
|
'it,' +
|
|
|
|
'ja,' +
|
|
|
|
'kn,' +
|
|
|
|
'ko,' +
|
|
|
|
'lt,' +
|
|
|
|
'lv,' +
|
|
|
|
'ml,' +
|
|
|
|
'mr,' +
|
|
|
|
'ms,' +
|
|
|
|
'nb,' +
|
|
|
|
'nl,' +
|
|
|
|
'pl,' +
|
|
|
|
'pt-BR,' +
|
|
|
|
'pt-PT,' +
|
|
|
|
'ro,' +
|
|
|
|
'ru,' +
|
|
|
|
'sk,' +
|
|
|
|
'sl,' +
|
|
|
|
'sr,' +
|
|
|
|
'sv,' +
|
|
|
|
'sw,' +
|
|
|
|
'ta,' +
|
|
|
|
'te,' +
|
|
|
|
'th,' +
|
|
|
|
'tr,' +
|
|
|
|
'uk,' +
|
|
|
|
'vi,' +
|
|
|
|
'zh-CN,' +
|
|
|
|
'zh-TW';
|
|
|
|
var
|
|
|
|
i : integer;
|
|
|
|
TempDir : string;
|
|
|
|
TempList : TStringList;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
TempList := nil;
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
if (length(aLocalesDirPath) > 0) then
|
|
|
|
TempDir := IncludeTrailingPathDelimiter(aLocalesDirPath)
|
|
|
|
else
|
2019-11-10 19:23:39 +02:00
|
|
|
TempDir := 'locales' + PathDelim;
|
2018-04-18 10:25:38 +02:00
|
|
|
|
|
|
|
TempList := TStringList.Create;
|
|
|
|
|
|
|
|
if (length(aLocalesRequired) > 0) then
|
|
|
|
TempList.CommaText := aLocalesRequired
|
|
|
|
else
|
|
|
|
TempList.CommaText := LOCALES_REQUIRED_DEFAULT;
|
|
|
|
|
|
|
|
i := 0;
|
2017-12-18 20:38:56 +02:00
|
|
|
while (i < TempList.Count) do
|
|
|
|
begin
|
|
|
|
TempList[i] := TempDir + TempList[i] + '.pak';
|
|
|
|
inc(i);
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
if DirectoryExists(TempDir) then
|
|
|
|
Result := CheckFilesExist(TempList, aMissingFiles)
|
|
|
|
else
|
|
|
|
aMissingFiles := trim(aMissingFiles) + CRLF + TempList.Text;
|
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('CheckLocales', e) then raise;
|
|
|
|
end;
|
2017-12-18 20:38:56 +02:00
|
|
|
finally
|
|
|
|
if (TempList <> nil) then FreeAndNil(TempList);
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2018-10-03 09:58:51 +02:00
|
|
|
function CheckResources(const aResourcesDirPath : string; var aMissingFiles : string; aCheckDevResources, aCheckExtensions: boolean) : boolean;
|
2018-04-18 10:25:38 +02:00
|
|
|
var
|
|
|
|
TempDir : string;
|
|
|
|
TempList : TStringList;
|
|
|
|
TempExists : boolean;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
TempExists := GetAbsoluteDirPath(aResourcesDirPath, TempDir);
|
|
|
|
|
|
|
|
TempList := TStringList.Create;
|
|
|
|
TempList.Add(TempDir + 'natives_blob.bin');
|
|
|
|
TempList.Add(TempDir + 'snapshot_blob.bin');
|
|
|
|
TempList.Add(TempDir + 'v8_context_snapshot.bin');
|
|
|
|
TempList.Add(TempDir + 'cef.pak');
|
|
|
|
TempList.Add(TempDir + 'cef_100_percent.pak');
|
|
|
|
TempList.Add(TempDir + 'cef_200_percent.pak');
|
|
|
|
|
2019-09-21 11:37:13 +02:00
|
|
|
if aCheckExtensions then TempList.Add(TempDir + 'cef_extensions.pak');
|
2018-04-18 10:25:38 +02:00
|
|
|
if aCheckDevResources then TempList.Add(TempDir + 'devtools_resources.pak');
|
|
|
|
|
|
|
|
if TempExists then
|
|
|
|
Result := CheckFilesExist(TempList, aMissingFiles)
|
|
|
|
else
|
|
|
|
aMissingFiles := trim(aMissingFiles) + CRLF + TempList.Text;
|
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('CheckResources', e) then raise;
|
|
|
|
end;
|
2017-12-18 20:38:56 +02:00
|
|
|
finally
|
|
|
|
if (TempList <> nil) then FreeAndNil(TempList);
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2018-10-12 12:21:43 +02:00
|
|
|
function CheckSubprocessPath(const aSubprocessPath : string; var aMissingFiles : string) : boolean;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
|
|
|
|
try
|
|
|
|
if (length(aSubprocessPath) = 0) or FileExists(aSubprocessPath) then
|
|
|
|
Result := True
|
|
|
|
else
|
|
|
|
aMissingFiles := trim(aMissingFiles) + CRLF + ExtractFileName(aSubprocessPath);
|
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('CheckSubprocessPath', e) then raise;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2018-04-18 10:25:38 +02:00
|
|
|
function CheckDLLs(const aFrameworkDirPath : string; var aMissingFiles : string) : boolean;
|
|
|
|
var
|
|
|
|
TempDir : string;
|
|
|
|
TempList : TStringList;
|
|
|
|
TempExists : boolean;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
TempList := nil;
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
TempExists := GetAbsoluteDirPath(aFrameworkDirPath, TempDir);
|
|
|
|
|
|
|
|
// The icudtl.dat file must be placed next to libcef.dll
|
|
|
|
// http://www.magpcss.org/ceforum/viewtopic.php?f=6&t=14503#p32263
|
|
|
|
|
|
|
|
TempList := TStringList.Create;
|
|
|
|
TempList.Add(TempDir + CHROMEELF_DLL);
|
|
|
|
TempList.Add(TempDir + LIBCEF_DLL);
|
2019-11-10 19:23:39 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2018-04-18 10:25:38 +02:00
|
|
|
TempList.Add(TempDir + 'd3dcompiler_47.dll');
|
|
|
|
TempList.Add(TempDir + 'libEGL.dll');
|
|
|
|
TempList.Add(TempDir + 'libGLESv2.dll');
|
|
|
|
TempList.Add(TempDir + 'swiftshader\libEGL.dll');
|
|
|
|
TempList.Add(TempDir + 'swiftshader\libGLESv2.dll');
|
2019-11-10 19:23:39 +02:00
|
|
|
{$ENDIF}
|
|
|
|
{$IFDEF LINUX}
|
|
|
|
TempList.Add(TempDir + 'libEGL.so');
|
|
|
|
TempList.Add(TempDir + 'libGLESv2.so');
|
|
|
|
TempList.Add(TempDir + 'swiftshader/libEGL.so');
|
|
|
|
TempList.Add(TempDir + 'swiftshader/libGLESv2.so');
|
|
|
|
{$ENDIF}
|
2018-04-18 10:25:38 +02:00
|
|
|
TempList.Add(TempDir + 'icudtl.dat');
|
|
|
|
|
|
|
|
if TempExists then
|
|
|
|
Result := CheckFilesExist(TempList, aMissingFiles)
|
|
|
|
else
|
|
|
|
aMissingFiles := trim(aMissingFiles) + CRLF + TempList.Text;
|
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('CheckDLLs', e) then raise;
|
|
|
|
end;
|
2017-12-18 20:38:56 +02:00
|
|
|
finally
|
|
|
|
if (TempList <> nil) then FreeAndNil(TempList);
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CheckFilesExist(var aList : TStringList; var aMissingFiles : string) : boolean;
|
|
|
|
var
|
|
|
|
i : integer;
|
|
|
|
begin
|
2017-12-18 20:38:56 +02:00
|
|
|
Result := True;
|
|
|
|
|
|
|
|
try
|
|
|
|
if (aList <> nil) then
|
|
|
|
begin
|
|
|
|
i := 0;
|
|
|
|
|
|
|
|
while (i < aList.Count) do
|
|
|
|
begin
|
|
|
|
if (length(aList[i]) > 0) and not(FileExists(aList[i])) then
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
aMissingFiles := aMissingFiles + aList[i] + CRLF;
|
|
|
|
end;
|
|
|
|
|
|
|
|
inc(i);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
except
|
2018-04-18 10:25:38 +02:00
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('CheckFilesExist', e) then raise;
|
2017-12-18 20:38:56 +02:00
|
|
|
end;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure UInt64ToFileVersionInfo(const aVersion : uint64; var aVersionInfo : TFileVersionInfo);
|
|
|
|
begin
|
|
|
|
aVersionInfo.MajorVer := uint16(aVersion shr 48);
|
|
|
|
aVersionInfo.MinorVer := uint16((aVersion shr 32) and $FFFF);
|
|
|
|
aVersionInfo.Release := uint16((aVersion shr 16) and $FFFF);
|
|
|
|
aVersionInfo.Build := uint16(aVersion and $FFFF);
|
|
|
|
end;
|
|
|
|
|
2019-01-08 20:15:25 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2018-04-18 10:25:38 +02:00
|
|
|
function GetExtendedFileVersion(const aFileName : string) : uint64;
|
|
|
|
var
|
|
|
|
TempSize : DWORD;
|
|
|
|
TempBuffer : pointer;
|
|
|
|
TempLen : UINT;
|
|
|
|
TempHandle : cardinal;
|
|
|
|
TempInfo : PVSFixedFileInfo;
|
|
|
|
begin
|
|
|
|
Result := 0;
|
|
|
|
TempBuffer := nil;
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
TempSize := GetFileVersioninfoSize(PChar(aFileName), TempHandle);
|
|
|
|
|
|
|
|
if (TempSize > 0) then
|
|
|
|
begin
|
|
|
|
GetMem(TempBuffer, TempSize);
|
|
|
|
|
|
|
|
if GetFileVersionInfo(PChar(aFileName), TempHandle, TempSize, TempBuffer) and
|
|
|
|
VerQueryValue(TempBuffer, '\', Pointer(TempInfo), TempLen) then
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := TempInfo^.dwFileVersionMS;
|
2018-04-18 10:25:38 +02:00
|
|
|
Result := Result shl 32;
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := Result or TempInfo^.dwFileVersionLS;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('GetExtendedFileVersion', e) then raise;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
if (TempBuffer <> nil) then FreeMem(TempBuffer);
|
|
|
|
end;
|
|
|
|
end;
|
2017-10-24 20:44:51 +02:00
|
|
|
|
|
|
|
function GetStringFileInfo(const aFileName, aField : string; var aValue : string) : boolean;
|
|
|
|
type
|
|
|
|
PLangAndCodepage = ^TLangAndCodepage;
|
|
|
|
TLangAndCodepage = record
|
|
|
|
wLanguage : word;
|
|
|
|
wCodePage : word;
|
|
|
|
end;
|
|
|
|
var
|
|
|
|
TempSize : DWORD;
|
|
|
|
TempBuffer : pointer;
|
|
|
|
TempHandle : cardinal;
|
|
|
|
TempPointer : pointer;
|
|
|
|
TempSubBlock : string;
|
|
|
|
TempLang : PLangAndCodepage;
|
|
|
|
TempArray : array of TLangAndCodepage;
|
|
|
|
i, j : DWORD;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
TempBuffer := nil;
|
|
|
|
TempArray := nil;
|
|
|
|
aValue := '';
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
TempSize := GetFileVersionInfoSize(PChar(aFileName), TempHandle);
|
|
|
|
|
|
|
|
if (TempSize > 0) then
|
|
|
|
begin
|
|
|
|
GetMem(TempBuffer, TempSize);
|
|
|
|
|
|
|
|
if GetFileVersionInfo(PChar(aFileName), 0, TempSize, TempBuffer) then
|
|
|
|
begin
|
|
|
|
if VerQueryValue(TempBuffer, '\VarFileInfo\Translation\', Pointer(TempLang), TempSize) then
|
|
|
|
begin
|
|
|
|
i := 0;
|
|
|
|
j := TempSize div SizeOf(TLangAndCodepage);
|
|
|
|
|
|
|
|
SetLength(TempArray, j);
|
|
|
|
|
|
|
|
while (i < j) do
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
TempArray[i].wLanguage := TempLang^.wLanguage;
|
|
|
|
TempArray[i].wCodePage := TempLang^.wCodePage;
|
2017-10-24 20:44:51 +02:00
|
|
|
inc(TempLang);
|
|
|
|
inc(i);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
i := 0;
|
|
|
|
j := Length(TempArray);
|
|
|
|
|
|
|
|
while (i < j) and not(Result) do
|
|
|
|
begin
|
|
|
|
TempSubBlock := '\StringFileInfo\' +
|
|
|
|
IntToHex(TempArray[i].wLanguage, 4) + IntToHex(TempArray[i].wCodePage, 4) +
|
|
|
|
'\' + aField;
|
|
|
|
|
|
|
|
if VerQueryValue(TempBuffer, PChar(TempSubBlock), TempPointer, TempSize) then
|
|
|
|
begin
|
|
|
|
aValue := trim(PChar(TempPointer));
|
|
|
|
Result := (length(aValue) > 0);
|
|
|
|
end;
|
|
|
|
|
|
|
|
inc(i);
|
|
|
|
end;
|
|
|
|
|
|
|
|
// Adobe's flash player DLL uses a different codepage to store the StringFileInfo fields
|
|
|
|
if not(Result) and (j > 0) and (TempArray[0].wCodePage <> 1252) then
|
|
|
|
begin
|
|
|
|
TempSubBlock := '\StringFileInfo\' +
|
|
|
|
IntToHex(TempArray[0].wLanguage, 4) + IntToHex(1252, 4) +
|
|
|
|
'\' + aField;
|
|
|
|
|
|
|
|
if VerQueryValue(TempBuffer, PChar(TempSubBlock), TempPointer, TempSize) then
|
|
|
|
begin
|
|
|
|
aValue := trim(PChar(TempPointer));
|
|
|
|
Result := (length(aValue) > 0);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('GetStringFileInfo', e) then raise;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
if (TempBuffer <> nil) then FreeMem(TempBuffer);
|
|
|
|
end;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function GetDLLVersion(const aDLLFile : string; var aVersionInfo : TFileVersionInfo) : boolean;
|
|
|
|
var
|
|
|
|
TempVersion : uint64;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
|
|
|
|
try
|
|
|
|
if FileExists(aDLLFile) then
|
|
|
|
begin
|
|
|
|
TempVersion := GetExtendedFileVersion(aDLLFile);
|
|
|
|
UInt64ToFileVersionInfo(TempVersion, aVersionInfo);
|
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('GetDLLVersion', e) then raise;
|
|
|
|
end;
|
2019-01-08 20:15:25 +02:00
|
|
|
end;
|
|
|
|
{$ENDIF}
|
2017-10-24 20:44:51 +02:00
|
|
|
|
|
|
|
function FileVersionInfoToString(const aVersionInfo : TFileVersionInfo) : string;
|
|
|
|
begin
|
|
|
|
Result := IntToStr(aVersionInfo.MajorVer) + '.' +
|
|
|
|
IntToStr(aVersionInfo.MinorVer) + '.' +
|
|
|
|
IntToStr(aVersionInfo.Release) + '.' +
|
|
|
|
IntToStr(aVersionInfo.Build);
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
2019-01-08 20:15:25 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2018-04-18 10:25:38 +02:00
|
|
|
function CheckDLLVersion(const aDLLFile : string; aMajor, aMinor, aRelease, aBuild : uint16) : boolean;
|
|
|
|
var
|
|
|
|
TempVersionInfo : TFileVersionInfo;
|
|
|
|
begin
|
|
|
|
Result := GetDLLVersion(aDLLFile, TempVersionInfo) and
|
|
|
|
(TempVersionInfo.MajorVer = aMajor) and
|
|
|
|
(TempVersionInfo.MinorVer = aMinor) and
|
|
|
|
(TempVersionInfo.Release = aRelease) and
|
|
|
|
(TempVersionInfo.Build = aBuild);
|
|
|
|
end;
|
|
|
|
|
2018-09-02 13:11:43 +02:00
|
|
|
// This function is based on the answer given by 'Alex' in StackOverflow
|
|
|
|
// https://stackoverflow.com/questions/2748474/how-to-determine-if-dll-file-was-compiled-as-x64-or-x86-bit-using-either-delphi
|
|
|
|
function GetDLLHeaderMachine(const aDLLFile : string; var aMachine : integer) : boolean;
|
|
|
|
var
|
|
|
|
TempHeader : TImageDosHeader;
|
|
|
|
TempImageNtHeaders : TImageNtHeaders;
|
|
|
|
TempStream : TFileStream;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
aMachine := IMAGE_FILE_MACHINE_UNKNOWN;
|
|
|
|
TempStream := nil;
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
if FileExists(aDLLFile) then
|
|
|
|
begin
|
|
|
|
TempStream := TFileStream.Create(aDLLFile, fmOpenRead);
|
|
|
|
TempStream.seek(0, soFromBeginning);
|
|
|
|
TempStream.ReadBuffer(TempHeader, SizeOf(TempHeader));
|
|
|
|
|
|
|
|
if (TempHeader.e_magic = IMAGE_DOS_SIGNATURE) and
|
|
|
|
(TempHeader._lfanew <> 0) then
|
|
|
|
begin
|
|
|
|
TempStream.Position := TempHeader._lfanew;
|
|
|
|
TempStream.ReadBuffer(TempImageNtHeaders, SizeOf(TempImageNtHeaders));
|
|
|
|
|
|
|
|
if (TempImageNtHeaders.Signature = IMAGE_NT_SIGNATURE) then
|
|
|
|
begin
|
|
|
|
aMachine := TempImageNtHeaders.FileHeader.Machine;
|
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
except
|
|
|
|
on e : exception do
|
2018-09-02 15:40:56 +02:00
|
|
|
if CustomExceptionHandler('GetDLLHeaderMachine', e) then raise;
|
2018-09-02 13:11:43 +02:00
|
|
|
end;
|
|
|
|
finally
|
|
|
|
if (TempStream <> nil) then FreeAndNil(TempStream);
|
|
|
|
end;
|
2019-01-08 20:15:25 +02:00
|
|
|
end;
|
|
|
|
{$ENDIF}
|
2018-09-02 13:11:43 +02:00
|
|
|
|
|
|
|
function Is32BitProcess : boolean;
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
var
|
|
|
|
TempResult : BOOL;
|
|
|
|
{$ENDIF}
|
|
|
|
begin
|
|
|
|
{$IFDEF CPUX32}
|
|
|
|
Result := True;
|
|
|
|
exit;
|
|
|
|
{$ENDIF}
|
|
|
|
|
2018-09-02 15:40:56 +02:00
|
|
|
{$IFDEF CPU386}
|
|
|
|
Result := True;
|
|
|
|
exit;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
{$IFDEF CPUi386}
|
|
|
|
Result := True;
|
|
|
|
exit;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
{$IFDEF CPUPOWERPC32}
|
|
|
|
Result := True;
|
|
|
|
exit;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
{$IFDEF CPUSPARC32}
|
|
|
|
Result := True;
|
|
|
|
exit;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
{$IFDEF CPU32BITS}
|
|
|
|
Result := True;
|
|
|
|
exit;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
{$IFDEF CPUARM32}
|
|
|
|
Result := True;
|
|
|
|
exit;
|
|
|
|
{$ENDIF}
|
|
|
|
|
2018-09-02 13:11:43 +02:00
|
|
|
{$IFDEF WIN32}
|
|
|
|
Result := True;
|
|
|
|
exit;
|
|
|
|
{$ENDIF}
|
|
|
|
|
2018-09-02 15:40:56 +02:00
|
|
|
{$IFDEF IOS32}
|
|
|
|
Result := True;
|
|
|
|
exit;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
{$IFDEF MACOS32}
|
|
|
|
Result := True;
|
|
|
|
exit;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
{$IFDEF LINUX32}
|
|
|
|
Result := True;
|
|
|
|
exit;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
{$IFDEF POSIX32}
|
|
|
|
Result := True;
|
|
|
|
exit;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
{$IFDEF ANDROID32}
|
|
|
|
Result := True;
|
|
|
|
exit;
|
|
|
|
{$ENDIF}
|
|
|
|
|
2018-09-02 13:11:43 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
Result := ProcessUnderWow64(GetCurrentProcess, TempResult) and TempResult;
|
|
|
|
exit;
|
|
|
|
{$ENDIF}
|
|
|
|
|
2018-11-15 20:08:16 +02:00
|
|
|
{$IFDEF DELPHI17_UP}
|
2018-09-02 13:11:43 +02:00
|
|
|
Result := TOSVersion.Architecture in [arIntelX86, arARM32];
|
|
|
|
{$ELSE}
|
|
|
|
Result := False;
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
2018-04-18 10:25:38 +02:00
|
|
|
function CustomPathIsRelative(const aPath : string) : boolean;
|
|
|
|
begin
|
|
|
|
{$IFDEF DELPHI12_UP}
|
|
|
|
Result := PathIsRelativeUnicode(PChar(aPath));
|
|
|
|
{$ELSE}
|
2019-01-08 20:15:25 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
Result := PathIsRelativeAnsi(PChar(aPath));
|
|
|
|
{$ELSE}
|
|
|
|
Result := (length(aPath) > 0) and (aPath[1] <> '/');
|
|
|
|
{$ENDIF}
|
2018-04-18 10:25:38 +02:00
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
2019-09-23 11:42:20 +02:00
|
|
|
function CustomPathIsURL(const aPath : string) : boolean;
|
|
|
|
begin
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
{$IFDEF DELPHI12_UP}
|
|
|
|
Result := PathIsURLUnicode(PChar(aPath + #0));
|
|
|
|
{$ELSE}
|
|
|
|
Result := PathIsURLAnsi(PChar(aPath + #0));
|
|
|
|
{$ENDIF}
|
|
|
|
{$ELSE}
|
|
|
|
Result := False;
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CustomPathIsUNC(const aPath : string) : boolean;
|
|
|
|
begin
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
{$IFDEF DELPHI12_UP}
|
|
|
|
Result := PathIsUNCUnicode(PChar(aPath + #0));
|
|
|
|
{$ELSE}
|
|
|
|
Result := PathIsUNCAnsi(PChar(aPath + #0));
|
|
|
|
{$ENDIF}
|
|
|
|
{$ELSE}
|
|
|
|
Result := False;
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
2019-09-21 11:37:13 +02:00
|
|
|
function CustomPathCanonicalize(const aOriginalPath : string; var aCanonicalPath : string) : boolean;
|
|
|
|
var
|
|
|
|
TempBuffer: array [0..pred(MAX_PATH)] of Char;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
aCanonicalPath := '';
|
|
|
|
|
2019-09-23 11:42:20 +02:00
|
|
|
if (length(aOriginalPath) > MAX_PATH) or
|
|
|
|
(Copy(aOriginalPath, 1, 4) = '\\?\') or
|
|
|
|
CustomPathIsUNC(aOriginalPath) then
|
|
|
|
exit;
|
|
|
|
|
2019-09-21 11:37:13 +02:00
|
|
|
FillChar(TempBuffer, MAX_PATH * SizeOf(Char), 0);
|
|
|
|
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
{$IFDEF DELPHI12_UP}
|
2019-09-23 11:42:20 +02:00
|
|
|
if PathCanonicalizeUnicode(@TempBuffer[0], PChar(aOriginalPath + #0)) then
|
2019-09-21 11:37:13 +02:00
|
|
|
begin
|
|
|
|
aCanonicalPath := TempBuffer;
|
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
{$ELSE}
|
2019-09-23 11:42:20 +02:00
|
|
|
if PathCanonicalizeAnsi(@TempBuffer[0], PChar(aOriginalPath + #0)) then
|
2019-09-21 11:37:13 +02:00
|
|
|
begin
|
|
|
|
aCanonicalPath := TempBuffer;
|
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
{$ENDIF}
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CustomAbsolutePath(const aPath : string; aMustExist : boolean) : string;
|
2019-11-10 19:23:39 +02:00
|
|
|
var
|
2019-09-25 17:23:16 +02:00
|
|
|
TempNewPath, TempOldPath : string;
|
2019-09-21 11:37:13 +02:00
|
|
|
begin
|
|
|
|
if (length(aPath) > 0) then
|
|
|
|
begin
|
2019-09-23 11:42:20 +02:00
|
|
|
if CustomPathIsRelative(aPath) then
|
2019-09-25 17:23:16 +02:00
|
|
|
TempOldPath := GetModulePath + aPath
|
2019-09-23 11:42:20 +02:00
|
|
|
else
|
2019-09-25 17:23:16 +02:00
|
|
|
TempOldPath := aPath;
|
|
|
|
|
|
|
|
if not(CustomPathCanonicalize(TempOldPath, TempNewPath)) then
|
|
|
|
TempNewPath := TempOldPath;
|
2019-09-23 11:42:20 +02:00
|
|
|
|
2019-09-25 17:23:16 +02:00
|
|
|
if aMustExist and not(DirectoryExists(TempNewPath)) then
|
2019-11-10 19:23:39 +02:00
|
|
|
Result := ''
|
|
|
|
else
|
2019-09-25 17:23:16 +02:00
|
|
|
Result := TempNewPath;
|
2019-09-21 11:37:13 +02:00
|
|
|
end
|
|
|
|
else
|
|
|
|
Result := '';
|
|
|
|
end;
|
|
|
|
|
2018-04-18 10:25:38 +02:00
|
|
|
function GetModulePath : string;
|
|
|
|
begin
|
2019-11-10 19:23:39 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2018-05-14 16:12:21 +02:00
|
|
|
Result := IncludeTrailingPathDelimiter(ExtractFileDir(GetModuleName(HINSTANCE{$IFDEF FPC}(){$ENDIF})));
|
2019-11-10 19:23:39 +02:00
|
|
|
{$ELSE}
|
|
|
|
// DLL filename not supported
|
|
|
|
Result := IncludeTrailingPathDelimiter(ExtractFileDir(ParamStr(0)));
|
|
|
|
{$ENDIF MSWINDOWS}
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function CefParseUrl(const url: ustring; var parts: TUrlParts): Boolean;
|
|
|
|
var
|
2018-06-11 09:01:38 +02:00
|
|
|
TempURL : TCefString;
|
|
|
|
TempParts : TCefUrlParts;
|
|
|
|
begin
|
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
begin
|
|
|
|
FillChar(TempParts, sizeof(TempParts), 0);
|
|
|
|
TempURL := CefString(url);
|
|
|
|
Result := cef_parse_url(@TempURL, TempParts) <> 0;
|
|
|
|
|
|
|
|
if Result then
|
|
|
|
begin
|
|
|
|
//parts.spec := CefString(@TempParts.spec);
|
|
|
|
parts.scheme := CefString(@TempParts.scheme);
|
|
|
|
parts.username := CefString(@TempParts.username);
|
|
|
|
parts.password := CefString(@TempParts.password);
|
|
|
|
parts.host := CefString(@TempParts.host);
|
|
|
|
parts.port := CefString(@TempParts.port);
|
|
|
|
parts.origin := CefString(@TempParts.origin);
|
|
|
|
parts.path := CefString(@TempParts.path);
|
|
|
|
parts.query := CefString(@TempParts.query);
|
|
|
|
end;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Result := False;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function CefCreateUrl(var parts: TUrlParts): ustring;
|
|
|
|
var
|
2018-06-11 09:01:38 +02:00
|
|
|
TempURL : TCefString;
|
|
|
|
TempParts : TCefUrlParts;
|
|
|
|
begin
|
|
|
|
Result := '';
|
|
|
|
|
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
begin
|
|
|
|
TempParts.spec := CefString(parts.spec);
|
|
|
|
TempParts.scheme := CefString(parts.scheme);
|
|
|
|
TempParts.username := CefString(parts.username);
|
|
|
|
TempParts.password := CefString(parts.password);
|
|
|
|
TempParts.host := CefString(parts.host);
|
|
|
|
TempParts.port := CefString(parts.port);
|
|
|
|
TempParts.origin := CefString(parts.origin);
|
|
|
|
TempParts.path := CefString(parts.path);
|
|
|
|
TempParts.query := CefString(parts.query);
|
|
|
|
|
2019-11-24 19:19:49 +02:00
|
|
|
CefStringInitialize(@TempURL);
|
|
|
|
|
|
|
|
if (cef_create_url(@TempParts, @TempURL) <> 0) then
|
|
|
|
Result := CefStringClearAndGet(@TempURL);
|
2018-06-11 09:01:38 +02:00
|
|
|
end;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function CefFormatUrlForSecurityDisplay(const originUrl: string): string;
|
|
|
|
var
|
2018-06-11 09:01:38 +02:00
|
|
|
TempOrigin : TCefString;
|
2018-04-18 10:25:38 +02:00
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
begin
|
|
|
|
TempOrigin := CefString(originUrl);
|
|
|
|
Result := CefStringFreeAndGet(cef_format_url_for_security_display(@TempOrigin));
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Result := '';
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function CefGetMimeType(const extension: ustring): ustring;
|
|
|
|
var
|
2018-06-11 09:01:38 +02:00
|
|
|
TempExt : TCefString;
|
2018-04-18 10:25:38 +02:00
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
TempExt := CefString(extension);
|
|
|
|
Result := CefStringFreeAndGet(cef_get_mime_type(@TempExt));
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure CefGetExtensionsForMimeType(const mimeType: ustring; var extensions: TStringList);
|
|
|
|
var
|
|
|
|
TempSL : ICefStringList;
|
|
|
|
TempMimeType : TCefString;
|
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (extensions <> nil) and (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
2018-04-18 10:25:38 +02:00
|
|
|
begin
|
|
|
|
TempSL := TCefStringListOwn.Create;
|
|
|
|
TempMimeType := CefString(mimeType);
|
|
|
|
cef_get_extensions_for_mime_type(@TempMimeType, TempSL.Handle);
|
|
|
|
TempSL.CopyToStrings(extensions);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CefBase64Encode(const data: Pointer; dataSize: NativeUInt): ustring;
|
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
Result := CefStringFreeAndGet(cef_base64encode(data, dataSize))
|
|
|
|
else
|
|
|
|
Result := '';
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function CefBase64Decode(const data: ustring): ICefBinaryValue;
|
|
|
|
var
|
2018-06-11 09:01:38 +02:00
|
|
|
TempData : TCefString;
|
2018-04-18 10:25:38 +02:00
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
begin
|
|
|
|
TempData := CefString(data);
|
|
|
|
Result := TCefBinaryValueRef.UnWrap(cef_base64decode(@TempData));
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Result := nil;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function CefUriEncode(const text: ustring; usePlus: Boolean): ustring;
|
|
|
|
var
|
2018-06-11 09:01:38 +02:00
|
|
|
TempText : TCefString;
|
2018-04-18 10:25:38 +02:00
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
begin
|
|
|
|
TempText := CefString(text);
|
|
|
|
Result := CefStringFreeAndGet(cef_uriencode(@TempText, Ord(usePlus)));
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Result := '';
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
2018-06-11 09:01:38 +02:00
|
|
|
function CefUriDecode(const text: ustring; convertToUtf8: Boolean; unescapeRule: TCefUriUnescapeRule): ustring;
|
2018-04-18 10:25:38 +02:00
|
|
|
var
|
2018-06-11 09:01:38 +02:00
|
|
|
TempText : TCefString;
|
2018-04-18 10:25:38 +02:00
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
begin
|
|
|
|
TempText := CefString(text);
|
|
|
|
Result := CefStringFreeAndGet(cef_uridecode(@TempText, Ord(convertToUtf8), unescapeRule));
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Result := '';
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function CefParseJson(const jsonString: ustring; options: TCefJsonParserOptions): ICefValue;
|
|
|
|
var
|
2018-06-11 09:01:38 +02:00
|
|
|
TempJSON : TCefString;
|
2018-04-18 10:25:38 +02:00
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
begin
|
|
|
|
TempJSON := CefString(jsonString);
|
|
|
|
Result := TCefValueRef.UnWrap(cef_parse_json(@TempJSON, options));
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Result := nil;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function CefParseJsonAndReturnError(const jsonString : ustring;
|
|
|
|
options : TCefJsonParserOptions;
|
|
|
|
out errorCodeOut : TCefJsonParserError;
|
|
|
|
out errorMsgOut : ustring): ICefValue;
|
|
|
|
var
|
2018-06-11 09:01:38 +02:00
|
|
|
TempJSON, TempError : TCefString;
|
2018-04-18 10:25:38 +02:00
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
begin
|
2019-11-24 19:19:49 +02:00
|
|
|
CefStringInitialize(@TempError);
|
2018-06-11 09:01:38 +02:00
|
|
|
TempJSON := CefString(jsonString);
|
|
|
|
Result := TCefValueRef.UnWrap(cef_parse_jsonand_return_error(@TempJSON, options, @errorCodeOut, @TempError));
|
2019-11-24 19:19:49 +02:00
|
|
|
errorMsgOut := CefStringClearAndGet(@TempError);
|
2018-06-11 09:01:38 +02:00
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
errorCodeOut := JSON_NO_ERROR;
|
|
|
|
Result := nil;
|
|
|
|
errorMsgOut := '';
|
|
|
|
end;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
2019-11-24 19:19:49 +02:00
|
|
|
function CefGetPath(const aPathKey : TCefPathKey) : ustring;
|
|
|
|
var
|
|
|
|
TempPath : TCefString;
|
|
|
|
begin
|
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
begin
|
|
|
|
CefStringInitialize(@TempPath);
|
|
|
|
|
|
|
|
if (cef_get_path(aPathKey, @TempPath) <> 0) then
|
|
|
|
Result := CefStringClearAndGet(@TempPath);
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Result := '';
|
|
|
|
end;
|
|
|
|
|
2018-04-18 10:25:38 +02:00
|
|
|
function CefWriteJson(const node: ICefValue; options: TCefJsonWriterOptions): ustring;
|
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
Result := CefStringFreeAndGet(cef_write_json(CefGetData(node), options))
|
|
|
|
else
|
|
|
|
Result := '';
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function CefCreateDirectory(const fullPath: ustring): Boolean;
|
|
|
|
var
|
2018-06-11 09:01:38 +02:00
|
|
|
TempPath : TCefString;
|
2018-04-18 10:25:38 +02:00
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
begin
|
|
|
|
TempPath := CefString(fullPath);
|
|
|
|
Result := cef_create_directory(@TempPath) <> 0;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Result := False;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function CefGetTempDirectory(out tempDir: ustring): Boolean;
|
|
|
|
var
|
2018-06-11 09:01:38 +02:00
|
|
|
TempPath : TCefString;
|
2018-04-18 10:25:38 +02:00
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
begin
|
2019-11-24 19:19:49 +02:00
|
|
|
CefStringInitialize(@TempPath);
|
2018-06-11 09:01:38 +02:00
|
|
|
Result := cef_get_temp_directory(@TempPath) <> 0;
|
2019-11-24 19:19:49 +02:00
|
|
|
tempDir := CefStringClearAndGet(@TempPath);
|
2018-06-11 09:01:38 +02:00
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
tempDir := '';
|
|
|
|
end;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function CefCreateNewTempDirectory(const prefix: ustring; out newTempPath: ustring): Boolean;
|
|
|
|
var
|
2018-06-11 09:01:38 +02:00
|
|
|
TempPath, TempPref : TCefString;
|
2018-04-18 10:25:38 +02:00
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
begin
|
2019-11-24 19:19:49 +02:00
|
|
|
CefStringInitialize(@TempPath);
|
2018-06-11 09:01:38 +02:00
|
|
|
TempPref := CefString(prefix);
|
|
|
|
Result := cef_create_new_temp_directory(@TempPref, @TempPath) <> 0;
|
2019-11-24 19:19:49 +02:00
|
|
|
newTempPath := CefStringClearAndGet(@TempPath);
|
2018-06-11 09:01:38 +02:00
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
newTempPath := '';
|
|
|
|
end;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
2018-06-11 09:01:38 +02:00
|
|
|
function CefCreateTempDirectoryInDirectory(const baseDir, prefix: ustring; out newDir: ustring): Boolean;
|
2018-04-18 10:25:38 +02:00
|
|
|
var
|
2018-06-11 09:01:38 +02:00
|
|
|
TempBase, TempPath, TempPref: TCefString;
|
2018-04-18 10:25:38 +02:00
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
begin
|
2019-11-24 19:19:49 +02:00
|
|
|
CefStringInitialize(@TempPath);
|
2018-06-11 09:01:38 +02:00
|
|
|
TempPref := CefString(prefix);
|
|
|
|
TempBase := CefString(baseDir);
|
|
|
|
Result := cef_create_temp_directory_in_directory(@TempBase, @TempPref, @TempPath) <> 0;
|
2019-11-24 19:19:49 +02:00
|
|
|
newDir := CefStringClearAndGet(@TempPath);
|
2018-06-11 09:01:38 +02:00
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
newDir := '';
|
|
|
|
end;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function CefDirectoryExists(const path: ustring): Boolean;
|
|
|
|
var
|
2018-06-11 09:01:38 +02:00
|
|
|
TempPath : TCefString;
|
2018-04-18 10:25:38 +02:00
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
begin
|
|
|
|
TempPath := CefString(path);
|
|
|
|
Result := cef_directory_exists(@TempPath) <> 0;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Result := False;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function CefDeleteFile(const path: ustring; recursive: Boolean): Boolean;
|
|
|
|
var
|
2018-06-11 09:01:38 +02:00
|
|
|
TempPath : TCefString;
|
2018-04-18 10:25:38 +02:00
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
begin
|
|
|
|
TempPath := CefString(path);
|
|
|
|
Result := cef_delete_file(@TempPath, Ord(recursive)) <> 0;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Result := False;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function CefZipDirectory(const srcDir, destFile: ustring; includeHiddenFiles: Boolean): Boolean;
|
|
|
|
var
|
2018-06-11 09:01:38 +02:00
|
|
|
TempSrc, TempDst : TCefString;
|
2018-04-18 10:25:38 +02:00
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
begin
|
|
|
|
TempSrc := CefString(srcDir);
|
|
|
|
TempDst := CefString(destFile);
|
|
|
|
Result := cef_zip_directory(@TempSrc, @TempDst, Ord(includeHiddenFiles)) <> 0;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Result := False;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure CefLoadCRLSetsFile(const path : ustring);
|
|
|
|
var
|
|
|
|
TempPath : TCefString;
|
|
|
|
begin
|
2018-06-11 09:01:38 +02:00
|
|
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
|
|
begin
|
|
|
|
TempPath := CefString(path);
|
|
|
|
cef_load_crlsets_file(@TempPath);
|
|
|
|
end;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
2019-01-08 20:15:25 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2018-04-18 10:25:38 +02:00
|
|
|
function CefIsKeyDown(aWparam : WPARAM) : boolean;
|
|
|
|
begin
|
|
|
|
Result := (GetKeyState(aWparam) < 0);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CefIsKeyToggled(aWparam : WPARAM) : boolean;
|
|
|
|
begin
|
|
|
|
Result := (GetKeyState(aWparam) and $1) <> 0;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function GetCefMouseModifiers(aWparam : WPARAM) : TCefEventFlags;
|
|
|
|
begin
|
|
|
|
Result := EVENTFLAG_NONE;
|
|
|
|
|
|
|
|
if ((aWparam and MK_CONTROL) <> 0) then Result := Result or EVENTFLAG_CONTROL_DOWN;
|
|
|
|
if ((aWparam and MK_SHIFT) <> 0) then Result := Result or EVENTFLAG_SHIFT_DOWN;
|
|
|
|
if ((aWparam and MK_LBUTTON) <> 0) then Result := Result or EVENTFLAG_LEFT_MOUSE_BUTTON;
|
|
|
|
if ((aWparam and MK_MBUTTON) <> 0) then Result := Result or EVENTFLAG_MIDDLE_MOUSE_BUTTON;
|
|
|
|
if ((aWparam and MK_RBUTTON) <> 0) then Result := Result or EVENTFLAG_RIGHT_MOUSE_BUTTON;
|
|
|
|
if CefIsKeyDown(VK_MENU) then Result := Result or EVENTFLAG_ALT_DOWN;
|
|
|
|
if CefIsKeyToggled(VK_NUMLOCK) then Result := Result or EVENTFLAG_NUM_LOCK_ON;
|
|
|
|
if CefIsKeyToggled(VK_CAPITAL) then Result := Result or EVENTFLAG_CAPS_LOCK_ON;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function GetCefMouseModifiers : TCefEventFlags;
|
|
|
|
begin
|
|
|
|
Result := EVENTFLAG_NONE;
|
|
|
|
|
|
|
|
if CefIsKeyDown(MK_CONTROL) then Result := Result or EVENTFLAG_CONTROL_DOWN;
|
|
|
|
if CefIsKeyDown(MK_SHIFT) then Result := Result or EVENTFLAG_SHIFT_DOWN;
|
|
|
|
if CefIsKeyDown(MK_LBUTTON) then Result := Result or EVENTFLAG_LEFT_MOUSE_BUTTON;
|
|
|
|
if CefIsKeyDown(MK_MBUTTON) then Result := Result or EVENTFLAG_MIDDLE_MOUSE_BUTTON;
|
|
|
|
if CefIsKeyDown(MK_RBUTTON) then Result := Result or EVENTFLAG_RIGHT_MOUSE_BUTTON;
|
|
|
|
if CefIsKeyDown(VK_MENU) then Result := Result or EVENTFLAG_ALT_DOWN;
|
|
|
|
if CefIsKeyToggled(VK_NUMLOCK) then Result := Result or EVENTFLAG_NUM_LOCK_ON;
|
|
|
|
if CefIsKeyToggled(VK_CAPITAL) then Result := Result or EVENTFLAG_CAPS_LOCK_ON;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function GetCefKeyboardModifiers(aWparam : WPARAM; aLparam : LPARAM) : TCefEventFlags;
|
|
|
|
begin
|
|
|
|
Result := EVENTFLAG_NONE;
|
|
|
|
|
|
|
|
if CefIsKeyDown(VK_SHIFT) then Result := Result or EVENTFLAG_SHIFT_DOWN;
|
|
|
|
if CefIsKeyDown(VK_CONTROL) then Result := Result or EVENTFLAG_CONTROL_DOWN;
|
|
|
|
if CefIsKeyDown(VK_MENU) then Result := Result or EVENTFLAG_ALT_DOWN;
|
|
|
|
if CefIsKeyToggled(VK_NUMLOCK) then Result := Result or EVENTFLAG_NUM_LOCK_ON;
|
|
|
|
if CefIsKeyToggled(VK_CAPITAL) then Result := Result or EVENTFLAG_CAPS_LOCK_ON;
|
|
|
|
|
|
|
|
|
|
|
|
case aWparam of
|
|
|
|
VK_RETURN:
|
|
|
|
if (((aLparam shr 16) and KF_EXTENDED) <> 0) then Result := Result or EVENTFLAG_IS_KEY_PAD;
|
|
|
|
|
|
|
|
VK_INSERT,
|
|
|
|
VK_DELETE,
|
|
|
|
VK_HOME,
|
|
|
|
VK_END,
|
|
|
|
VK_PRIOR,
|
|
|
|
VK_NEXT,
|
|
|
|
VK_UP,
|
|
|
|
VK_DOWN,
|
|
|
|
VK_LEFT,
|
|
|
|
VK_RIGHT :
|
|
|
|
if (((aLparam shr 16) and KF_EXTENDED) = 0) then Result := Result or EVENTFLAG_IS_KEY_PAD;
|
|
|
|
|
|
|
|
VK_NUMLOCK,
|
|
|
|
VK_NUMPAD0,
|
|
|
|
VK_NUMPAD1,
|
|
|
|
VK_NUMPAD2,
|
|
|
|
VK_NUMPAD3,
|
|
|
|
VK_NUMPAD4,
|
|
|
|
VK_NUMPAD5,
|
|
|
|
VK_NUMPAD6,
|
|
|
|
VK_NUMPAD7,
|
|
|
|
VK_NUMPAD8,
|
|
|
|
VK_NUMPAD9,
|
|
|
|
VK_DIVIDE,
|
|
|
|
VK_MULTIPLY,
|
|
|
|
VK_SUBTRACT,
|
|
|
|
VK_ADD,
|
|
|
|
VK_DECIMAL,
|
|
|
|
VK_CLEAR :
|
|
|
|
Result := Result or EVENTFLAG_IS_KEY_PAD;
|
|
|
|
|
|
|
|
VK_SHIFT :
|
|
|
|
if CefIsKeyDown(VK_LSHIFT) then
|
|
|
|
Result := Result or EVENTFLAG_IS_LEFT
|
|
|
|
else
|
|
|
|
if CefIsKeyDown(VK_RSHIFT) then
|
|
|
|
Result := Result or EVENTFLAG_IS_RIGHT;
|
|
|
|
|
|
|
|
VK_CONTROL :
|
|
|
|
if CefIsKeyDown(VK_LCONTROL) then
|
|
|
|
Result := Result or EVENTFLAG_IS_LEFT
|
|
|
|
else
|
|
|
|
if CefIsKeyDown(VK_RCONTROL) then
|
|
|
|
Result := Result or EVENTFLAG_IS_RIGHT;
|
|
|
|
|
|
|
|
VK_MENU :
|
|
|
|
if CefIsKeyDown(VK_LMENU) then
|
|
|
|
Result := Result or EVENTFLAG_IS_LEFT
|
|
|
|
else
|
|
|
|
if CefIsKeyDown(VK_RMENU) then
|
|
|
|
Result := Result or EVENTFLAG_IS_RIGHT;
|
|
|
|
|
|
|
|
VK_LWIN :
|
|
|
|
Result := Result or EVENTFLAG_IS_LEFT;
|
|
|
|
|
|
|
|
VK_RWIN :
|
|
|
|
Result := Result or EVENTFLAG_IS_RIGHT;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure DropEffectToDragOperation(aEffect: Longint; var aAllowedOps : TCefDragOperations);
|
|
|
|
begin
|
|
|
|
aAllowedOps := DRAG_OPERATION_NONE;
|
|
|
|
|
|
|
|
if ((aEffect and DROPEFFECT_COPY) <> 0) then aAllowedOps := aAllowedOps or DRAG_OPERATION_COPY;
|
|
|
|
if ((aEffect and DROPEFFECT_LINK) <> 0) then aAllowedOps := aAllowedOps or DRAG_OPERATION_LINK;
|
|
|
|
if ((aEffect and DROPEFFECT_MOVE) <> 0) then aAllowedOps := aAllowedOps or DRAG_OPERATION_MOVE;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure DragOperationToDropEffect(const aDragOperations : TCefDragOperations; var aEffect: Longint);
|
|
|
|
begin
|
|
|
|
aEffect := DROPEFFECT_NONE;
|
|
|
|
|
|
|
|
if ((aDragOperations and DRAG_OPERATION_COPY) <> 0) then aEffect := aEffect or DROPEFFECT_COPY;
|
|
|
|
if ((aDragOperations and DRAG_OPERATION_LINK) <> 0) then aEffect := aEffect or DROPEFFECT_LINK;
|
|
|
|
if ((aDragOperations and DRAG_OPERATION_MOVE) <> 0) then aEffect := aEffect or DROPEFFECT_MOVE;
|
2019-01-08 20:15:25 +02:00
|
|
|
end;
|
|
|
|
{$ENDIF}
|
2018-04-18 10:25:38 +02:00
|
|
|
|
|
|
|
function DeviceToLogical(aValue : integer; const aDeviceScaleFactor : double) : integer;
|
|
|
|
begin
|
|
|
|
Result := floor(aValue / aDeviceScaleFactor);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure DeviceToLogical(var aEvent : TCEFMouseEvent; const aDeviceScaleFactor : double);
|
|
|
|
begin
|
|
|
|
aEvent.x := DeviceToLogical(aEvent.x, aDeviceScaleFactor);
|
|
|
|
aEvent.y := DeviceToLogical(aEvent.y, aDeviceScaleFactor);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure DeviceToLogical(var aPoint : TPoint; const aDeviceScaleFactor : double);
|
|
|
|
begin
|
|
|
|
aPoint.x := DeviceToLogical(aPoint.x, aDeviceScaleFactor);
|
|
|
|
aPoint.y := DeviceToLogical(aPoint.y, aDeviceScaleFactor);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function LogicalToDevice(aValue : integer; const aDeviceScaleFactor : double) : integer;
|
|
|
|
begin
|
|
|
|
Result := floor(aValue * aDeviceScaleFactor);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure LogicalToDevice(var aRect : TCEFRect; const aDeviceScaleFactor : double);
|
|
|
|
begin
|
|
|
|
aRect.x := LogicalToDevice(aRect.x, aDeviceScaleFactor);
|
|
|
|
aRect.y := LogicalToDevice(aRect.y, aDeviceScaleFactor);
|
|
|
|
aRect.width := LogicalToDevice(aRect.width, aDeviceScaleFactor);
|
|
|
|
aRect.height := LogicalToDevice(aRect.height, aDeviceScaleFactor);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function GetScreenDPI : integer;
|
2019-01-08 20:15:25 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2018-04-18 10:25:38 +02:00
|
|
|
var
|
|
|
|
TempDC : HDC;
|
2019-01-08 20:15:25 +02:00
|
|
|
{$ENDIF}
|
2018-04-18 10:25:38 +02:00
|
|
|
begin
|
2019-01-08 20:15:25 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2018-04-18 10:25:38 +02:00
|
|
|
TempDC := GetDC(0);
|
|
|
|
Result := GetDeviceCaps(TempDC, LOGPIXELSX);
|
|
|
|
ReleaseDC(0, TempDC);
|
2019-01-08 20:15:25 +02:00
|
|
|
{$ELSE}
|
|
|
|
Result := screen.PrimaryMonitor.PixelsPerInch;
|
|
|
|
{$ENDIF}
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function GetDeviceScaleFactor : single;
|
|
|
|
begin
|
|
|
|
Result := GetScreenDPI / 96;
|
|
|
|
end;
|
|
|
|
|
2019-06-19 16:53:26 +02:00
|
|
|
function DeleteDirContents(const aDirectory : string; const aExcludeFiles : TStringList) : boolean;
|
2018-09-18 16:19:21 +02:00
|
|
|
var
|
|
|
|
TempRec : TSearchRec;
|
|
|
|
TempPath : string;
|
2019-06-19 16:53:26 +02:00
|
|
|
TempIdx : integer;
|
2018-09-18 16:19:21 +02:00
|
|
|
begin
|
|
|
|
Result := True;
|
|
|
|
|
|
|
|
try
|
|
|
|
if (length(aDirectory) > 0) and
|
|
|
|
DirectoryExists(aDirectory) and
|
|
|
|
(FindFirst(aDirectory + '\*', faAnyFile, TempRec) = 0) then
|
|
|
|
try
|
|
|
|
repeat
|
|
|
|
TempPath := aDirectory + PathDelim + TempRec.Name;
|
|
|
|
|
|
|
|
if ((TempRec.Attr and faDirectory) <> 0) then
|
|
|
|
begin
|
|
|
|
if (TempRec.Name <> '.') and (TempRec.Name <> '..') then
|
|
|
|
begin
|
2019-06-19 16:53:26 +02:00
|
|
|
if DeleteDirContents(TempPath, aExcludeFiles) then
|
2018-09-18 16:19:21 +02:00
|
|
|
Result := RemoveDir(TempPath) and Result
|
|
|
|
else
|
|
|
|
Result := False;
|
|
|
|
end;
|
|
|
|
end
|
|
|
|
else
|
2019-06-19 16:53:26 +02:00
|
|
|
if (aExcludeFiles <> nil) then
|
|
|
|
begin
|
|
|
|
TempIdx := aExcludeFiles.IndexOf(TempRec.Name);
|
|
|
|
Result := ((TempIdx >= 0) or
|
|
|
|
((TempIdx < 0) and DeleteFile(TempPath))) and
|
|
|
|
Result;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Result := DeleteFile(TempPath) and Result;
|
|
|
|
|
2018-09-18 16:19:21 +02:00
|
|
|
until (FindNext(TempRec) <> 0) or not(Result);
|
|
|
|
finally
|
|
|
|
FindClose(TempRec);
|
|
|
|
end;
|
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('DeleteDirContents', e) then raise;
|
|
|
|
end;
|
2018-09-18 15:19:44 +02:00
|
|
|
end;
|
|
|
|
|
2019-06-19 16:53:26 +02:00
|
|
|
function DeleteFileList(const aFileList : TStringList) : boolean;
|
|
|
|
var
|
|
|
|
i, TempCount : integer;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
|
|
|
|
try
|
|
|
|
if (aFileList <> nil) then
|
|
|
|
begin
|
|
|
|
i := 0;
|
|
|
|
TempCount := 0;
|
|
|
|
|
|
|
|
while (i < aFileList.Count) do
|
|
|
|
begin
|
|
|
|
if FileExists(aFileList[i]) and DeleteFile(aFileList[i]) then inc(TempCount);
|
|
|
|
inc(i);
|
|
|
|
end;
|
|
|
|
|
|
|
|
Result := (aFileList.Count = TempCount);
|
|
|
|
end;
|
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('DeleteFileList', e) then raise;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function MoveFileList(const aFileList : TStringList; const aSrcDirectory, aDstDirectory : string) : boolean;
|
|
|
|
var
|
|
|
|
i, TempCount : integer;
|
|
|
|
TempSrcPath, TempDstPath : string;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
|
|
|
|
try
|
|
|
|
if (aFileList <> nil) and
|
|
|
|
(length(aSrcDirectory) > 0) and
|
2019-11-10 19:23:39 +02:00
|
|
|
(length(aDstDirectory) > 0) and
|
|
|
|
DirectoryExists(aSrcDirectory) and
|
2019-06-19 16:53:26 +02:00
|
|
|
(DirectoryExists(aDstDirectory) or CreateDir(aDstDirectory)) then
|
|
|
|
begin
|
|
|
|
i := 0;
|
|
|
|
TempCount := 0;
|
|
|
|
|
|
|
|
while (i < aFileList.Count) do
|
|
|
|
begin
|
2019-11-10 19:23:39 +02:00
|
|
|
TempSrcPath := IncludeTrailingPathDelimiter(aSrcDirectory) + aFileList[i];
|
|
|
|
TempDstPath := IncludeTrailingPathDelimiter(aDstDirectory) + aFileList[i];
|
|
|
|
|
2019-06-19 16:53:26 +02:00
|
|
|
if FileExists(TempSrcPath) and RenameFile(TempSrcPath, TempDstPath) then inc(TempCount);
|
|
|
|
|
|
|
|
inc(i);
|
|
|
|
end;
|
|
|
|
|
|
|
|
Result := (aFileList.Count = TempCount);
|
|
|
|
end;
|
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('MoveFileList', e) then raise;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2019-10-13 18:50:23 +02:00
|
|
|
function CefGetDataURI(const aString, aMimeType : ustring) : ustring;
|
|
|
|
var
|
|
|
|
TempUTF : AnsiString;
|
|
|
|
begin
|
|
|
|
TempUTF := UTF8Encode(aString);
|
|
|
|
|
|
|
|
if (length(TempUTF) > 0) then
|
|
|
|
Result := CefGetDataURI(@TempUTF[1], length(TempUTF), aMimeType, 'utf-8')
|
|
|
|
else
|
|
|
|
Result := '';
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CefGetDataURI(aData : pointer; aSize : integer; const aMimeType, aCharset : ustring) : ustring;
|
|
|
|
begin
|
|
|
|
Result := 'data:' + aMimeType;
|
|
|
|
|
|
|
|
if (length(aCharset) > 0) then Result := Result + ';charset=' + aCharset;
|
|
|
|
|
|
|
|
Result := Result + ';base64,' + CefURIEncode(CefBase64Encode(aData, aSize), false);
|
|
|
|
end;
|
|
|
|
|
2018-04-18 10:25:38 +02:00
|
|
|
end.
|