1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2025-11-23 21:34:53 +02:00

Added ConsoleBrowser2 and WebpageSnapshot demos

- Split the Lazarus demos directory into "Lazarus_Windows" and "Lazarus_Linux".
- Added OSRExternalPumpBrowser and TinyBrowser2 demos to "Lazarus_Linux".
- Set TBufferPanel.GetScreenScale as virtual.
- Added DevTools to the SchemeRegistrationBrowser demo.
- Modified the SchemeRegistrationBrowser demo to receive XMLHttpRequest requests from JavaScript.
This commit is contained in:
Salvador Diaz Fau
2020-12-13 18:36:10 +01:00
parent 8f55182540
commit 1299a6f596
390 changed files with 12796 additions and 370 deletions

View File

@@ -0,0 +1,2 @@
rmdir /S /Q lib
rmdir /S /Q backup

View File

@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasUsesSectionForAllUnits Value="False"/>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="URLRequest"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes Count="1">
<Item1 Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
<Modes Count="0"/>
</RunParams>
<RequiredPackages Count="2">
<Item1>
<PackageName Value="CEF4Delphi_Lazarus"/>
</Item1>
<Item2>
<PackageName Value="LCL"/>
</Item2>
</RequiredPackages>
<Units Count="2">
<Unit0>
<Filename Value="URLRequest.lpr"/>
<IsPartOfProject Value="True"/>
</Unit0>
<Unit1>
<Filename Value="uURLRequest.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="URLRequestFrm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
</Unit1>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="..\..\..\bin"/>
</SearchPaths>
<Parsing>
<SyntaxOptions>
<SyntaxMode Value="Delphi"/>
</SyntaxOptions>
</Parsing>
<Linking>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
<Other>
<CustomOptions Value="-dBorland -dVer150 -dDelphi7 -dCompiler6_Up -dPUREPASCAL"/>
</Other>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">
<Item1>
<Name Value="EAbort"/>
</Item1>
<Item2>
<Name Value="ECodetoolError"/>
</Item2>
<Item3>
<Name Value="EFOpenError"/>
</Item3>
</Exceptions>
</Debugging>
</CONFIG>

View File

@@ -0,0 +1,75 @@
// ************************************************************************
// ***************************** CEF4Delphi *******************************
// ************************************************************************
//
// CEF4Delphi is based on DCEF3 which uses CEF3 to embed a chromium-based
// 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
//
// Copyright © 2018 Salvador Díaz Fau. All rights reserved.
//
// ************************************************************************
// ************ 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.
*
*)
program URLRequest;
{$MODE Delphi}
{$I cef.inc}
uses
{$IFDEF DELPHI16_UP}
Vcl.Forms,
WinApi.Windows,
{$ELSE}
Forms,
LCLIntf, LCLType, LMessages, Interfaces,
{$ENDIF }
uCEFApplication,
uURLRequest in 'uURLRequest.pas' {URLRequestFrm};
{.$R *.res}
// CEF3 needs to set the LARGEADDRESSAWARE flag which allows 32-bit processes to use up to 3GB of RAM.
// If you don't add this flag the rederer process will crash when you try to load large images.
{$SetPEFlags $20}
begin
CreateGlobalCEFApp;
if GlobalCEFApp.StartMainProcess then
begin
Application.Initialize;
{$IFDEF DELPHI11_UP}
Application.MainFormOnTaskbar := True;
{$ENDIF}
Application.CreateForm(TURLRequestFrm, URLRequestFrm);
Application.Run;
end;
DestroyGlobalCEFApp;
end.

View File

