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,91 @@
<?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="SimpleServer"/>
<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="SimpleServer.lpr"/>
<IsPartOfProject Value="True"/>
</Unit0>
<Unit1>
<Filename Value="uSimpleServer.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="SimpleServerFrm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
</Unit1>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="..\..\..\bin\SimpleServer"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</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,70 @@
// ************************************************************************
// ***************************** 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 SimpleServer;
{$MODE Delphi}
{$I cef.inc}
uses
{$IFDEF DELPHI16_UP}
Vcl.Forms,
{$ELSE}
Forms, Interfaces,
{$ENDIF }
uCEFApplication,
uSimpleServer in 'uSimpleServer.pas' {SimpleServerFrm};
{.$R *.res}
begin
GlobalCEFApp := TCefApplication.Create;
if GlobalCEFApp.StartMainProcess then
begin
Application.Initialize;
{$IFDEF DELPHI11_UP}
Application.MainFormOnTaskbar := True;
{$ENDIF}
Application.CreateForm(TSimpleServerFrm, SimpleServerFrm);
Application.Run;
end;
GlobalCEFApp.Free;
GlobalCEFApp := nil;
end.

View File

@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="11"/>
<BuildModes Active="Default"/>
<Units Count="5">
<Unit0>
<Filename Value="SimpleServer.lpr"/>
<IsPartOfProject Value="True"/>
<TopLine Value="35"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
<DefaultSyntaxHighlighter Value="Delphi"/>
</Unit0>
<Unit1>
<Filename Value="uSimpleServer.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="SimpleServerFrm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="1"/>
<CursorPos X="80" Y="16"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
<DefaultSyntaxHighlighter Value="Delphi"/>
</Unit1>
<Unit2>
<Filename Value="..\..\..\source\uCEFMiscFunctions.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="267"/>
<CursorPos X="37" Y="291"/>
<UsageCount Value="10"/>
</Unit2>
<Unit3>
<Filename Value="..\..\..\source\uCEFBufferPanel.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="45"/>
<CursorPos X="92" Y="57"/>
<UsageCount Value="10"/>
</Unit3>
<Unit4>
<Filename Value="..\..\..\source\uCEFConstants.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="577"/>
<CursorPos X="40" Y="599"/>
<UsageCount Value="10"/>
</Unit4>
</Units>
<JumpHistory Count="1">
<Position1>
<Filename Value="SimpleServer.lpr"/>
<Caret TopLine="35"/>
</Position1>
</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,124 @@
object SimpleServerFrm: TSimpleServerFrm
Left = 498
Height = 436
Top = 311
Width = 554
BorderIcons = [biSystemMenu, biMinimize]
BorderStyle = bsSingle
Caption = 'Simple Server'
ClientHeight = 436
ClientWidth = 554
Color = clBtnFace
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
OnCloseQuery = FormCloseQuery
OnCreate = FormCreate
Position = poScreenCenter
LCLVersion = '2.0.4.0'
object ButtonPnl: TPanel
Left = 0
Height = 94
Top = 0
Width = 554
Align = alTop
BevelOuter = bvNone
ClientHeight = 94
ClientWidth = 554
TabOrder = 0
object AddressLbl: TLabel
Left = 14
Height = 13
Top = 11
Width = 39
Caption = 'Address'
ParentColor = False
end
object PortLbl: TLabel
Left = 14
Height = 13
Top = 39
Width = 20
Caption = 'Port'
ParentColor = False
end
object BacklogLbl: TLabel
Left = 14
Height = 13
Top = 68
Width = 36
Caption = 'Backlog'
ParentColor = False
end
object AddressEdt: TEdit
Left = 87
Height = 21
Top = 8
Width = 211
OnChange = AddressEdtChange
TabOrder = 0
Text = '127.0.0.1'
end
object PortEdt: TSpinEdit
Left = 87
Height = 21
Top = 36
Width = 211
MaxValue = 65535
MinValue = 1025
TabOrder = 1
Value = 8099
end
object BacklogEdt: TSpinEdit
Left = 87
Height = 21
Top = 65
Width = 211
MaxValue = 512
MinValue = 1
TabOrder = 2
Value = 10
end
object StartBtn: TButton
Left = 312
Height = 79
Top = 8
Width = 105
Caption = 'Start'
OnClick = StartBtnClick
TabOrder = 3
end
object StopBtn: TButton
Left = 434
Height = 79
Top = 8
Width = 105
Caption = 'Stop'
Enabled = False
OnClick = StopBtnClick
TabOrder = 4
end
end
object ConnectionLogMem: TMemo
Left = 0
Height = 342
Top = 94
Width = 554
Align = alClient
ReadOnly = True
ScrollBars = ssBoth
TabOrder = 1
end
object CEFServerComponent1: TCEFServerComponent
OnServerCreated = CEFServerComponent1ServerCreated
OnServerDestroyed = CEFServerComponent1ServerDestroyed
OnClientConnected = CEFServerComponent1ClientConnected
OnClientDisconnected = CEFServerComponent1ClientDisconnected
OnHttpRequest = CEFServerComponent1HttpRequest
OnWebSocketRequest = CEFServerComponent1WebSocketRequest
OnWebSocketConnected = CEFServerComponent1WebSocketConnected
OnWebSocketMessage = CEFServerComponent1WebSocketMessage
left = 456
top = 304
end
end

