1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2025-06-22 22:17:48 +02:00

Added Printing support in Linux

Added the GlobalCEFApp.DisableZygote property
Added the GlobalCEFApp.OnPrintStart event.
Added the GlobalCEFApp.OnPrintSettings event.
Added the GlobalCEFApp.OnPrintDialog event.
Added the GlobalCEFApp.OnPrintJob event.
Added the GlobalCEFApp.OnPrintReset event.
Added the GlobalCEFApp.OnGetPDFPaperSize event.
This commit is contained in:
Salvador Diaz Fau
2021-01-01 17:51:09 +01:00
parent 1d984307ad
commit e3f1a0902d
18 changed files with 720 additions and 126 deletions

View File

@ -19,12 +19,12 @@
<HasResources Value="True"/> <HasResources Value="True"/>
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
<IsVisibleTab Value="True"/> <IsVisibleTab Value="True"/>
<TopLine Value="123"/> <TopLine Value="44"/>
<CursorPos X="61" Y="156"/> <CursorPos X="3" Y="171"/>
<UsageCount Value="49"/> <UsageCount Value="49"/>
<Bookmarks Count="2"> <Bookmarks Count="2">
<Item0 Y="259" ID="3"/> <Item0 Y="258" ID="3"/>
<Item1 X="57" Y="222" ID="1"/> <Item1 X="57" Y="221" ID="1"/>
</Bookmarks> </Bookmarks>
<Loaded Value="True"/> <Loaded Value="True"/>
<LoadedDesigner Value="True"/> <LoadedDesigner Value="True"/>

View File