@@ -0,0 +1,131 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="11"/>
<BuildModes Active="Default"/>
<Units Count="6">
<Unit0>
<Filename Value="URLRequest.lpr"/>
<IsPartOfProject Value="True"/>
<TopLine Value="44"/>
<CursorPos X="17" Y="59"/>
<UsageCount Value="21"/>
<Loaded Value="True"/>
<DefaultSyntaxHighlighter Value="Delphi"/>
</Unit0>
<Unit1>
<Filename Value="uURLRequest.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="URLRequestFrm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="1"/>
<TopLine Value="187"/>
<CursorPos Y="207"/>
<UsageCount Value="21"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
<DefaultSyntaxHighlighter Value="Delphi"/>
</Unit1>
<Unit2>
<Filename Value="..\..\..\source\uCEFAudioHandler.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="40"/>
<CursorPos X="54" Y="55"/>
<UsageCount Value="10"/>
</Unit2>
<Unit3>
<Filename Value="..\..\..\source\uCEFUrlRequestClientComponent.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="179"/>
<CursorPos Y="208"/>
<UsageCount Value="10"/>
</Unit3>
<Unit4>
<Filename Value="..\..\..\source\uCEFInterfaces.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="1857"/>
<CursorPos X="3" Y="1872"/>
<UsageCount Value="10"/>
</Unit4>
<Unit5>
<Filename Value="..\..\..\source\uCEFSentinel.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="266"/>
<CursorPos X="23" Y="292"/>
<UsageCount Value="10"/>
</Unit5>
</Units>
<JumpHistory Count="16" HistoryIndex="15">
<Position1>
<Filename Value="uURLRequest.pas"/>
</Position1>
<Position2>
<Filename Value="uURLRequest.pas"/>
<Caret Line="147" Column="3" TopLine="133"/>
</Position2>
<Position3>
<Filename Value="uURLRequest.pas"/>
<Caret Line="107" Column="15" TopLine="93"/>
</Position3>
<Position4>
<Filename Value="uURLRequest.pas"/>
<Caret Line="228" Column="3" TopLine="226"/>
</Position4>
<Position5>
<Filename Value="uURLRequest.pas"/>
<Caret Line="313" Column="3" TopLine="311"/>
</Position5>
<Position6>
<Filename Value="uURLRequest.pas"/>
<Caret Line="330" Column="3" TopLine="311"/>
</Position6>
<Position7>
<Filename Value="uURLRequest.pas"/>
<Caret Line="344" Column="3" TopLine="55"/>
</Position7>
<Position8>
<Filename Value="uURLRequest.pas"/>
<Caret Line="69" Column="39" TopLine="55"/>
</Position8>
<Position9>
<Filename Value="uURLRequest.pas"/>
<Caret Line="195" Column="40" TopLine="171"/>
</Position9>
<Position10>
<Filename Value="uURLRequest.pas"/>
<Caret Line="251" Column="73" TopLine="227"/>
</Position10>
<Position11>
<Filename Value="uURLRequest.pas"/>
<Caret Line="301" Column="77" TopLine="277"/>
</Position11>
<Position12>
<Filename Value="uURLRequest.pas"/>
<Caret Line="413" Column="61" TopLine="390"/>
</Position12>
<Position13>
<Filename Value="uURLRequest.pas"/>
<Caret Line="215" TopLine="215"/>
</Position13>
<Position14>
<Filename Value="uURLRequest.pas"/>
<Caret Line="226" Column="64" TopLine="205"/>
</Position14>
<Position15>
<Filename Value="uURLRequest.pas"/>
<Caret Line="361" Column="23" TopLine="335"/>
</Position15>
<Position16>
<Filename Value="uURLRequest.pas"/>
<Caret Line="360" Column="23" TopLine="334"/>
</Position16>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes Count="0" ActiveMode=""/>
</RunParams>
</ProjectSession>
</CONFIG>

View File