View File

@@ -0,0 +1,344 @@
// ************************************************************************
// ***************************** 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 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.
*
*)
unit uSimpleServer;
{$MODE Delphi}
{$I cef.inc}
interface
uses
{$IFDEF DELPHI16_UP}
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Samples.Spin, Vcl.ExtCtrls, System.Math,
{$ELSE}
LCLIntf, LCLType, LMessages, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls, Spin, ExtCtrls, Math,
{$ENDIF}
uCEFInterfaces, uCEFServerComponent, uCEFTypes, uCEFMiscFunctions;
type
TSimpleServerFrm = class(TForm)
CEFServerComponent1: TCEFServerComponent;
ButtonPnl: TPanel;
ConnectionLogMem: TMemo;
AddressLbl: TLabel;
AddressEdt: TEdit;
PortLbl: TLabel;
PortEdt: TSpinEdit;
BacklogLbl: TLabel;
BacklogEdt: TSpinEdit;
StartBtn: TButton;
StopBtn: TButton;
procedure StartBtnClick(Sender: TObject);
procedure AddressEdtChange(Sender: TObject);
procedure CEFServerComponent1ServerCreated(Sender: TObject;
const server: ICefServer);
procedure CEFServerComponent1ServerDestroyed(Sender: TObject;
const server: ICefServer);
procedure CEFServerComponent1ClientConnected(Sender: TObject;
const server: ICefServer; connection_id: Integer);
procedure CEFServerComponent1ClientDisconnected(Sender: TObject;
const server: ICefServer; connection_id: Integer);
procedure StopBtnClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormCreate(Sender: TObject);
procedure CEFServerComponent1HttpRequest(Sender: TObject;
const server: ICefServer; connection_id: Integer;
const client_address: ustring; const request: ICefRequest);
procedure CEFServerComponent1WebSocketConnected(Sender: TObject;
const server: ICefServer; connection_id: Integer);
procedure CEFServerComponent1WebSocketMessage(Sender: TObject;
const server: ICefServer; connection_id: Integer;
const data: Pointer; data_size: NativeUInt);
procedure CEFServerComponent1WebSocketRequest(Sender: TObject;
const server: ICefServer; connection_id: Integer;
const client_address: ustring; const request: ICefRequest;
const callback: ICefCallback);
protected
FClosing : boolean;
function BufferToString(const aBuffer : TBytes) : string;
procedure ShowRequestInfo(const aRequest : ICefRequest);
procedure ShowPostDataInfo(const aPostData : ICefPostData);
public
{ Public declarations }
end;
var
SimpleServerFrm: TSimpleServerFrm;
implementation
{$R *.lfm}
// Server capacity is limited and is intended to handle only a small number of
// simultaneous connections (e.g. for communicating between applications on localhost).
// To test the HTTP server follow these steps :
// 1- Build and run this demo.
// 2- Click on the Start button.
// 3- Open your web browser and visit this address http://127.0.0.1:8099
// 4- You should see some connection details in the server log and a "Hellow world" text in your web browser.
// To test the websockets server follow these steps :
// 1- Build and run this demo.
// 2- Click on the "Start" button.
// 3- Open your web browser and visit this address https://www.websocket.org/echo.html
// 4- Type this in the "Location" field ws://127.0.0.1:8099
// 5- Click the "Connect" button.
// 6- Click the "Send" button.
// 7- You should see some connection details in the server log and the default text message "Rock it with HTML5 WebSocket"
procedure TSimpleServerFrm.AddressEdtChange(Sender: TObject);
begin
if not(CEFServerComponent1.IsRunning) then
StartBtn.Enabled := (length(trim(AddressEdt.Text)) > 0);
end;
procedure TSimpleServerFrm.StartBtnClick(Sender: TObject);
begin
if (length(trim(AddressEdt.Text)) > 0) then
CEFServerComponent1.CreateServer(AddressEdt.Text, PortEdt.Value, BacklogEdt.Value);
end;
procedure TSimpleServerFrm.StopBtnClick(Sender: TObject);
begin
CEFServerComponent1.Shutdown;
end;
procedure TSimpleServerFrm.CEFServerComponent1ClientConnected(
Sender: TObject; const server: ICefServer; connection_id: Integer);
begin
ConnectionLogMem.Lines.Add('Client connected : ' + inttostr(connection_id));
end;
procedure TSimpleServerFrm.CEFServerComponent1ClientDisconnected(
Sender: TObject; const server: ICefServer; connection_id: Integer);
begin
ConnectionLogMem.Lines.Add('Client disconnected : ' + inttostr(connection_id));
end;
procedure TSimpleServerFrm.CEFServerComponent1HttpRequest(Sender: TObject;
const server: ICefServer; connection_id: Integer;
const client_address: ustring; const request: ICefRequest);
var
TempData : string;
TempParts : TUrlParts;
begin
ConnectionLogMem.Lines.Add('---------------------------------------');
ConnectionLogMem.Lines.Add('HTTP request received from connection ' + inttostr(connection_id));
ConnectionLogMem.Lines.Add('Client address : ' + client_address);
ShowRequestInfo(request);
ConnectionLogMem.Lines.Add('---------------------------------------');
if (request <> nil) and CefParseUrl(Request.URL, TempParts) then
begin
if (TempParts.path = '') or (TempParts.path = '/') then
begin
TempData := 'Hello world from Simple Server';
CEFServerComponent1.SendHttp200response(connection_id, 'text/html', @TempData[1], length(TempData) * SizeOf(char));
end
else
CEFServerComponent1.SendHttp404response(connection_id);
end
else
CEFServerComponent1.SendHttp404response(connection_id);
end;
procedure TSimpleServerFrm.ShowRequestInfo(const aRequest : ICefRequest);
begin
if (aRequest = nil) then exit;
ConnectionLogMem.Lines.Add('Request URL : ' + aRequest.URL);
ConnectionLogMem.Lines.Add('Request Method : ' + aRequest.Method);
if (length(aRequest.ReferrerUrl) > 0) then
ConnectionLogMem.Lines.Add('Request Referrer : ' + aRequest.ReferrerUrl);
ShowPostDataInfo(aRequest.PostData);
end;
procedure TSimpleServerFrm.ShowPostDataInfo(const aPostData : ICefPostData);
var
i : integer;
TempLen : NativeUInt;
TempBytes : TBytes;
TempArray : TCefPostDataElementArray;
begin
TempArray := nil;
try
try
if (aPostData <> nil) and (aPostData.GetElementCount > 0) then
begin
aPostData.GetElements(aPostData.GetElementCount, TempArray);
i := 0;
while (i < length(TempArray)) do
begin
if (TempArray[i].GetBytesCount > 0) then
begin
SetLength(TempBytes, TempArray[i].GetBytesCount);
TempLen := TempArray[i].GetBytes(TempArray[i].GetBytesCount, @TempBytes[0]);
if (TempLen > 0) then
begin
ConnectionLogMem.Lines.Add('Post contents length : ' + inttostr(TempLen));
ConnectionLogMem.Lines.Add('Post contents sample : ' + BufferToString(TempBytes));
end;
end;
inc(i);
end;
i := 0;
while (i < length(TempArray)) do
begin
TempArray[i] := nil;
inc(i);
end;
end;
except
on e : exception do
if CustomExceptionHandler('TSimpleServerFrm.ShowPostDataInfo', e) then raise;
end;
finally
if (TempArray <> nil) then
begin
Finalize(TempArray);
TempArray := nil;
end;
end;
end;
function TSimpleServerFrm.BufferToString(const aBuffer : TBytes) : string;
var
i, j : integer;
begin
Result := '';
i := 0;
j := min(length(aBuffer), 5);
while (i < j) do
begin
Result := Result + IntToHex(aBuffer[i], 2);
inc(i);
end;
end;
procedure TSimpleServerFrm.CEFServerComponent1ServerCreated(Sender: TObject; const server: ICefServer);
begin
if CEFServerComponent1.Initialized then
begin
ConnectionLogMem.Lines.Add('Server created');
StartBtn.Enabled := False;
StopBtn.Enabled := True;
end
else
ConnectionLogMem.Lines.Add('Server creation error!');
end;
procedure TSimpleServerFrm.CEFServerComponent1ServerDestroyed(Sender: TObject; const server: ICefServer);
begin
if FClosing then
PostMessage(Handle, WM_CLOSE, 0, 0)
else
begin
ConnectionLogMem.Lines.Add('Server destroyed');
StartBtn.Enabled := True;
StopBtn.Enabled := False;
end;
end;
procedure TSimpleServerFrm.CEFServerComponent1WebSocketConnected(
Sender: TObject; const server: ICefServer; connection_id: Integer);
begin
ConnectionLogMem.Lines.Add('Client connected : ' + inttostr(connection_id));
end;
procedure TSimpleServerFrm.CEFServerComponent1WebSocketMessage(
Sender: TObject; const server: ICefServer; connection_id: Integer;
const data: Pointer; data_size: NativeUInt);
var
TempStream : TStringStream;
begin
TempStream := nil;
try
if (data_size > 0) and (data <> nil) then
begin
TempStream := TStringStream.Create('');
TempStream.WriteBuffer(data^, data_size);
ConnectionLogMem.Lines.Add('Client message received : ' + quotedstr(TempStream.DataString));
end;
finally
if (TempStream <> nil) then FreeAndNil(TempStream);
end;
end;
procedure TSimpleServerFrm.CEFServerComponent1WebSocketRequest(
Sender: TObject; const server: ICefServer; connection_id: Integer;
const client_address: ustring; const request: ICefRequest;
const callback: ICefCallback);
begin
if (callback <> nil) then callback.cont;
end;
procedure TSimpleServerFrm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if CEFServerComponent1.Initialized then
begin
CanClose := False;
FClosing := True;
Visible := False;
CEFServerComponent1.Shutdown;
end
else
CanClose := True;
end;
procedure TSimpleServerFrm.FormCreate(Sender: TObject);
begin
FClosing := False;
end;
end.