You've already forked CEF4Delphi
mirror of
https://github.com/salvadordf/CEF4Delphi.git
synced 2025-09-30 21:28:55 +02:00
Update to CEF 74.1.16
- Copied the GlobalCEFApp_OnWebKitInitializedEvent fix for D2007 made by jepp to other demos. - Added TChromium.DownloadImage and TChromium.OnDownloadImageFinished to download images - Added a TChromium.DownloadImage example to the MiniBrowser demo. - Modified some parameters in TCefImageRef
This commit is contained in:
@@ -92,6 +92,8 @@ type
|
||||
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
|
||||
procedure WMEnterMenuLoop(var aMessage: TMessage); message WM_ENTERMENULOOP;
|
||||
procedure WMExitMenuLoop(var aMessage: TMessage); message WM_EXITMENULOOP;
|
||||
|
||||
{$IFNDEF DELPHI12_UP}class procedure GlobalCEFApp_OnWebKitInitializedEvent;{$ENDIF}
|
||||
public
|
||||
{ Public declarations }
|
||||
end;
|
||||
@@ -120,7 +122,8 @@ uses
|
||||
// 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.
|
||||
|
||||
procedure GlobalCEFApp_OnWebKitInitializedEvent;
|
||||
{$IFDEF DELPHI12_UP}procedure
|
||||
{$ELSE}class procedure TJSSimpleExtensionFrm.{$ENDIF}GlobalCEFApp_OnWebKitInitializedEvent;
|
||||
var
|
||||
TempExtensionCode : string;
|
||||
TempHandler : ICefv8Handler;
|
||||
@@ -146,7 +149,8 @@ end;
|
||||
procedure CreateGlobalCEFApp;
|
||||
begin
|
||||
GlobalCEFApp := TCefApplication.Create;
|
||||
GlobalCEFApp.OnWebKitInitialized := GlobalCEFApp_OnWebKitInitializedEvent;
|
||||
GlobalCEFApp.OnWebKitInitialized := {$IFNDEF DELPHI12_UP}TJSSimpleExtensionFrm.{$ENDIF}
|
||||
GlobalCEFApp_OnWebKitInitializedEvent;
|
||||
end;
|
||||
|
||||
procedure TJSExtensionWithFunctionFrm.GoBtnClick(Sender: TObject);
|
||||
|
@@ -88,6 +88,8 @@ type
|
||||
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
|
||||
procedure WMEnterMenuLoop(var aMessage: TMessage); message WM_ENTERMENULOOP;
|
||||
procedure WMExitMenuLoop(var aMessage: TMessage); message WM_EXITMENULOOP;
|
||||
|
||||
{$IFNDEF DELPHI12_UP}class procedure GlobalCEFApp_OnWebKitInitializedEvent;{$ENDIF}
|
||||
public
|
||||
{ Public declarations }
|
||||
end;
|
||||
@@ -119,7 +121,8 @@ uses
|
||||
// 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.
|
||||
|
||||
procedure GlobalCEFApp_OnWebKitInitializedEvent;
|
||||
{$IFDEF DELPHI12_UP}procedure
|
||||
{$ELSE}class procedure TJSSimpleExtensionFrm.{$ENDIF}GlobalCEFApp_OnWebKitInitializedEvent;
|
||||
var
|
||||
TempExtensionCode : string;
|
||||
TempHandler : ICefv8Handler;
|
||||
@@ -149,7 +152,8 @@ end;
|
||||
procedure CreateGlobalCEFApp;
|
||||
begin
|
||||
GlobalCEFApp := TCefApplication.Create;
|
||||
GlobalCEFApp.OnWebKitInitialized := GlobalCEFApp_OnWebKitInitializedEvent;
|
||||
GlobalCEFApp.OnWebKitInitialized := {$IFNDEF DELPHI12_UP}TJSSimpleExtensionFrm.{$ENDIF}
|
||||
GlobalCEFApp_OnWebKitInitializedEvent;
|
||||
end;
|
||||
|
||||
procedure TJSExtensionWithObjectParameterFrm.GoBtnClick(Sender: TObject);
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// ************************************************************************
|
||||
// ************************************************************************
|
||||
// ***************************** CEF4Delphi *******************************
|
||||
// ************************************************************************
|
||||
//
|
||||
@@ -88,6 +88,7 @@ type
|
||||
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
|
||||
procedure WMEnterMenuLoop(var aMessage: TMessage); message WM_ENTERMENULOOP;
|
||||
procedure WMExitMenuLoop(var aMessage: TMessage); message WM_EXITMENULOOP;
|
||||
|
||||
{$IFNDEF DELPHI12_UP}class procedure GlobalCEFApp_OnWebKitInitializedEvent;{$ENDIF}
|
||||
public
|
||||
{ Public declarations }
|
||||
|
@@ -137,6 +137,9 @@ object MiniBrowserFrm: TMiniBrowserFrm
|
||||
'https://www.w3schools.com/js/tryit.asp?filename=tryjs_win_close'
|
||||
'https://www.w3schools.com/js/tryit.asp?filename=tryjs_alert'
|
||||
'https://www.w3schools.com/js/tryit.asp?filename=tryjs_loc_assign'
|
||||
|
||||
'https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_styl' +
|
||||
'e_backgroundcolor'
|
||||
'https://www.w3schools.com/html/html5_video.asp'
|
||||
'http://www.adobe.com/software/flash/about/'
|
||||
'http://isflashinstalled.com/'
|
||||
@@ -264,6 +267,7 @@ object MiniBrowserFrm: TMiniBrowserFrm
|
||||
OnPrefsAvailable = Chromium1PrefsAvailable
|
||||
OnResolvedHostAvailable = Chromium1ResolvedHostAvailable
|
||||
OnNavigationVisitorResultAvailable = Chromium1NavigationVisitorResultAvailable
|
||||
OnDownloadImageFinished = Chromium1DownloadImageFinished
|
||||
OnRenderCompMsg = Chromium1RenderCompMsg
|
||||
OnLoadEnd = Chromium1LoadEnd
|
||||
OnLoadError = Chromium1LoadError
|
||||
@@ -347,6 +351,10 @@ object MiniBrowserFrm: TMiniBrowserFrm
|
||||
Caption = 'Resolve host...'
|
||||
OnClick = Resolvehost1Click
|
||||
end
|
||||
object Downloadimage1: TMenuItem
|
||||
Caption = 'Download image...'
|
||||
OnClick = Downloadimage1Click
|
||||
end
|
||||
object N5: TMenuItem
|
||||
Caption = '-'
|
||||
end
|
||||
|
@@ -122,6 +122,7 @@ type
|
||||
OpenfilewithaDAT1: TMenuItem;
|
||||
N5: TMenuItem;
|
||||
Memoryinfo1: TMenuItem;
|
||||
Downloadimage1: TMenuItem;
|
||||
procedure FormShow(Sender: TObject);
|
||||
procedure BackBtnClick(Sender: TObject);
|
||||
procedure ForwardBtnClick(Sender: TObject);
|
||||
@@ -215,6 +216,10 @@ type
|
||||
procedure Chromium1NavigationVisitorResultAvailable(
|
||||
const entry: ICefNavigationEntry; current: Boolean; index, total: Integer;
|
||||
var aResult: Boolean);
|
||||
procedure Downloadimage1Click(Sender: TObject);
|
||||
procedure Chromium1DownloadImageFinished(Sender: TObject;
|
||||
const imageUrl: ustring; httpStatusCode: Integer;
|
||||
const image: ICefImage);
|
||||
|
||||
protected
|
||||
FResponse : TStringList;
|
||||
@@ -1216,6 +1221,82 @@ begin
|
||||
ShowDevTools;
|
||||
end;
|
||||
|
||||
procedure TMiniBrowserFrm.Downloadimage1Click(Sender: TObject);
|
||||
var
|
||||
TempURL : string;
|
||||
begin
|
||||
TempURL := InputBox('Download Image', 'URL:', 'https://www.briskbard.com/images/logo.png');
|
||||
|
||||
if (length(TempURL) > 0) then
|
||||
Chromium1.DownloadImage(TempURL, False, 0, False);
|
||||
end;
|
||||
|
||||
procedure TMiniBrowserFrm.Chromium1DownloadImageFinished( Sender : TObject;
|
||||
const imageUrl : ustring;
|
||||
httpStatusCode : Integer;
|
||||
const image : ICefImage);
|
||||
var
|
||||
TempBinValue : ICefBinaryValue;
|
||||
TempWidth : integer;
|
||||
TempHeight : integer;
|
||||
TempBuffer : TBytes;
|
||||
TempPointer : pointer;
|
||||
TempSize : NativeUInt;
|
||||
TempStream : TFileStream;
|
||||
TempParts : TUrlParts;
|
||||
i : integer;
|
||||
begin
|
||||
TempStream := nil;
|
||||
|
||||
try
|
||||
try
|
||||
if (httpStatusCode = 200) and (image <> nil) and not(image.IsEmpty) then
|
||||
begin
|
||||
TempBinValue := image.GetAsPng(1, True, TempWidth, TempHeight);
|
||||
|
||||
if (TempBinValue <> nil) and
|
||||
TempBinValue.IsValid then
|
||||
begin
|
||||
TempSize := TempBinValue.Size;
|
||||
|
||||
SaveDialog1.DefaultExt := 'png';
|
||||
SaveDialog1.Filter := 'PNG files (*.png)|*.PNG';
|
||||
|
||||
CefParseUrl(imageUrl, TempParts);
|
||||
i := LastDelimiter('/', TempParts.path);
|
||||
|
||||
// TODO : The file name should be sanitized.
|
||||
if (i > 0) then
|
||||
SaveDialog1.FileName := copy(TempParts.path, succ(i), length(TempParts.path))
|
||||
else
|
||||
SaveDialog1.FileName := TempParts.path;
|
||||
|
||||
if (TempSize > 0) and
|
||||
SaveDialog1.Execute and
|
||||
(length(SaveDialog1.FileName) > 0) then
|
||||
begin
|
||||
SetLength(TempBuffer, TempSize);
|
||||
TempPointer := @TempBuffer[0];
|
||||
TempSize := TempBinValue.GetData(TempPointer, TempSize, 0);
|
||||
|
||||
if (TempSize > 0) then
|
||||
begin
|
||||
TempStream := TFileStream.Create(SaveDialog1.FileName, fmCreate);
|
||||
TempStream.Write(TempBuffer, TempSize);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
except
|
||||
on e : exception do
|
||||
if CustomExceptionHandler('Chromium1DownloadImageFinishedEvent', e) then raise;
|
||||
end;
|
||||
finally
|
||||
if (TempStream <> nil) then FreeAndNil(TempStream);
|
||||
SetLength(TempBuffer, 0);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMiniBrowserFrm.ShowDevTools(aPoint : TPoint);
|
||||
begin
|
||||
Splitter1.Visible := True;
|
||||
|
@@ -1,22 +1,22 @@
|
||||
object ChildForm: TChildForm
|
||||
Left = 224
|
||||
Height = 600
|
||||
Top = 175
|
||||
Left = 45
|
||||
Height = 503
|
||||
Top = 239
|
||||
Width = 800
|
||||
BorderIcons = [biSystemMenu, biMinimize]
|
||||
BorderStyle = bsSingle
|
||||
Caption = 'ChildForm'
|
||||
ClientHeight = 600
|
||||
ClientHeight = 503
|
||||
ClientWidth = 800
|
||||
OnClose = FormClose
|
||||
OnCloseQuery = FormCloseQuery
|
||||
OnCreate = FormCreate
|
||||
OnDestroy = FormDestroy
|
||||
OnShow = FormShow
|
||||
LCLVersion = '2.0.0.4'
|
||||
LCLVersion = '2.0.2.0'
|
||||
object CEFWindowParent1: TCEFWindowParent
|
||||
Left = 0
|
||||
Height = 600
|
||||
Height = 503
|
||||
Top = 0
|
||||
Width = 800
|
||||
Align = alClient
|
||||
|
Reference in New Issue
Block a user