@ -138,8 +138,6 @@ begin
// GlobalCEFApp.StartMainProcess call. // GlobalCEFApp.StartMainProcess call.
GlobalCEFWorkScheduler := TCEFWorkScheduler.Create(nil); GlobalCEFWorkScheduler := TCEFWorkScheduler.Create(nil);
//sleep(1000);
GlobalCEFApp := TCefApplication.Create; GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.ExternalMessagePump := True; GlobalCEFApp.ExternalMessagePump := True;
GlobalCEFApp.MultiThreadedMessageLoop := False; GlobalCEFApp.MultiThreadedMessageLoop := False;
@ -147,7 +145,7 @@ begin
// This is a workaround for the 'GPU is not usable error' issue : // This is a workaround for the 'GPU is not usable error' issue :
// https://bitbucket.org/chromiumembedded/cef/issues/2964/gpu-is-not-usable-error-during-cef // https://bitbucket.org/chromiumembedded/cef/issues/2964/gpu-is-not-usable-error-during-cef
GlobalCEFApp.AddCustomCommandLine('--no-zygote'); GlobalCEFApp.DisableZygote := True; // this property adds the "--no-zygote" command line switch
{ {
GlobalCEFApp.LogFile := 'cef.log'; GlobalCEFApp.LogFile := 'cef.log';
GlobalCEFApp.LogSeverity := LOGSEVERITY_VERBOSE; GlobalCEFApp.LogSeverity := LOGSEVERITY_VERBOSE;
@ -170,6 +168,7 @@ end;
procedure TForm1.Timer1Timer(Sender: TObject); procedure TForm1.Timer1Timer(Sender: TObject);
begin begin
Timer1.Enabled := False; Timer1.Enabled := False;
if not(Chromium1.CreateBrowser(CEFLinkedWindowParent1.Handle, CEFLinkedWindowParent1.BoundsRect)) and if not(Chromium1.CreateBrowser(CEFLinkedWindowParent1.Handle, CEFLinkedWindowParent1.BoundsRect)) and
not(Chromium1.Initialized) then not(Chromium1.Initialized) then
Timer1.Enabled := True; Timer1.Enabled := True;

View File

@ -3,14 +3,14 @@
<ProjectSession> <ProjectSession>
<Version Value="11"/> <Version Value="11"/>
<BuildModes Active="Default"/> <BuildModes Active="Default"/>
<Units Count="55"> <Units Count="58">
<Unit0> <Unit0>
<Filename Value="SimpleBrowser2.lpr"/> <Filename Value="SimpleBrowser2.lpr"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="18"/> <TopLine Value="18"/>
<CursorPos X="74" Y="42"/> <CursorPos X="74" Y="42"/>
<UsageCount Value="44"/> <UsageCount Value="45"/>
</Unit0> </Unit0>
<Unit1> <Unit1>
<Filename Value="usimplebrowser2.pas"/> <Filename Value="usimplebrowser2.pas"/>
@ -19,10 +19,12 @@
<HasResources Value="True"/> <HasResources Value="True"/>
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
<UnitName Value="uSimpleBrowser2"/> <UnitName Value="uSimpleBrowser2"/>
<CursorPos X="80" Y="223"/> <IsVisibleTab Value="True"/>
<UsageCount Value="44"/> <TopLine Value="113"/>
<CursorPos X="54" Y="135"/>
<UsageCount Value="45"/>
<Bookmarks Count="1"> <Bookmarks Count="1">
<Item0 Y="250" ID="3"/> <Item0 Y="249" ID="3"/>
</Bookmarks> </Bookmarks>
<Loaded Value="True"/> <Loaded Value="True"/>
<LoadedDesigner Value="True"/> <LoadedDesigner Value="True"/>
@ -32,7 +34,7 @@
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="Interfaces"/> <UnitName Value="Interfaces"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<UsageCount Value="42"/> <UsageCount Value="43"/>
</Unit2> </Unit2>
<Unit3> <Unit3>
<Filename Value="../../../../source/uCEFConstants.pas"/> <Filename Value="../../../../source/uCEFConstants.pas"/>
@ -106,11 +108,10 @@
</Unit12> </Unit12>
<Unit13> <Unit13>
<Filename Value="../../../source/uCEFWinControl.pas"/> <Filename Value="../../../source/uCEFWinControl.pas"/>
<EditorIndex Value="2"/> <EditorIndex Value="-1"/>
<TopLine Value="51"/> <TopLine Value="51"/>
<CursorPos X="29" Y="73"/> <CursorPos X="29" Y="73"/>
<UsageCount Value="19"/> <UsageCount Value="19"/>
<Loaded Value="True"/>
</Unit13> </Unit13>
<Unit14> <Unit14>
<Filename Value="/usr/share/lazarus/2.0.10/lcl/include/winapih.inc"/> <Filename Value="/usr/share/lazarus/2.0.10/lcl/include/winapih.inc"/>
@ -140,16 +141,14 @@
</Unit17> </Unit17>
<Unit18> <Unit18>
<Filename Value="../../../source/uCEFChromiumCore.pas"/> <Filename Value="../../../source/uCEFChromiumCore.pas"/>
<IsVisibleTab Value="True"/> <EditorIndex Value="-1"/>
<EditorIndex Value="3"/> <TopLine Value="43"/>
<TopLine Value="2524"/>
<CursorPos X="59" Y="2566"/> <CursorPos X="59" Y="2566"/>
<UsageCount Value="20"/> <UsageCount Value="20"/>
<Bookmarks Count="2"> <Bookmarks Count="2">
<Item0 Y="2564" ID="1"/> <Item0 Y="2564" ID="1"/>
<Item1 Y="4727" ID="2"/> <Item1 Y="4727" ID="2"/>
</Bookmarks> </Bookmarks>
<Loaded Value="True"/>
</Unit18> </Unit18>
<Unit19> <Unit19>
<Filename Value="../../../source/uCEFTypes.pas"/> <Filename Value="../../../source/uCEFTypes.pas"/>
@ -235,11 +234,10 @@
</Unit30> </Unit30>
<Unit31> <Unit31>
<Filename Value="../../../source/uCEFLinkedWindowParent.pas"/> <Filename Value="../../../source/uCEFLinkedWindowParent.pas"/>
<EditorIndex Value="1"/> <EditorIndex Value="-1"/>
<TopLine Value="51"/> <TopLine Value="51"/>
<CursorPos X="91" Y="87"/> <CursorPos X="17" Y="73"/>
<UsageCount Value="18"/> <UsageCount Value="18"/>
<Loaded Value="True"/>
</Unit31> </Unit31>
<Unit32> <Unit32>
<Filename Value="../../../../fpCEF3/cef3lib.pas"/> <Filename Value="../../../../fpCEF3/cef3lib.pas"/>
@ -265,22 +263,22 @@
<Unit35> <Unit35>
<Filename Value="../../../source/uCEFApplicationCore.pas"/> <Filename Value="../../../source/uCEFApplicationCore.pas"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="2222"/> <TopLine Value="520"/>
<CursorPos X="3" Y="2227"/> <CursorPos X="53" Y="563"/>
<UsageCount Value="9"/> <UsageCount Value="10"/>
</Unit35> </Unit35>
<Unit36> <Unit36>
<Filename Value="../../../source/uCEFApplication.pas"/> <Filename Value="../../../source/uCEFApplication.pas"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="31"/> <TopLine Value="31"/>
<CursorPos X="21" Y="38"/> <CursorPos X="21" Y="38"/>
<UsageCount Value="9"/> <UsageCount Value="10"/>
</Unit36> </Unit36>
<Unit37> <Unit37>
<Filename Value="../../../source/uCEFInterfaces.pas"/> <Filename Value="../../../source/uCEFInterfaces.pas"/>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
<TopLine Value="441"/> <TopLine Value="2269"/>
<CursorPos Y="484"/> <CursorPos X="3" Y="2276"/>
<UsageCount Value="16"/> <UsageCount Value="16"/>
</Unit37> </Unit37>
<Unit38> <Unit38>
@ -413,128 +411,90 @@
<CursorPos Y="2285"/> <CursorPos Y="2285"/>
<UsageCount Value="10"/> <UsageCount Value="10"/>
</Unit54> </Unit54>
<Unit55>
<Filename Value="../../../source/uCEFClient.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="61"/>
<UsageCount Value="10"/>
</Unit55>
<Unit56>
<Filename Value="../../../source/uCEFApp.pas"/>
<EditorIndex Value="-1"/>
<UsageCount Value="10"/>
</Unit56>
<Unit57>
<Filename Value="../../../source/uCEFBrowserProcessHandler.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="220"/>
<CursorPos Y="252"/>
<UsageCount Value="10"/>
</Unit57>
</Units> </Units>
<JumpHistory Count="30" HistoryIndex="29"> <JumpHistory Count="16" HistoryIndex="15">
<Position1> <Position1>
<Filename Value="usimplebrowser2.pas"/> <Filename Value="usimplebrowser2.pas"/>
<Caret Line="212" TopLine="190"/> <Caret Line="214" Column="47" TopLine="187"/>
</Position1> </Position1>
<Position2> <Position2>
<Filename Value="usimplebrowser2.pas"/> <Filename Value="usimplebrowser2.pas"/>
<Caret Line="218" TopLine="190"/> <Caret Line="268" Column="61" TopLine="231"/>
</Position2> </Position2>
<Position3> <Position3>
<Filename Value="../../../source/uCEFChromiumCore.pas"/> <Filename Value="usimplebrowser2.pas"/>
<Caret Line="4735" Column="59" TopLine="4717"/> <Caret Line="91" TopLine="70"/>
</Position3> </Position3>
<Position4> <Position4>
<Filename Value="../../../source/uCEFChromiumCore.pas"/> <Filename Value="usimplebrowser2.pas"/>
<Caret Line="649" TopLine="627"/> <Caret Line="211" TopLine="187"/>
</Position4> </Position4>
<Position5> <Position5>
<Filename Value="../../../source/uCEFChromiumCore.pas"/> <Filename Value="usimplebrowser2.pas"/>
<Caret Line="2566" Column="39" TopLine="2552"/> <Caret Line="265" Column="85" TopLine="229"/>
</Position5> </Position5>
<Position6> <Position6>
<Filename Value="../../../source/uCEFChromiumCore.pas"/> <Filename Value="usimplebrowser2.pas"/>
<Caret Line="4764" Column="55" TopLine="4730"/> <Caret Line="266" TopLine="229"/>
</Position6> </Position6>
<Position7> <Position7>
<Filename Value="../../../source/uCEFChromiumCore.pas"/> <Filename Value="usimplebrowser2.pas"/>
<Caret Line="818" TopLine="798"/> <Caret Line="219" Column="5" TopLine="193"/>
</Position7> </Position7>
<Position8> <Position8>
<Filename Value="../../../source/uCEFChromiumCore.pas"/> <Filename Value="usimplebrowser2.pas"/>
<Caret Line="4759" Column="5" TopLine="4733"/> <Caret Line="119" Column="67" TopLine="36"/>
</Position8> </Position8>
<Position9> <Position9>
<Filename Value="../../../source/uCEFChromiumCore.pas"/> <Filename Value="usimplebrowser2.pas"/>
<Caret Line="441" TopLine="420"/> <Caret Line="85" Column="35" TopLine="70"/>
</Position9> </Position9>
<Position10> <Position10>
<Filename Value="usimplebrowser2.pas"/> <Filename Value="usimplebrowser2.pas"/>
<Caret Line="214" Column="47" TopLine="187"/> <Caret Line="63" Column="27" TopLine="53"/>
</Position10> </Position10>
<Position11> <Position11>
<Filename Value="usimplebrowser2.pas"/> <Filename Value="usimplebrowser2.pas"/>
<Caret Line="268" Column="61" TopLine="231"/> <Caret Line="216" Column="5" TopLine="197"/>
</Position11> </Position11>
<Position12> <Position12>
<Filename Value="usimplebrowser2.pas"/> <Filename Value="usimplebrowser2.pas"/>
<Caret Line="91" TopLine="70"/> <Caret Line="137" Column="43" TopLine="101"/>
</Position12> </Position12>
<Position13> <Position13>
<Filename Value="usimplebrowser2.pas"/> <Filename Value="usimplebrowser2.pas"/>
<Caret Line="211" TopLine="187"/> <Caret Line="139" TopLine="101"/>
</Position13> </Position13>
<Position14> <Position14>
<Filename Value="usimplebrowser2.pas"/> <Filename Value="usimplebrowser2.pas"/>
<Caret Line="265" Column="85" TopLine="229"/> <Caret Line="135" TopLine="125"/>
</Position14> </Position14>
<Position15> <Position15>
<Filename Value="usimplebrowser2.pas"/> <Filename Value="usimplebrowser2.pas"/>
<Caret Line="266" TopLine="229"/> <Caret Line="140" TopLine="125"/>
</Position15> </Position15>
<Position16> <Position16>
<Filename Value="usimplebrowser2.pas"/> <Filename Value="usimplebrowser2.pas"/>
<Caret Line="219" Column="5" TopLine="193"/> <Caret Line="145" TopLine="125"/>
</Position16> </Position16>
<Position17>
<Filename Value="usimplebrowser2.pas"/>
<Caret Line="119" Column="67" TopLine="36"/>
</Position17>
<Position18>
<Filename Value="usimplebrowser2.pas"/>
<Caret Line="85" Column="35" TopLine="70"/>
</Position18>
<Position19>
<Filename Value="usimplebrowser2.pas"/>
<Caret Line="63" Column="27" TopLine="53"/>
</Position19>
<Position20>
<Filename Value="../../../source/uCEFLinkedWindowParent.pas"/>
<Caret Line="170" Column="50" TopLine="53"/>
</Position20>
<Position21>
<Filename Value="../../../source/uCEFWinControl.pas"/>
<Caret Line="63" Column="3" TopLine="42"/>
</Position21>
<Position22>
<Filename Value="../../../source/uCEFWinControl.pas"/>
<Caret Line="66" Column="20" TopLine="42"/>
</Position22>
<Position23>
<Filename Value="../../../source/uCEFWinControl.pas"/>
<Caret Line="194" Column="19" TopLine="154"/>
</Position23>
<Position24>
<Filename Value="../../../source/uCEFWinControl.pas"/>
<Caret Line="73" Column="23" TopLine="51"/>
</Position24>
<Position25>
<Filename Value="../../../source/uCEFWinControl.pas"/>
<Caret Line="144" Column="61" TopLine="114"/>
</Position25>
<Position26>
<Filename Value="../../../source/uCEFWinControl.pas"/>
<Caret Line="195" Column="13" TopLine="154"/>
</Position26>
<Position27>
<Filename Value="../../../source/uCEFLinkedWindowParent.pas"/>
<Caret Line="154" Column="54" TopLine="131"/>
</Position27>
<Position28>
<Filename Value="../../../source/uCEFLinkedWindowParent.pas"/>
<Caret Line="73" Column="20" TopLine="58"/>
</Position28>
<Position29>
<Filename Value="../../../source/uCEFLinkedWindowParent.pas"/>
<Caret Line="176" Column="58" TopLine="151"/>
</Position29>
<Position30>
<Filename Value="usimplebrowser2.pas"/>
<Caret Line="216" Column="5" TopLine="197"/>
</Position30>
</JumpHistory> </JumpHistory>
<RunParams> <RunParams>
<FormatVersion Value="2"/> <FormatVersion Value="2"/>

View File

@ -1,7 +1,7 @@
object Form1: TForm1 object Form1: TForm1
Left = 768 Left = 380
Height = 589 Height = 589
Top = 220 Top = 222
Width = 967 Width = 967
Caption = 'Initializing browser. Please wait...' Caption = 'Initializing browser. Please wait...'
ClientHeight = 589 ClientHeight = 589

View File

@ -130,7 +130,6 @@ uses
{ TForm1 } { TForm1 }
procedure CreateGlobalCEFApp; procedure CreateGlobalCEFApp;
begin begin
GlobalCEFApp := TCefApplication.Create; GlobalCEFApp := TCefApplication.Create;

View File

@ -218,7 +218,10 @@ contains
uCEFDevToolsMessageObserver in '..\source\uCEFDevToolsMessageObserver.pas', uCEFDevToolsMessageObserver in '..\source\uCEFDevToolsMessageObserver.pas',
uCEFMediaSinkDeviceInfoCallback in '..\source\uCEFMediaSinkDeviceInfoCallback.pas', uCEFMediaSinkDeviceInfoCallback in '..\source\uCEFMediaSinkDeviceInfoCallback.pas',
uCEFJson in '..\source\uCEFJson.pas', uCEFJson in '..\source\uCEFJson.pas',
uCEFBitmapBitBuffer in '..\source\uCEFBitmapBitBuffer.pas'; uCEFBitmapBitBuffer in '..\source\uCEFBitmapBitBuffer.pas',
uCEFPrintHandler in '..\source\uCEFPrintHandler.pas',
uCEFPrintDialogCallback in '..\source\uCEFPrintDialogCallback.pas',
uCEFPrintJobCallback in '..\source\uCEFPrintJobCallback.pas';
end. end.

View File

@ -215,6 +215,9 @@ contains
uCEFDevToolsMessageObserver in '..\source\uCEFDevToolsMessageObserver.pas', uCEFDevToolsMessageObserver in '..\source\uCEFDevToolsMessageObserver.pas',
uCEFMediaSinkDeviceInfoCallback in '..\source\uCEFMediaSinkDeviceInfoCallback.pas', uCEFMediaSinkDeviceInfoCallback in '..\source\uCEFMediaSinkDeviceInfoCallback.pas',
uCEFJson in '..\source\uCEFJson.pas', uCEFJson in '..\source\uCEFJson.pas',
uCEFBitmapBitBuffer in '..\source\uCEFBitmapBitBuffer.pas'; uCEFBitmapBitBuffer in '..\source\uCEFBitmapBitBuffer.pas',
uCEFPrintHandler in '..\source\uCEFPrintHandler.pas',
uCEFPrintDialogCallback in '..\source\uCEFPrintDialogCallback.pas',
uCEFPrintJobCallback in '..\source\uCEFPrintJobCallback.pas';
end. end.

View File

@ -223,7 +223,10 @@ contains
uCEFDevToolsMessageObserver in '..\source\uCEFDevToolsMessageObserver.pas', uCEFDevToolsMessageObserver in '..\source\uCEFDevToolsMessageObserver.pas',
uCEFMediaSinkDeviceInfoCallback in '..\source\uCEFMediaSinkDeviceInfoCallback.pas', uCEFMediaSinkDeviceInfoCallback in '..\source\uCEFMediaSinkDeviceInfoCallback.pas',
uCEFJson in '..\source\uCEFJson.pas', uCEFJson in '..\source\uCEFJson.pas',
uCEFBitmapBitBuffer in '..\source\uCEFBitmapBitBuffer.pas'; uCEFBitmapBitBuffer in '..\source\uCEFBitmapBitBuffer.pas',
uCEFPrintHandler in '..\source\uCEFPrintHandler.pas',
uCEFPrintDialogCallback in '..\source\uCEFPrintDialogCallback.pas',
uCEFPrintJobCallback in '..\source\uCEFPrintJobCallback.pas';
end. end.

View File

@ -339,6 +339,9 @@
<DCCReference Include="..\source\uCEFMediaSinkDeviceInfoCallback.pas"/> <DCCReference Include="..\source\uCEFMediaSinkDeviceInfoCallback.pas"/>
<DCCReference Include="..\source\uCEFJson.pas"/> <DCCReference Include="..\source\uCEFJson.pas"/>
<DCCReference Include="..\source\uCEFBitmapBitBuffer.pas"/> <DCCReference Include="..\source\uCEFBitmapBitBuffer.pas"/>
<DCCReference Include="..\source\uCEFPrintHandler.pas"/>
<DCCReference Include="..\source\uCEFPrintDialogCallback.pas"/>
<DCCReference Include="..\source\uCEFPrintJobCallback.pas"/>
<BuildConfiguration Include="Base"> <BuildConfiguration Include="Base">
<Key>Base</Key> <Key>Base</Key>
</BuildConfiguration> </BuildConfiguration>

View File

@ -22,7 +22,7 @@
<Description Value="CEF4Delphi is an open source project created by Salvador Díaz Fau to embed Chromium-based browsers in applications made with Delphi or Lazarus/FPC."/> <Description Value="CEF4Delphi is an open source project created by Salvador Díaz Fau to embed Chromium-based browsers in applications made with Delphi or Lazarus/FPC."/>
<License Value="MPL 1.1"/> <License Value="MPL 1.1"/>
<Version Major="87" Minor="1" Release="12"/> <Version Major="87" Minor="1" Release="12"/>
<Files Count="190"> <Files Count="193">
<Item1> <Item1>
<Filename Value="..\source\uCEFAccessibilityHandler.pas"/> <Filename Value="..\source\uCEFAccessibilityHandler.pas"/>
<UnitName Value="uCEFAccessibilityHandler"/> <UnitName Value="uCEFAccessibilityHandler"/>
@ -799,6 +799,18 @@
<Filename Value="..\source\uCEFBitmapBitBuffer.pas"/> <Filename Value="..\source\uCEFBitmapBitBuffer.pas"/>
<UnitName Value="uCEFBitmapBitBuffer"/> <UnitName Value="uCEFBitmapBitBuffer"/>
</Item190> </Item190>
<Item191>
<Filename Value="..\source\uCEFPrintDialogCallback.pas"/>
<UnitName Value="uCEFPrintDialogCallback"/>
</Item191>
<Item192>
<Filename Value="..\source\uCEFPrintHandler.pas"/>
<UnitName Value="uCEFPrintHandler"/>
</Item192>
<Item193>
<Filename Value="..\source\uCEFPrintJobCallback.pas"/>
<UnitName Value="uCEFPrintJobCallback"/>
</Item193>
</Files> </Files>
<RequiredPkgs Count="4"> <RequiredPkgs Count="4">
<Item1> <Item1>

View File

@ -63,6 +63,7 @@ uses
uCEFScrollViewComponent, uCEFTextfieldComponent, uCEFViewComponent, uCEFScrollViewComponent, uCEFTextfieldComponent, uCEFViewComponent,
uCEFViewsFrameworkEvents, uCEFAudioHandler, uCEFDevToolsMessageObserver, uCEFViewsFrameworkEvents, uCEFAudioHandler, uCEFDevToolsMessageObserver,
uCEFMediaSinkDeviceInfoCallback, uCEFJson, uCEFBitmapBitBuffer, uCEFMediaSinkDeviceInfoCallback, uCEFJson, uCEFBitmapBitBuffer,
uCEFPrintDialogCallback, uCEFPrintHandler, uCEFPrintJobCallback,
LazarusPackageIntf; LazarusPackageIntf;
implementation implementation

View File

@ -172,6 +172,7 @@ type
FDevToolsProtocolLogFile : ustring; FDevToolsProtocolLogFile : ustring;
FDeviceScaleFactor : single; FDeviceScaleFactor : single;
FForcedDeviceScaleFactor : single; FForcedDeviceScaleFactor : single;
FDisableZygote : boolean;
FPluginPolicy : TCefPluginPolicySwitch; FPluginPolicy : TCefPluginPolicySwitch;
FDefaultEncoding : ustring; FDefaultEncoding : ustring;
@ -197,6 +198,7 @@ type
FMustCreateBrowserProcessHandler : boolean; FMustCreateBrowserProcessHandler : boolean;
FMustCreateRenderProcessHandler : boolean; FMustCreateRenderProcessHandler : boolean;
FMustCreateLoadHandler : boolean; FMustCreateLoadHandler : boolean;
FMustCreatePrintHandler : boolean;
// ICefBrowserProcessHandler // ICefBrowserProcessHandler
FOnGetCookieableSchemes : TOnGetCookieableSchemesEvent; FOnGetCookieableSchemes : TOnGetCookieableSchemesEvent;
@ -229,6 +231,14 @@ type
FOnLoadEnd : TOnRenderLoadEnd; FOnLoadEnd : TOnRenderLoadEnd;
FOnLoadError : TOnRenderLoadError; FOnLoadError : TOnRenderLoadError;
// ICefPrintHandler
FOnPrintStart : TOnPrintStartEvent;
FOnPrintSettings : TOnPrintSettingsEvent;
FOnPrintDialog : TOnPrintDialogEvent;
FOnPrintJob : TOnPrintJobEvent;
FOnPrintReset : TOnPrintResetEvent;
FOnGetPDFPaperSize : TOnGetPDFPaperSizeEvent;
procedure SetCache(const aValue : ustring); procedure SetCache(const aValue : ustring);
procedure SetRootCache(const aValue : ustring); procedure SetRootCache(const aValue : ustring);
procedure SetUserDataPath(const aValue : ustring); procedure SetUserDataPath(const aValue : ustring);
@ -246,6 +256,7 @@ type
function GetMustCreateBrowserProcessHandler : boolean; virtual; function GetMustCreateBrowserProcessHandler : boolean; virtual;
function GetMustCreateRenderProcessHandler : boolean; virtual; function GetMustCreateRenderProcessHandler : boolean; virtual;
function GetMustCreateLoadHandler : boolean; virtual; function GetMustCreateLoadHandler : boolean; virtual;
function GetMustCreatePrintHandler : boolean; virtual;
function GetGlobalContextInitialized : boolean; function GetGlobalContextInitialized : boolean;
function GetChildProcessesCount : integer; function GetChildProcessesCount : integer;
function GetUsedMemory : uint64; function GetUsedMemory : uint64;
@ -345,9 +356,9 @@ type
procedure QuitMessageLoop; procedure QuitMessageLoop;
procedure UpdateDeviceScaleFactor; virtual; procedure UpdateDeviceScaleFactor; virtual;
// Internal procedures. Only TInternalApp, TCefCustomBrowserProcessHandler, // Internal procedures. Only ICefApp, ICefBrowserProcessHandler,
// ICefResourceBundleHandler, ICefRenderProcessHandler, ICefRegisterCDMCallback // ICefResourceBundleHandler, ICefRenderProcessHandler, ICefRegisterCDMCallback,
// and ICefLoadHandler should use them. // ICefLoadHandler and ICefPrintHandler should use them.
procedure Internal_OnBeforeCommandLineProcessing(const processType: ustring; const commandLine: ICefCommandLine); procedure Internal_OnBeforeCommandLineProcessing(const processType: ustring; const commandLine: ICefCommandLine);
procedure Internal_OnRegisterCustomSchemes(const registrar: TCefSchemeRegistrarRef); procedure Internal_OnRegisterCustomSchemes(const registrar: TCefSchemeRegistrarRef);
procedure Internal_OnContextInitialized; procedure Internal_OnContextInitialized;
@ -371,6 +382,12 @@ type
procedure Internal_OnLoadError(const browser: ICefBrowser; const frame: ICefFrame; errorCode: Integer; const errorText, failedUrl: ustring); procedure Internal_OnLoadError(const browser: ICefBrowser; const frame: ICefFrame; errorCode: Integer; const errorText, failedUrl: ustring);
procedure Internal_GetCookieableSchemes(var schemes: TStringList; var include_defaults : boolean); procedure Internal_GetCookieableSchemes(var schemes: TStringList; var include_defaults : boolean);
procedure Internal_GetDefaultClient(var aClient : ICefClient); procedure Internal_GetDefaultClient(var aClient : ICefClient);
procedure Internal_OnPrintStart(const browser: ICefBrowser);
procedure Internal_OnPrintSettings(const browser: ICefBrowser; const settings: ICefPrintSettings; getDefaults: boolean);
procedure Internal_OnPrintDialog(const browser: ICefBrowser; hasSelection: boolean; const callback: ICefPrintDialogCallback; var aResult : boolean);
procedure Internal_OnPrintJob(const browser: ICefBrowser; const documentName, PDFFilePath: ustring; const callback: ICefPrintJobCallback; var aResult : boolean);
procedure Internal_OnPrintReset(const browser: ICefBrowser);
procedure Internal_OnGetPDFPaperSize(deviceUnitsPerInch: Integer; var aResult : TCefSize);
// Properties used to populate TCefSettings (cef_settings_t) // Properties used to populate TCefSettings (cef_settings_t)
property NoSandbox : Boolean read FNoSandbox write FNoSandbox; property NoSandbox : Boolean read FNoSandbox write FNoSandbox;
@ -454,6 +471,7 @@ type
property DisableNewBrowserInfoTimeout : boolean read FDisableNewBrowserInfoTimeout write FDisableNewBrowserInfoTimeout; // --disable-new-browser-info-timeout property DisableNewBrowserInfoTimeout : boolean read FDisableNewBrowserInfoTimeout write FDisableNewBrowserInfoTimeout; // --disable-new-browser-info-timeout
property DevToolsProtocolLogFile : ustring read FDevToolsProtocolLogFile write FDevToolsProtocolLogFile; // --devtools-protocol-log-file property DevToolsProtocolLogFile : ustring read FDevToolsProtocolLogFile write FDevToolsProtocolLogFile; // --devtools-protocol-log-file
property ForcedDeviceScaleFactor : single read FForcedDeviceScaleFactor write FForcedDeviceScaleFactor; // --device-scale-factor property ForcedDeviceScaleFactor : single read FForcedDeviceScaleFactor write FForcedDeviceScaleFactor; // --device-scale-factor
property DisableZygote : boolean read FDisableZygote write FDisableZygote; // --no-zygote
// Properties used during the CEF initialization // Properties used during the CEF initialization
property WindowsSandboxInfo : Pointer read FWindowsSandboxInfo write FWindowsSandboxInfo; property WindowsSandboxInfo : Pointer read FWindowsSandboxInfo write FWindowsSandboxInfo;
@ -487,6 +505,7 @@ type
property MustCreateBrowserProcessHandler : boolean read GetMustCreateBrowserProcessHandler write FMustCreateBrowserProcessHandler; property MustCreateBrowserProcessHandler : boolean read GetMustCreateBrowserProcessHandler write FMustCreateBrowserProcessHandler;
property MustCreateRenderProcessHandler : boolean read GetMustCreateRenderProcessHandler write FMustCreateRenderProcessHandler; property MustCreateRenderProcessHandler : boolean read GetMustCreateRenderProcessHandler write FMustCreateRenderProcessHandler;
property MustCreateLoadHandler : boolean read GetMustCreateLoadHandler write FMustCreateLoadHandler; property MustCreateLoadHandler : boolean read GetMustCreateLoadHandler write FMustCreateLoadHandler;
property MustCreatePrintHandler : boolean read GetMustCreatePrintHandler write FMustCreatePrintHandler;
property OsmodalLoop : boolean write SetOsmodalLoop; property OsmodalLoop : boolean write SetOsmodalLoop;
property Status : TCefAplicationStatus read FStatus; property Status : TCefAplicationStatus read FStatus;
property MissingLibFiles : string read FMissingLibFiles; property MissingLibFiles : string read FMissingLibFiles;
@ -535,6 +554,16 @@ type
property OnLoadStart : TOnRenderLoadStart read FOnLoadStart write FOnLoadStart; property OnLoadStart : TOnRenderLoadStart read FOnLoadStart write FOnLoadStart;
property OnLoadEnd : TOnRenderLoadEnd read FOnLoadEnd write FOnLoadEnd; property OnLoadEnd : TOnRenderLoadEnd read FOnLoadEnd write FOnLoadEnd;
property OnLoadError : TOnRenderLoadError read FOnLoadError write FOnLoadError; property OnLoadError : TOnRenderLoadError read FOnLoadError write FOnLoadError;
// ICefPrintHandler
{$IFDEF LINUX}
property OnPrintStart : TOnPrintStartEvent read FOnPrintStart write FOnPrintStart;
property OnPrintSettings : TOnPrintSettingsEvent read FOnPrintSettings write FOnPrintSettings;
property OnPrintDialog : TOnPrintDialogEvent read FOnPrintDialog write FOnPrintDialog;
property OnPrintJob : TOnPrintJobEvent read FOnPrintJob write FOnPrintJob;
property OnPrintReset : TOnPrintResetEvent read FOnPrintReset write FOnPrintReset;
property OnGetPDFPaperSize : TOnGetPDFPaperSizeEvent read FOnGetPDFPaperSize write FOnGetPDFPaperSize;
{$ENDIF}
end; end;
TCEFDirectoryDeleterThread = class(TThread) TCEFDirectoryDeleterThread = class(TThread)
@ -697,6 +726,7 @@ begin
FDisableNewBrowserInfoTimeout := False; FDisableNewBrowserInfoTimeout := False;
FDevToolsProtocolLogFile := ''; FDevToolsProtocolLogFile := '';
FForcedDeviceScaleFactor := 0; FForcedDeviceScaleFactor := 0;
FDisableZygote := False;
FDisableJavascriptCloseWindows := False; FDisableJavascriptCloseWindows := False;
FDisableJavascriptAccessClipboard := False; FDisableJavascriptAccessClipboard := False;
@ -719,6 +749,7 @@ begin
FMustCreateBrowserProcessHandler := True; FMustCreateBrowserProcessHandler := True;
FMustCreateRenderProcessHandler := False; FMustCreateRenderProcessHandler := False;
FMustCreateLoadHandler := False; FMustCreateLoadHandler := False;
FMustCreatePrintHandler := False;
// ICefBrowserProcessHandler // ICefBrowserProcessHandler
FOnGetCookieableSchemes := nil; FOnGetCookieableSchemes := nil;
@ -751,6 +782,14 @@ begin
FOnLoadEnd := nil; FOnLoadEnd := nil;
FOnLoadError := nil; FOnLoadError := nil;
// ICefPrintHandler
FOnPrintStart := nil;
FOnPrintSettings := nil;
FOnPrintDialog := nil;
FOnPrintJob := nil;
FOnPrintReset := nil;
FOnGetPDFPaperSize := nil;
UpdateDeviceScaleFactor; UpdateDeviceScaleFactor;
FillChar(FAppSettings, SizeOf(TCefSettings), 0); FillChar(FAppSettings, SizeOf(TCefSettings), 0);
@ -1699,6 +1738,42 @@ begin
FOnGetDefaultClient(aClient); FOnGetDefaultClient(aClient);
end; end;
procedure TCefApplicationCore.Internal_OnPrintStart(const browser: ICefBrowser);
begin
if assigned(FOnPrintStart) then
FOnPrintStart(browser);
end;
procedure TCefApplicationCore.Internal_OnPrintSettings(const browser: ICefBrowser; const settings: ICefPrintSettings; getDefaults: boolean);
begin
if assigned(FOnPrintSettings) then
FOnPrintSettings(browser, settings, getDefaults);
end;
procedure TCefApplicationCore.Internal_OnPrintDialog(const browser: ICefBrowser; hasSelection: boolean; const callback: ICefPrintDialogCallback; var aResult : boolean);
begin
if assigned(FOnPrintDialog) then
FOnPrintDialog(browser, hasSelection, callback, aResult);
end;
procedure TCefApplicationCore.Internal_OnPrintJob(const browser: ICefBrowser; const documentName, PDFFilePath: ustring; const callback: ICefPrintJobCallback; var aResult : boolean);
begin
if assigned(FOnPrintJob) then
FOnPrintJob(browser, documentName, PDFFilePath, callback, aResult);
end;
procedure TCefApplicationCore.Internal_OnPrintReset(const browser: ICefBrowser);
begin
if assigned(FOnPrintReset) then
FOnPrintReset(browser);
end;
procedure TCefApplicationCore.Internal_OnGetPDFPaperSize(deviceUnitsPerInch: Integer; var aResult : TCefSize);
begin
if assigned(FOnGetPDFPaperSize) then
FOnGetPDFPaperSize(deviceUnitsPerInch, aResult);
end;
procedure TCefApplicationCore.AppendSwitch(var aKeys, aValues : TStringList; const aNewKey, aNewValue : ustring); procedure TCefApplicationCore.AppendSwitch(var aKeys, aValues : TStringList; const aNewKey, aNewValue : ustring);
var var
TempKey : ustring; TempKey : ustring;
@ -1940,6 +2015,9 @@ begin
ReplaceSwitch(aKeys, aValues, '--force-device-scale-factor', FloatToStr(FForcedDeviceScaleFactor, TempFormatSettings)); ReplaceSwitch(aKeys, aValues, '--force-device-scale-factor', FloatToStr(FForcedDeviceScaleFactor, TempFormatSettings));
end; end;
if FDisableZygote then
ReplaceSwitch(aKeys, aValues, '--no-zygote');
// The list of features you can enable is here : // The list of features you can enable is here :
// https://chromium.googlesource.com/chromium/src/+/master/chrome/common/chrome_features.cc // https://chromium.googlesource.com/chromium/src/+/master/chrome/common/chrome_features.cc
if (length(FEnableFeatures) > 0) then if (length(FEnableFeatures) > 0) then
@ -2050,6 +2128,7 @@ function TCefApplicationCore.GetMustCreateBrowserProcessHandler : boolean;
begin begin
Result := ((FSingleProcess or (FProcessType = ptBrowser)) and Result := ((FSingleProcess or (FProcessType = ptBrowser)) and
(FMustCreateBrowserProcessHandler or (FMustCreateBrowserProcessHandler or
MustCreatePrintHandler or
assigned(FOnGetCookieableSchemes) or assigned(FOnGetCookieableSchemes) or
assigned(FOnContextInitialized) or assigned(FOnContextInitialized) or
assigned(FOnBeforeChildProcessLaunch) or assigned(FOnBeforeChildProcessLaunch) or
@ -2082,6 +2161,22 @@ begin
assigned(FOnLoadError))); assigned(FOnLoadError)));
end; end;
function TCefApplicationCore.GetMustCreatePrintHandler : boolean;
begin
{$IFDEF LINUX}
Result := ((FSingleProcess or (FProcessType = ptBrowser)) and
(FMustCreatePrintHandler or
assigned(FOnPrintStart) or
assigned(FOnPrintSettings) or
assigned(FOnPrintDialog) or
assigned(FOnPrintJob) or
assigned(FOnPrintReset) or
assigned(FOnGetPDFPaperSize)));
{$ELSE}
Result := False;
{$ENDIF}
end;
function TCefApplicationCore.GetGlobalContextInitialized : boolean; function TCefApplicationCore.GetGlobalContextInitialized : boolean;
begin begin
Result := FGlobalContextInitialized or not(MustCreateBrowserProcessHandler); Result := FGlobalContextInitialized or not(MustCreateBrowserProcessHandler);

View File

@ -74,11 +74,13 @@ type
TCefCustomBrowserProcessHandler = class(TCefBrowserProcessHandlerOwn) TCefCustomBrowserProcessHandler = class(TCefBrowserProcessHandlerOwn)
protected protected
FCefApp : TCefApplicationCore; FCefApp : TCefApplicationCore;
FPrintHandler : ICefPrintHandler;
procedure GetCookieableSchemes(var schemes: TStringList; var include_defaults : boolean); override; procedure GetCookieableSchemes(var schemes: TStringList; var include_defaults : boolean); override;
procedure OnContextInitialized; override; procedure OnContextInitialized; override;
procedure OnBeforeChildProcessLaunch(const commandLine: ICefCommandLine); override; procedure OnBeforeChildProcessLaunch(const commandLine: ICefCommandLine); override;
procedure GetPrintHandler(var aHandler : ICefPrintHandler); override;
procedure OnScheduleMessagePumpWork(const delayMs: Int64); override; procedure OnScheduleMessagePumpWork(const delayMs: Int64); override;
procedure GetDefaultClient(var aClient : ICefClient); override; procedure GetDefaultClient(var aClient : ICefClient); override;
@ -97,7 +99,8 @@ uses
{$ELSE} {$ELSE}
SysUtils, SysUtils,
{$ENDIF} {$ENDIF}
uCEFMiscFunctions, uCEFLibFunctions, uCEFCommandLine, uCEFListValue, uCEFConstants, uCEFStringList; uCEFMiscFunctions, uCEFLibFunctions, uCEFCommandLine, uCEFListValue, uCEFConstants, uCEFStringList,
uCEFPrintHandler;
procedure cef_browser_process_handler_get_cookieable_schemes(self : PCefBrowserProcessHandler; procedure cef_browser_process_handler_get_cookieable_schemes(self : PCefBrowserProcessHandler;
schemes : TCefStringList; schemes : TCefStringList;
@ -228,7 +231,7 @@ end;
procedure TCefBrowserProcessHandlerOwn.GetPrintHandler(var aHandler : ICefPrintHandler); procedure TCefBrowserProcessHandlerOwn.GetPrintHandler(var aHandler : ICefPrintHandler);
begin begin
aHandler := nil; // only linux aHandler := nil;
end; end;
procedure TCefBrowserProcessHandlerOwn.GetDefaultClient(var aClient : ICefClient); procedure TCefBrowserProcessHandlerOwn.GetDefaultClient(var aClient : ICefClient);
@ -245,6 +248,11 @@ begin
inherited Create; inherited Create;
FCefApp := aCefApp; FCefApp := aCefApp;
if (FCefApp <> nil) and FCefApp.MustCreatePrintHandler then
FPrintHandler := TCustomPrintHandler.Create(FCefApp)
else
FPrintHandler := nil;
end; end;
destructor TCefCustomBrowserProcessHandler.Destroy; destructor TCefCustomBrowserProcessHandler.Destroy;
@ -256,7 +264,11 @@ end;
procedure TCefCustomBrowserProcessHandler.RemoveReferences; procedure TCefCustomBrowserProcessHandler.RemoveReferences;
begin begin
if (FPrintHandler <> nil) then
FPrintHandler.RemoveReferences;
FCefApp := nil;
FPrintHandler := nil; FPrintHandler := nil;
end; end;
@ -289,6 +301,14 @@ begin
on e : exception do on e : exception do
if CustomExceptionHandler('TCefCustomBrowserProcessHandler.OnBeforeChildProcessLaunch', e) then raise; if CustomExceptionHandler('TCefCustomBrowserProcessHandler.OnBeforeChildProcessLaunch', e) then raise;
end; end;
end;
procedure TCefCustomBrowserProcessHandler.GetPrintHandler(var aHandler : ICefPrintHandler);
begin
if (FPrintHandler <> nil) then
aHandler := FPrintHandler
else
inherited GetPrintHandler(aHandler);
end; end;
procedure TCefCustomBrowserProcessHandler.OnScheduleMessagePumpWork(const delayMs: Int64); procedure TCefCustomBrowserProcessHandler.OnScheduleMessagePumpWork(const delayMs: Int64);

View File

@ -154,6 +154,7 @@ type
ICefAudioHandler = interface; ICefAudioHandler = interface;
ICefDevToolsMessageObserver = interface; ICefDevToolsMessageObserver = interface;
ICefValue = interface; ICefValue = interface;
ICefPrintSettings = interface;
TCefv8ValueArray = array of ICefv8Value; TCefv8ValueArray = array of ICefv8Value;
TCefX509CertificateArray = array of ICefX509Certificate; TCefX509CertificateArray = array of ICefX509Certificate;
@ -219,6 +220,12 @@ type
TOnRenderLoadEnd = {$IFDEF DELPHI12_UP}reference to{$ENDIF} procedure(const browser: ICefBrowser; const frame: ICefFrame; httpStatusCode: Integer) {$IFNDEF DELPHI12_UP}{$IFNDEF FPC}of object{$ENDIF}{$ENDIF}; TOnRenderLoadEnd = {$IFDEF DELPHI12_UP}reference to{$ENDIF} procedure(const browser: ICefBrowser; const frame: ICefFrame; httpStatusCode: Integer) {$IFNDEF DELPHI12_UP}{$IFNDEF FPC}of object{$ENDIF}{$ENDIF};
TOnRenderLoadError = {$IFDEF DELPHI12_UP}reference to{$ENDIF} procedure(const browser: ICefBrowser; const frame: ICefFrame; errorCode: TCefErrorCode; const errorText, failedUrl: ustring) {$IFNDEF DELPHI12_UP}{$IFNDEF FPC}of object{$ENDIF}{$ENDIF}; TOnRenderLoadError = {$IFDEF DELPHI12_UP}reference to{$ENDIF} procedure(const browser: ICefBrowser; const frame: ICefFrame; errorCode: TCefErrorCode; const errorText, failedUrl: ustring) {$IFNDEF DELPHI12_UP}{$IFNDEF FPC}of object{$ENDIF}{$ENDIF};
TOnRenderLoadingStateChange = {$IFDEF DELPHI12_UP}reference to{$ENDIF} procedure(const browser: ICefBrowser; isLoading, canGoBack, canGoForward: Boolean) {$IFNDEF DELPHI12_UP}{$IFNDEF FPC}of object{$ENDIF}{$ENDIF}; TOnRenderLoadingStateChange = {$IFDEF DELPHI12_UP}reference to{$ENDIF} procedure(const browser: ICefBrowser; isLoading, canGoBack, canGoForward: Boolean) {$IFNDEF DELPHI12_UP}{$IFNDEF FPC}of object{$ENDIF}{$ENDIF};
TOnPrintStartEvent = {$IFDEF DELPHI12_UP}reference to{$ENDIF} procedure(const browser: ICefBrowser) {$IFNDEF DELPHI12_UP}{$IFNDEF FPC}of object{$ENDIF}{$ENDIF};
TOnPrintSettingsEvent = {$IFDEF DELPHI12_UP}reference to{$ENDIF} procedure(const browser: ICefBrowser; const settings: ICefPrintSettings; getDefaults: boolean) {$IFNDEF DELPHI12_UP}{$IFNDEF FPC}of object{$ENDIF}{$ENDIF};
TOnPrintDialogEvent = {$IFDEF DELPHI12_UP}reference to{$ENDIF} procedure(const browser: ICefBrowser; hasSelection: boolean; const callback: ICefPrintDialogCallback; var aResult : boolean) {$IFNDEF DELPHI12_UP}{$IFNDEF FPC}of object{$ENDIF}{$ENDIF};
TOnPrintJobEvent = {$IFDEF DELPHI12_UP}reference to{$ENDIF} procedure(const browser: ICefBrowser; const documentName, PDFFilePath: ustring; const callback: ICefPrintJobCallback; var aResult : boolean) {$IFNDEF DELPHI12_UP}{$IFNDEF FPC}of object{$ENDIF}{$ENDIF};
TOnPrintResetEvent = {$IFDEF DELPHI12_UP}reference to{$ENDIF} procedure(const browser: ICefBrowser) {$IFNDEF DELPHI12_UP}{$IFNDEF FPC}of object{$ENDIF}{$ENDIF};
TOnGetPDFPaperSizeEvent = {$IFDEF DELPHI12_UP}reference to{$ENDIF} procedure(deviceUnitsPerInch: Integer; var aResult : TCefSize) {$IFNDEF DELPHI12_UP}{$IFNDEF FPC}of object{$ENDIF}{$ENDIF};
// ******************************************* // *******************************************
// **** Callback procedures and functions **** // **** Callback procedures and functions ****
@ -2322,10 +2329,12 @@ type
['{2831D5C9-6E2B-4A30-A65A-0F4435371EFC}'] ['{2831D5C9-6E2B-4A30-A65A-0F4435371EFC}']
procedure OnPrintStart(const browser: ICefBrowser); procedure OnPrintStart(const browser: ICefBrowser);
procedure OnPrintSettings(const browser: ICefBrowser; const settings: ICefPrintSettings; getDefaults: boolean); procedure OnPrintSettings(const browser: ICefBrowser; const settings: ICefPrintSettings; getDefaults: boolean);
function OnPrintDialog(const browser: ICefBrowser; hasSelection: boolean; const callback: ICefPrintDialogCallback): boolean; procedure OnPrintDialog(const browser: ICefBrowser; hasSelection: boolean; const callback: ICefPrintDialogCallback; var aResult: boolean);
function OnPrintJob(const browser: ICefBrowser; const documentName, PDFFilePath: ustring; const callback: ICefPrintJobCallback): boolean; procedure OnPrintJob(const browser: ICefBrowser; const documentName, PDFFilePath: ustring; const callback: ICefPrintJobCallback; var aResult: boolean);
procedure OnPrintReset(const browser: ICefBrowser); procedure OnPrintReset(const browser: ICefBrowser);
function GetPDFPaperSize(deviceUnitsPerInch: Integer): TCefSize; procedure GetPDFPaperSize(deviceUnitsPerInch: integer; var aResult: TCefSize);
procedure RemoveReferences; // custom procedure to clear all references
end; end;
// TCefNavigationEntry // TCefNavigationEntry

View File

@ -0,0 +1,87 @@
// ************************************************************************
// ***************************** 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 � 2021 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 uCEFPrintDialogCallback;
{$IFDEF FPC}
{$MODE OBJFPC}{$H+}
{$ENDIF}
{$IFNDEF CPUX64}{$ALIGN ON}{$ENDIF}
{$MINENUMSIZE 4}
{$I cef.inc}
interface
uses
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes;
type
TCefPrintDialogCallbackRef = class(TCefBaseRefCountedRef, ICefPrintDialogCallback)
protected
procedure cont(const settings: ICefPrintSettings);
procedure cancel;
public
class function UnWrap(data: Pointer): ICefPrintDialogCallback;
end;
implementation
uses
uCEFMiscFunctions, uCEFLibFunctions;
procedure TCefPrintDialogCallbackRef.cancel;
begin
PCefPrintDialogCallback(FData)^.cancel(PCefPrintDialogCallback(FData));
end;
procedure TCefPrintDialogCallbackRef.cont(const settings: ICefPrintSettings);
begin
PCefPrintDialogCallback(FData)^.cont(PCefPrintDialogCallback(FData), CefGetData(settings));
end;
class function TCefPrintDialogCallbackRef.UnWrap(data: Pointer): ICefPrintDialogCallback;
begin
if (data <> nil) then
Result := Create(data) as ICefPrintDialogCallback
else
Result := nil;
end;
end.

319
source/uCEFPrintHandler.pas Normal file
View File

@ -0,0 +1,319 @@
// ************************************************************************
// ***************************** 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 � 2021 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 uCEFPrintHandler;
{$IFDEF FPC}
{$MODE OBJFPC}{$H+}
{$ENDIF}
{$IFNDEF CPUX64}{$ALIGN ON}{$ENDIF}
{$MINENUMSIZE 4}
{$I cef.inc}
interface
uses
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes, uCEFApplicationCore;
type
TCefPrintHandlerOwn = class(TCefBaseRefCountedOwn, ICefPrintHandler)
protected
procedure OnPrintStart(const browser: ICefBrowser); virtual; abstract;
procedure OnPrintSettings(const browser: ICefBrowser; const settings: ICefPrintSettings; getDefaults: boolean); virtual; abstract;
procedure OnPrintDialog(const browser: ICefBrowser; hasSelection: boolean; const callback: ICefPrintDialogCallback; var aResult: boolean); virtual;
procedure OnPrintJob(const browser: ICefBrowser; const documentName, PDFFilePath: ustring; const callback: ICefPrintJobCallback; var aResult: boolean); virtual;
procedure OnPrintReset(const browser: ICefBrowser); virtual; abstract;
procedure GetPDFPaperSize(deviceUnitsPerInch: Integer; var aResult: TCefSize); virtual;
procedure RemoveReferences; virtual; abstract;
public
constructor Create; virtual;
end;
TCustomPrintHandler = class(TCefPrintHandlerOwn)
protected
FCefApp : TCefApplicationCore;
procedure OnPrintStart(const browser: ICefBrowser); override;
procedure OnPrintSettings(const browser: ICefBrowser; const settings: ICefPrintSettings; getDefaults: boolean); override;
procedure OnPrintDialog(const browser: ICefBrowser; hasSelection: boolean; const callback: ICefPrintDialogCallback; var aResult: boolean); override;
procedure OnPrintJob(const browser: ICefBrowser; const documentName, PDFFilePath: ustring; const callback: ICefPrintJobCallback; var aResult: boolean); override;
procedure OnPrintReset(const browser: ICefBrowser); override;
procedure GetPDFPaperSize(deviceUnitsPerInch: Integer; var aResult: TCefSize); override;
procedure RemoveReferences; override;
public
constructor Create(const aCefApp : TCefApplicationCore); reintroduce; virtual;
destructor Destroy; override;
end;
implementation
uses
{$IFDEF DELPHI16_UP}
System.SysUtils,
{$ELSE}
SysUtils,
{$ENDIF}
uCEFMiscFunctions, uCEFLibFunctions, uCEFBrowser, uCEFPrintSettings,
uCEFPrintDialogCallback, uCEFPrintJobCallback;
// TCefPrintHandlerOwn
procedure cef_print_handler_on_print_start(self: PCefPrintHandler; browser: PCefBrowser); stdcall;
var
TempObject : TObject;
begin
TempObject := CefGetObject(self);
if (TempObject <> nil) and (TempObject is TCefPrintHandlerOwn) then
TCefPrintHandlerOwn(TempObject).OnPrintStart(TCefBrowserRef.UnWrap(browser));
end;
procedure cef_print_handler_on_print_settings(self : PCefPrintHandler;
browser : PCefBrowser;
settings : PCefPrintSettings;
get_defaults : Integer); stdcall;
var
TempObject : TObject;
begin
TempObject := CefGetObject(self);
if (TempObject <> nil) and (TempObject is TCefPrintHandlerOwn) then
TCefPrintHandlerOwn(TempObject).OnPrintSettings(TCefBrowserRef.UnWrap(browser),
TCefPrintSettingsRef.UnWrap(settings),
get_defaults <> 0);
end;
function cef_print_handler_on_print_dialog(self : PCefPrintHandler;
browser : PCefBrowser;
has_selection : Integer;
callback : PCefPrintDialogCallback): Integer; stdcall;
var
TempObject : TObject;
TempResult : boolean;
begin
TempResult := False;
TempObject := CefGetObject(self);
if (TempObject <> nil) and (TempObject is TCefPrintHandlerOwn) then
TCefPrintHandlerOwn(TempObject).OnPrintDialog(TCefBrowserRef.UnWrap(browser),
has_selection <> 0,
TCefPrintDialogCallbackRef.UnWrap(callback),
TempResult);
Result := ord(TempResult);
end;
function cef_print_handler_on_print_job( self : PCefPrintHandler;
browser : PCefBrowser;
const document_name : PCefString;
const pdf_file_path : PCefString;
callback : PCefPrintJobCallback): Integer; stdcall;
var
TempObject : TObject;
TempResult : boolean;
begin
TempResult := False;
TempObject := CefGetObject(self);
if (TempObject <> nil) and (TempObject is TCefPrintHandlerOwn) then
TCefPrintHandlerOwn(TempObject).OnPrintJob(TCefBrowserRef.UnWrap(browser),
CefString(document_name),
CefString(pdf_file_path),
TCefPrintJobCallbackRef.UnWrap(callback),
TempResult);
Result := ord(TempResult);
end;
procedure cef_print_handler_on_print_reset(self : PCefPrintHandler;
browser : PCefBrowser); stdcall;
var
TempObject : TObject;
begin
TempObject := CefGetObject(self);
if (TempObject <> nil) and (TempObject is TCefPrintHandlerOwn) then
TCefPrintHandlerOwn(TempObject).OnPrintReset(TCefBrowserRef.UnWrap(browser));
end;
function cef_print_handler_get_pdf_paper_size(self : PCefPrintHandler;
device_units_per_inch : Integer): TCefSize; stdcall;
var
TempObject : TObject;
TempSize : TCefSize;
begin
TempObject := CefGetObject(self);
TempSize.Width := 0;
TempSize.Height := 0;
if (TempObject <> nil) and (TempObject is TCefPrintHandlerOwn) then
TCefPrintHandlerOwn(TempObject).GetPDFPaperSize(device_units_per_inch, TempSize);
Result := TempSize;
end;
constructor TCefPrintHandlerOwn.Create;
begin
inherited CreateData(SizeOf(TCefPrintHandler));
with PCefPrintHandler(FData)^ do
begin
on_print_start := {$IFDEF FPC}@{$ENDIF}cef_print_handler_on_print_start;
on_print_settings := {$IFDEF FPC}@{$ENDIF}cef_print_handler_on_print_settings;
on_print_dialog := {$IFDEF FPC}@{$ENDIF}cef_print_handler_on_print_dialog;
on_print_job := {$IFDEF FPC}@{$ENDIF}cef_print_handler_on_print_job;
on_print_reset := {$IFDEF FPC}@{$ENDIF}cef_print_handler_on_print_reset;
get_pdf_paper_size := {$IFDEF FPC}@{$ENDIF}cef_print_handler_get_pdf_paper_size;
end;
end;
procedure TCefPrintHandlerOwn.OnPrintDialog(const browser: ICefBrowser; hasSelection: boolean; const callback: ICefPrintDialogCallback; var aResult: boolean);
begin
aResult := False;
end;
procedure TCefPrintHandlerOwn.OnPrintJob(const browser: ICefBrowser; const documentName, PDFFilePath: ustring; const callback: ICefPrintJobCallback; var aResult: boolean);
begin
aResult := False;
end;
procedure TCefPrintHandlerOwn.GetPDFPaperSize(deviceUnitsPerInch: Integer; var aResult: TCefSize);
begin
aResult.Width := 0;
aResult.Height := 0;
end;
// TCustomPrintHandler
constructor TCustomPrintHandler.Create(const aCefApp : TCefApplicationCore);
begin
inherited Create;
FCefApp := aCefApp;
end;
destructor TCustomPrintHandler.Destroy;
begin
RemoveReferences;
inherited Destroy;
end;
procedure TCustomPrintHandler.RemoveReferences;
begin
FCefApp := nil;
end;
procedure TCustomPrintHandler.OnPrintStart(const browser : ICefBrowser);
begin
try
if (FCefApp <> nil) then FCefApp.Internal_OnPrintStart(browser);
except
on e : exception do
if CustomExceptionHandler('TCustomPrintHandler.OnPrintStart', e) then raise;
end;
end;
procedure TCustomPrintHandler.OnPrintSettings(const browser : ICefBrowser;
const settings : ICefPrintSettings;
getDefaults : boolean);
begin
try
if (FCefApp <> nil) then FCefApp.Internal_OnPrintSettings(browser, settings, getDefaults);
except
on e : exception do
if CustomExceptionHandler('TCustomPrintHandler.OnPrintSettings', e) then raise;
end;
end;
procedure TCustomPrintHandler.OnPrintDialog(const browser : ICefBrowser;
hasSelection : boolean;
const callback : ICefPrintDialogCallback;
var aResult : boolean);
begin
try
if (FCefApp <> nil) then FCefApp.Internal_OnPrintDialog(browser, hasSelection, callback, aResult);
except
on e : exception do
if CustomExceptionHandler('TCustomPrintHandler.OnPrintDialog', e) then raise;
end;
end;
procedure TCustomPrintHandler.OnPrintJob(const browser : ICefBrowser;
const documentName : ustring;
const PDFFilePath : ustring;
const callback : ICefPrintJobCallback;
var aResult : boolean);
begin
try
if (FCefApp <> nil) then FCefApp.Internal_OnPrintJob(browser, documentName, PDFFilePath, callback, aResult);
except
on e : exception do
if CustomExceptionHandler('TCustomPrintHandler.OnPrintJob', e) then raise;
end;
end;
procedure TCustomPrintHandler.OnPrintReset(const browser : ICefBrowser);
begin
try
if (FCefApp <> nil) then FCefApp.Internal_OnPrintReset(browser);
except
on e : exception do
if CustomExceptionHandler('TCustomPrintHandler.OnPrintReset', e) then raise;
end;
end;
procedure TCustomPrintHandler.GetPDFPaperSize( deviceUnitsPerInch : Integer;
var aResult : TCefSize);
begin
try
if (FCefApp <> nil) then FCefApp.Internal_OnGetPDFPaperSize(deviceUnitsPerInch, aResult);
except
on e : exception do
if CustomExceptionHandler('TCustomPrintHandler.GetPDFPaperSize', e) then raise;
end;
end;
end.

View File

@ -0,0 +1,81 @@
// ************************************************************************
// ***************************** 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 � 2021 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 uCEFPrintJobCallback;
{$IFDEF FPC}
{$MODE OBJFPC}{$H+}
{$ENDIF}
{$IFNDEF CPUX64}{$ALIGN ON}{$ENDIF}
{$MINENUMSIZE 4}
{$I cef.inc}
interface
uses
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes;
type
TCefPrintJobCallbackRef = class(TCefBaseRefCountedRef, ICefPrintJobCallback)
protected
procedure cont;
public
class function UnWrap(data: Pointer): ICefPrintJobCallback;
end;
implementation
uses
uCEFMiscFunctions, uCEFLibFunctions;
procedure TCefPrintJobCallbackRef.cont;
begin
PCefPrintJobCallback(FData)^.cont(PCefPrintJobCallback(FData));
end;
class function TCefPrintJobCallbackRef.UnWrap(data: Pointer): ICefPrintJobCallback;
begin
if (data <> nil) then
Result := Create(data) as ICefPrintJobCallback
else
Result := nil;
end;
end.

View File

@ -2,7 +2,7 @@
"UpdateLazPackages" : [ "UpdateLazPackages" : [
{ {
"ForceNotify" : true, "ForceNotify" : true,
"InternalVersion" : 217, "InternalVersion" : 218,
"Name" : "cef4delphi_lazarus.lpk", "Name" : "cef4delphi_lazarus.lpk",
"Version" : "87.1.12.0" "Version" : "87.1.12.0"
} }