2017-01-27 17:37:51 +02:00
|
|
|
unit uCEFPostDataElement;
|
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
{$IFDEF FPC}
|
|
|
|
{$MODE OBJFPC}{$H+}
|
|
|
|
{$ENDIF}
|
|
|
|
|
2017-02-05 21:56:46 +02:00
|
|
|
{$I cef.inc}
|
|
|
|
|
2022-02-19 19:56:41 +02:00
|
|
|
{$IFNDEF TARGET_64BITS}{$ALIGN ON}{$ENDIF}
|
|
|
|
{$MINENUMSIZE 4}
|
|
|
|
|
2017-01-27 17:37:51 +02:00
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2017-03-16 20:09:42 +02:00
|
|
|
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes;
|
2017-01-27 17:37:51 +02:00
|
|
|
|
|
|
|
type
|
2017-03-16 20:09:42 +02:00
|
|
|
TCefPostDataElementRef = class(TCefBaseRefCountedRef, ICefPostDataElement)
|
2017-01-27 17:37:51 +02:00
|
|
|
protected
|
|
|
|
function IsReadOnly: Boolean;
|
|
|
|
procedure SetToEmpty;
|
|
|
|
procedure SetToFile(const fileName: ustring);
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure SetToBytes(size: NativeUInt; const bytes: Pointer);
|
2017-01-27 17:37:51 +02:00
|
|
|
function GetType: TCefPostDataElementType;
|
|
|
|
function GetFile: ustring;
|
|
|
|
function GetBytesCount: NativeUInt;
|
|
|
|
function GetBytes(size: NativeUInt; bytes: Pointer): NativeUInt;
|
|
|
|
|
|
|
|
public
|
|
|
|
class function UnWrap(data: Pointer): ICefPostDataElement;
|
|
|
|
class function New: ICefPostDataElement;
|
|
|
|
end;
|
|
|
|
|
2017-03-16 20:09:42 +02:00
|
|
|
TCefPostDataElementOwn = class(TCefBaseRefCountedOwn, ICefPostDataElement)
|
2017-01-27 17:37:51 +02:00
|
|
|
protected
|
2018-03-29 20:02:04 +02:00
|
|
|
FDataType : TCefPostDataElementType;
|
|
|
|
FValueByte : Pointer;
|
|
|
|
FValueStr : TCefString;
|
|
|
|
FSize : NativeUInt;
|
|
|
|
FReadOnly : Boolean;
|
2017-01-27 17:37:51 +02:00
|
|
|
|
|
|
|
procedure Clear;
|
|
|
|
function IsReadOnly: Boolean; virtual;
|
|
|
|
procedure SetToEmpty; virtual;
|
|
|
|
procedure SetToFile(const fileName: ustring); virtual;
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure SetToBytes(size: NativeUInt; const bytes: Pointer); virtual;
|
2017-01-27 17:37:51 +02:00
|
|
|
function GetType: TCefPostDataElementType; virtual;
|
|
|
|
function GetFile: ustring; virtual;
|
|
|
|
function GetBytesCount: NativeUInt; virtual;
|
|
|
|
function GetBytes(size: NativeUInt; bytes: Pointer): NativeUInt; virtual;
|
|
|
|
|
|
|
|
public
|
|
|
|
constructor Create(readonly: Boolean); virtual;
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
|
|
|
uCEFMiscFunctions, uCEFLibFunctions;
|
|
|
|
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
// **************************************************
|
|
|
|
// ************* TCefPostDataElementRef *************
|
|
|
|
// **************************************************
|
|
|
|
|
|
|
|
|
|
|
|
function TCefPostDataElementRef.IsReadOnly: Boolean;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
Result := PCefPostDataElement(FData)^.is_read_only(PCefPostDataElement(FData)) <> 0;
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
function TCefPostDataElementRef.GetBytes(size: NativeUInt; bytes: Pointer): NativeUInt;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
Result := PCefPostDataElement(FData)^.get_bytes(PCefPostDataElement(FData), size, bytes);
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
function TCefPostDataElementRef.GetBytesCount: NativeUInt;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
Result := PCefPostDataElement(FData)^.get_bytes_count(PCefPostDataElement(FData));
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
function TCefPostDataElementRef.GetFile: ustring;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
Result := CefStringFreeAndGet(PCefPostDataElement(FData)^.get_file(PCefPostDataElement(FData)));
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
function TCefPostDataElementRef.GetType: TCefPostDataElementType;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
Result := PCefPostDataElement(FData)^.get_type(PCefPostDataElement(FData));
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
class function TCefPostDataElementRef.New: ICefPostDataElement;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := UnWrap(cef_post_data_element_create());
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure TCefPostDataElementRef.SetToBytes(size: NativeUInt; const bytes: Pointer);
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
PCefPostDataElement(FData)^.set_to_bytes(PCefPostDataElement(FData), size, bytes);
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure TCefPostDataElementRef.SetToEmpty;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
PCefPostDataElement(FData)^.set_to_empty(PCefPostDataElement(FData));
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure TCefPostDataElementRef.SetToFile(const fileName: ustring);
|
|
|
|
var
|
|
|
|
TempFileName : TCefString;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
TempFileName := CefString(fileName);
|
|
|
|
PCefPostDataElement(FData)^.set_to_file(PCefPostDataElement(FData), @TempFileName);
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
class function TCefPostDataElementRef.UnWrap(data: Pointer): ICefPostDataElement;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
if (data <> nil) then
|
|
|
|
Result := Create(data) as ICefPostDataElement
|
|
|
|
else
|
|
|
|
Result := nil;
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
|
|
|
|
// **************************************************
|
|
|
|
// ************* TCefPostDataElementOwn *************
|
|
|
|
// **************************************************
|
|
|
|
|
|
|
|
|
|
|
|
function cef_post_data_element_is_read_only(self: PCefPostDataElement): Integer; stdcall;
|
|
|
|
var
|
|
|
|
TempObject : TObject;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
Result := Ord(False);
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefPostDataElementOwn) then
|
|
|
|
Result := Ord(TCefPostDataElementOwn(TempObject).IsReadOnly);
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure cef_post_data_element_set_to_empty(self: PCefPostDataElement); stdcall;
|
|
|
|
var
|
|
|
|
TempObject : TObject;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefPostDataElementOwn) then
|
|
|
|
TCefPostDataElementOwn(TempObject).SetToEmpty;
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure cef_post_data_element_set_to_file( self : PCefPostDataElement;
|
|
|
|
const fileName : PCefString); stdcall;
|
|
|
|
var
|
|
|
|
TempObject : TObject;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefPostDataElementOwn) then
|
|
|
|
TCefPostDataElementOwn(TempObject).SetToFile(CefString(fileName));
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure cef_post_data_element_set_to_bytes( self : PCefPostDataElement;
|
|
|
|
size : NativeUInt;
|
|
|
|
const bytes : Pointer); stdcall;
|
|
|
|
var
|
|
|
|
TempObject : TObject;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefPostDataElementOwn) then
|
|
|
|
TCefPostDataElementOwn(TempObject).SetToBytes(size, bytes);
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
function cef_post_data_element_get_type(self: PCefPostDataElement): TCefPostDataElementType; stdcall;
|
|
|
|
var
|
|
|
|
TempObject : TObject;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
Result := PDE_TYPE_EMPTY;
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefPostDataElementOwn) then
|
|
|
|
Result := TCefPostDataElementOwn(TempObject).GetType;
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
function cef_post_data_element_get_file(self: PCefPostDataElement): PCefStringUserFree; stdcall;
|
|
|
|
var
|
|
|
|
TempObject : TObject;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
Result := nil;
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefPostDataElementOwn) then
|
|
|
|
Result := CefUserFreeString(TCefPostDataElementOwn(TempObject).GetFile);
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
function cef_post_data_element_get_bytes_count(self: PCefPostDataElement): NativeUInt; stdcall;
|
2017-01-27 17:37:51 +02:00
|
|
|
var
|
2018-03-29 20:02:04 +02:00
|
|
|
TempObject : TObject;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
Result := 0;
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefPostDataElementOwn) then
|
|
|
|
Result := TCefPostDataElementOwn(TempObject).GetBytesCount;
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
function cef_post_data_element_get_bytes(self: PCefPostDataElement; size: NativeUInt; bytes: Pointer): NativeUInt; stdcall;
|
|
|
|
var
|
|
|
|
TempObject : TObject;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
Result := 0;
|
|
|
|
TempObject := CefGetObject(self);
|
2017-01-27 17:37:51 +02:00
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
if (TempObject <> nil) and (TempObject is TCefPostDataElementOwn) then
|
|
|
|
Result := TCefPostDataElementOwn(TempObject).GetBytes(size, bytes)
|
|
|
|
end;
|
2017-01-27 17:37:51 +02:00
|
|
|
|
|
|
|
procedure TCefPostDataElementOwn.Clear;
|
|
|
|
begin
|
|
|
|
case FDataType of
|
2018-03-29 20:02:04 +02:00
|
|
|
PDE_TYPE_FILE : CefStringFree(@FValueStr);
|
|
|
|
|
|
|
|
PDE_TYPE_BYTES :
|
2017-01-27 17:37:51 +02:00
|
|
|
if (FValueByte <> nil) then
|
2018-03-29 20:02:04 +02:00
|
|
|
begin
|
|
|
|
FreeMem(FValueByte);
|
|
|
|
FValueByte := nil;
|
|
|
|
end;
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
2018-03-29 20:02:04 +02:00
|
|
|
|
2017-01-27 17:37:51 +02:00
|
|
|
FDataType := PDE_TYPE_EMPTY;
|
2018-03-29 20:02:04 +02:00
|
|
|
FSize := 0;
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
constructor TCefPostDataElementOwn.Create(readonly: Boolean);
|
|
|
|
begin
|
|
|
|
inherited CreateData(SizeOf(TCefPostDataElement));
|
2018-03-29 20:02:04 +02:00
|
|
|
|
|
|
|
FReadOnly := readonly;
|
|
|
|
FDataType := PDE_TYPE_EMPTY;
|
2017-01-27 17:37:51 +02:00
|
|
|
FValueByte := nil;
|
2018-03-29 20:02:04 +02:00
|
|
|
FSize := 0;
|
|
|
|
|
2019-11-24 19:19:49 +02:00
|
|
|
CefStringInitialize(@FValueStr);
|
|
|
|
|
2017-01-27 17:37:51 +02:00
|
|
|
with PCefPostDataElement(FData)^ do
|
2018-03-29 20:02:04 +02:00
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
is_read_only := {$IFDEF FPC}@{$ENDIF}cef_post_data_element_is_read_only;
|
|
|
|
set_to_empty := {$IFDEF FPC}@{$ENDIF}cef_post_data_element_set_to_empty;
|
|
|
|
set_to_file := {$IFDEF FPC}@{$ENDIF}cef_post_data_element_set_to_file;
|
|
|
|
set_to_bytes := {$IFDEF FPC}@{$ENDIF}cef_post_data_element_set_to_bytes;
|
|
|
|
get_type := {$IFDEF FPC}@{$ENDIF}cef_post_data_element_get_type;
|
|
|
|
get_file := {$IFDEF FPC}@{$ENDIF}cef_post_data_element_get_file;
|
|
|
|
get_bytes_count := {$IFDEF FPC}@{$ENDIF}cef_post_data_element_get_bytes_count;
|
|
|
|
get_bytes := {$IFDEF FPC}@{$ENDIF}cef_post_data_element_get_bytes;
|
2018-03-29 20:02:04 +02:00
|
|
|
end;
|
2017-01-27 17:37:51 +02:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
function TCefPostDataElementOwn.GetBytes(size: NativeUInt; bytes: Pointer): NativeUInt;
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
|
|
|
if (FDataType = PDE_TYPE_BYTES) and (FValueByte <> nil) then
|
2018-03-29 20:02:04 +02:00
|
|
|
begin
|
|
|
|
if (size > FSize) then
|
|
|
|
Result := FSize
|
|
|
|
else
|
|
|
|
Result := size;
|
|
|
|
|
|
|
|
Move(FValueByte^, bytes^, Result);
|
|
|
|
end
|
|
|
|
else
|
2017-01-27 17:37:51 +02:00
|
|
|
Result := 0;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefPostDataElementOwn.GetBytesCount: NativeUInt;
|
|
|
|
begin
|
|
|
|
if (FDataType = PDE_TYPE_BYTES) then
|
2018-03-29 20:02:04 +02:00
|
|
|
Result := FSize
|
|
|
|
else
|
2017-01-27 17:37:51 +02:00
|
|
|
Result := 0;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefPostDataElementOwn.GetFile: ustring;
|
|
|
|
begin
|
|
|
|
if (FDataType = PDE_TYPE_FILE) then
|
2018-03-29 20:02:04 +02:00
|
|
|
Result := CefString(@FValueStr)
|
|
|
|
else
|
2017-01-27 17:37:51 +02:00
|
|
|
Result := '';
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefPostDataElementOwn.GetType: TCefPostDataElementType;
|
|
|
|
begin
|
|
|
|
Result := FDataType;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefPostDataElementOwn.IsReadOnly: Boolean;
|
|
|
|
begin
|
|
|
|
Result := FReadOnly;
|
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
procedure TCefPostDataElementOwn.SetToBytes(size: NativeUInt; const bytes: Pointer);
|
2017-01-27 17:37:51 +02:00
|
|
|
begin
|
|
|
|
Clear;
|
2018-03-29 20:02:04 +02:00
|
|
|
|
2017-01-27 17:37:51 +02:00
|
|
|
if (size > 0) and (bytes <> nil) then
|
2018-03-29 20:02:04 +02:00
|
|
|
begin
|
|
|
|
GetMem(FValueByte, size);
|
|
|
|
Move(bytes^, FValueByte, size);
|
|
|
|
FSize := size;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
FValueByte := nil;
|
|
|
|
FSize := 0;
|
|
|
|
end;
|
|
|
|
|
2017-01-27 17:37:51 +02:00
|
|
|
FDataType := PDE_TYPE_BYTES;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefPostDataElementOwn.SetToEmpty;
|
|
|
|
begin
|
|
|
|
Clear;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefPostDataElementOwn.SetToFile(const fileName: ustring);
|
|
|
|
begin
|
|
|
|
Clear;
|
2018-03-29 20:02:04 +02:00
|
|
|
|
|
|
|
FSize := 0;
|
2017-01-27 17:37:51 +02:00
|
|
|
FValueStr := CefStringAlloc(fileName);
|
|
|
|
FDataType := PDE_TYPE_FILE;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|