2019-06-16 10:31:13 +02:00
|
|
|
unit uCEFCookieAccessFilter;
|
|
|
|
|
|
|
|
{$IFDEF FPC}
|
|
|
|
{$MODE OBJFPC}{$H+}
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
{$I cef.inc}
|
|
|
|
|
2022-02-19 18:56:41 +01:00
|
|
|
{$IFNDEF TARGET_64BITS}{$ALIGN ON}{$ENDIF}
|
|
|
|
{$MINENUMSIZE 4}
|
|
|
|
|
2019-06-16 10:31:13 +02:00
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes;
|
|
|
|
|
|
|
|
type
|
|
|
|
TCefCookieAccessFilterRef = class(TCefBaseRefCountedRef, ICefCookieAccessFilter)
|
|
|
|
protected
|
|
|
|
function CanSendCookie(const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; const cookie: PCefCookie): boolean;
|
|
|
|
function CanSaveCookie(const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; const response: ICefResponse; const cookie: PCefCookie): boolean;
|
|
|
|
|
|
|
|
procedure RemoveReferences;
|
|
|
|
|
|
|
|
public
|
|
|
|
class function UnWrap(data: Pointer): ICefCookieAccessFilter;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TCefCookieAccessFilterOwn = class(TCefBaseRefCountedOwn, ICefCookieAccessFilter)
|
|
|
|
protected
|
|
|
|
function CanSendCookie(const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; const cookie: PCefCookie): boolean; virtual;
|
|
|
|
function CanSaveCookie(const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; const response: ICefResponse; const cookie: PCefCookie): boolean; virtual;
|
|
|
|
|
|
|
|
procedure RemoveReferences; virtual;
|
|
|
|
|
|
|
|
public
|
|
|
|
constructor Create; virtual;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TCustomCookieAccessFilter = class(TCefCookieAccessFilterOwn)
|
|
|
|
protected
|
|
|
|
FEvents : Pointer;
|
|
|
|
|
|
|
|
function CanSendCookie(const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; const cookie: PCefCookie): boolean; override;
|
|
|
|
function CanSaveCookie(const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; const response: ICefResponse; const cookie: PCefCookie): boolean; override;
|
|
|
|
|
|
|
|
public
|
2019-06-19 16:53:26 +02:00
|
|
|
constructor Create(const events : IChromiumEvents); reintroduce;
|
2019-06-16 10:31:13 +02:00
|
|
|
procedure BeforeDestruction; override;
|
|
|
|
procedure RemoveReferences; override;
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
|
|
|
{$IFDEF DELPHI16_UP}
|
|
|
|
System.SysUtils,
|
|
|
|
{$ELSE}
|
|
|
|
SysUtils,
|
|
|
|
{$ENDIF}
|
2021-10-22 19:19:57 +02:00
|
|
|
uCEFMiscFunctions, uCEFLibFunctions, uCEFBrowser, uCEFFrame, uCEFRequest, uCefResponse;
|
2019-06-16 10:31:13 +02:00
|
|
|
|
|
|
|
// TCefCookieAccessFilterOwn
|
|
|
|
|
|
|
|
function cef_cookie_access_filter_can_send_cookie( self : PCefCookieAccessFilter;
|
|
|
|
browser : PCefBrowser;
|
|
|
|
frame : PCefFrame;
|
|
|
|
request : PCefRequest;
|
|
|
|
const cookie : PCefCookie): Integer; stdcall;
|
|
|
|
var
|
|
|
|
TempObject : TObject;
|
|
|
|
begin
|
|
|
|
Result := Ord(True);
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefCookieAccessFilterOwn) then
|
|
|
|
Result := Ord(TCefCookieAccessFilterOwn(TempObject).CanSendCookie(TCefBrowserRef.UnWrap(browser),
|
|
|
|
TCefFrameRef.UnWrap(frame),
|
|
|
|
TCefRequestRef.UnWrap(request),
|
|
|
|
cookie));
|
|
|
|
end;
|
|
|
|
|
|
|
|
function cef_cookie_access_filter_can_save_cookie( self : PCefCookieAccessFilter;
|
|
|
|
browser : PCefBrowser;
|
|
|
|
frame : PCefFrame;
|
|
|
|
request : PCefRequest;
|
|
|
|
response : PCefResponse;
|
|
|
|
const cookie : PCefCookie): Integer; stdcall;
|
|
|
|
var
|
|
|
|
TempObject : TObject;
|
|
|
|
begin
|
|
|
|
Result := Ord(True);
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefCookieAccessFilterOwn) then
|
|
|
|
Result := Ord(TCefCookieAccessFilterOwn(TempObject).CanSaveCookie(TCefBrowserRef.UnWrap(browser),
|
|
|
|
TCefFrameRef.UnWrap(frame),
|
|
|
|
TCefRequestRef.UnWrap(request),
|
|
|
|
TCefResponseRef.UnWrap(response),
|
|
|
|
cookie));
|
|
|
|
end;
|
|
|
|
|
|
|
|
constructor TCefCookieAccessFilterOwn.Create;
|
|
|
|
begin
|
|
|
|
inherited CreateData(SizeOf(TCefCookieAccessFilter));
|
|
|
|
|
|
|
|
with PCefCookieAccessFilter(FData)^ do
|
|
|
|
begin
|
|
|
|
can_send_cookie := {$IFDEF FPC}@{$ENDIF}cef_cookie_access_filter_can_send_cookie;
|
|
|
|
can_save_cookie := {$IFDEF FPC}@{$ENDIF}cef_cookie_access_filter_can_save_cookie;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefCookieAccessFilterOwn.CanSendCookie(const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; const cookie: PCefCookie): boolean;
|
|
|
|
begin
|
2019-06-19 16:53:26 +02:00
|
|
|
Result := True;
|
2019-06-16 10:31:13 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefCookieAccessFilterOwn.CanSaveCookie(const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; const response: ICefResponse; const cookie: PCefCookie): boolean;
|
|
|
|
begin
|
2019-06-19 16:53:26 +02:00
|
|
|
Result := True;
|
2019-06-16 10:31:13 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefCookieAccessFilterOwn.RemoveReferences;
|
|
|
|
begin
|
|
|
|
//
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
// TCefCookieAccessFilterRef
|
|
|
|
|
|
|
|
class function TCefCookieAccessFilterRef.UnWrap(data: Pointer): ICefCookieAccessFilter;
|
|
|
|
begin
|
|
|
|
if (data <> nil) then
|
|
|
|
Result := Create(data) as ICefCookieAccessFilter
|
|
|
|
else
|
|
|
|
Result := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefCookieAccessFilterRef.CanSendCookie(const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; const cookie: PCefCookie): boolean;
|
|
|
|
begin
|
|
|
|
Result := (PCefCookieAccessFilter(FData)^.can_send_cookie(PCefCookieAccessFilter(FData),
|
|
|
|
CefGetData(browser),
|
|
|
|
CefGetData(frame),
|
|
|
|
CefGetData(request),
|
|
|
|
cookie) <> 0);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefCookieAccessFilterRef.CanSaveCookie(const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; const response: ICefResponse; const cookie: PCefCookie): boolean;
|
|
|
|
begin
|
|
|
|
Result := (PCefCookieAccessFilter(FData)^.can_save_cookie(PCefCookieAccessFilter(FData),
|
|
|
|
CefGetData(browser),
|
|
|
|
CefGetData(frame),
|
|
|
|
CefGetData(request),
|
|
|
|
CefGetData(response),
|
|
|
|
cookie) <> 0);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefCookieAccessFilterRef.RemoveReferences;
|
|
|
|
begin
|
|
|
|
//
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
// TCustomCookieAccessFilter
|
|
|
|
|
|
|
|
|
2019-06-19 16:53:26 +02:00
|
|
|
constructor TCustomCookieAccessFilter.Create(const events : IChromiumEvents);
|
2019-06-16 10:31:13 +02:00
|
|
|
begin
|
|
|
|
inherited Create;
|
|
|
|
|
2019-06-19 16:53:26 +02:00
|
|
|
FEvents := Pointer(events);
|
2019-06-16 10:31:13 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCustomCookieAccessFilter.BeforeDestruction;
|
|
|
|
begin
|
|
|
|
FEvents := nil;
|
|
|
|
|
|
|
|
inherited BeforeDestruction;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCustomCookieAccessFilter.RemoveReferences;
|
|
|
|
begin
|
|
|
|
FEvents := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCustomCookieAccessFilter.CanSendCookie(const browser : ICefBrowser;
|
|
|
|
const frame : ICefFrame;
|
|
|
|
const request : ICefRequest;
|
|
|
|
const cookie : PCefCookie): boolean;
|
|
|
|
begin
|
|
|
|
if (FEvents <> nil) then
|
|
|
|
Result := IChromiumEvents(FEvents).doCanSendCookie(browser, frame, request, cookie)
|
|
|
|
else
|
|
|
|
Result := inherited CanSendCookie(browser, frame, request, cookie);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCustomCookieAccessFilter.CanSaveCookie(const browser : ICefBrowser;
|
|
|
|
const frame : ICefFrame;
|
|
|
|
const request : ICefRequest;
|
|
|
|
const response : ICefResponse;
|
|
|
|
const cookie : PCefCookie): boolean;
|
|
|
|
begin
|
|
|
|
if (FEvents <> nil) then
|
|
|
|
Result := IChromiumEvents(FEvents).doCanSaveCookie(browser, frame, request, response, cookie)
|
|
|
|
else
|
|
|
|
Result := inherited CanSaveCookie(browser, frame, request, response, cookie);
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|