@@ -0,0 +1,456 @@
// ************************************************************************
// ***************************** CEF4Delphi *******************************
// ************************************************************************
//
// CEF4Delphi is based on DCEF3 which uses CEF3 to embed a chromium-based
// 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
//
// Copyright � 2017 Salvador Diaz Fau. All rights reserved.
//
// ************************************************************************
// ************ 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.
*
*)
// The complete list of compiler versions is here :
// http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Compiler_Versions
{$DEFINE DELPHI_VERSION_UNKNOW}
// Delphi 5
{$IFDEF VER130}
{$UNDEF DELPHI_VERSION_UNKNOW}
{$DEFINE DELPHI5_UP}
{$ENDIF}
// Delphi 6
{$IFDEF VER140}
{$UNDEF DELPHI_VERSION_UNKNOW}
{$DEFINE DELPHI5_UP}
{$DEFINE DELPHI6_UP}
{$ENDIF}
// Delphi 7
{$IFDEF VER150}
{$UNDEF DELPHI_VERSION_UNKNOW}
{$DEFINE DELPHI5_UP}
{$DEFINE DELPHI6_UP}
{$DEFINE DELPHI7_UP}
{$ENDIF}
// Delphi 8
{$IFDEF VER160}
{$UNDEF DELPHI_VERSION_UNKNOW}
{$DEFINE DELPHI5_UP}
{$DEFINE DELPHI6_UP}
{$DEFINE DELPHI7_UP}
{$DEFINE DELPHI8_UP}
{$ENDIF}
// Delphi 2005
{$IFDEF VER170}
{$UNDEF DELPHI_VERSION_UNKNOW}
{$DEFINE DELPHI5_UP}
{$DEFINE DELPHI6_UP}
{$DEFINE DELPHI7_UP}
{$DEFINE DELPHI8_UP}
{$DEFINE DELPHI9_UP}
{$ENDIF}
{$IFDEF VER180}
{$UNDEF DELPHI_VERSION_UNKNOW}
// Delphi 2007
{$IFDEF VER185}
{$DEFINE DELPHI5_UP}
{$DEFINE DELPHI6_UP}
{$DEFINE DELPHI7_UP}
{$DEFINE DELPHI8_UP}
{$DEFINE DELPHI9_UP}
{$DEFINE DELPHI10_UP}
{$DEFINE DELPHI11_UP}
// Delphi 2006
{$ELSE}
{$DEFINE DELPHI5_UP}
{$DEFINE DELPHI6_UP}
{$DEFINE DELPHI7_UP}
{$DEFINE DELPHI8_UP}
{$DEFINE DELPHI9_UP}
{$DEFINE DELPHI10_UP}
{$ENDIF}
{$ENDIF}
// Delphi 2009
{$IFDEF VER200}
{$UNDEF DELPHI_VERSION_UNKNOW}
{$DEFINE DELPHI5_UP}
{$DEFINE DELPHI6_UP}
{$DEFINE DELPHI7_UP}
{$DEFINE DELPHI8_UP}
{$DEFINE DELPHI9_UP}
{$DEFINE DELPHI10_UP}
{$DEFINE DELPHI11_UP}
{$DEFINE DELPHI12_UP}
{$ENDIF}
//Delphi 2010
{$IFDEF VER210}
{$UNDEF DELPHI_VERSION_UNKNOW}
{$DEFINE DELPHI5_UP}
{$DEFINE DELPHI6_UP}
{$DEFINE DELPHI7_UP}
{$DEFINE DELPHI8_UP}
{$DEFINE DELPHI9_UP}
{$DEFINE DELPHI10_UP}
{$DEFINE DELPHI11_UP}
{$DEFINE DELPHI12_UP}
{$DEFINE DELPHI14_UP}
{$ENDIF}
// Delphi XE
{$IFDEF VER220}
{$UNDEF DELPHI_VERSION_UNKNOW}
{$DEFINE DELPHI5_UP}
{$DEFINE DELPHI6_UP}
{$DEFINE DELPHI7_UP}
{$DEFINE DELPHI8_UP}
{$DEFINE DELPHI9_UP}
{$DEFINE DELPHI10_UP}
{$DEFINE DELPHI11_UP}
{$DEFINE DELPHI12_UP}
{$DEFINE DELPHI14_UP}
{$DEFINE DELPHI15_UP}
{$ENDIF}
// Delphi XE2 (First FireMonkey and 64bit compiler)
{$IFDEF VER230}
{$UNDEF DELPHI_VERSION_UNKNOW}
{$DEFINE DELPHI5_UP}
{$DEFINE DELPHI6_UP}
{$DEFINE DELPHI7_UP}
{$DEFINE DELPHI8_UP}
{$DEFINE DELPHI9_UP}
{$DEFINE DELPHI10_UP}
{$DEFINE DELPHI11_UP}
{$DEFINE DELPHI12_UP}
{$DEFINE DELPHI14_UP}
{$DEFINE DELPHI15_UP}
{$DEFINE DELPHI16_UP}
{$ENDIF}
// Delphi XE3
{$IFDEF VER240}
{$UNDEF DELPHI_VERSION_UNKNOW}
{$DEFINE DELPHI5_UP}
{$DEFINE DELPHI6_UP}
{$DEFINE DELPHI7_UP}
{$DEFINE DELPHI8_UP}
{$DEFINE DELPHI9_UP}
{$DEFINE DELPHI10_UP}
{$DEFINE DELPHI11_UP}
{$DEFINE DELPHI12_UP}
{$DEFINE DELPHI14_UP}
{$DEFINE DELPHI15_UP}
{$DEFINE DELPHI16_UP}
{$DEFINE DELPHI17_UP}
{$ENDIF}
// Delphi XE4
{$IFDEF VER250}
{$UNDEF DELPHI_VERSION_UNKNOW}
{$DEFINE DELPHI5_UP}
{$DEFINE DELPHI6_UP}
{$DEFINE DELPHI7_UP}
{$DEFINE DELPHI8_UP}
{$DEFINE DELPHI9_UP}
{$DEFINE DELPHI10_UP}
{$DEFINE DELPHI11_UP}
{$DEFINE DELPHI12_UP}
{$DEFINE DELPHI14_UP}
{$DEFINE DELPHI15_UP}
{$DEFINE DELPHI16_UP}
{$DEFINE DELPHI17_UP}
{$DEFINE DELPHI18_UP}
{$ENDIF}
// Delphi XE5
{$IFDEF VER260}
{$UNDEF DELPHI_VERSION_UNKNOW}
{$DEFINE DELPHI5_UP}
{$DEFINE DELPHI6_UP}
{$DEFINE DELPHI7_UP}
{$DEFINE DELPHI8_UP}
{$DEFINE DELPHI9_UP}
{$DEFINE DELPHI10_UP}
{$DEFINE DELPHI11_UP}
{$DEFINE DELPHI12_UP}
{$DEFINE DELPHI14_UP}
{$DEFINE DELPHI15_UP}
{$DEFINE DELPHI16_UP}
{$DEFINE DELPHI17_UP}
{$DEFINE DELPHI18_UP}
{$DEFINE DELPHI19_UP}
{$ENDIF}
// Delphi XE6
{$IFDEF VER270}
{$UNDEF DELPHI_VERSION_UNKNOW}
{$DEFINE DELPHI5_UP}
{$DEFINE DELPHI6_UP}
{$DEFINE DELPHI7_UP}
{$DEFINE DELPHI8_UP}
{$DEFINE DELPHI9_UP}
{$DEFINE DELPHI10_UP}
{$DEFINE DELPHI11_UP}
{$DEFINE DELPHI12_UP}
{$DEFINE DELPHI14_UP}
{$DEFINE DELPHI15_UP}
{$DEFINE DELPHI16_UP}
{$DEFINE DELPHI17_UP}
{$DEFINE DELPHI18_UP}
{$DEFINE DELPHI19_UP}
{$DEFINE DELPHI20_UP}
{$ENDIF}
// Delphi XE7
{$IFDEF VER280}
{$UNDEF DELPHI_VERSION_UNKNOW}
{$DEFINE DELPHI5_UP}
{$DEFINE DELPHI6_UP}
{$DEFINE DELPHI7_UP}
{$DEFINE DELPHI8_UP}
{$DEFINE DELPHI9_UP}
{$DEFINE DELPHI10_UP}
{$DEFINE DELPHI11_UP}
{$DEFINE DELPHI12_UP}
{$DEFINE DELPHI14_UP}
{$DEFINE DELPHI15_UP}
{$DEFINE DELPHI16_UP}
{$DEFINE DELPHI17_UP}
{$DEFINE DELPHI18_UP}
{$DEFINE DELPHI19_UP}
{$DEFINE DELPHI20_UP}
{$DEFINE DELPHI21_UP}
{$ENDIF}
// Delphi XE8
{$IFDEF VER290}
{$UNDEF DELPHI_VERSION_UNKNOW}
{$DEFINE DELPHI5_UP}
{$DEFINE DELPHI6_UP}
{$DEFINE DELPHI7_UP}
{$DEFINE DELPHI8_UP}
{$DEFINE DELPHI9_UP}
{$DEFINE DELPHI10_UP}
{$DEFINE DELPHI11_UP}
{$DEFINE DELPHI12_UP}
{$DEFINE DELPHI14_UP}
{$DEFINE DELPHI15_UP}
{$DEFINE DELPHI16_UP}
{$DEFINE DELPHI17_UP}
{$DEFINE DELPHI18_UP}
{$DEFINE DELPHI19_UP}
{$DEFINE DELPHI20_UP}
{$DEFINE DELPHI21_UP}
{$DEFINE DELPHI22_UP}
{$ENDIF VER290}
// Rad Studio 10 - Delphi Seattle
{$IFDEF VER300}
{$UNDEF DELPHI_VERSION_UNKNOW}
{$DEFINE DELPHI5_UP}
{$DEFINE DELPHI6_UP}
{$DEFINE DELPHI7_UP}
{$DEFINE DELPHI8_UP}
{$DEFINE DELPHI9_UP}
{$DEFINE DELPHI10_UP}
{$DEFINE DELPHI11_UP}
{$DEFINE DELPHI12_UP}
{$DEFINE DELPHI14_UP}
{$DEFINE DELPHI15_UP}
{$DEFINE DELPHI16_UP}
{$DEFINE DELPHI17_UP}
{$DEFINE DELPHI18_UP}
{$DEFINE DELPHI19_UP}
{$DEFINE DELPHI20_UP}
{$DEFINE DELPHI21_UP}
{$DEFINE DELPHI22_UP}
{$DEFINE DELPHI23_UP}
{$ENDIF}
// Rad Studio 10.1 - Delphi Berlin
{$IFDEF VER310}
{$UNDEF DELPHI_VERSION_UNKNOW}
{$DEFINE DELPHI5_UP}
{$DEFINE DELPHI6_UP}
{$DEFINE DELPHI7_UP}
{$DEFINE DELPHI8_UP}
{$DEFINE DELPHI9_UP}
{$DEFINE DELPHI10_UP}
{$DEFINE DELPHI11_UP}
{$DEFINE DELPHI12_UP}
{$DEFINE DELPHI14_UP}
{$DEFINE DELPHI15_UP}
{$DEFINE DELPHI16_UP}
{$DEFINE DELPHI17_UP}
{$DEFINE DELPHI18_UP}
{$DEFINE DELPHI19_UP}
{$DEFINE DELPHI20_UP}
{$DEFINE DELPHI21_UP}
{$DEFINE DELPHI22_UP}
{$DEFINE DELPHI23_UP}
{$DEFINE DELPHI24_UP}
{$ENDIF}
// Rad Studio 10.2 - Delphi Tokyo
{$IFDEF VER320}
{$UNDEF DELPHI_VERSION_UNKNOW}
{$DEFINE DELPHI5_UP}
{$DEFINE DELPHI6_UP}
{$DEFINE DELPHI7_UP}
{$DEFINE DELPHI8_UP}
{$DEFINE DELPHI9_UP}
{$DEFINE DELPHI10_UP}
{$DEFINE DELPHI11_UP}
{$DEFINE DELPHI12_UP}
{$DEFINE DELPHI14_UP}
{$DEFINE DELPHI15_UP}
{$DEFINE DELPHI16_UP}
{$DEFINE DELPHI17_UP}
{$DEFINE DELPHI18_UP}
{$DEFINE DELPHI19_UP}
{$DEFINE DELPHI20_UP}
{$DEFINE DELPHI21_UP}
{$DEFINE DELPHI22_UP}
{$DEFINE DELPHI23_UP}
{$DEFINE DELPHI24_UP}
{$DEFINE DELPHI25_UP}
{$ENDIF}
// Rad Studio 10.3 - Delphi Rio
{$IFDEF VER330}
{$UNDEF DELPHI_VERSION_UNKNOW}
{$DEFINE DELPHI5_UP}
{$DEFINE DELPHI6_UP}
{$DEFINE DELPHI7_UP}
{$DEFINE DELPHI8_UP}
{$DEFINE DELPHI9_UP}
{$DEFINE DELPHI10_UP}
{$DEFINE DELPHI11_UP}
{$DEFINE DELPHI12_UP}
{$DEFINE DELPHI14_UP}
{$DEFINE DELPHI15_UP}
{$DEFINE DELPHI16_UP}
{$DEFINE DELPHI17_UP}
{$DEFINE DELPHI18_UP}
{$DEFINE DELPHI19_UP}
{$DEFINE DELPHI20_UP}
{$DEFINE DELPHI21_UP}
{$DEFINE DELPHI22_UP}
{$DEFINE DELPHI23_UP}
{$DEFINE DELPHI24_UP}
{$DEFINE DELPHI25_UP}
{$DEFINE DELPHI26_UP}
{$ENDIF}
// Rad Studio 10.4 - Delphi Sydney
{$IFDEF VER340}
{$UNDEF DELPHI_VERSION_UNKNOW}
{$DEFINE DELPHI5_UP}
{$DEFINE DELPHI6_UP}
{$DEFINE DELPHI7_UP}
{$DEFINE DELPHI8_UP}
{$DEFINE DELPHI9_UP}
{$DEFINE DELPHI10_UP}
{$DEFINE DELPHI11_UP}
{$DEFINE DELPHI12_UP}
{$DEFINE DELPHI14_UP}
{$DEFINE DELPHI15_UP}
{$DEFINE DELPHI16_UP}
{$DEFINE DELPHI17_UP}
{$DEFINE DELPHI18_UP}
{$DEFINE DELPHI19_UP}
{$DEFINE DELPHI20_UP}
{$DEFINE DELPHI21_UP}
{$DEFINE DELPHI22_UP}
{$DEFINE DELPHI23_UP}
{$DEFINE DELPHI24_UP}
{$DEFINE DELPHI25_UP}
{$DEFINE DELPHI26_UP}
{$DEFINE DELPHI27_UP}
{$ENDIF}
{$IFDEF FPC}
{$DEFINE SUPPORTS_INLINE}
{$IF DEFINED(FPC_FULLVERSION) AND (FPC_FULLVERSION >= 30200)}
{$DEFINE FPC_VER_320}
{$IFEND}
{$ELSE}
{$IFDEF DELPHI_VERSION_UNKNOW}
{$DEFINE DELPHI5_UP}
{$DEFINE DELPHI6_UP}
{$DEFINE DELPHI7_UP}
{$DEFINE DELPHI8_UP}
{$DEFINE DELPHI9_UP}
{$DEFINE DELPHI10_UP}
{$DEFINE DELPHI11_UP}
{$DEFINE DELPHI12_UP}
{$DEFINE DELPHI14_UP}
{$DEFINE DELPHI15_UP}
{$DEFINE DELPHI16_UP}
{$DEFINE DELPHI17_UP}
{$DEFINE DELPHI18_UP}
{$DEFINE DELPHI19_UP}
{$DEFINE DELPHI20_UP}
{$DEFINE DELPHI21_UP}
{$DEFINE DELPHI22_UP}
{$DEFINE DELPHI23_UP}
{$DEFINE DELPHI24_UP}
{$DEFINE DELPHI25_UP}
{$DEFINE DELPHI26_UP}
{$DEFINE DELPHI27_UP}
{$ENDIF}
{$ENDIF}
{$IFDEF DELPHI9_UP}
{$DEFINE SUPPORTS_INLINE}
{$ENDIF}
{$IF DEFINED(CPUX32) OR
DEFINED(CPU386) OR
DEFINED(CPUi386) OR
DEFINED(CPUPOWERPC32) OR
DEFINED(CPUSPARC32) OR
DEFINED(CPU32BITS) OR
DEFINED(CPUARM32) OR
DEFINED(WIN32) OR
DEFINED(IOS32) OR
DEFINED(MACOS32) OR
DEFINED(LINUX32) OR
DEFINED(POSIX32) OR
DEFINED(ANDROID32)}
{$DEFINE TARGET_32BITS}
{$IFEND}

