You've already forked CEF4Delphi
mirror of
https://github.com/salvadordf/CEF4Delphi.git
synced 2025-07-02 22:26:53 +02:00
Added ResponseFilterBrowser demo for Lazarus in Windows
This commit is contained in:
@ -0,0 +1,2 @@
|
|||||||
|
rmdir /S /Q lib
|
||||||
|
rmdir /S /Q backup
|
@ -0,0 +1,89 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<CONFIG>
|
||||||
|
<ProjectOptions>
|
||||||
|
<Version Value="12"/>
|
||||||
|
<PathDelim Value="\"/>
|
||||||
|
<General>
|
||||||
|
<Flags>
|
||||||
|
<MainUnitHasUsesSectionForAllUnits Value="False"/>
|
||||||
|
<MainUnitHasCreateFormStatements Value="False"/>
|
||||||
|
<MainUnitHasTitleStatement Value="False"/>
|
||||||
|
<MainUnitHasScaledStatement Value="False"/>
|
||||||
|
</Flags>
|
||||||
|
<SessionStorage Value="InProjectDir"/>
|
||||||
|
<Title Value="ResponseFilterBrowser"/>
|
||||||
|
<UseAppBundle Value="False"/>
|
||||||
|
<ResourceType Value="res"/>
|
||||||
|
</General>
|
||||||
|
<BuildModes>
|
||||||
|
<Item Name="Default" Default="True"/>
|
||||||
|
</BuildModes>
|
||||||
|
<PublishOptions>
|
||||||
|
<Version Value="2"/>
|
||||||
|
<UseFileFilters Value="True"/>
|
||||||
|
</PublishOptions>
|
||||||
|
<RunParams>
|
||||||
|
<FormatVersion Value="2"/>
|
||||||
|
</RunParams>
|
||||||
|
<RequiredPackages>
|
||||||
|
<Item>
|
||||||
|
<PackageName Value="CEF4Delphi_Lazarus"/>
|
||||||
|
</Item>
|
||||||
|
<Item>
|
||||||
|
<PackageName Value="LCL"/>
|
||||||
|
</Item>
|
||||||
|
</RequiredPackages>
|
||||||
|
<Units>
|
||||||
|
<Unit>
|
||||||
|
<Filename Value="ResponseFilterBrowser.lpr"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit>
|
||||||
|
<Unit>
|
||||||
|
<Filename Value="uResponseFilterBrowser.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
<ComponentName Value="ResponseFilterBrowserFrm"/>
|
||||||
|
<HasResources Value="True"/>
|
||||||
|
<ResourceBaseClass Value="Form"/>
|
||||||
|
</Unit>
|
||||||
|
</Units>
|
||||||
|
</ProjectOptions>
|
||||||
|
<CompilerOptions>
|
||||||
|
<Version Value="11"/>
|
||||||
|
<PathDelim Value="\"/>
|
||||||
|
<Target>
|
||||||
|
<Filename Value="..\..\..\bin\ResponseFilterBrowser"/>
|
||||||
|
</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>
|
||||||
|
<Item>
|
||||||
|
<Name Value="EAbort"/>
|
||||||
|
</Item>
|
||||||
|
<Item>
|
||||||
|
<Name Value="ECodetoolError"/>
|
||||||
|
</Item>
|
||||||
|
<Item>
|
||||||
|
<Name Value="EFOpenError"/>
|
||||||
|
</Item>
|
||||||
|
</Exceptions>
|
||||||
|
</Debugging>
|
||||||
|
</CONFIG>
|
@ -0,0 +1,69 @@
|
|||||||
|
// ************************************************************************
|
||||||
|
// ***************************** 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 ResponseFilterBrowser;
|
||||||
|
|
||||||
|
{$MODE Delphi}
|
||||||
|
|
||||||
|
{$I cef.inc}
|
||||||
|
|
||||||
|
uses
|
||||||
|
Forms, Interfaces,
|
||||||
|
Windows,
|
||||||
|
uCEFApplication,
|
||||||
|
uResponseFilterBrowser in 'uResponseFilterBrowser.pas' {ResponseFilterBrowserFrm};
|
||||||
|
|
||||||
|
{.$R *.res}
|
||||||
|
|
||||||
|
// CEF3 needs to set the LARGEADDRESSAWARE flag which allows 32-bit processes to use up to 3GB of RAM.
|
||||||
|
{$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}
|
||||||
|
|
||||||
|
begin
|
||||||
|
CreateGlobalCEFApp;
|
||||||
|
|
||||||
|
if GlobalCEFApp.StartMainProcess then
|
||||||
|
begin
|
||||||
|
Application.Initialize;
|
||||||
|
{$IFDEF DELPHI11_UP}
|
||||||
|
Application.MainFormOnTaskbar := True;
|
||||||
|
{$ENDIF}
|
||||||
|
Application.CreateForm(TResponseFilterBrowserFrm, ResponseFilterBrowserFrm);
|
||||||
|
Application.Run;
|
||||||
|
end;
|
||||||
|
|
||||||
|
DestroyGlobalCEFApp;
|
||||||
|
end.
|
507
demos/Lazarus_Windows/ResponseFilterBrowser/cef.inc
Normal file
507
demos/Lazarus_Windows/ResponseFilterBrowser/cef.inc
Normal file
@ -0,0 +1,507 @@
|
|||||||
|
// ************************************************************************
|
||||||
|
// ***************************** 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}
|
||||||
|
|
||||||
|
// Rad Studio 11.0 - Delphi Alexandria
|
||||||
|
{$IFDEF VER350}
|
||||||
|
{$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}
|
||||||
|
{$DEFINE DELPHI28_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}
|
||||||
|
{$DEFINE DELPHI28_UP}
|
||||||
|
{$ENDIF}
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
|
{$IFDEF DELPHI9_UP}
|
||||||
|
{$DEFINE SUPPORTS_INLINE}
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
|
{$IF DEFINED(CPUX32) OR
|
||||||
|
DEFINED(CPU32) 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}
|
||||||
|
{$ELSE}
|
||||||
|
{$IF DEFINED(CPUX64) OR
|
||||||
|
DEFINED(CPU64) OR
|
||||||
|
DEFINED(CPU64BITS) OR
|
||||||
|
DEFINED(CPUARM64) OR
|
||||||
|
DEFINED(WIN64) OR
|
||||||
|
DEFINED(IOS64) OR
|
||||||
|
DEFINED(MACOS64) OR
|
||||||
|
DEFINED(LINUX64) OR
|
||||||
|
DEFINED(POSIX64) OR
|
||||||
|
DEFINED(ANDROID64)}
|
||||||
|
{$DEFINE TARGET_64BITS}
|
||||||
|
{$IFEND}
|
||||||
|
{$IFEND}
|
||||||
|
|
||||||
|
// Delphi uses MACOS for the new MacOSX and DARWIN is not defined
|
||||||
|
// FPC uses DARWIN for the new MacOSX and MACOS is defined for the classic Macintosh OS (System 7)
|
||||||
|
// We define MACOSX to avoid conflicts in both situations
|
||||||
|
{$IFDEF FPC}
|
||||||
|
{$IFDEF DARWIN}
|
||||||
|
{$DEFINE MACOSX}
|
||||||
|
{$ENDIF}
|
||||||
|
{$ELSE}
|
||||||
|
{$IFDEF MACOS}
|
||||||
|
{$DEFINE MACOSX}
|
||||||
|
{$ENDIF}
|
||||||
|
{$ENDIF}
|
@ -0,0 +1,173 @@
|
|||||||
|
object ResponseFilterBrowserFrm: TResponseFilterBrowserFrm
|
||||||
|
Left = 0
|
||||||
|
Height = 710
|
||||||
|
Top = 0
|
||||||
|
Width = 1054
|
||||||
|
Caption = 'Initializing browser. Please wait...'
|
||||||
|
ClientHeight = 710
|
||||||
|
ClientWidth = 1054
|
||||||
|
Color = clBtnFace
|
||||||
|
Font.Color = clWindowText
|
||||||
|
Font.Height = -11
|
||||||
|
Font.Name = 'Tahoma'
|
||||||
|
OnCloseQuery = FormCloseQuery
|
||||||
|
OnCreate = FormCreate
|
||||||
|
OnDestroy = FormDestroy
|
||||||
|
OnShow = FormShow
|
||||||
|
Position = poScreenCenter
|
||||||
|
LCLVersion = '2.2.0.4'
|
||||||
|
object Splitter1: TSplitter
|
||||||
|
Cursor = crVSplit
|
||||||
|
Left = 0
|
||||||
|
Height = 3
|
||||||
|
Top = 477
|
||||||
|
Width = 1054
|
||||||
|
Align = alBottom
|
||||||
|
ResizeAnchor = akBottom
|
||||||
|
end
|
||||||
|
object AddressPnl: TPanel
|
||||||
|
Left = 0
|
||||||
|
Height = 67
|
||||||
|
Top = 0
|
||||||
|
Width = 1054
|
||||||
|
Align = alTop
|
||||||
|
BevelOuter = bvNone
|
||||||
|
ClientHeight = 67
|
||||||
|
ClientWidth = 1054
|
||||||
|
Enabled = False
|
||||||
|
TabOrder = 0
|
||||||
|
object AddressEdt: TEdit
|
||||||
|
Left = 3
|
||||||
|
Height = 21
|
||||||
|
Top = 3
|
||||||
|
Width = 735
|
||||||
|
Anchors = [akTop, akLeft, akRight]
|
||||||
|
ReadOnly = True
|
||||||
|
TabOrder = 0
|
||||||
|
Text = 'https://www.briskbard.com/'
|
||||||
|
end
|
||||||
|
object Panel1: TPanel
|
||||||
|
Left = 750
|
||||||
|
Height = 67
|
||||||
|
Top = 0
|
||||||
|
Width = 304
|
||||||
|
Align = alRight
|
||||||
|
BevelOuter = bvNone
|
||||||
|
ClientHeight = 67
|
||||||
|
ClientWidth = 304
|
||||||
|
TabOrder = 1
|
||||||
|
object GoBtn: TButton
|
||||||
|
Left = 3
|
||||||
|
Height = 21
|
||||||
|
Top = 0
|
||||||
|
Width = 63
|
||||||
|
Caption = 'Go'
|
||||||
|
OnClick = GoBtnClick
|
||||||
|
TabOrder = 0
|
||||||
|
end
|
||||||
|
object RscNameEdt: TEdit
|
||||||
|
Left = 174
|
||||||
|
Height = 21
|
||||||
|
Top = 0
|
||||||
|
Width = 122
|
||||||
|
TabOrder = 1
|
||||||
|
Text = 'script.js'
|
||||||
|
end
|
||||||
|
object CopyScriptBtn: TRadioButton
|
||||||
|
Left = 72
|
||||||
|
Height = 19
|
||||||
|
Top = 0
|
||||||
|
Width = 81
|
||||||
|
Caption = 'Copy script :'
|
||||||
|
Checked = True
|
||||||
|
TabOrder = 2
|
||||||
|
TabStop = True
|
||||||
|
end
|
||||||
|
object ReplaceLogoBtn: TRadioButton
|
||||||
|
Left = 72
|
||||||
|
Height = 19
|
||||||
|
Top = 19
|
||||||
|
Width = 81
|
||||||
|
Caption = 'Replace logo'
|
||||||
|
TabOrder = 3
|
||||||
|
end
|
||||||
|
object ReplaceTextBtn: TRadioButton
|
||||||
|
Left = 72
|
||||||
|
Height = 19
|
||||||
|
Top = 38
|
||||||
|
Width = 81
|
||||||
|
Caption = 'Replace text'
|
||||||
|
TabOrder = 4
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
object CEFWindowParent1: TCEFWindowParent
|
||||||
|
Left = 0
|
||||||
|
Height = 410
|
||||||
|
Top = 67
|
||||||
|
Width = 1054
|
||||||
|
Align = alClient
|
||||||
|
TabOrder = 1
|
||||||
|
end
|
||||||
|
object Panel2: TPanel
|
||||||
|
Left = 0
|
||||||
|
Height = 230
|
||||||
|
Top = 480
|
||||||
|
Width = 1054
|
||||||
|
Align = alBottom
|
||||||
|
BevelOuter = bvNone
|
||||||
|
ClientHeight = 230
|
||||||
|
ClientWidth = 1054
|
||||||
|
TabOrder = 2
|
||||||
|
object Memo1: TMemo
|
||||||
|
Left = 0
|
||||||
|
Height = 207
|
||||||
|
Top = 0
|
||||||
|
Width = 1054
|
||||||
|
Align = alClient
|
||||||
|
ReadOnly = True
|
||||||
|
ScrollBars = ssBoth
|
||||||
|
TabOrder = 0
|
||||||
|
end
|
||||||
|
object StatusBar1: TStatusBar
|
||||||
|
Left = 0
|
||||||
|
Height = 23
|
||||||
|
Top = 207
|
||||||
|
Width = 1054
|
||||||
|
Panels = <
|
||||||
|
item
|
||||||
|
Width = 200
|
||||||
|
end
|
||||||
|
item
|
||||||
|
Width = 200
|
||||||
|
end
|
||||||
|
item
|
||||||
|
Width = 200
|
||||||
|
end
|
||||||
|
item
|
||||||
|
Width = 200
|
||||||
|
end>
|
||||||
|
SimplePanel = False
|
||||||
|
end
|
||||||
|
end
|
||||||
|
object Timer1: TTimer
|
||||||
|
Enabled = False
|
||||||
|
Interval = 300
|
||||||
|
OnTimer = Timer1Timer
|
||||||
|
Left = 56
|
||||||
|
Top = 88
|
||||||
|
end
|
||||||
|
object Chromium1: TChromium
|
||||||
|
OnLoadStart = Chromium1LoadStart
|
||||||
|
OnBeforePopup = Chromium1BeforePopup
|
||||||
|
OnAfterCreated = Chromium1AfterCreated
|
||||||
|
OnBeforeClose = Chromium1BeforeClose
|
||||||
|
OnClose = Chromium1Close
|
||||||
|
OnBeforeResourceLoad = Chromium1BeforeResourceLoad
|
||||||
|
OnResourceResponse = Chromium1ResourceResponse
|
||||||
|
OnGetResourceResponseFilter = Chromium1GetResourceResponseFilter
|
||||||
|
OnResourceLoadComplete = Chromium1ResourceLoadComplete
|
||||||
|
Left = 56
|
||||||
|
Top = 160
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,933 @@
|
|||||||
|
// ************************************************************************
|
||||||
|
// ***************************** 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 @ 2022 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 uResponseFilterBrowser;
|
||||||
|
|
||||||
|
{$MODE Delphi}
|
||||||
|
|
||||||
|
{$I cef.inc}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Windows, Messages, SysUtils, Variants, Classes, Graphics,
|
||||||
|
Controls, Forms, Dialogs, StdCtrls, ExtCtrls, SyncObjs, ComCtrls,
|
||||||
|
uCEFChromium, uCEFWindowParent, uCEFInterfaces, uCEFConstants, uCEFTypes,
|
||||||
|
uCEFResponseFilter, uCEFWinControl, uCEFChromiumCore;
|
||||||
|
|
||||||
|
const
|
||||||
|
STREAM_COPY_COMPLETE = WM_APP + $B00;
|
||||||
|
|
||||||
|
type
|
||||||
|
TResponseFilterBrowserFrm = class(TForm)
|
||||||
|
AddressPnl: TPanel;
|
||||||
|
AddressEdt: TEdit;
|
||||||
|
Timer1: TTimer;
|
||||||
|
Chromium1: TChromium;
|
||||||
|
CEFWindowParent1: TCEFWindowParent;
|
||||||
|
Splitter1: TSplitter;
|
||||||
|
Panel1: TPanel;
|
||||||
|
GoBtn: TButton;
|
||||||
|
RscNameEdt: TEdit;
|
||||||
|
Panel2: TPanel;
|
||||||
|
Memo1: TMemo;
|
||||||
|
StatusBar1: TStatusBar;
|
||||||
|
CopyScriptBtn: TRadioButton;
|
||||||
|
ReplaceLogoBtn: TRadioButton;
|
||||||
|
ReplaceTextBtn: TRadioButton;
|
||||||
|
|
||||||
|
procedure Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser);
|
||||||
|
procedure Chromium1GetResourceResponseFilter(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; const response: ICefResponse; out Result: ICefResponseFilter);
|
||||||
|
procedure Chromium1ResourceLoadComplete(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; const response: ICefResponse; status: TCefUrlRequestStatus; receivedContentLength: Int64);
|
||||||
|
procedure Chromium1BeforePopup(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const targetUrl, targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean; const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo; var client: ICefClient; var settings: TCefBrowserSettings; var extra_info: ICefDictionaryValue; var noJavascriptAccess: Boolean; var Result: Boolean);
|
||||||
|
procedure Chromium1Close(Sender: TObject; const browser: ICefBrowser; var aAction : TCefCloseBrowserAction);
|
||||||
|
procedure Chromium1BeforeClose(Sender: TObject; const browser: ICefBrowser);
|
||||||
|
procedure Chromium1LoadStart(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; transitionType: Cardinal);
|
||||||
|
procedure Chromium1BeforeResourceLoad(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; const callback: ICefCallback; out Result: TCefReturnValue);
|
||||||
|
procedure Chromium1ResourceResponse(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; const response: ICefResponse; out Result: Boolean);
|
||||||
|
|
||||||
|
procedure FormShow(Sender: TObject);
|
||||||
|
procedure FormCreate(Sender: TObject);
|
||||||
|
procedure FormDestroy(Sender: TObject);
|
||||||
|
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||||
|
|
||||||
|
procedure GoBtnClick(Sender: TObject);
|
||||||
|
procedure Timer1Timer(Sender: TObject);
|
||||||
|
|
||||||
|
protected
|
||||||
|
FFilter : ICefResponseFilter; // CEF Filter interface that receives the resource contents
|
||||||
|
FStream : TMemoryStream; // TMemoryStream to hold the resource contents
|
||||||
|
FStreamCS : TCriticalSection; // Critical section used to protect the memory stream
|
||||||
|
FRscSize : int64; // size of the resource if the server sends the Content-Length header
|
||||||
|
FRscCompleted : boolean; // This variable will be used to handle the results only once.
|
||||||
|
FRscEncoding : TEncoding; // The resource response Encoding. When encoding is unicode. The response data may be sent by multi chains, will cause encoding parsing problem.
|
||||||
|
FRscMimeType : String;
|
||||||
|
FFilterInit : boolean;
|
||||||
|
FReload : boolean;
|
||||||
|
|
||||||
|
// Variables to control when can we destroy the form safely
|
||||||
|
FCanClose : boolean; // Set to True in TChromium.OnBeforeClose
|
||||||
|
FClosing : boolean; // Set to True in the CloseQuery event.
|
||||||
|
|
||||||
|
procedure WMMove(var aMessage: TWMMove); message WM_MOVE;
|
||||||
|
procedure WMMoving(var aMessage: TMessage); message WM_MOVING;
|
||||||
|
procedure WMEnterMenuLoop(var aMessage: TMessage); message WM_ENTERMENULOOP;
|
||||||
|
procedure WMExitMenuLoop(var aMessage: TMessage); message WM_EXITMENULOOP;
|
||||||
|
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
|
||||||
|
procedure BrowserDestroyMsg(var aMessage: TMessage); message CEF_DESTROY;
|
||||||
|
procedure StreamCopyCompleteMsg(var aMessage : TMessage); message STREAM_COPY_COMPLETE;
|
||||||
|
|
||||||
|
procedure Filter_OnFilter(Sender: TObject; data_in: Pointer; data_in_size: NativeUInt; var data_in_read: NativeUInt; data_out: Pointer; data_out_size : NativeUInt; var data_out_written: NativeUInt; var aResult : TCefResponseFilterStatus);
|
||||||
|
|
||||||
|
procedure CopyScript(data_in: Pointer; data_in_size: NativeUInt; var data_in_read: NativeUInt; data_out: Pointer; data_out_size : NativeUInt; var data_out_written: NativeUInt; var aResult : TCefResponseFilterStatus);
|
||||||
|
procedure ReplaceLogo(data_in: Pointer; data_in_size: NativeUInt; var data_in_read: NativeUInt; data_out: Pointer; data_out_size : NativeUInt; var data_out_written: NativeUInt; var aResult : TCefResponseFilterStatus);
|
||||||
|
procedure ReplaceBufferText(data_in: Pointer; data_in_size: NativeUInt; var data_in_read: NativeUInt; data_out: Pointer; data_out_size : NativeUInt; var data_out_written: NativeUInt; var aResult : TCefResponseFilterStatus);
|
||||||
|
procedure UpdateRscEncoding(const aMimeType, aContentType : string);
|
||||||
|
function IsMyResource(const aRequest : ICefRequest) : boolean;
|
||||||
|
procedure CheckResponseHeaders(const response : ICefResponse);
|
||||||
|
procedure GetResponseEncoding(const aContentType: string);
|
||||||
|
public
|
||||||
|
{ Public declarations }
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
ResponseFilterBrowserFrm: TResponseFilterBrowserFrm;
|
||||||
|
|
||||||
|
procedure CreateGlobalCEFApp;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
{$R *.lfm}
|
||||||
|
|
||||||
|
uses
|
||||||
|
Math,
|
||||||
|
uCEFApplication, uCEFMiscFunctions, uCEFStringMultimap;
|
||||||
|
|
||||||
|
// This demo uses a TCustomResponseFilter to read the contents from a
|
||||||
|
// JavaScript file in briskbard.com into a TMemoryStream. The stream
|
||||||
|
// is shown in the TMemo when it's finished.
|
||||||
|
|
||||||
|
// For more information read the CEF code comments here :
|
||||||
|
// https://github.com/chromiumembedded/cef/blob/master/include/capi/cef_response_filter_capi.h
|
||||||
|
|
||||||
|
// Destruction steps
|
||||||
|
// =================
|
||||||
|
// 1. FormCloseQuery sets CanClose to FALSE calls TChromium.CloseBrowser
|
||||||
|
// which triggers the TChromium.OnClose event.
|
||||||
|
// 2. TChromium.OnClose sends a CEFBROWSER_DESTROY message to destroy
|
||||||
|
// CEFWindowParent1 in the main thread, which triggers the
|
||||||
|
// TChromium.OnBeforeClose event.
|
||||||
|
// 3. TChromium.OnBeforeClose sets FCanClose := True and sends WM_CLOSE to the form.
|
||||||
|
|
||||||
|
// TCustomResponseFilter.OnFilter event might be called multiple times
|
||||||
|
// when the resource is too big. In that case the resource will be split into
|
||||||
|
// "chunks of data" and each chunk will be passed in the "data_in" parameter.
|
||||||
|
|
||||||
|
// For example, if the original resource is 95 Kb long you could see that the
|
||||||
|
// TCustomResponseFilter.OnFilter event is triggered 10 times with different
|
||||||
|
// "data_in_size" values.
|
||||||
|
|
||||||
|
// If you replace the original resource with a shorter resource then you might
|
||||||
|
// need less chunks to send the data. In that case you would just set
|
||||||
|
// "aResult" to RESPONSE_FILTER_DONE when you write the last chunk of the new
|
||||||
|
// resource.
|
||||||
|
|
||||||
|
// If you replace the original resource with a larger resource then you might
|
||||||
|
// need more chunks to send all the data. In that case you would set "aResult"
|
||||||
|
// to RESPONSE_FILTER_NEED_MORE_DATA in the last chunk of the original resource.
|
||||||
|
// This will trigger the TCustomResponseFilter.OnFilter event again and you
|
||||||
|
// will be able to send another chunk.
|
||||||
|
|
||||||
|
// If the server sends compressed data or it doesn't include a "Content-Length"
|
||||||
|
// HTTP response header then the filter *might* fail. In this case,
|
||||||
|
// Filter_OnFilter will receive a NIL value in data_in before the recource
|
||||||
|
// response is really complete.
|
||||||
|
|
||||||
|
// If this demo is too complicated or the filter fails, consider using the
|
||||||
|
// URLRequest demo if possible.
|
||||||
|
|
||||||
|
procedure CreateGlobalCEFApp;
|
||||||
|
begin
|
||||||
|
GlobalCEFApp := TCefApplication.Create;
|
||||||
|
GlobalCEFApp.LogFile := 'cef.log';
|
||||||
|
GlobalCEFApp.LogSeverity := LOGSEVERITY_VERBOSE;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TResponseFilterBrowserFrm.Filter_OnFilter( Sender : TObject;
|
||||||
|
data_in : Pointer;
|
||||||
|
data_in_size : NativeUInt;
|
||||||
|
var data_in_read : NativeUInt;
|
||||||
|
data_out : Pointer;
|
||||||
|
data_out_size : NativeUInt;
|
||||||
|
var data_out_written : NativeUInt;
|
||||||
|
var aResult : TCefResponseFilterStatus);
|
||||||
|
begin
|
||||||
|
if CopyScriptBtn.Checked then
|
||||||
|
CopyScript(data_in, data_in_size, data_in_read, data_out, data_out_size, data_out_written, aResult)
|
||||||
|
else
|
||||||
|
if ReplaceLogoBtn.Checked then
|
||||||
|
ReplaceLogo(data_in, data_in_size, data_in_read, data_out, data_out_size, data_out_written, aResult)
|
||||||
|
else
|
||||||
|
if ReplaceTextBtn.Checked then
|
||||||
|
ReplaceBufferText(data_in, data_in_size, data_in_read, data_out, data_out_size, data_out_written, aResult);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TResponseFilterBrowserFrm.CopyScript( data_in : Pointer;
|
||||||
|
data_in_size : NativeUInt;
|
||||||
|
var data_in_read : NativeUInt;
|
||||||
|
data_out : Pointer;
|
||||||
|
data_out_size : NativeUInt;
|
||||||
|
var data_out_written : NativeUInt;
|
||||||
|
var aResult : TCefResponseFilterStatus);
|
||||||
|
begin
|
||||||
|
try
|
||||||
|
try
|
||||||
|
FStreamCS.Acquire;
|
||||||
|
|
||||||
|
if FFilterInit then
|
||||||
|
begin
|
||||||
|
// This event will be called repeatedly until the input buffer has been fully read.
|
||||||
|
// When there's no more data then data_in is nil and you can show the stream contents.
|
||||||
|
|
||||||
|
if (data_in = nil) then
|
||||||
|
begin
|
||||||
|
data_in_read := 0; // data_in_size is 0 too in this situation
|
||||||
|
data_out_written := 0;
|
||||||
|
aResult := RESPONSE_FILTER_DONE;
|
||||||
|
|
||||||
|
// Send the message only if this is the first time that this event has data_in = nil
|
||||||
|
if not(FRscCompleted) and
|
||||||
|
(FStream.Size > 0) and
|
||||||
|
((FRscSize = -1) or (FRscSize = FStream.Size)) then
|
||||||
|
FRscCompleted := PostMessage(Handle, STREAM_COPY_COMPLETE, 0, 0);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
if (data_out <> nil) then
|
||||||
|
begin
|
||||||
|
data_out_written := min(data_in_size, data_out_size);
|
||||||
|
|
||||||
|
if (data_out_written > 0) then
|
||||||
|
Move(data_in^, data_out^, data_out_written);
|
||||||
|
end;
|
||||||
|
|
||||||
|
if (data_in_size > 0) then
|
||||||
|
data_in_read := FStream.Write(data_in^, data_in_size);
|
||||||
|
|
||||||
|
// Send the STREAM_COPY_COMPLETE message only if the server sent the data size in
|
||||||
|
// a Content-Length header and we can compare it with the stream size
|
||||||
|
if not(FRscCompleted) and (FRscSize <> -1) and (FRscSize = FStream.Size) then
|
||||||
|
begin
|
||||||
|
FRscCompleted := PostMessage(Handle, STREAM_COPY_COMPLETE, 0, 0);
|
||||||
|
aResult := RESPONSE_FILTER_DONE;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
aResult := RESPONSE_FILTER_NEED_MORE_DATA;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
except
|
||||||
|
on e : exception do
|
||||||
|
begin
|
||||||
|
aResult := RESPONSE_FILTER_ERROR;
|
||||||
|
if CustomExceptionHandler('TResponseFilterBrowserFrm.CopyScript', e) then raise;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
FStreamCS.Release;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TResponseFilterBrowserFrm.ReplaceLogo( data_in : Pointer;
|
||||||
|
data_in_size : NativeUInt;
|
||||||
|
var data_in_read : NativeUInt;
|
||||||
|
data_out : Pointer;
|
||||||
|
data_out_size : NativeUInt;
|
||||||
|
var data_out_written : NativeUInt;
|
||||||
|
var aResult : TCefResponseFilterStatus);
|
||||||
|
begin
|
||||||
|
// The default return value is RESPONSE_FILTER_DONE to stop the filter
|
||||||
|
aResult := RESPONSE_FILTER_DONE;
|
||||||
|
|
||||||
|
try
|
||||||
|
try
|
||||||
|
FStreamCS.Acquire;
|
||||||
|
|
||||||
|
// FStream has the new logo and it has a much larger size than the original so we'll have to
|
||||||
|
// return RESPONSE_FILTER_NEED_MORE_DATA until we send all its contents.
|
||||||
|
|
||||||
|
if FFilterInit and (FStream <> nil) and (FStream.Size > 0) then
|
||||||
|
begin
|
||||||
|
// This event will be called repeatedly until the input buffer has been fully read.
|
||||||
|
// When there's no more data then data_in is nil and you can show the stream contents.
|
||||||
|
|
||||||
|
if (data_in = nil) and (FStream.Position >= FStream.Size) then
|
||||||
|
begin
|
||||||
|
// This is the last filter call
|
||||||
|
data_in_read := 0; // data_in_size is 0 too in this situation
|
||||||
|
data_out_written := 0;
|
||||||
|
|
||||||
|
// Send the message only if this is the first time that this event has data_in = nil
|
||||||
|
if not(FRscCompleted) then
|
||||||
|
FRscCompleted := PostMessage(Handle, STREAM_COPY_COMPLETE, 0, 0);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if (data_out <> nil) then
|
||||||
|
begin
|
||||||
|
data_in_read := data_in_size;
|
||||||
|
data_out_written := FStream.Read(data_out^, data_out_size); // Write the next chunk with a data_out_size size at most.
|
||||||
|
|
||||||
|
if not(FRscCompleted) and (FStream.Position >= FStream.Size) then
|
||||||
|
FRscCompleted := PostMessage(Handle, STREAM_COPY_COMPLETE, 0, 0)
|
||||||
|
else
|
||||||
|
aResult := RESPONSE_FILTER_NEED_MORE_DATA; // We still need to send more stream data
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
except
|
||||||
|
on e : exception do
|
||||||
|
begin
|
||||||
|
aResult := RESPONSE_FILTER_ERROR;
|
||||||
|
if CustomExceptionHandler('TResponseFilterBrowserFrm.ReplaceLogo', e) then raise;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
FStreamCS.Release;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TResponseFilterBrowserFrm.ReplaceBufferText( data_in : Pointer;
|
||||||
|
data_in_size : NativeUInt;
|
||||||
|
var data_in_read : NativeUInt;
|
||||||
|
data_out : Pointer;
|
||||||
|
data_out_size : NativeUInt;
|
||||||
|
var data_out_written : NativeUInt;
|
||||||
|
var aResult : TCefResponseFilterStatus);
|
||||||
|
const
|
||||||
|
// To keep this demo as simple as possible we replace strings with the same length
|
||||||
|
REPLACE_TEXT : AnsiString = 'Save time and effort with BriskBard';
|
||||||
|
NEW_TEXT : AnsiString = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
|
||||||
|
var
|
||||||
|
TempAnsiString : AnsiString;
|
||||||
|
TempChar : PAnsiChar;
|
||||||
|
i : integer;
|
||||||
|
begin
|
||||||
|
try
|
||||||
|
try
|
||||||
|
FStreamCS.Acquire;
|
||||||
|
|
||||||
|
if FFilterInit then
|
||||||
|
begin
|
||||||
|
// This event will be called repeatedly until the input buffer has been fully read.
|
||||||
|
// When there's no more data then data_in is nil and you can show the stream contents.
|
||||||
|
|
||||||
|
if (data_in = nil) then
|
||||||
|
begin
|
||||||
|
// This is the last filter call
|
||||||
|
data_in_read := 0; // data_in_size is 0 too in this situation
|
||||||
|
data_out_written := 0;
|
||||||
|
aResult := RESPONSE_FILTER_DONE;
|
||||||
|
FRscCompleted := True;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if (data_out <> nil) then
|
||||||
|
begin
|
||||||
|
// The filter may call this function several times because it splits the resource contents in several chunks.
|
||||||
|
// If you replace a long string it could be part of 2 or more chunks and this demo would not find it.
|
||||||
|
|
||||||
|
aResult := RESPONSE_FILTER_DONE;
|
||||||
|
data_out_written := min(data_in_size, data_out_size);
|
||||||
|
data_in_read := data_out_written;
|
||||||
|
|
||||||
|
if (data_out_written > 0) then
|
||||||
|
begin
|
||||||
|
// We assume that this is a UTF8 or Ansi string.
|
||||||
|
// We use deprecated ansi string functions to search and replace strings but we should
|
||||||
|
// be decoding the buffer contents to a normal string, replace the text, encode the
|
||||||
|
// new string and copy it to the output buffer (data_out).
|
||||||
|
|
||||||
|
SetLength(TempAnsiString, data_out_written);
|
||||||
|
Move(data_in^, TempAnsiString[1], data_out_written);
|
||||||
|
TempChar := AnsiStrPos(PAnsiChar(TempAnsiString), PAnsiChar(REPLACE_TEXT));
|
||||||
|
|
||||||
|
if (TempChar <> nil) then
|
||||||
|
begin
|
||||||
|
i := (IntPtr(TempChar) - IntPtr(PAnsiChar(TempAnsiString))) div SizeOf(AnsiChar) + 1;
|
||||||
|
TempAnsiString := copy(TempAnsiString, 1, pred(i)) + NEW_TEXT + copy(TempAnsiString, i + length(REPLACE_TEXT), data_out_written);
|
||||||
|
end;
|
||||||
|
|
||||||
|
Move(TempAnsiString[1], data_out^, data_out_written);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
except
|
||||||
|
on e : exception do
|
||||||
|
begin
|
||||||
|
aResult := RESPONSE_FILTER_ERROR;
|
||||||
|
if CustomExceptionHandler('TResponseFilterBrowserFrm.ReplaceBufferText', e) then raise;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
FStreamCS.Release;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TResponseFilterBrowserFrm.IsMyResource(const aRequest : ICefRequest) : boolean;
|
||||||
|
var
|
||||||
|
TempName : ustring;
|
||||||
|
begin
|
||||||
|
Result := False;
|
||||||
|
|
||||||
|
if CopyScriptBtn.Checked then
|
||||||
|
begin
|
||||||
|
TempName := UTF8Decode(trim(RscNameEdt.Text));
|
||||||
|
|
||||||
|
if (aRequest <> nil) and (length(TempName) > 0) then
|
||||||
|
Result := (pos(TempName, aRequest.URL) > 0);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if ReplaceLogoBtn.Checked then
|
||||||
|
Result := (aRequest <> nil) and
|
||||||
|
(CompareText(UTF8Encode(aRequest.URL), 'https://www.briskbard.com/images/logo.png') = 0)
|
||||||
|
else
|
||||||
|
if ReplaceTextBtn.Checked then
|
||||||
|
Result := (aRequest <> nil) and
|
||||||
|
(CompareText(UTF8Encode(aRequest.URL), 'https://www.briskbard.com/index.php?lang=en') = 0);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TResponseFilterBrowserFrm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||||
|
begin
|
||||||
|
CanClose := FCanClose;
|
||||||
|
|
||||||
|
if not(FClosing) then
|
||||||
|
begin
|
||||||
|
FClosing := True;
|
||||||
|
Visible := False;
|
||||||
|
Chromium1.CloseBrowser(True);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TResponseFilterBrowserFrm.FormCreate(Sender: TObject);
|
||||||
|
begin
|
||||||
|
FReload := False;
|
||||||
|
FFilterInit := False;
|
||||||
|
FRscCompleted := False;
|
||||||
|
FRscSize := -1;
|
||||||
|
FStream := TMemoryStream.Create;
|
||||||
|
FStreamCS := TCriticalSection.Create;
|
||||||
|
FRscEncoding := TEncoding.Default;
|
||||||
|
|
||||||
|
FFilter := TCustomResponseFilter.Create;
|
||||||
|
(FFilter as TCustomResponseFilter).OnFilter := Filter_OnFilter;
|
||||||
|
|
||||||
|
FCanClose := False;
|
||||||
|
FClosing := False;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TResponseFilterBrowserFrm.FormDestroy(Sender: TObject);
|
||||||
|
begin
|
||||||
|
FFilter := nil;
|
||||||
|
FStream.Free;
|
||||||
|
FStreamCS.Free;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TResponseFilterBrowserFrm.FormShow(Sender: TObject);
|
||||||
|
begin
|
||||||
|
// GlobalCEFApp.GlobalContextInitialized has to be TRUE before creating any browser
|
||||||
|
// If it's not initialized yet, we use a simple timer to create the browser later.
|
||||||
|
if not(Chromium1.CreateBrowser(CEFWindowParent1)) then Timer1.Enabled := True;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TResponseFilterBrowserFrm.Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser);
|
||||||
|
begin
|
||||||
|
// Now the browser is fully initialized we can send a message to the main form to load the initial web page.
|
||||||
|
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TResponseFilterBrowserFrm.Chromium1BeforeClose(Sender: TObject; const browser: ICefBrowser);
|
||||||
|
begin
|
||||||
|
FCanClose := True;
|
||||||
|
PostMessage(Handle, WM_CLOSE, 0, 0);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TResponseFilterBrowserFrm.Chromium1BeforePopup( Sender : TObject;
|
||||||
|
const browser : ICefBrowser;
|
||||||
|
const frame : ICefFrame;
|
||||||
|
const targetUrl : ustring;
|
||||||
|
const targetFrameName : ustring;
|
||||||
|
targetDisposition : TCefWindowOpenDisposition;
|
||||||
|
userGesture : Boolean;
|
||||||
|
const popupFeatures : TCefPopupFeatures;
|
||||||
|
var windowInfo : TCefWindowInfo;
|
||||||
|
var client : ICefClient;
|
||||||
|
var settings : TCefBrowserSettings;
|
||||||
|
var extra_info : ICefDictionaryValue;
|
||||||
|
var noJavascriptAccess : Boolean;
|
||||||
|
var Result : Boolean);
|
||||||
|
begin
|
||||||
|
// For simplicity, this demo blocks all popup windows and new tabs
|
||||||
|
Result := (targetDisposition in [WOD_NEW_FOREGROUND_TAB, WOD_NEW_BACKGROUND_TAB, WOD_NEW_POPUP, WOD_NEW_WINDOW]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TResponseFilterBrowserFrm.Chromium1BeforeResourceLoad( Sender : TObject;
|
||||||
|
const browser : ICefBrowser;
|
||||||
|
const frame : ICefFrame;
|
||||||
|
const request : ICefRequest;
|
||||||
|
const callback : ICefCallback;
|
||||||
|
out Result : TCefReturnValue);
|
||||||
|
var
|
||||||
|
TempOldMap, TempNewMap : ICefStringMultimap;
|
||||||
|
i : NativeUInt;
|
||||||
|
TempReplaced : boolean;
|
||||||
|
begin
|
||||||
|
Result := RV_CONTINUE;
|
||||||
|
|
||||||
|
try
|
||||||
|
// We replace the Accept-Encoding HTTP header to request uncompressed resources.
|
||||||
|
// If the server sends uncompressed resources it should be easier to handle the
|
||||||
|
// end of the resource reception because we may know its length.
|
||||||
|
|
||||||
|
TempNewMap := TCefStringMultimapOwn.Create;
|
||||||
|
TempOldMap := TCefStringMultimapOwn.Create;
|
||||||
|
|
||||||
|
request.GetHeaderMap(TempOldMap);
|
||||||
|
|
||||||
|
TempReplaced := False;
|
||||||
|
i := 0;
|
||||||
|
while (i < TempOldMap.Size) do
|
||||||
|
begin
|
||||||
|
if (CompareText(UTF8Encode(TempOldMap.Key[i]), 'Accept-Encoding') = 0) then
|
||||||
|
begin
|
||||||
|
TempNewMap.Append('Accept-Encoding', 'identity');
|
||||||
|
TempReplaced := True;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
TempNewMap.Append(TempOldMap.Key[i], TempOldMap.Value[i]);
|
||||||
|
|
||||||
|
inc(i);
|
||||||
|
end;
|
||||||
|
|
||||||
|
if not(TempReplaced) then TempNewMap.Append('Accept-Encoding', 'identity');
|
||||||
|
request.SetHeaderMap(TempNewMap);
|
||||||
|
finally
|
||||||
|
TempNewMap := nil;
|
||||||
|
TempOldMap := nil;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TResponseFilterBrowserFrm.Chromium1Close(Sender: TObject; const browser: ICefBrowser; var aAction : TCefCloseBrowserAction);
|
||||||
|
begin
|
||||||
|
PostMessage(Handle, CEF_DESTROY, 0, 0);
|
||||||
|
aAction := cbaDelay;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TResponseFilterBrowserFrm.Chromium1GetResourceResponseFilter( Sender : TObject;
|
||||||
|
const browser : ICefBrowser;
|
||||||
|
const frame : ICefFrame;
|
||||||
|
const request : ICefRequest;
|
||||||
|
const response : ICefResponse;
|
||||||
|
out Result : ICefResponseFilter);
|
||||||
|
begin
|
||||||
|
if not(FRscCompleted) and (response <> nil) and IsMyResource(request) then
|
||||||
|
begin
|
||||||
|
Result := FFilter;
|
||||||
|
FFilterInit := True;
|
||||||
|
|
||||||
|
CheckResponseHeaders(response);
|
||||||
|
UpdateRscEncoding(UTF8Encode(response.MimeType), UTF8Encode(response.GetHeaderByName('Content-Type')));
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Result := nil;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TResponseFilterBrowserFrm.Chromium1LoadStart( Sender : TObject;
|
||||||
|
const browser : ICefBrowser;
|
||||||
|
const frame : ICefFrame;
|
||||||
|
transitionType : Cardinal);
|
||||||
|
const
|
||||||
|
IMAGE_FILENAME = 'jupiter.png';
|
||||||
|
var
|
||||||
|
TempPath : string;
|
||||||
|
begin
|
||||||
|
if (frame <> nil) and frame.IsValid and frame.IsMain then
|
||||||
|
try
|
||||||
|
try
|
||||||
|
FStreamCS.Acquire;
|
||||||
|
FStream.Clear;
|
||||||
|
|
||||||
|
TempPath := IncludeTrailingPathDelimiter(ExtractFileDir(GetModuleName(HInstance))) + IMAGE_FILENAME;
|
||||||
|
|
||||||
|
if ReplaceLogoBtn.Checked and FileExists(TempPath) then
|
||||||
|
begin
|
||||||
|
FStream.LoadFromFile(TempPath);
|
||||||
|
FStream.Seek(0, soBeginning);
|
||||||
|
end;
|
||||||
|
except
|
||||||
|
on e : exception do
|
||||||
|
if CustomExceptionHandler('TResponseFilterBrowserFrm.Chromium1LoadStart', e) then raise;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
FStreamCS.Release;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TResponseFilterBrowserFrm.UpdateRscEncoding(const aMimeType, aContentType : string);
|
||||||
|
begin
|
||||||
|
FRscMimeType := aMimeType;
|
||||||
|
|
||||||
|
if (aMimeType = 'text/html') or
|
||||||
|
(aMimeType = 'application/json') or
|
||||||
|
(aMimeType = 'text/json') or
|
||||||
|
(aMimeType = 'text/javascript') or
|
||||||
|
(aMimeType = 'application/javascript') then
|
||||||
|
GetResponseEncoding(aContentType);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TResponseFilterBrowserFrm.CheckResponseHeaders(const response : ICefResponse);
|
||||||
|
var
|
||||||
|
TempContentLength, TempContentEncoding : ustring;
|
||||||
|
TempLen : integer;
|
||||||
|
begin
|
||||||
|
try
|
||||||
|
FStreamCS.Acquire;
|
||||||
|
|
||||||
|
TempContentEncoding := trim(lowercase(response.GetHeaderByName('Content-Encoding')));
|
||||||
|
|
||||||
|
if (length(TempContentEncoding) > 0) and (TempContentEncoding <> 'identity') then
|
||||||
|
begin
|
||||||
|
// We can't use this information because Content-Length has the
|
||||||
|
// compressed length but the OnFilter event has uncompressed data.
|
||||||
|
FRscSize := -1;
|
||||||
|
StatusBar1.Panels[0].Text := 'Content-Length : compressed';
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
TempContentLength := trim(response.GetHeaderByName('Content-Length'));
|
||||||
|
|
||||||
|
if (length(TempContentLength) > 0) and
|
||||||
|
TryStrToInt(UTF8Encode(TempContentLength), TempLen) and
|
||||||
|
(TempLen > 0) then
|
||||||
|
begin
|
||||||
|
FRscSize := TempLen;
|
||||||
|
StatusBar1.Panels[0].Text := 'Content-Length : ' + inttostr(FRscSize);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
StatusBar1.Panels[0].Text := 'Content-Length : not available';
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
FStreamCS.Release;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TResponseFilterBrowserFrm.Chromium1ResourceLoadComplete( Sender : TObject;
|
||||||
|
const browser : ICefBrowser;
|
||||||
|
const frame : ICefFrame;
|
||||||
|
const request : ICefRequest;
|
||||||
|
const response : ICefResponse;
|
||||||
|
status : TCefUrlRequestStatus;
|
||||||
|
receivedContentLength : Int64);
|
||||||
|
begin
|
||||||
|
try
|
||||||
|
FStreamCS.Acquire;
|
||||||
|
|
||||||
|
// In case the server didn't send a Content-Length header
|
||||||
|
// and CEF didn't send a data_in = nil in Filter_OnFilter
|
||||||
|
// we still can use this event to know when the resource is complete
|
||||||
|
if IsMyResource(request) and CopyScriptBtn.Checked then
|
||||||
|
begin
|
||||||
|
UpdateRscEncoding(UTF8Encode(response.MimeType), UTF8Encode(response.GetHeaderByName('Content-Type')));
|
||||||
|
|
||||||
|
// Only send the message if this event is triggered before we have a OnFilter event with data_in = nil
|
||||||
|
if not(FRscCompleted) then
|
||||||
|
FRscCompleted := PostMessage(Handle, STREAM_COPY_COMPLETE, 0, 0);
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
FStreamCS.Release;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TResponseFilterBrowserFrm.Chromium1ResourceResponse( Sender : TObject;
|
||||||
|
const browser : ICefBrowser;
|
||||||
|
const frame : ICefFrame;
|
||||||
|
const request : ICefRequest;
|
||||||
|
const response : ICefResponse;
|
||||||
|
out Result : Boolean);
|
||||||
|
begin
|
||||||
|
Result := False;
|
||||||
|
|
||||||
|
if not(FRscCompleted) and (response <> nil) and IsMyResource(request) then
|
||||||
|
begin
|
||||||
|
CheckResponseHeaders(response);
|
||||||
|
UpdateRscEncoding(UTF8Encode(response.MimeType), UTF8Encode(response.GetHeaderByName('Content-Type')));
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TResponseFilterBrowserFrm.BrowserCreatedMsg(var aMessage : TMessage);
|
||||||
|
begin
|
||||||
|
Caption := 'Response Filter Browser';
|
||||||
|
AddressPnl.Enabled := True;
|
||||||
|
GoBtn.Click;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TResponseFilterBrowserFrm.BrowserDestroyMsg(var aMessage : TMessage);
|
||||||
|
begin
|
||||||
|
CEFWindowParent1.Free;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// This procedure handles the stream contents after it's fully downloaded
|
||||||
|
procedure TResponseFilterBrowserFrm.StreamCopyCompleteMsg(var aMessage : TMessage);
|
||||||
|
var
|
||||||
|
TempAnsiString : AnsiString;
|
||||||
|
TempString : String;
|
||||||
|
begin
|
||||||
|
try
|
||||||
|
FStreamCS.Acquire;
|
||||||
|
|
||||||
|
if CopyScriptBtn.Checked then
|
||||||
|
begin
|
||||||
|
if (FStream.Size > 0) then
|
||||||
|
begin
|
||||||
|
FStream.Seek(0, soBeginning);
|
||||||
|
|
||||||
|
Memo1.Lines.Clear;
|
||||||
|
|
||||||
|
if (FRscMimeType = 'application/json') or
|
||||||
|
(FRscMimeType = 'text/json') or
|
||||||
|
(FRscMimeType = 'text/javascript') or
|
||||||
|
(FRscMimeType = 'application/javascript') then
|
||||||
|
begin
|
||||||
|
StatusBar1.Panels[1].Text := 'Stream size : ' + inttostr(FStream.Size);
|
||||||
|
|
||||||
|
SetLength(TempAnsiString, FStream.Size);
|
||||||
|
FStream.Read(TempAnsiString[1], FStream.Size);
|
||||||
|
|
||||||
|
if (FRscEncoding = TEncoding.UTF8) then
|
||||||
|
TempString := TempAnsiString // UTF8 Here
|
||||||
|
else
|
||||||
|
TempString := UTF8Encode(TempAnsiString); // Others encoding text
|
||||||
|
|
||||||
|
Memo1.Lines.Add(TempString);
|
||||||
|
|
||||||
|
StatusBar1.Panels[2].Text := 'Decoded size : ' + inttostr(length(TempString));
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Memo1.Lines.LoadFromStream(FStream); // Image or others
|
||||||
|
|
||||||
|
StatusBar1.Panels[3].Text := 'Memo size : ' + inttostr(length(trim(Memo1.Lines.Text)));
|
||||||
|
|
||||||
|
// There might be a small difference in sizes because of the text decoding
|
||||||
|
|
||||||
|
FStream.Clear;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Memo1.Lines.Clear;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if ReplaceLogoBtn.Checked then
|
||||||
|
StatusBar1.Panels[1].Text := 'Stream size : ' + inttostr(FStream.Size);
|
||||||
|
finally
|
||||||
|
FStreamCS.Release;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TResponseFilterBrowserFrm.GoBtnClick(Sender: TObject);
|
||||||
|
begin
|
||||||
|
try
|
||||||
|
FStreamCS.Acquire;
|
||||||
|
|
||||||
|
FFilterInit := False;
|
||||||
|
FRscCompleted := False;
|
||||||
|
FRscSize := -1;
|
||||||
|
StatusBar1.Panels[0].Text := '';
|
||||||
|
StatusBar1.Panels[1].Text := '';
|
||||||
|
StatusBar1.Panels[2].Text := '';
|
||||||
|
StatusBar1.Panels[3].Text := '';
|
||||||
|
Memo1.Lines.Clear;
|
||||||
|
FStream.Clear;
|
||||||
|
finally
|
||||||
|
FStreamCS.Release;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
// In this demo we just reload the same web page ignoring the cache because the filter only works
|
||||||
|
// if the resources are downloaded, not if they are read from the cache.
|
||||||
|
// If you need to add this code to your app set some custom HTTP headers to download all
|
||||||
|
// resources in all cases.
|
||||||
|
|
||||||
|
if FReload then
|
||||||
|
Chromium1.ReloadIgnoreCache
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
FReload := True;
|
||||||
|
GoBtn.Caption := 'Reload';
|
||||||
|
Chromium1.LoadURL(UTF8Decode(AddressEdt.Text));
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TResponseFilterBrowserFrm.Timer1Timer(Sender: TObject);
|
||||||
|
begin
|
||||||
|
Timer1.Enabled := False;
|
||||||
|
if not(Chromium1.CreateBrowser(CEFWindowParent1)) and not(Chromium1.Initialized) then
|
||||||
|
Timer1.Enabled := True;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TResponseFilterBrowserFrm.WMMove(var aMessage : TWMMove);
|
||||||
|
begin
|
||||||
|
inherited;
|
||||||
|
|
||||||
|
if (Chromium1 <> nil) then Chromium1.NotifyMoveOrResizeStarted;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TResponseFilterBrowserFrm.WMMoving(var aMessage : TMessage);
|
||||||
|
begin
|
||||||
|
inherited;
|
||||||
|
|
||||||
|
if (Chromium1 <> nil) then Chromium1.NotifyMoveOrResizeStarted;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TResponseFilterBrowserFrm.WMEnterMenuLoop(var aMessage: TMessage);
|
||||||
|
begin
|
||||||
|
inherited;
|
||||||
|
|
||||||
|
if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := True;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TResponseFilterBrowserFrm.WMExitMenuLoop(var aMessage: TMessage);
|
||||||
|
begin
|
||||||
|
inherited;
|
||||||
|
|
||||||
|
if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := False;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TResponseFilterBrowserFrm.GetResponseEncoding(const aContentType: string);
|
||||||
|
var
|
||||||
|
LEncoding: String;
|
||||||
|
begin
|
||||||
|
{
|
||||||
|
(Name: 'Latin-US (DOS)'; CodePage: 437),
|
||||||
|
(Name: 'Western (DOS Latin 1)'; CodePage: 850),
|
||||||
|
(Name: 'Thai (Windows, DOS)'; CodePage: 874),
|
||||||
|
(Name: 'Japanese (Windows, DOS)'; CodePage: 932),
|
||||||
|
(Name: 'Simplified Chinese (Windows, DOS)'; CodePage: 936),
|
||||||
|
(Name: 'Korean (Windows, DOS)'; CodePage: 949),
|
||||||
|
(Name: 'Traditional Chinese (Windows, DOS)'; CodePage: 950),
|
||||||
|
(Name: 'Unicode (UTF-16)'; CodePage: 1200),
|
||||||
|
(Name: 'Unicode (UTF-16LE)'; CodePage: 1200),
|
||||||
|
(Name: 'Unicode (UTF-16BE)'; CodePage: 1201),
|
||||||
|
(Name: 'Central European (Windows Latin 2)'; CodePage: 1250),
|
||||||
|
(Name: 'Cyrillic (Windows)'; CodePage: 1251),
|
||||||
|
(Name: 'Western (Windows Latin 1)'; CodePage: 1252),
|
||||||
|
(Name: 'Greek (Windows)'; CodePage: 1253),
|
||||||
|
(Name: 'Turkish (Windows Latin 5)'; CodePage: 1254),
|
||||||
|
(Name: 'Hebrew (Windows)'; CodePage: 1255),
|
||||||
|
(Name: 'Arabic (Windows)'; CodePage: 1256),
|
||||||
|
(Name: 'Baltic (Windows)'; CodePage: 1257),
|
||||||
|
(Name: 'Vietnamese (Windows)'; CodePage: 1258),
|
||||||
|
(Name: 'Western (ASCII)'; CodePage: 20127),
|
||||||
|
(Name: 'Unicode (UTF-7)'; CodePage: CP_UTF7),
|
||||||
|
(Name: 'Unicode (UTF-8)'; CodePage: CP_UTF8),
|
||||||
|
// Windows code pages...
|
||||||
|
(Name: 'Windows-1252'; CodePage: 1252),
|
||||||
|
(Name: 'US-ASCII'; CodePage: 20127),
|
||||||
|
(Name: 'UTF-7'; CodePage: CP_UTF7),
|
||||||
|
(Name: 'UTF-8'; CodePage: CP_UTF8),
|
||||||
|
(Name: 'UTF-16'; CodePage: 1200),
|
||||||
|
(Name: 'UTF-16BE'; CodePage: 1201),
|
||||||
|
(Name: 'UTF-16LE'; CodePage: 1200),
|
||||||
|
(Name: 'SHIFT-JIS'; CodePage: 932),
|
||||||
|
(Name: 'ISO-8859-1'; CodePage: 28591),
|
||||||
|
(Name: 'iso-8859-1'; CodePage: 28591),
|
||||||
|
(Name: 'MACCROATIAN'; CodePage: 10082),
|
||||||
|
(Name: 'ASCII'; CodePage: 20127),
|
||||||
|
(Name: ''; CodePage: 0)
|
||||||
|
}
|
||||||
|
LEncoding := Trim(Copy(UpperCase(aContentType), Pos('CHARSET=',
|
||||||
|
UpperCase(aContentType)) + Length('CHARSET='), MaxInt));
|
||||||
|
|
||||||
|
if LEncoding = 'ANSI' then
|
||||||
|
begin
|
||||||
|
FRscEncoding := TEncoding.ANSI;
|
||||||
|
end
|
||||||
|
else if LEncoding = 'ASCII' then
|
||||||
|
begin
|
||||||
|
FRscEncoding := TEncoding.ASCII;
|
||||||
|
end
|
||||||
|
else if LEncoding = 'UTF-8' then
|
||||||
|
begin
|
||||||
|
FRscEncoding := TEncoding.UTF8;
|
||||||
|
end
|
||||||
|
else if LEncoding = 'UTF-7' then
|
||||||
|
begin
|
||||||
|
FRscEncoding := TEncoding.UTF7;
|
||||||
|
end
|
||||||
|
else if LEncoding = 'UTF-16' then
|
||||||
|
begin
|
||||||
|
FRscEncoding := TEncoding.Unicode;
|
||||||
|
end
|
||||||
|
else if LEncoding = 'UNICODEFFFE' then
|
||||||
|
begin
|
||||||
|
FRscEncoding := TEncoding.GetEncoding(1201);
|
||||||
|
end
|
||||||
|
else if LEncoding = 'UNICODE' then
|
||||||
|
begin
|
||||||
|
FRscEncoding := TEncoding.Unicode;
|
||||||
|
end
|
||||||
|
else if LEncoding = 'GB2312' then
|
||||||
|
begin
|
||||||
|
FRscEncoding := TEncoding.GetEncoding(936);
|
||||||
|
end
|
||||||
|
else if LEncoding = 'GBK' then
|
||||||
|
begin
|
||||||
|
FRscEncoding := TEncoding.GetEncoding(936);
|
||||||
|
end
|
||||||
|
else if LEncoding = 'GB18030' then
|
||||||
|
begin
|
||||||
|
FRscEncoding := TEncoding.GetEncoding(54936);
|
||||||
|
end
|
||||||
|
else if LEncoding = 'ISO-8859-1' then
|
||||||
|
begin
|
||||||
|
FRscEncoding := TEncoding.GetEncoding(28591);
|
||||||
|
end
|
||||||
|
else if LEncoding = 'BIG5' then
|
||||||
|
begin
|
||||||
|
FRscEncoding := TEncoding.GetEncoding(950);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
FRscEncoding := TEncoding.Default;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
end.
|
@ -2,7 +2,7 @@
|
|||||||
"UpdateLazPackages" : [
|
"UpdateLazPackages" : [
|
||||||
{
|
{
|
||||||
"ForceNotify" : true,
|
"ForceNotify" : true,
|
||||||
"InternalVersion" : 385,
|
"InternalVersion" : 386,
|
||||||
"Name" : "cef4delphi_lazarus.lpk",
|
"Name" : "cef4delphi_lazarus.lpk",
|
||||||
"Version" : "100.0.23.0"
|
"Version" : "100.0.23.0"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user