2017-01-27 16:37:51 +01:00
|
|
|
unit uCEFRequest;
|
|
|
|
|
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
|
|
|
TCefRequestRef = class(TCefBaseRefCountedRef, ICefRequest)
|
2017-01-27 16:37:51 +01:00
|
|
|
protected
|
2018-05-12 14:50:54 +02:00
|
|
|
function IsReadOnly: Boolean;
|
|
|
|
function GetUrl: ustring;
|
|
|
|
function GetMethod: ustring;
|
|
|
|
function GetPostData: ICefPostData;
|
2017-01-27 16:37:51 +01:00
|
|
|
procedure GetHeaderMap(const HeaderMap: ICefStringMultimap);
|
|
|
|
procedure SetUrl(const value: ustring);
|
|
|
|
procedure SetMethod(const value: ustring);
|
|
|
|
procedure SetReferrer(const referrerUrl: ustring; policy: TCefReferrerPolicy);
|
2018-05-12 14:50:54 +02:00
|
|
|
function GetReferrerUrl: ustring;
|
|
|
|
function GetReferrerPolicy: TCefReferrerPolicy;
|
2017-01-27 16:37:51 +01:00
|
|
|
procedure SetPostData(const value: ICefPostData);
|
|
|
|
procedure SetHeaderMap(const HeaderMap: ICefStringMultimap);
|
2019-06-16 10:31:13 +02:00
|
|
|
function GetHeaderByName(const name: ustring): ustring;
|
|
|
|
procedure SetHeaderByName(const name, value: ustring; overwrite: boolean);
|
2018-05-12 14:50:54 +02:00
|
|
|
function GetFlags: TCefUrlRequestFlags;
|
2017-01-27 16:37:51 +01:00
|
|
|
procedure SetFlags(flags: TCefUrlRequestFlags);
|
2018-05-12 14:50:54 +02:00
|
|
|
function GetFirstPartyForCookies: ustring;
|
2017-01-27 16:37:51 +01:00
|
|
|
procedure SetFirstPartyForCookies(const url: ustring);
|
|
|
|
procedure Assign(const url, method: ustring; const postData: ICefPostData; const headerMap: ICefStringMultimap);
|
2018-05-12 14:50:54 +02:00
|
|
|
function GetResourceType: TCefResourceType;
|
|
|
|
function GetTransitionType: TCefTransitionType;
|
|
|
|
function GetIdentifier: UInt64;
|
2017-01-27 16:37:51 +01:00
|
|
|
public
|
|
|
|
class function UnWrap(data: Pointer): ICefRequest;
|
|
|
|
class function New: ICefRequest;
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
|
|
|
uCEFMiscFunctions, uCEFLibFunctions, uCEFPostData;
|
|
|
|
|
|
|
|
function TCefRequestRef.IsReadOnly: Boolean;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefRequest(FData)^.is_read_only(PCefRequest(FData)) <> 0;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefRequestRef.Assign(const url, method: ustring; const postData: ICefPostData; const headerMap: ICefStringMultimap);
|
|
|
|
var
|
2018-05-12 14:50:54 +02:00
|
|
|
TempURL, TempMethod : TCefString;
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
TempURL := cefstring(url);
|
|
|
|
TempMethod := cefstring(method);
|
|
|
|
PCefRequest(FData)^.set_(PCefRequest(FData), @TempURL, @TempMethod, CefGetData(postData), headerMap.Handle);
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefRequestRef.GetFirstPartyForCookies: ustring;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := CefStringFreeAndGet(PCefRequest(FData)^.get_first_party_for_cookies(PCefRequest(FData)));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefRequestRef.GetFlags: TCefUrlRequestFlags;
|
|
|
|
begin
|
2017-07-18 17:50:28 +02:00
|
|
|
Result := PCefRequest(FData)^.get_flags(PCefRequest(FData));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefRequestRef.GetHeaderMap(const HeaderMap: ICefStringMultimap);
|
|
|
|
begin
|
|
|
|
PCefRequest(FData)^.get_header_map(PCefRequest(FData), HeaderMap.Handle);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefRequestRef.GetIdentifier: UInt64;
|
|
|
|
begin
|
|
|
|
Result := PCefRequest(FData)^.get_identifier(PCefRequest(FData));
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefRequestRef.GetMethod: ustring;
|
|
|
|
begin
|
|
|
|
Result := CefStringFreeAndGet(PCefRequest(FData)^.get_method(PCefRequest(FData)))
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefRequestRef.GetPostData: ICefPostData;
|
|
|
|
begin
|
|
|
|
Result := TCefPostDataRef.UnWrap(PCefRequest(FData)^.get_post_data(PCefRequest(FData)));
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefRequestRef.GetResourceType: TCefResourceType;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefRequest(FData)^.get_resource_type(FData);
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefRequestRef.GetTransitionType: TCefTransitionType;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefRequest(FData)^.get_transition_type(FData);
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefRequestRef.GetUrl: ustring;
|
|
|
|
begin
|
|
|
|
Result := CefStringFreeAndGet(PCefRequest(FData)^.get_url(PCefRequest(FData)))
|
|
|
|
end;
|
|
|
|
|
|
|
|
class function TCefRequestRef.New: ICefRequest;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := UnWrap(cef_request_create());
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefRequestRef.SetFirstPartyForCookies(const url: ustring);
|
|
|
|
var
|
2018-05-12 14:50:54 +02:00
|
|
|
TempURL : TCefString;
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
TempURL := CefString(url);
|
|
|
|
PCefRequest(FData)^.set_first_party_for_cookies(PCefRequest(FData), @TempURL);
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefRequestRef.SetFlags(flags: TCefUrlRequestFlags);
|
|
|
|
begin
|
|
|
|
PCefRequest(FData)^.set_flags(PCefRequest(FData), PByte(@flags)^);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefRequestRef.SetHeaderMap(const HeaderMap: ICefStringMultimap);
|
|
|
|
begin
|
|
|
|
PCefRequest(FData)^.set_header_map(PCefRequest(FData), HeaderMap.Handle);
|
|
|
|
end;
|
|
|
|
|
2019-06-16 10:31:13 +02:00
|
|
|
function TCefRequestRef.GetHeaderByName(const name: ustring): ustring;
|
|
|
|
var
|
|
|
|
TempName : TCefString;
|
|
|
|
begin
|
|
|
|
TempName := CefString(name);
|
|
|
|
Result := CefStringFreeAndGet(PCefRequest(FData)^.get_header_by_name(PCefRequest(FData), @TempName));
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefRequestRef.SetHeaderByName(const name, value: ustring; overwrite: boolean);
|
|
|
|
var
|
|
|
|
TempName, TempValue : TCefString;
|
|
|
|
begin
|
|
|
|
TempName := CefString(name);
|
|
|
|
TempValue := CefString(value);
|
|
|
|
PCefRequest(FData)^.set_header_by_name(PCefRequest(FData), @TempName, @TempValue, ord(overwrite));
|
|
|
|
end;
|
|
|
|
|
2017-01-27 16:37:51 +01:00
|
|
|
procedure TCefRequestRef.SetMethod(const value: ustring);
|
|
|
|
var
|
2018-05-12 14:50:54 +02:00
|
|
|
TempValue : TCefString;
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
TempValue := CefString(value);
|
|
|
|
PCefRequest(FData)^.set_method(PCefRequest(FData), @TempValue);
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefRequestRef.SetReferrer(const referrerUrl: ustring; policy: TCefReferrerPolicy);
|
|
|
|
var
|
2018-05-12 14:50:54 +02:00
|
|
|
TempURL : TCefString;
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
TempURL := CefString(referrerUrl);
|
|
|
|
PCefRequest(FData)^.set_referrer(PCefRequest(FData), @TempURL, policy);
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefRequestRef.GetReferrerUrl: ustring;
|
|
|
|
begin
|
|
|
|
Result := CefStringFreeAndGet(PCefRequest(FData)^.get_referrer_url(PCefRequest(FData)));
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefRequestRef.GetReferrerPolicy: TCefReferrerPolicy;
|
|
|
|
begin
|
|
|
|
Result := PCefRequest(FData)^.get_referrer_policy(PCefRequest(FData));
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefRequestRef.SetPostData(const value: ICefPostData);
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
if (value <> nil) then
|
2017-01-27 16:37:51 +01:00
|
|
|
PCefRequest(FData)^.set_post_data(PCefRequest(FData), CefGetData(value));
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefRequestRef.SetUrl(const value: ustring);
|
|
|
|
var
|
2018-05-12 14:50:54 +02:00
|
|
|
TempURL : TCefString;
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
TempURL := CefString(value);
|
|
|
|
PCefRequest(FData)^.set_url(PCefRequest(FData), @TempURL);
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
class function TCefRequestRef.UnWrap(data: Pointer): ICefRequest;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
if (data <> nil) then
|
|
|
|
Result := Create(data) as ICefRequest
|
|
|
|
else
|
2017-01-27 16:37:51 +01:00
|
|
|
Result := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
end.
|