View File

@@ -0,0 +1,206 @@
object URLRequestFrm: TURLRequestFrm
Left = 613
Height = 445
Top = 279
Width = 518
BorderIcons = [biSystemMenu]
BorderStyle = bsSingle
Caption = 'URL request'
ClientHeight = 445
ClientWidth = 518
Color = clBtnFace
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
OnCloseQuery = FormCloseQuery
OnCreate = FormCreate
OnDestroy = FormDestroy
Position = poScreenCenter
LCLVersion = '2.0.6.0'
object StatusBar1: TStatusBar
Left = 0
Height = 23
Top = 422
Width = 518
Panels = <
item
Width = 500
end>
SimplePanel = False
end
object GETGbx: TGroupBox
Left = 10
Height = 105
Top = 8
Width = 494
Caption = ' GET example '
ClientHeight = 87
ClientWidth = 490
TabOrder = 1
object Label1: TLabel
Left = 14
Height = 13
Top = 16
Width = 19
Caption = 'URL'
ParentColor = False
end
object DownloadBtn: TButton
Left = 11
Height = 25
Top = 48
Width = 465
Caption = 'Download'
OnClick = DownloadBtnClick
TabOrder = 0
end
object GetURLEdt: TEdit
Left = 43
Height = 21
Top = 13
Width = 433
TabOrder = 1
Text = 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf'
end
end
object POSTGbx: TGroupBox
Left = 10
Height = 274
Top = 136
Width = 494
Caption = ' POST example '
ClientHeight = 256
ClientWidth = 490
TabOrder = 2
object Label2: TLabel
Left = 14
Height = 13
Top = 15
Width = 19
Caption = 'URL'
ParentColor = False
end
object PostURLEdt: TEdit
Left = 43
Height = 21
Top = 12
Width = 433
TabOrder = 0
Text = 'https://ptsv2.com/t/cef4delphi/post'
end
object SendPostReqBtn: TButton
Left = 14
Height = 25
Top = 179
Width = 462
Caption = 'Send POST request'
OnClick = SendPostReqBtnClick
TabOrder = 1
end
object Button1: TButton
Left = 14
Height = 25
Top = 217
Width = 462
Caption = 'Check results in PTSV2.com'
OnClick = Button1Click
TabOrder = 2
end
object GroupBox1: TGroupBox
Left = 14
Height = 57
Top = 42
Width = 462
Caption = ' Parameter 1 '
ClientHeight = 39
ClientWidth = 458
TabOrder = 3
object Label3: TLabel
Left = 14
Height = 13
Top = 10
Width = 34
Caption = 'Name :'
ParentColor = False
end
object Label4: TLabel
Left = 262
Height = 13
Top = 10
Width = 33
Caption = 'Value :'
ParentColor = False
end
object PostParam1NameEdt: TEdit
Left = 54
Height = 21
Top = 7
Width = 121
TabOrder = 0
Text = 'name1'
end
object PostParam1ValueEdt: TEdit
Left = 302
Height = 21
Top = 7
Width = 137
TabOrder = 1
Text = 'value1'
end
end
object GroupBox2: TGroupBox
Left = 14
Height = 57
Top = 109
Width = 462
Caption = ' Parameter 2 '
ClientHeight = 39
ClientWidth = 458
TabOrder = 4
object Label5: TLabel
Left = 14
Height = 13
Top = 10
Width = 34
Caption = 'Name :'
ParentColor = False
end
object Label6: TLabel
Left = 262
Height = 13
Top = 10
Width = 33
Caption = 'Value :'
ParentColor = False
end
object PostParam2NameEdt: TEdit
Left = 54
Height = 21
Top = 7
Width = 121
TabOrder = 0
Text = 'name2'
end
object PostParam2ValueEdt: TEdit
Left = 302
Height = 21
Top = 7
Width = 137
TabOrder = 1
Text = 'value2'
end
end
end
object SaveDialog1: TSaveDialog
left = 448
top = 104
end
object CEFUrlRequestClientComponent1: TCEFUrlRequestClientComponent
OnRequestComplete = CEFUrlRequestClientComponent1RequestComplete
OnDownloadProgress = CEFUrlRequestClientComponent1DownloadProgress
OnDownloadData = CEFUrlRequestClientComponent1DownloadData
OnCreateURLRequest = CEFUrlRequestClientComponent1CreateURLRequest
left = 304
top = 104
end
end

