2017-01-27 16:37:51 +01:00
|
|
|
unit uCEFUrlrequestClient;
|
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
{$IFDEF FPC}
|
|
|
|
{$MODE OBJFPC}{$H+}
|
|
|
|
{$ENDIF}
|
|
|
|
|
2017-02-05 20:56:46 +01:00
|
|
|
{$I cef.inc}
|
|
|
|
|
2022-02-19 18:56:41 +01:00
|
|
|
{$IFNDEF TARGET_64BITS}{$ALIGN ON}{$ENDIF}
|
|
|
|
{$MINENUMSIZE 4}
|
|
|
|
|
2017-01-27 16:37:51 +01:00
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2017-03-16 19:09:42 +01:00
|
|
|
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
|
|
|
type
|
2017-03-16 19:09:42 +01:00
|
|
|
TCefUrlrequestClientOwn = class(TCefBaseRefCountedOwn, ICefUrlrequestClient)
|
2018-11-17 11:50:34 +01:00
|
|
|
protected
|
|
|
|
procedure OnRequestComplete(const request: ICefUrlRequest); virtual;
|
|
|
|
procedure OnUploadProgress(const request: ICefUrlRequest; current, total: Int64); virtual;
|
|
|
|
procedure OnDownloadProgress(const request: ICefUrlRequest; current, total: Int64); virtual;
|
|
|
|
procedure OnDownloadData(const request: ICefUrlRequest; data: Pointer; dataLength: NativeUInt); virtual;
|
|
|
|
function OnGetAuthCredentials(isProxy: Boolean; const host: ustring; port: Integer; const realm, scheme: ustring; const callback: ICefAuthCallback): Boolean; virtual;
|
2018-12-06 11:49:08 +01:00
|
|
|
|
|
|
|
procedure RemoveReferences; virtual;
|
|
|
|
|
2018-11-17 11:50:34 +01:00
|
|
|
public
|
|
|
|
constructor Create; virtual;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TCustomCefUrlrequestClient = class(TCefUrlrequestClientOwn)
|
|
|
|
protected
|
2018-12-06 11:49:08 +01:00
|
|
|
FEvents : Pointer;
|
2018-11-17 11:50:34 +01:00
|
|
|
|
|
|
|
procedure OnRequestComplete(const request: ICefUrlRequest); override;
|
|
|
|
procedure OnUploadProgress(const request: ICefUrlRequest; current, total: Int64); override;
|
|
|
|
procedure OnDownloadProgress(const request: ICefUrlRequest; current, total: Int64); override;
|
|
|
|
procedure OnDownloadData(const request: ICefUrlRequest; data: Pointer; dataLength: NativeUInt); override;
|
|
|
|
function OnGetAuthCredentials(isProxy: Boolean; const host: ustring; port: Integer; const realm, scheme: ustring; const callback: ICefAuthCallback): Boolean; override;
|
2018-12-06 11:49:08 +01:00
|
|
|
|
|
|
|
procedure RemoveReferences; override;
|
|
|
|
|
2018-11-17 11:50:34 +01:00
|
|
|
public
|
|
|
|
constructor Create(const events: ICEFUrlRequestClientEvents); reintroduce;
|
|
|
|
destructor Destroy; override;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2023-08-07 20:21:42 +02:00
|
|
|
TCefUrlrequestClientRef = class(TCefBaseRefCountedRef, ICefUrlrequestClient)
|
|
|
|
protected
|
|
|
|
procedure OnRequestComplete(const request: ICefUrlRequest);
|
|
|
|
procedure OnUploadProgress(const request: ICefUrlRequest; current, total: Int64);
|
|
|
|
procedure OnDownloadProgress(const request: ICefUrlRequest; current, total: Int64);
|
|
|
|
procedure OnDownloadData(const request: ICefUrlRequest; data: Pointer; dataLength: NativeUInt);
|
|
|
|
function OnGetAuthCredentials(isProxy: Boolean; const host: ustring; port: Integer; const realm, scheme: ustring; const callback: ICefAuthCallback): Boolean;
|
|
|
|
procedure RemoveReferences;
|
|
|
|
public
|
|
|
|
class function UnWrap(data: Pointer): ICefUrlrequestClient;
|
|
|
|
end;
|
|
|
|
|
2017-01-27 16:37:51 +01:00
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
2018-11-17 11:50:34 +01:00
|
|
|
{$IFDEF DELPHI16_UP}
|
|
|
|
System.SysUtils,
|
|
|
|
{$ELSE}
|
|
|
|
SysUtils,
|
|
|
|
{$ENDIF}
|
2017-01-27 16:37:51 +01:00
|
|
|
uCEFMiscFunctions, uCEFLibFunctions, uCEFUrlRequest, uCEFAuthCallback;
|
|
|
|
|
|
|
|
|
2018-11-17 11:50:34 +01:00
|
|
|
// TCefUrlrequestClientOwn
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure cef_url_request_client_on_request_complete(self : PCefUrlRequestClient;
|
|
|
|
request : PCefUrlRequest); stdcall;
|
|
|
|
var
|
|
|
|
TempObject : TObject;
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefUrlrequestClientOwn) then
|
|
|
|
TCefUrlrequestClientOwn(TempObject).OnRequestComplete(TCefUrlRequestRef.UnWrap(request));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure cef_url_request_client_on_upload_progress(self : PCefUrlRequestClient;
|
|
|
|
request : PCefUrlRequest;
|
|
|
|
current : Int64;
|
|
|
|
total : Int64); stdcall;
|
|
|
|
var
|
|
|
|
TempObject : TObject;
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefUrlrequestClientOwn) then
|
|
|
|
TCefUrlrequestClientOwn(TempObject).OnUploadProgress(TCefUrlRequestRef.UnWrap(request),
|
|
|
|
current,
|
|
|
|
total);
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure cef_url_request_client_on_download_progress(self : PCefUrlRequestClient;
|
|
|
|
request : PCefUrlRequest;
|
|
|
|
current : Int64;
|
|
|
|
total : Int64); stdcall;
|
|
|
|
var
|
|
|
|
TempObject : TObject;
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefUrlrequestClientOwn) then
|
|
|
|
TCefUrlrequestClientOwn(TempObject).OnDownloadProgress(TCefUrlRequestRef.UnWrap(request),
|
|
|
|
current,
|
|
|
|
total);
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure cef_url_request_client_on_download_data( self : PCefUrlRequestClient;
|
|
|
|
request : PCefUrlRequest;
|
|
|
|
const data : Pointer;
|
|
|
|
data_length : NativeUInt); stdcall;
|
|
|
|
var
|
|
|
|
TempObject : TObject;
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefUrlrequestClientOwn) then
|
|
|
|
TCefUrlrequestClientOwn(TempObject).OnDownloadData(TCefUrlRequestRef.UnWrap(request),
|
|
|
|
data,
|
|
|
|
data_length);
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
function cef_url_request_client_get_auth_credentials( self : PCefUrlRequestClient;
|
|
|
|
isProxy : Integer;
|
|
|
|
const host : PCefString;
|
|
|
|
port : Integer;
|
|
|
|
const realm : PCefString;
|
|
|
|
const scheme : PCefString;
|
|
|
|
callback : PCefAuthCallback): Integer; stdcall;
|
|
|
|
var
|
|
|
|
TempObject : TObject;
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
Result := Ord(False);
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefUrlrequestClientOwn) then
|
|
|
|
Result := Ord(TCefUrlrequestClientOwn(TempObject).OnGetAuthCredentials(isProxy <> 0,
|
|
|
|
CefString(host),
|
|
|
|
port,
|
|
|
|
CefString(realm),
|
|
|
|
CefString(scheme),
|
|
|
|
TCefAuthCallbackRef.UnWrap(callback)));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
constructor TCefUrlrequestClientOwn.Create;
|
|
|
|
begin
|
|
|
|
inherited CreateData(SizeOf(TCefUrlrequestClient));
|
2018-03-29 20:02:04 +02:00
|
|
|
|
2017-01-27 16:37:51 +01:00
|
|
|
with PCefUrlrequestClient(FData)^ do
|
2018-03-29 20:02:04 +02:00
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
on_request_complete := {$IFDEF FPC}@{$ENDIF}cef_url_request_client_on_request_complete;
|
|
|
|
on_upload_progress := {$IFDEF FPC}@{$ENDIF}cef_url_request_client_on_upload_progress;
|
|
|
|
on_download_progress := {$IFDEF FPC}@{$ENDIF}cef_url_request_client_on_download_progress;
|
|
|
|
on_download_data := {$IFDEF FPC}@{$ENDIF}cef_url_request_client_on_download_data;
|
|
|
|
get_auth_credentials := {$IFDEF FPC}@{$ENDIF}cef_url_request_client_get_auth_credentials;
|
2018-03-29 20:02:04 +02:00
|
|
|
end;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure TCefUrlrequestClientOwn.OnDownloadData(const request: ICefUrlRequest; data: Pointer; dataLength: NativeUInt);
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
//
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure TCefUrlrequestClientOwn.OnDownloadProgress(const request: ICefUrlRequest; current, total: Int64);
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
//
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
function TCefUrlrequestClientOwn.OnGetAuthCredentials(isProxy: Boolean; const host: ustring; port: Integer; const realm, scheme: ustring; const callback: ICefAuthCallback): Boolean;
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
end;
|
|
|
|
|
2018-12-06 11:49:08 +01:00
|
|
|
procedure TCefUrlrequestClientOwn.RemoveReferences;
|
|
|
|
begin
|
|
|
|
//
|
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure TCefUrlrequestClientOwn.OnRequestComplete(const request: ICefUrlRequest);
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
//
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure TCefUrlrequestClientOwn.OnUploadProgress(const request: ICefUrlRequest; current, total: Int64);
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
//
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2018-11-17 11:50:34 +01:00
|
|
|
|
|
|
|
// TCustomCefUrlrequestClient
|
|
|
|
|
|
|
|
constructor TCustomCefUrlrequestClient.Create(const events: ICEFUrlRequestClientEvents);
|
|
|
|
begin
|
|
|
|
inherited Create;
|
|
|
|
|
2018-12-06 11:49:08 +01:00
|
|
|
FEvents := Pointer(events);
|
2018-11-17 11:50:34 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TCustomCefUrlrequestClient.Destroy;
|
|
|
|
begin
|
2018-12-06 11:49:08 +01:00
|
|
|
RemoveReferences;
|
2018-11-17 11:50:34 +01:00
|
|
|
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCustomCefUrlrequestClient.OnRequestComplete(const request: ICefUrlRequest);
|
|
|
|
begin
|
|
|
|
try
|
2018-12-06 11:49:08 +01:00
|
|
|
if (FEvents <> nil) then
|
|
|
|
ICEFUrlRequestClientEvents(FEvents).doOnRequestComplete(request);
|
2018-11-17 11:50:34 +01:00
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('TCustomCefUrlrequestClient.OnRequestComplete', e) then raise;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCustomCefUrlrequestClient.OnUploadProgress(const request: ICefUrlRequest; current, total: Int64);
|
|
|
|
begin
|
|
|
|
try
|
2018-12-06 11:49:08 +01:00
|
|
|
if (FEvents <> nil) then
|
|
|
|
ICEFUrlRequestClientEvents(FEvents).doOnUploadProgress(request, current, total);
|
2018-11-17 11:50:34 +01:00
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('TCustomCefUrlrequestClient.OnUploadProgress', e) then raise;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCustomCefUrlrequestClient.OnDownloadProgress(const request: ICefUrlRequest; current, total: Int64);
|
|
|
|
begin
|
|
|
|
try
|
2018-12-06 11:49:08 +01:00
|
|
|
if (FEvents <> nil) then
|
|
|
|
ICEFUrlRequestClientEvents(FEvents).doOnDownloadProgress(request, current, total);
|
2018-11-17 11:50:34 +01:00
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('TCustomCefUrlrequestClient.OnDownloadProgress', e) then raise;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCustomCefUrlrequestClient.OnDownloadData(const request: ICefUrlRequest; data: Pointer; dataLength: NativeUInt);
|
|
|
|
begin
|
|
|
|
try
|
2018-12-06 11:49:08 +01:00
|
|
|
if (FEvents <> nil) then
|
|
|
|
ICEFUrlRequestClientEvents(FEvents).doOnDownloadData(request, data, dataLength);
|
2018-11-17 11:50:34 +01:00
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('TCustomCefUrlrequestClient.OnDownloadData', e) then raise;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCustomCefUrlrequestClient.OnGetAuthCredentials(isProxy: Boolean; const host: ustring; port: Integer; const realm, scheme: ustring; const callback: ICefAuthCallback): Boolean;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
try
|
2018-12-06 11:49:08 +01:00
|
|
|
if (FEvents <> nil) then
|
|
|
|
Result := ICEFUrlRequestClientEvents(FEvents).doOnGetAuthCredentials(isProxy, host, port, realm, scheme, callback);
|
2018-11-17 11:50:34 +01:00
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('TCustomCefUrlrequestClient.OnGetAuthCredentials', e) then raise;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2018-12-06 11:49:08 +01:00
|
|
|
procedure TCustomCefUrlrequestClient.RemoveReferences;
|
|
|
|
begin
|
|
|
|
FEvents := nil;
|
|
|
|
end;
|
2018-11-17 11:50:34 +01:00
|
|
|
|
2023-08-07 20:21:42 +02:00
|
|
|
|
|
|
|
// TCefUrlrequestClientRef
|
|
|
|
|
|
|
|
procedure TCefUrlrequestClientRef.OnRequestComplete(const request: ICefUrlRequest);
|
|
|
|
begin
|
|
|
|
PCefUrlRequestClient(FData)^.on_request_complete(PCefUrlRequestClient(FData), CefGetData(request));
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefUrlrequestClientRef.OnUploadProgress(const request: ICefUrlRequest; current, total: Int64);
|
|
|
|
begin
|
|
|
|
PCefUrlRequestClient(FData)^.on_upload_progress(PCefUrlRequestClient(FData), CefGetData(request), current, total);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefUrlrequestClientRef.OnDownloadProgress(const request: ICefUrlRequest; current, total: Int64);
|
|
|
|
begin
|
|
|
|
PCefUrlRequestClient(FData)^.on_download_progress(PCefUrlRequestClient(FData), CefGetData(request), current, total);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefUrlrequestClientRef.OnDownloadData(const request: ICefUrlRequest; data: Pointer; dataLength: NativeUInt);
|
|
|
|
begin
|
|
|
|
PCefUrlRequestClient(FData)^.on_download_data(PCefUrlRequestClient(FData), CefGetData(request), data, dataLength);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefUrlrequestClientRef.OnGetAuthCredentials(isProxy: Boolean; const host: ustring; port: Integer; const realm, scheme: ustring; const callback: ICefAuthCallback): Boolean;
|
|
|
|
var
|
|
|
|
TempHost, TempRealm, TempScheme : TCefString;
|
|
|
|
begin
|
|
|
|
TempHost := CefString(host);
|
|
|
|
TempRealm := CefString(realm);
|
|
|
|
TempScheme := CefString(scheme);
|
|
|
|
Result := PCefUrlRequestClient(FData)^.get_auth_credentials(PCefUrlRequestClient(FData), ord(isProxy), @TempHost, port, @TempRealm, @TempScheme, CefGetData(callback)) <> 0;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefUrlrequestClientRef.RemoveReferences;
|
|
|
|
begin
|
|
|
|
//
|
|
|
|
end;
|
|
|
|
|
|
|
|
class function TCefUrlrequestClientRef.UnWrap(data: Pointer): ICEFUrlRequestClient;
|
|
|
|
begin
|
|
|
|
if (data <> nil) then
|
|
|
|
Result := Create(data) as ICEFUrlRequestClient
|
|
|
|
else
|
|
|
|
Result := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2017-01-27 16:37:51 +01:00
|
|
|
end.
|