View File

@@ -0,0 +1,441 @@
// ************************************************************************
// ***************************** CEF4Delphi *******************************
// ************************************************************************
//
// CEF4Delphi is based on DCEF3 which uses CEF to embed a chromium-based
// 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
//
// Copyright © 2020 Salvador Díaz Fau. All rights reserved.
//
// ************************************************************************
// ************ 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 uURLRequest;
{$MODE Delphi}
interface
uses
{$IFDEF DELPHI16_UP}
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.StdCtrls,
{$ELSE}
LCLIntf, LCLType, LMessages, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs, ComCtrls, StdCtrls,
{$ENDIF}
uCEFInterfaces, uCEFUrlRequestClientComponent, uCEFRequest, uCEFUrlRequest,
uCEFSentinel;
const
URLREQUEST_SUCCESS = WM_APP + $101;
URLREQUEST_ERROR = WM_APP + $102;
type
{ TURLRequestFrm }
TURLRequestFrm = class(TForm)
StatusBar1: TStatusBar;
SaveDialog1: TSaveDialog;
CEFUrlRequestClientComponent1: TCEFUrlRequestClientComponent;
GETGbx: TGroupBox;
DownloadBtn: TButton;
GetURLEdt: TEdit;
Label1: TLabel;
POSTGbx: TGroupBox;
PostURLEdt: TEdit;
Label2: TLabel;
SendPostReqBtn: TButton;
Button1: TButton;
GroupBox1: TGroupBox;
Label3: TLabel;
PostParam1NameEdt: TEdit;
Label4: TLabel;
PostParam1ValueEdt: TEdit;
GroupBox2: TGroupBox;
Label5: TLabel;
Label6: TLabel;
PostParam2NameEdt: TEdit;
PostParam2ValueEdt: TEdit;
procedure CEFSentinel1Close(Sender: TObject);
procedure DownloadBtnClick(Sender: TObject);
procedure SendPostReqBtnClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure CEFUrlRequestClientComponent1DownloadData(Sender: TObject; const request: ICefUrlRequest; data: Pointer; dataLength: NativeUInt);
procedure CEFUrlRequestClientComponent1DownloadProgress(Sender: TObject; const request: ICefUrlRequest; current, total: Int64);
procedure CEFUrlRequestClientComponent1RequestComplete(Sender: TObject; const request: ICefUrlRequest);
procedure CEFUrlRequestClientComponent1CreateURLRequest(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
FMemStream : TMemoryStream;
FCanClose : boolean;
FClosing : boolean;
FBusy : boolean;
FPendingURL : string;
FSendingGET : boolean;
FSendingPOST : boolean;
procedure CreateGETRequest;
procedure CreatePOSTRequest;
procedure URLRequestSuccessMsg(var aMessage : TMessage); message URLREQUEST_SUCCESS;
procedure URLRequestErrorMsg(var aMessage : TMessage); message URLREQUEST_ERROR;
procedure SaveStreamToFile;
end;
var
URLRequestFrm: TURLRequestFrm;
procedure CreateGlobalCEFApp;
implementation
{$R *.lfm}
// This is a simple URL request example to download small files using TCEFUrlRequestClientComponent.
// WARNING : If you try to download big files you may get an "Out of memory" exception. Replace TMemoryStream in that case.
// All TCEFUrlRequestClientComponent events are executed in a different thread. Don't create or destroy VCL componets
// inside them.
// To keep this demo as simple as possible, it's only allowed to download one file at a time. You can add as many requests
// as you want but then you would have to use a different way to store the data with synchronization objects.
// It's much safer to cancel all requests before closing the app.
// This demo follows this destruction sequence in case there is a file download running :
// --------------------------------------------------------------------------------------
// 1- Set CanClose to FALSE in the TForm.OnCloseQuery event and set FClosing to TRUE.
// 2- The next time TCEFUrlRequestClientComponent.OnDownloadProgress is executed we call request.Cancel, which triggers the
// TCEFUrlRequestClientComponent.OnRequestComplete event.
// 3- in the TCEFUrlRequestClientComponent.OnRequestComplete event we set FCanClose to TRUE and send WM_CLOSE to the form.
uses
uCEFApplication, uCEFMiscFunctions, uCEFTypes, uCEFPostData, uCEFPostDataElement, uCEFConstants;
procedure CreateGlobalCEFApp;
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.LogFile := 'cef.log';
GlobalCEFApp.LogSeverity := LOGSEVERITY_VERBOSE;
end;
procedure TURLRequestFrm.DownloadBtnClick(Sender: TObject);
var
TempURL, TempPath, TempName : string;
TempParts : TUrlParts;
i : integer;
begin
TempURL := trim(GetURLEdt.Text);
if (length(TempURL) > 0) then
begin
CefParseUrl(TempURL, TempParts);
TempPath := trim(TempParts.path);
TempName := '';
if (length(TempPath) > 0) then
begin
i := LastDelimiter('/', TempPath);
if (i > 0) then
TempName := trim(copy(TempPath, succ(i), length(TempPath)))
else
TempName := TempPath;
end;
if (length(TempName) > 0) then
SaveDialog1.FileName := TempName // This name should be decoded and sanitized before using it in Windows
else
SaveDialog1.FileName := 'UnknownFileName';
if SaveDialog1.Execute and
(length(SaveDialog1.FileName) > 0) then
begin
FPendingURL := TempURL;
GETGbx.Enabled := False;
POSTGbx.Enabled := False;
StatusBar1.Panels[0].Text := 'Downloading...';
FMemStream.Clear;
FSendingPOST := False;
FSendingGET := True;
// TCEFUrlRequestClientComponent.AddURLRequest will trigger the
// TCEFUrlRequestClientComponent.OnCreateURLRequest event in the right
// thread where you can create your custom requests.
CEFUrlRequestClientComponent1.AddURLRequest;
end;
end;
end;
procedure TURLRequestFrm.CEFSentinel1Close(Sender: TObject);
begin
end;
procedure TURLRequestFrm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose := FCanClose or not(FBusy);
FClosing := True;
end;
procedure TURLRequestFrm.FormCreate(Sender: TObject);
begin
FMemStream := TMemoryStream.Create;
FCanClose := False;
FClosing := False;
FBusy := False;
FSendingGET := False;
FSendingPOST := False;
end;
procedure TURLRequestFrm.FormDestroy(Sender: TObject);
begin
if (FMemStream <> nil) then FreeAndNil(FMemStream);
end;
procedure TURLRequestFrm.Button1Click(Sender: TObject);
begin
OpenURL('https://ptsv2.com/t/cef4delphi'); { *Converted from ShellExecute* }
end;
procedure TURLRequestFrm.CEFUrlRequestClientComponent1CreateURLRequest(Sender: TObject);
begin
if FSendingGET then
CreateGETRequest
else
if FSendingPOST then
CreatePOSTRequest;
end;
procedure TURLRequestFrm.CreateGETRequest;
var
TempRequest : ICefRequest;
begin
try
if (length(FPendingURL) > 0) then
begin
FBusy := True;
TempRequest := TCefRequestRef.New;
TempRequest.URL := FPendingURL;
TempRequest.Method := 'GET';
TempRequest.Flags := UR_FLAG_ALLOW_STORED_CREDENTIALS;
// Set the "client" parameter to the TCEFUrlRequestClientComponent.Client property
// to use the TCEFUrlRequestClientComponent events.
// The "requestContext" parameter can be nil to use the global request context.
TCefUrlRequestRef.New(TempRequest, CEFUrlRequestClientComponent1.Client, nil);
end;
finally
TempRequest := nil;
end;
end;
procedure TURLRequestFrm.CreatePOSTRequest;
var
TempRequest : ICefRequest;
TempPostData : ICefPostData;
TempElement : ICefPostDataElement;
TempParams : AnsiString;
begin
try
if (length(FPendingURL) > 0) then
begin
FBusy := True;
TempRequest := TCefRequestRef.New;
TempRequest.URL := FPendingURL;
TempRequest.Method := 'POST';
TempRequest.Flags := UR_FLAG_ALLOW_STORED_CREDENTIALS;
// TODO : The parameters should be converted to ansistring and encoded
if (length(PostParam1NameEdt.Text) > 0) and (length(PostParam1ValueEdt.Text) > 0) then
TempParams := PostParam1NameEdt.Text + '=' + PostParam1ValueEdt.Text;
if (length(PostParam2NameEdt.Text) > 0) and (length(PostParam2ValueEdt.Text) > 0) then
begin
if (length(TempParams) > 0) then
TempParams := TempParams + '&' + PostParam2NameEdt.Text + '=' + PostParam2ValueEdt.Text
else
TempParams := PostParam2NameEdt.Text + '=' + PostParam2ValueEdt.Text;
end;
if (length(TempParams) > 0) then
begin
TempElement := TCefPostDataElementRef.New;
TempElement.SetToBytes(length(TempParams), @TempParams[1]);
TempPostData := TCefPostDataRef.New;
TempPostData.AddElement(TempElement);
TempRequest.PostData := TempPostData;
// Set the "client" parameter to the TCEFUrlRequestClientComponent.Client property
// to use the TCEFUrlRequestClientComponent events.
// The "requestContext" parameter can be nil to use the global request context.
TCefUrlRequestRef.New(TempRequest, CEFUrlRequestClientComponent1.Client, nil);
end;
end;
finally
TempElement := nil;
TempPostData := nil;
TempRequest := nil;
end;
end;
procedure TURLRequestFrm.CEFUrlRequestClientComponent1DownloadData(Sender: TObject; const request: ICefUrlRequest; data: Pointer; dataLength: NativeUInt);
begin
try
if FClosing then
request.Cancel
else
if FSendingGET then
begin
if (data <> nil) and (dataLength > 0) then
FMemStream.WriteBuffer(data^, dataLength);
end;
except
on e : exception do
if CustomExceptionHandler('TURLRequestFrm.CEFUrlRequestClientComponent1DownloadData', e) then raise;
end;
end;
procedure TURLRequestFrm.CEFUrlRequestClientComponent1DownloadProgress(Sender: TObject; const request: ICefUrlRequest; current, total: Int64);
begin
if FClosing then
request.Cancel
else
if FSendingGET then
begin
if (total > 0) then
StatusBar1.Panels[0].Text := 'Downloading : ' + inttostr(round((current / total) * 100)) + ' %'
else
StatusBar1.Panels[0].Text := 'Downloading : ' + inttostr(current) + ' bytes';
end;
end;
procedure TURLRequestFrm.CEFUrlRequestClientComponent1RequestComplete(Sender: TObject; const request: ICefUrlRequest);
begin
FBusy := False;
// Use request.response here to get a ICefResponse interface with all the response headers, status, error code, etc.
if FClosing then
begin
FCanClose := True;
PostMessage(Handle, WM_CLOSE, 0, 0);
end
else
if (request <> nil) and (request.RequestStatus = UR_SUCCESS) then
PostMessage(Handle, URLREQUEST_SUCCESS, 0, 0)
else
PostMessage(Handle, URLREQUEST_ERROR, 0, request.RequestError);
end;
procedure TURLRequestFrm.URLRequestSuccessMsg(var aMessage : TMessage);
var
TempMessage : string;
begin
if FSendingGET then
begin
TempMessage := 'Download complete!';
SaveStreamToFile;
end
else
if FSendingPOST then
TempMessage := 'Parameters sent!';
StatusBar1.Panels[0].Text := TempMessage;
showmessage(TempMessage);
GETGbx.Enabled := True;
POSTGbx.Enabled := True;
FSendingGET := False;
FSendingPOST := False;
end;
procedure TURLRequestFrm.URLRequestErrorMsg(var aMessage : TMessage);
var
TempMessage : string;
begin
TempMessage := 'Error code : ' + inttostr(aMessage.lParam);
StatusBar1.Panels[0].Text := TempMessage;
showmessage(TempMessage);
GETGbx.Enabled := True;
POSTGbx.Enabled := True;
FSendingGET := False;
FSendingPOST := False;
end;
procedure TURLRequestFrm.SaveStreamToFile;
begin
try
FMemStream.SaveToFile(SaveDialog1.FileName);
FMemStream.Clear;
except
on e : exception do
if CustomExceptionHandler('TURLRequestFrm.SaveStreamToFile', e) then raise;
end;
end;
procedure TURLRequestFrm.SendPostReqBtnClick(Sender: TObject);
var
TempURL : string;
begin
TempURL := trim(PostURLEdt.Text);
if (length(TempURL) > 0) then
begin
FPendingURL := TempURL;
GETGbx.Enabled := False;
POSTGbx.Enabled := False;
StatusBar1.Panels[0].Text := 'Sending...';
FMemStream.Clear;
FSendingPOST := True;
FSendingGET := False;
// TCEFUrlRequestClientComponent.AddURLRequest will trigger the
// TCEFUrlRequestClientComponent.OnCreateURLRequest event in the right
// thread where you can create your custom requests.
CEFUrlRequestClientComponent1.AddURLRequest;
end;
end;
end.