1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2024-11-24 08:02:15 +02:00

Added all TCefCookieManager functions to TChromium

- Added TChromium.VisitAllCookies
- Added TChromium.VisitURLCookies
- Added TChromium.SetCookie
- Added TChromium.OnCookiesVisited
- Added TChromium.OnCookieSet
- Removed unused constants.
- CookieVisitor demo adapted to the new TChromium functions and events.
This commit is contained in:
Salvador Díaz Fau 2019-10-29 16:13:35 +01:00
parent d8ea60d8fd
commit 2fe89069a4
16 changed files with 697 additions and 256 deletions

View File

@ -14,7 +14,6 @@ object CookieVisitorFrm: TCookieVisitorFrm
Position = poScreenCenter
OnCloseQuery = FormCloseQuery
OnCreate = FormCreate
OnDestroy = FormDestroy
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 13
@ -66,6 +65,8 @@ object CookieVisitorFrm: TCookieVisitorFrm
end
object Chromium1: TChromium
OnCookiesDeleted = Chromium1CookiesDeleted
OnCookiesVisited = Chromium1CookiesVisited
OnCookieSet = Chromium1CookieSet
OnBeforeContextMenu = Chromium1BeforeContextMenu
OnContextMenuCommand = Chromium1ContextMenuCommand
OnBeforePopup = Chromium1BeforePopup

View File

@ -54,11 +54,13 @@ uses
const
MINIBROWSER_SHOWCOOKIES = WM_APP + $101;
MINIBROWSER_SETCOOKIERSLT = WM_APP + $102;
MINIBROWSER_COOKIESDELETED = WM_APP + $102;
MINIBROWSER_COOKIESET = WM_APP + $103;
MINIBROWSER_CONTEXTMENU_DELETECOOKIES = MENU_ID_USER_FIRST + 1;
MINIBROWSER_CONTEXTMENU_GETCOOKIES = MENU_ID_USER_FIRST + 2;
MINIBROWSER_CONTEXTMENU_SETCOOKIE = MENU_ID_USER_FIRST + 3;
MINIBROWSER_CONTEXTMENU_GETGOOGLECOOKIES = MENU_ID_USER_FIRST + 4;
type
TCookieVisitorFrm = class(TForm)
@ -82,7 +84,6 @@ type
procedure Chromium1CookiesDeleted(Sender: TObject;
numDeleted: Integer);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Chromium1BeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
@ -98,6 +99,12 @@ type
procedure Chromium1BeforeClose(Sender: TObject;
const browser: ICefBrowser);
procedure CEFSentinel1Close(Sender: TObject);
procedure Chromium1CookiesVisited(Sender: TObject; const name_, value,
domain, path: ustring; secure, httponly, hasExpires: Boolean;
const creation, lastAccess, expires: TDateTime; count,
total, aID : Integer; var aDeleteCookie, aResult: Boolean);
procedure Chromium1CookieSet(Sender: TObject; aSuccess: Boolean;
aID: Integer);
private
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
@ -107,11 +114,11 @@ type
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
procedure BrowserDestroyMsg(var aMessage : TMessage); message CEF_DESTROY;
procedure ShowCookiesMsg(var aMessage : TMessage); message MINIBROWSER_SHOWCOOKIES;
procedure SetCookieRsltMsg(var aMessage : TMessage); message MINIBROWSER_SETCOOKIERSLT;
procedure CookiesDeletedMsg(var aMessage : TMessage); message MINIBROWSER_COOKIESDELETED;
procedure CookieSetMsg(var aMessage : TMessage); message MINIBROWSER_COOKIESET;
protected
FText : string;
FVisitor : ICefCookieVisitor;
// Variables to control when can we destroy the form safely
FCanClose : boolean; // Set to True in TChromium.OnBeforeClose
FClosing : boolean; // Set to True in the CloseQuery event.
@ -133,12 +140,17 @@ implementation
uses
uSimpleTextViewer, uCEFTask, uCEFMiscFunctions;
// This demo has a context menu to test the DeleteCookies function and a CookieVisitor example.
// This demo has a context menu to test several TChromium functions related to cookies like TChromium.VisitAllCookies,
// TChromium.SetCookie, TChromium.DeleteCookies, etc.
// The cookie visitor gets the global cookie manager to call the VisitAllCookies function.
// The cookie visitor will call CookieVisitorProc for each cookie and it'll save the information using the AddCookieInfo function.
// TChromium.VisitAllCookies and TChromium.VisitURLCookies trigger the TChromium.OnCookiesVisited event for each
// cookie and it'll save the information using the AddCookieInfo function.
// When the last cookie arrives we show the information in a SimpleTextViewer form.
// TChromium.SetCookie triggers TChromium.OnCookieSet when it has set the cookie.
// TChromium.DeleteCookies triggers TChromium.OnCookiesDeleted when the cookies have been deleted.
// Destruction steps
// =================
// 1. FormCloseQuery sets CanClose to FALSE calls TChromium.CloseBrowser which triggers the TChromium.OnClose event.
@ -153,41 +165,6 @@ begin
//GlobalCEFApp.LogSeverity := LOGSEVERITY_VERBOSE;
end;
// This function is called in the IO thread.
function CookieVisitorProc(const name, value, domain, path: ustring;
secure, httponly, hasExpires: Boolean;
const creation, lastAccess, expires: TDateTime;
count, total: Integer;
out deleteCookie: Boolean): Boolean;
var
TempCookie : TCookie;
begin
deleteCookie := False;
TempCookie.name := name;
TempCookie.value := value;
TempCookie.domain := domain;
TempCookie.path := path;
TempCookie.secure := secure;
TempCookie.httponly := httponly;
TempCookie.creation := creation;
TempCookie.last_access := lastAccess;
TempCookie.has_expires := hasExpires;
TempCookie.expires := expires;
CookieVisitorFrm.AddCookieInfo(TempCookie);
if (count = pred(total)) then
begin
if (CookieVisitorFrm <> nil) and CookieVisitorFrm.HandleAllocated then
PostMessage(CookieVisitorFrm.Handle, MINIBROWSER_SHOWCOOKIES, 0, 0);
Result := False;
end
else
Result := True;
end;
procedure TCookieVisitorFrm.AddCookieInfo(const aCookie : TCookie);
begin
// This should be protected by a mutex.
@ -212,12 +189,17 @@ begin
SimpleTextViewerFrm.ShowModal;
end;
procedure TCookieVisitorFrm.SetCookieRsltMsg(var aMessage : TMessage);
procedure TCookieVisitorFrm.CookiesDeletedMsg(var aMessage : TMessage);
begin
if (aMessage.wParam = 0) then
showmessage('There was a problem setting the cookie')
showmessage('Deleted cookies : ' + inttostr(aMessage.lParam));
end;
procedure TCookieVisitorFrm.CookieSetMsg(var aMessage : TMessage);
begin
if (aMessage.wParam <> 0) then
showmessage('Cookie set successfully !')
else
showmessage('Cookie set successfully !');
showmessage('There was a problem setting the cookie');
end;
procedure TCookieVisitorFrm.Timer1Timer(Sender: TObject);
@ -255,7 +237,8 @@ begin
model.AddSeparator;
model.AddItem(MINIBROWSER_CONTEXTMENU_DELETECOOKIES, 'Delete cookies');
model.AddSeparator;
model.AddItem(MINIBROWSER_CONTEXTMENU_GETCOOKIES, 'Visit cookies');
model.AddItem(MINIBROWSER_CONTEXTMENU_GETCOOKIES, 'Visit all cookies');
model.AddItem(MINIBROWSER_CONTEXTMENU_GETGOOGLECOOKIES, 'Visit cookies from Google');
model.AddItem(MINIBROWSER_CONTEXTMENU_SETCOOKIE, 'Set cookie');
end;
@ -284,8 +267,6 @@ procedure TCookieVisitorFrm.Chromium1ContextMenuCommand(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; commandId: Integer;
eventFlags: Cardinal; out Result: Boolean);
var
TempManager : ICefCookieManager;
begin
Result := False;
@ -296,15 +277,18 @@ begin
begin
// This should be protected by a mutex
FText := '';
TempManager := TCefCookieManagerRef.Global(nil);
TempManager.VisitAllCookies(FVisitor);
Chromium1.VisitAllCookies;
end;
MINIBROWSER_CONTEXTMENU_GETGOOGLECOOKIES :
begin
// This should be protected by a mutex
FText := '';
Chromium1.VisitURLCookies('https://www.google.com');
end;
MINIBROWSER_CONTEXTMENU_SETCOOKIE :
begin
TempManager := TCefCookieManagerRef.Global(nil);
if TempManager.SetCookie('https://www.example.com',
Chromium1.SetCookie('https://www.example.com',
'example_cookie_name',
'1234',
'',
@ -315,17 +299,50 @@ begin
now,
now,
now,
nil) then
PostMessage(Handle, MINIBROWSER_SETCOOKIERSLT, ord(True), 0)
else
PostMessage(Handle, MINIBROWSER_SETCOOKIERSLT, ord(False), 0);
end;
False);
end;
end;
procedure TCookieVisitorFrm.Chromium1CookiesDeleted(Sender: TObject; numDeleted: Integer);
begin
showmessage('Deleted cookies : ' + inttostr(numDeleted));
PostMessage(Handle, MINIBROWSER_COOKIESDELETED, 0, numDeleted);
end;
procedure TCookieVisitorFrm.Chromium1CookieSet(Sender: TObject;
aSuccess: Boolean; aID: Integer);
begin
PostMessage(Handle, MINIBROWSER_COOKIESET, ord(aSuccess), aID);
end;
procedure TCookieVisitorFrm.Chromium1CookiesVisited(Sender: TObject;
const name_, value, domain, path: ustring; secure, httponly,
hasExpires: Boolean; const creation, lastAccess, expires: TDateTime;
count, total, aID: Integer; var aDeleteCookie, aResult: Boolean);
var
TempCookie : TCookie;
begin
aDeleteCookie := False;
TempCookie.name := name_;
TempCookie.value := value;
TempCookie.domain := domain;
TempCookie.path := path;
TempCookie.secure := secure;
TempCookie.httponly := httponly;
TempCookie.creation := creation;
TempCookie.last_access := lastAccess;
TempCookie.has_expires := hasExpires;
TempCookie.expires := expires;
AddCookieInfo(TempCookie);
if (count = pred(total)) then
begin
PostMessage(Handle, MINIBROWSER_SHOWCOOKIES, 0, 0);
aResult := False;
end
else
aResult := True;
end;
procedure TCookieVisitorFrm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
@ -342,16 +359,10 @@ end;
procedure TCookieVisitorFrm.FormCreate(Sender: TObject);
begin
FVisitor := TCefFastCookieVisitor.Create(CookieVisitorProc);
FCanClose := False;
FClosing := False;
end;
procedure TCookieVisitorFrm.FormDestroy(Sender: TObject);
begin
FVisitor := nil;
end;
procedure TCookieVisitorFrm.FormShow(Sender: TObject);
begin
// GlobalCEFApp.GlobalContextInitialized has to be TRUE before creating any browser

View File

@ -83,7 +83,7 @@
</Other>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">
<Exceptions Count="4">
<Item1>
<Name Value="EAbort"/>
</Item1>
@ -93,6 +93,10 @@
<Item3>
<Name Value="EFOpenError"/>
</Item3>
<Item4>
<Name Value="EThread"/>
<Enabled Value="False"/>
</Item4>
</Exceptions>
</Debugging>
</CONFIG>

View File

@ -10,7 +10,7 @@
<IsPartOfProject Value="True"/>
<TopLine Value="40"/>
<CursorPos X="25" Y="74"/>
<UsageCount Value="22"/>
<UsageCount Value="24"/>
<Loaded Value="True"/>
<DefaultSyntaxHighlighter Value="Delphi"/>
</Unit0>
@ -22,9 +22,14 @@
<ResourceBaseClass Value="Form"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="1"/>
<TopLine Value="131"/>
<CursorPos X="82" Y="150"/>
<UsageCount Value="22"/>
<TopLine Value="231"/>
<CursorPos X="13" Y="235"/>
<UsageCount Value="24"/>
<Bookmarks Count="3">
<Item0 Y="350" ID="1"/>
<Item1 X="3" Y="198" ID="2"/>
<Item2 X="66" Y="229" ID="3"/>
</Bookmarks>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
<DefaultSyntaxHighlighter Value="Delphi"/>
@ -37,73 +42,138 @@
<ResourceBaseClass Value="Form"/>
<EditorIndex Value="-1"/>
<CursorPos X="8" Y="29"/>
<UsageCount Value="22"/>
<UsageCount Value="24"/>
<DefaultSyntaxHighlighter Value="Delphi"/>
</Unit2>
<Unit3>
<Filename Value="C:\lazarus\lcl\interfaces\win32\win32object.inc"/>
<EditorIndex Value="-1"/>
<TopLine Value="354"/>
<TopLine Value="399"/>
<CursorPos Y="413"/>
<UsageCount Value="10"/>
</Unit3>
</Units>
<JumpHistory Count="14" HistoryIndex="13">
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="CookieVisitor.lpr"/>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="252" Column="5" TopLine="249"/>
</Position1>
<Position2>
<Filename Value="CookieVisitor.lpr"/>
<Caret Line="50" Column="3" TopLine="32"/>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="64" Column="35" TopLine="42"/>
</Position2>
<Position3>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="368" TopLine="335"/>
<Caret Line="85" Column="41" TopLine="61"/>
</Position3>
<Position4>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="126" Column="8" TopLine="116"/>
<Caret Line="356" Column="81" TopLine="334"/>
</Position4>
<Position5>
<Filename Value="CookieVisitor.lpr"/>
<Caret Line="74" TopLine="39"/>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="223" TopLine="206"/>
</Position5>
<Position6>
<Filename Value="CookieVisitor.lpr"/>
<Caret Line="57" TopLine="39"/>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="251" Column="70" TopLine="234"/>
</Position6>
<Position7>
<Filename Value="CookieVisitor.lpr"/>
<Caret Line="40" TopLine="40"/>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="252" Column="3" TopLine="239"/>
</Position7>
<Position8>
<Filename Value="CookieVisitor.lpr"/>
<Caret Line="75" TopLine="40"/>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="79" Column="67" TopLine="75"/>
</Position8>
<Position9>
<Filename Value="CookieVisitor.lpr"/>
<Caret Line="58" Column="31" TopLine="36"/>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="352" Column="38" TopLine="336"/>
</Position9>
<Position10>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="86" Column="26" TopLine="72"/>
<Caret Line="41" Column="100" TopLine="29"/>
</Position10>
<Position11>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="125" Column="11" TopLine="115"/>
<Caret Line="99" Column="40" TopLine="71"/>
</Position11>
<Position12>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="149" Column="69" TopLine="139"/>
<Caret Line="119" Column="15" TopLine="103"/>
</Position12>
<Position13>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="150" Column="58" TopLine="139"/>
<Caret Line="191" Column="3" TopLine="182"/>
</Position13>
<Position14>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="155" Column="58" TopLine="144"/>
<Caret Line="339" Column="60" TopLine="324"/>
</Position14>
<Position15>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="191" Column="62" TopLine="176"/>
</Position15>
<Position16>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="120" Column="67" TopLine="106"/>
</Position16>
<Position17>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="339" Column="31" TopLine="324"/>
</Position17>
<Position18>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="117" Column="84" TopLine="94"/>
</Position18>
<Position19>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="115" Column="96" TopLine="95"/>
</Position19>
<Position20>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="119" Column="87" TopLine="95"/>
</Position20>
<Position21>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="245" Column="11" TopLine="222"/>
</Position21>
<Position22>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="340" TopLine="325"/>
</Position22>
<Position23>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="339" Column="74" TopLine="325"/>
</Position23>
<Position24>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="216" Column="51" TopLine="202"/>
</Position24>
<Position25>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="340" Column="68" TopLine="326"/>
</Position25>
<Position26>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="121" Column="15" TopLine="109"/>
</Position26>
<Position27>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="198" Column="5" TopLine="190"/>
</Position27>
<Position28>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="221" Column="66" TopLine="208"/>
</Position28>
<Position29>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="198" Column="28" TopLine="178"/>
</Position29>
<Position30>
<Filename Value="uCookieVisitor.pas"/>
<Caret Line="83" Column="72" TopLine="75"/>
</Position30>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>

View File

@ -1,7 +1,7 @@
object CookieVisitorFrm: TCookieVisitorFrm
Left = 183
Left = 449
Height = 762
Top = 77
Top = 101
Width = 884
Caption = 'Cookie Visitor'
ClientHeight = 762
@ -59,6 +59,8 @@ object CookieVisitorFrm: TCookieVisitorFrm
end
object Chromium1: TChromium
OnCookiesDeleted = Chromium1CookiesDeleted
OnCookiesVisited = Chromium1CookiesVisited
OnCookieSet = Chromium1CookieSet
OnBeforeContextMenu = Chromium1BeforeContextMenu
OnContextMenuCommand = Chromium1ContextMenuCommand
OnBeforePopup = Chromium1BeforePopup

View File

@ -50,15 +50,17 @@ uses
Controls, Forms, Dialogs, StdCtrls, ExtCtrls,
{$ENDIF}
uCEFChromium, uCEFWindowParent, uCEFInterfaces, uCEFApplication, uCEFTypes, uCEFConstants,
uCEFCookieManager, uCEFCookieVisitor, uCEFWinControl, uCEFSentinel;
uCEFCookieManager, uCEFCookieVisitor, uCEFWinControl, uCEFSentinel, uCEFChromiumEvents;
const
MINIBROWSER_SHOWCOOKIES = WM_APP + $101;
MINIBROWSER_SETCOOKIERSLT = WM_APP + $102;
MINIBROWSER_COOKIESDELETED = WM_APP + $102;
MINIBROWSER_COOKIESET = WM_APP + $103;
MINIBROWSER_CONTEXTMENU_DELETECOOKIES = MENU_ID_USER_FIRST + 1;
MINIBROWSER_CONTEXTMENU_GETCOOKIES = MENU_ID_USER_FIRST + 2;
MINIBROWSER_CONTEXTMENU_SETCOOKIE = MENU_ID_USER_FIRST + 3;
MINIBROWSER_CONTEXTMENU_GETGOOGLECOOKIES = MENU_ID_USER_FIRST + 4;
type
@ -74,6 +76,12 @@ type
Timer1: TTimer;
procedure CEFSentinel1Close(Sender: TObject);
procedure Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser);
procedure Chromium1CookieSet(Sender: TObject; aSuccess: boolean;
aID: integer);
procedure Chromium1CookiesVisited(Sender: TObject; const name_, value,
domain, path: ustring; secure, httponly, hasExpires: Boolean;
const creation, lastAccess, expires: TDateTime; count, total, aID: Integer;
var aDeleteCookie, aResult: Boolean);
procedure FormShow(Sender: TObject);
procedure GoBtnClick(Sender: TObject);
procedure Chromium1BeforeContextMenu(Sender: TObject;
@ -110,11 +118,11 @@ type
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
procedure BrowserDestroyMsg(var aMessage : TMessage); message CEF_DESTROY;
procedure ShowCookiesMsg(var aMessage : TMessage); message MINIBROWSER_SHOWCOOKIES;
procedure SetCookieRsltMsg(var aMessage : TMessage); message MINIBROWSER_SETCOOKIERSLT;
procedure CookiesDeletedMsg(var aMessage : TMessage); message MINIBROWSER_COOKIESDELETED;
procedure CookieSetMsg(var aMessage : TMessage); message MINIBROWSER_COOKIESET;
protected
FText : string;
FVisitor : ICefCookieVisitor;
// Variables to control when can we destroy the form safely
FCanClose : boolean; // Set to True in TChromium.OnBeforeClose
FClosing : boolean; // Set to True in the CloseQuery event.
@ -136,12 +144,17 @@ implementation
uses
uSimpleTextViewer, uCEFTask, uCEFMiscFunctions;
// This demo has a context menu to test the DeleteCookies function and a CookieVisitor example.
// This demo has a context menu to test several TChromium functions related to cookies like TChromium.VisitAllCookies,
// TChromium.SetCookie, TChromium.DeleteCookies, etc.
// The cookie visitor gets the global cookie manager to call the VisitAllCookies function.
// The cookie visitor will call CookieVisitorProc for each cookie and it'll save the information using the AddCookieInfo function.
// TChromium.VisitAllCookies and TChromium.VisitURLCookies trigger the TChromium.OnCookiesVisited event for each
// cookie and it'll save the information using the AddCookieInfo function.
// When the last cookie arrives we show the information in a SimpleTextViewer form.
// TChromium.SetCookie triggers TChromium.OnCookieSet when it has set the cookie.
// TChromium.DeleteCookies triggers TChromium.OnCookiesDeleted when the cookies have been deleted.
// Destruction steps
// =================
// 1. FormCloseQuery sets CanClose to FALSE calls TChromium.CloseBrowser which triggers the TChromium.OnClose event.
@ -156,41 +169,6 @@ begin
//GlobalCEFApp.LogSeverity := LOGSEVERITY_VERBOSE;
end;
// This function is called in the IO thread.
function CookieVisitorProc(const name, value, domain, path: ustring;
secure, httponly, hasExpires: Boolean;
const creation, lastAccess, expires: TDateTime;
count, total: Integer;
out deleteCookie: Boolean): Boolean;
var
TempCookie : TCookie;
begin
deleteCookie := False;
TempCookie.name := name;
TempCookie.value := value;
TempCookie.domain := domain;
TempCookie.path := path;
TempCookie.secure := secure;
TempCookie.httponly := httponly;
TempCookie.creation := creation;
TempCookie.last_access := lastAccess;
TempCookie.has_expires := hasExpires;
TempCookie.expires := expires;
CookieVisitorFrm.AddCookieInfo(TempCookie);
if (count = pred(total)) then
begin
if (CookieVisitorFrm <> nil) and CookieVisitorFrm.HandleAllocated then
PostMessage(CookieVisitorFrm.Handle, MINIBROWSER_SHOWCOOKIES, 0, 0);
Result := False;
end
else
Result := True;
end;
procedure TCookieVisitorFrm.AddCookieInfo(const aCookie : TCookie);
begin
// This should be protected by a mutex.
@ -215,12 +193,17 @@ begin
SimpleTextViewerFrm.ShowModal;
end;
procedure TCookieVisitorFrm.SetCookieRsltMsg(var aMessage : TMessage);
procedure TCookieVisitorFrm.CookiesDeletedMsg(var aMessage : TMessage);
begin
if (aMessage.wParam = 0) then
showmessage('There was a problem setting the cookie')
showmessage('Deleted cookies : ' + inttostr(aMessage.lParam));
end;
procedure TCookieVisitorFrm.CookieSetMsg(var aMessage : TMessage);
begin
if (aMessage.wParam <> 0) then
showmessage('Cookie set successfully !')
else
showmessage('Cookie set successfully !');
showmessage('There was a problem setting the cookie');
end;
procedure TCookieVisitorFrm.Timer1Timer(Sender: TObject);
@ -240,6 +223,43 @@ begin
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
end;
procedure TCookieVisitorFrm.Chromium1CookieSet(Sender: TObject;
aSuccess: boolean; aID: integer);
begin
PostMessage(Handle, MINIBROWSER_COOKIESET, ord(aSuccess), aID);
end;
procedure TCookieVisitorFrm.Chromium1CookiesVisited(Sender: TObject;
const name_, value, domain, path: ustring; secure, httponly,
hasExpires: Boolean; const creation, lastAccess, expires: TDateTime; count,
total, aID: Integer; var aDeleteCookie, aResult: Boolean);
var
TempCookie : TCookie;
begin
aDeleteCookie := False;
TempCookie.name := name_;
TempCookie.value := value;
TempCookie.domain := domain;
TempCookie.path := path;
TempCookie.secure := secure;
TempCookie.httponly := httponly;
TempCookie.creation := creation;
TempCookie.last_access := lastAccess;
TempCookie.has_expires := hasExpires;
TempCookie.expires := expires;
AddCookieInfo(TempCookie);
if (count = pred(total)) then
begin
PostMessage(Handle, MINIBROWSER_SHOWCOOKIES, 0, 0);
aResult := False;
end
else
aResult := True;
end;
procedure TCookieVisitorFrm.CEFSentinel1Close(Sender: TObject);
begin
FCanClose := True;
@ -258,7 +278,8 @@ begin
model.AddSeparator;
model.AddItem(MINIBROWSER_CONTEXTMENU_DELETECOOKIES, 'Delete cookies');
model.AddSeparator;
model.AddItem(MINIBROWSER_CONTEXTMENU_GETCOOKIES, 'Visit cookies');
model.AddItem(MINIBROWSER_CONTEXTMENU_GETCOOKIES, 'Visit all cookies');
model.AddItem(MINIBROWSER_CONTEXTMENU_GETGOOGLECOOKIES, 'Visit cookies from Google');
model.AddItem(MINIBROWSER_CONTEXTMENU_SETCOOKIE, 'Set cookie');
end;
@ -287,8 +308,6 @@ procedure TCookieVisitorFrm.Chromium1ContextMenuCommand(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; commandId: Integer;
eventFlags: Cardinal; out Result: Boolean);
var
TempManager : ICefCookieManager;
begin
Result := False;
@ -299,15 +318,18 @@ begin
begin
// This should be protected by a mutex
FText := '';
TempManager := TCefCookieManagerRef.Global(nil);
TempManager.VisitAllCookies(FVisitor);
Chromium1.VisitAllCookies;
end;
MINIBROWSER_CONTEXTMENU_GETGOOGLECOOKIES :
begin
// This should be protected by a mutex
FText := '';
Chromium1.VisitURLCookies('https://www.google.com');
end;
MINIBROWSER_CONTEXTMENU_SETCOOKIE :
begin
TempManager := TCefCookieManagerRef.Global(nil);
if TempManager.SetCookie('https://www.example.com',
Chromium1.SetCookie('https://www.example.com',
'example_cookie_name',
'1234',
'',
@ -318,17 +340,13 @@ begin
now,
now,
now,
nil) then
PostMessage(Handle, MINIBROWSER_SETCOOKIERSLT, ord(True), 0)
else
PostMessage(Handle, MINIBROWSER_SETCOOKIERSLT, ord(False), 0);
end;
False);
end;
end;
procedure TCookieVisitorFrm.Chromium1CookiesDeleted(Sender: TObject; numDeleted: Integer);
begin
showmessage('Deleted cookies : ' + inttostr(numDeleted));
PostMessage(Handle, MINIBROWSER_COOKIESDELETED, 0, numDeleted);
end;
procedure TCookieVisitorFrm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
@ -345,14 +363,13 @@ end;
procedure TCookieVisitorFrm.FormCreate(Sender: TObject);
begin
FVisitor := TCefFastCookieVisitor.Create(CookieVisitorProc);
FCanClose := False;
FClosing := False;
end;
procedure TCookieVisitorFrm.FormDestroy(Sender: TObject);
begin
FVisitor := nil;
end;
procedure TCookieVisitorFrm.FormShow(Sender: TObject);

View File

@ -20,7 +20,6 @@
<ComponentName Value="MainForm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="1"/>
<TopLine Value="128"/>
<CursorPos X="58" Y="152"/>
@ -38,7 +37,7 @@
<ComponentName Value="ChildForm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<EditorIndex Value="2"/>
<EditorIndex Value="3"/>
<TopLine Value="52"/>
<CursorPos X="54" Y="97"/>
<UsageCount Value="23"/>
@ -55,10 +54,12 @@
</Unit3>
<Unit4>
<Filename Value="..\..\..\source\uCEFChromium.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="1009"/>
<CursorPos X="9" Y="1022"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="2"/>
<TopLine Value="2395"/>
<CursorPos X="3" Y="2406"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit4>
<Unit5>
<Filename Value="..\..\..\source\uCEFMiscFunctions.pas"/>
@ -86,123 +87,123 @@
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="uMainForm.pas"/>
<Caret Line="344" Column="17" TopLine="320"/>
<Caret Line="346" Column="58" TopLine="320"/>
</Position1>
<Position2>
<Filename Value="uMainForm.pas"/>
<Caret Line="346" Column="19" TopLine="322"/>
<Caret Line="337" TopLine="320"/>
</Position2>
<Position3>
<Filename Value="uMainForm.pas"/>
<Caret Line="197" Column="72" TopLine="182"/>
<Caret Line="184" Column="66" TopLine="175"/>
</Position3>
<Position4>
<Filename Value="uMainForm.pas"/>
<Caret Line="352" Column="56" TopLine="322"/>
<Caret Line="337" Column="30" TopLine="322"/>
</Position4>
<Position5>
<Filename Value="uMainForm.pas"/>
<Caret Line="332" TopLine="310"/>
<Caret Line="67" TopLine="49"/>
</Position5>
<Position6>
<Filename Value="uMainForm.pas"/>
<Caret Line="334" Column="51" TopLine="310"/>
<Caret Line="180" Column="40" TopLine="166"/>
</Position6>
<Position7>
<Filename Value="uMainForm.pas"/>
<Caret Line="67" TopLine="49"/>
<Caret Line="335" Column="59" TopLine="309"/>
</Position7>
<Position8>
<Filename Value="uMainForm.pas"/>
<Caret Line="340" TopLine="311"/>
<Caret Line="333" Column="40" TopLine="309"/>
</Position8>
<Position9>
<Filename Value="uMainForm.pas"/>
<Caret Line="337" TopLine="311"/>
<Caret Line="332" TopLine="309"/>
</Position9>
<Position10>
<Filename Value="uMainForm.pas"/>
<Caret Line="343" Column="33" TopLine="314"/>
<Caret Line="339" TopLine="309"/>
</Position10>
<Position11>
<Filename Value="uMainForm.pas"/>
<Caret Line="337" TopLine="314"/>
<Caret Line="188" Column="99" TopLine="177"/>
</Position11>
<Position12>
<Filename Value="uMainForm.pas"/>
<Caret Line="346" Column="58" TopLine="320"/>
<Caret Line="343" Column="19" TopLine="333"/>
</Position12>
<Position13>
<Filename Value="uMainForm.pas"/>
<Caret Line="337" TopLine="320"/>
<Caret Line="69" TopLine="52"/>
</Position13>
<Position14>
<Filename Value="uMainForm.pas"/>
<Caret Line="184" Column="66" TopLine="175"/>
<Caret Line="336" TopLine="321"/>
</Position14>
<Position15>
<Filename Value="uMainForm.pas"/>
<Caret Line="337" Column="30" TopLine="322"/>
<Caret Line="335" TopLine="320"/>
</Position15>
<Position16>
<Filename Value="uMainForm.pas"/>
<Caret Line="67" TopLine="49"/>
<Caret Line="330" Column="32" TopLine="320"/>
</Position16>
<Position17>
<Filename Value="uMainForm.pas"/>
<Caret Line="180" Column="40" TopLine="166"/>
<Caret Line="67" TopLine="49"/>
</Position17>
<Position18>
<Filename Value="uMainForm.pas"/>
<Caret Line="335" Column="59" TopLine="309"/>
<Caret Line="328" Column="59" TopLine="313"/>
</Position18>
<Position19>
<Filename Value="uMainForm.pas"/>
<Caret Line="333" Column="40" TopLine="309"/>
<Caret Line="335" Column="59" TopLine="315"/>
</Position19>
<Position20>
<Filename Value="uMainForm.pas"/>
<Caret Line="332" TopLine="309"/>
<Caret Line="152" Column="58" TopLine="128"/>
</Position20>
<Position21>
<Filename Value="uMainForm.pas"/>
<Caret Line="339" TopLine="309"/>
<Filename Value="..\..\..\source\uCEFChromium.pas"/>
<Caret Line="507" Column="42" TopLine="495"/>
</Position21>
<Position22>
<Filename Value="uMainForm.pas"/>
<Caret Line="188" Column="99" TopLine="177"/>
<Filename Value="..\..\..\source\uCEFChromium.pas"/>
<Caret Line="582" Column="55" TopLine="568"/>
</Position22>
<Position23>
<Filename Value="uMainForm.pas"/>
<Caret Line="343" Column="19" TopLine="333"/>
<Filename Value="..\..\..\source\uCEFChromium.pas"/>
<Caret Line="507" Column="44" TopLine="495"/>
</Position23>
<Position24>
<Filename Value="uMainForm.pas"/>
<Caret Line="69" TopLine="52"/>
<Filename Value="..\..\..\source\uCEFChromium.pas"/>
<Caret Line="582" Column="29" TopLine="568"/>
</Position24>
<Position25>
<Filename Value="uMainForm.pas"/>
<Caret Line="336" TopLine="321"/>
<Filename Value="..\..\..\source\uCEFChromium.pas"/>
<Caret Line="2406" Column="3" TopLine="2395"/>
</Position25>
<Position26>
<Filename Value="uMainForm.pas"/>
<Caret Line="335" TopLine="320"/>
<Filename Value="..\..\..\source\uCEFChromium.pas"/>
<Caret Line="582" Column="45" TopLine="569"/>
</Position26>
<Position27>
<Filename Value="uMainForm.pas"/>
<Caret Line="330" Column="32" TopLine="320"/>
<Filename Value="..\..\..\source\uCEFChromium.pas"/>
<Caret Line="2415" Column="68" TopLine="2395"/>
</Position27>
<Position28>
<Filename Value="uMainForm.pas"/>
<Caret Line="67" TopLine="49"/>
<Filename Value="..\..\..\source\uCEFChromium.pas"/>
<Caret Line="507" Column="19" TopLine="497"/>
</Position28>
<Position29>
<Filename Value="uMainForm.pas"/>
<Caret Line="328" Column="59" TopLine="313"/>
<Filename Value="..\..\..\source\uCEFChromium.pas"/>
<Caret Line="3423" Column="60" TopLine="3410"/>
</Position29>
<Position30>
<Filename Value="uMainForm.pas"/>
<Caret Line="335" Column="59" TopLine="315"/>
<Filename Value="..\..\..\source\uCEFChromium.pas"/>
<Caret Line="582" Column="19" TopLine="564"/>
</Position30>
</JumpHistory>
<RunParams>

View File

@ -253,6 +253,8 @@ type
FOnHttpAuthCredentialsCleared : TNotifyEvent;
FOnAllConnectionsClosed : TNotifyEvent;
FOnExecuteTaskOnCefThread : TOnExecuteTaskOnCefThread;
FOnCookiesVisited : TOnCookiesVisited;
FOnCookieSet : TOnCookieSet;
{$IFNDEF FPC}
FOnBrowserCompMsg : TOnCompMsgEvent;
FOnWidgetCompMsg : TOnCompMsgEvent;
@ -502,6 +504,8 @@ type
procedure doHttpAuthCredentialsCleared; virtual;
procedure doAllConnectionsClosed; virtual;
procedure doOnExecuteTaskOnCefThread(aTaskID : cardinal); virtual;
procedure doOnCookiesVisited(const name_, value, domain, path: ustring; secure, httponly, hasExpires: Boolean; const creation, lastAccess, expires: TDateTime; count, total, aID : Integer; var aDeleteCookie, aResult : Boolean); virtual;
procedure doOnCookieSet(aSuccess : boolean; aID : integer); virtual;
function MustCreateLoadHandler : boolean; virtual;
function MustCreateFocusHandler : boolean; virtual;
function MustCreateContextMenuHandler : boolean; virtual;
@ -549,8 +553,6 @@ type
procedure DownloadImage(const imageUrl: ustring; isFavicon: Boolean; maxImageSize: cardinal; bypassCache: Boolean);
procedure SimulateMouseWheel(aDeltaX, aDeltaY : integer);
function DeleteCookies(const url : ustring = ''; const cookieName : ustring = '') : boolean;
function FlushCookieStore(aFlushImmediately : boolean = True) : boolean;
function ClearCertificateExceptions(aClearImmediately : boolean = True) : boolean;
function ClearHttpAuthCredentials(aClearImmediately : boolean = True) : boolean;
function CloseAllConnections(aCloseImmediately : boolean = True) : boolean;
@ -574,6 +576,12 @@ type
function IsSameBrowser(const aBrowser : ICefBrowser) : boolean;
function ExecuteTaskOnCefThread(aCefThreadId : TCefThreadId; aTaskID : cardinal; aDelayMs : Int64 = 0) : boolean;
function DeleteCookies(const url : ustring = ''; const cookieName : ustring = '') : boolean;
function VisitAllCookies(aID : integer = 0) : boolean;
function VisitURLCookies(const url : ustring; includeHttpOnly : boolean = False; aID : integer = 0) : boolean;
function SetCookie(const url, name_, value, domain, path: ustring; secure, httponly, hasExpires: Boolean; const creation, lastAccess, expires: TDateTime; aSetImmediately : boolean = True; aID : integer = 0): Boolean;
function FlushCookieStore(aFlushImmediately : boolean = True) : boolean;
procedure ShowDevTools(inspectElementAt: TPoint; const aDevTools : TWinControl);
procedure CloseDevTools(const aDevTools : TWinControl = nil);
@ -719,6 +727,8 @@ type
property OnHttpAuthCredentialsCleared : TNotifyEvent read FOnHttpAuthCredentialsCleared write FOnHttpAuthCredentialsCleared;
property OnAllConnectionsClosed : TNotifyEvent read FOnAllConnectionsClosed write FOnAllConnectionsClosed;
property OnExecuteTaskOnCefThread : TOnExecuteTaskOnCefThread read FOnExecuteTaskOnCefThread write FOnExecuteTaskOnCefThread;
property OnCookiesVisited : TOnCookiesVisited read FOnCookiesVisited write FOnCookiesVisited;
property OnCookieSet : TOnCookieSet read FOnCookieSet write FOnCookieSet;
{$IFNDEF FPC}
property OnBrowserCompMsg : TOnCompMsgEvent read FOnBrowserCompMsg write FOnBrowserCompMsg;
property OnWidgetCompMsg : TOnCompMsgEvent read FOnWidgetCompMsg write FOnWidgetCompMsg;
@ -877,7 +887,7 @@ uses
uCEFApplication, uCEFProcessMessage, uCEFRequestContext, {$IFNDEF FPC}uCEFOLEDragAndDrop,{$ENDIF}
uCEFPDFPrintCallback, uCEFResolveCallback, uCEFDeleteCookiesCallback, uCEFStringVisitor,
uCEFListValue, uCEFNavigationEntryVisitor, uCEFDownloadImageCallBack, uCEFCookieManager,
uCEFRequestContextHandler;
uCEFRequestContextHandler, uCEFCookieVisitor, uCEFSetCookieCallback;
constructor TChromium.Create(AOwner: TComponent);
begin
@ -1252,6 +1262,8 @@ begin
FOnHttpAuthCredentialsCleared := nil;
FOnAllConnectionsClosed := nil;
FOnExecuteTaskOnCefThread := nil;
FOnCookiesVisited := nil;
FOnCookieSet := nil;
{$IFNDEF FPC}
FOnBrowserCompMsg := nil;
FOnWidgetCompMsg := nil;
@ -2340,6 +2352,89 @@ begin
end;
end;
// TChromium.VisitAllCookies triggers the TChromium.OnCookiesVisited event for each cookie
// aID is an optional parameter to identify which VisitAllCookies call has triggered the
// OnCookiesVisited event.
function TChromium.VisitAllCookies(aID : integer) : boolean;
var
TempManager : ICefCookieManager;
TempVisitor : ICefCookieVisitor;
begin
Result := False;
if Initialized and (FBrowser.Host <> nil) and (FBrowser.Host.RequestContext <> nil) then
begin
TempManager := FBrowser.Host.RequestContext.GetCookieManager(nil);
if (TempManager <> nil) then
try
TempVisitor := TCefCustomCookieVisitor.Create(self, aID);
Result := TempManager.VisitAllCookies(TempVisitor);
finally
TempVisitor := nil;
end;
end;
end;
// TChromium.VisitURLCookies triggers the TChromium.OnCookiesVisited event for each cookie
// aID is an optional parameter to identify which VisitAllCookies call has triggered the
// OnCookiesVisited event.
function TChromium.VisitURLCookies(const url : ustring; includeHttpOnly : boolean; aID : integer) : boolean;
var
TempManager : ICefCookieManager;
TempVisitor : ICefCookieVisitor;
begin
Result := False;
if Initialized and (FBrowser.Host <> nil) and (FBrowser.Host.RequestContext <> nil) then
begin
TempManager := FBrowser.Host.RequestContext.GetCookieManager(nil);
if (TempManager <> nil) then
try
TempVisitor := TCefCustomCookieVisitor.Create(self, aID);
Result := TempManager.VisitUrlCookies(url, includeHttpOnly, TempVisitor);
finally
TempVisitor := nil;
end;
end;
end;
// TChromium.SetCookie triggers the TChromium.OnCookieSet event when the cookie has been set
// aID is an optional parameter to identify which SetCookie call has triggered the
// OnCookieSet event.
function TChromium.SetCookie(const url, name_, value, domain, path: ustring;
secure, httponly, hasExpires: Boolean;
const creation, lastAccess, expires: TDateTime;
aSetImmediately : boolean;
aID : integer): Boolean;
var
TempManager : ICefCookieManager;
TempCallback : ICefSetCookieCallback;
begin
Result := False;
if Initialized and (FBrowser.Host <> nil) and (FBrowser.Host.RequestContext <> nil) then
begin
TempManager := FBrowser.Host.RequestContext.GetCookieManager(nil);
if (TempManager <> nil) then
try
if aSetImmediately then
TempCallback := nil
else
TempCallback := TCefCustomSetCookieCallback.Create(self, aID);
Result := TempManager.SetCookie(url, name_, value, domain, path,
secure, httponly, hasExpires,
creation, lastAccess, expires,
TempCallback);
finally
TempCallback := nil;
end;
end;
end;
// If aFlushImmediately is false then OnCookiesFlushed is triggered when the cookies are flushed
function TChromium.FlushCookieStore(aFlushImmediately : boolean) : boolean;
var
@ -3323,6 +3418,25 @@ begin
if assigned(FOnExecuteTaskOnCefThread) then FOnExecuteTaskOnCefThread(self, aTaskID);
end;
procedure TChromium.doOnCookiesVisited(const name_, value, domain, path: ustring;
secure, httponly, hasExpires: Boolean;
const creation, lastAccess, expires: TDateTime;
count, total, aID : Integer;
var aDeleteCookie, aResult : Boolean);
begin
if assigned(FOnCookiesVisited) then
FOnCookiesVisited(self, name_, value, domain, path,
secure, httponly, hasExpires,
creation, lastAccess, expires,
count, total, aID,
aDeleteCookie, aResult);
end;
procedure TChromium.doOnCookieSet(aSuccess : boolean; aID : integer);
begin
if assigned(FOnCookieSet) then FOnCookieSet(self, aSuccess, aID);
end;
function TChromium.MustCreateLoadHandler : boolean;
begin
Result := assigned(FOnLoadStart) or

View File

@ -174,6 +174,8 @@ type
TOnNavigationVisitorResultAvailableEvent = procedure(const entry: ICefNavigationEntry; current: Boolean; index, total: Integer; var aResult : boolean) of object;
TOnDownloadImageFinishedEvent = procedure(Sender: TObject; const imageUrl: ustring; httpStatusCode: Integer; const image: ICefImage) of object;
TOnExecuteTaskOnCefThread = procedure(Sender: TObject; aTaskID : cardinal) of object;
TOnCookiesVisited = procedure(Sender: TObject; const name_, value, domain, path: ustring; secure, httponly, hasExpires: Boolean; const creation, lastAccess, expires: TDateTime; count, total, aID : Integer; var aDeleteCookie, aResult : Boolean) of object;
TOnCookieSet = procedure(Sender: TObject; aSuccess : boolean; aID : integer) of object;
{$IFDEF MSWINDOWS}
TOnCompMsgEvent = procedure(var aMessage: TMessage; var aHandled: Boolean) of object;
{$ENDIF}

View File

@ -536,13 +536,6 @@ const
CEF_PROXYTYPE_FIXED_SERVERS = 3;
CEF_PROXYTYPE_PAC_SCRIPT = 4;
CEF_CONTENT_SETTING_DEFAULT = 0;
CEF_CONTENT_SETTING_ALLOW = 1;
CEF_CONTENT_SETTING_BLOCK = 2;
CEF_CONTENT_SETTING_ASK = 3;
CEF_CONTENT_SETTING_SESSION_ONLY = 4;
CEF_CONTENT_SETTING_NUM_SETTINGS = 5;
// Used in the severity parameter in the 'cef_log' function, also known as 'CefLog' in CEF4Delphi.
CEF_LOG_SEVERITY_INFO = 0;
CEF_LOG_SEVERITY_WARNING = 1;

View File

@ -65,7 +65,7 @@ type
function VisitAllCookiesProc(const visitor: TCefCookieVisitorProc): Boolean;
function VisitUrlCookies(const url: ustring; includeHttpOnly: Boolean; const visitor: ICefCookieVisitor): Boolean;
function VisitUrlCookiesProc(const url: ustring; includeHttpOnly: Boolean; const visitor: TCefCookieVisitorProc): Boolean;
function SetCookie(const url: ustring; const name, value, domain, path: ustring; secure, httponly, hasExpires: Boolean; const creation, lastAccess, expires: TDateTime; const callback: ICefSetCookieCallback): Boolean;
function SetCookie(const url, name, value, domain, path: ustring; secure, httponly, hasExpires: Boolean; const creation, lastAccess, expires: TDateTime; const callback: ICefSetCookieCallback): Boolean;
function SetCookieProc(const url: ustring; const name, value, domain, path: ustring; secure, httponly, hasExpires: Boolean; const creation, lastAccess, expires: TDateTime; const callback: TCefSetCookieCallbackProc): Boolean;
function DeleteCookies(const url, cookieName: ustring; const callback: ICefDeleteCookiesCallback): Boolean;
function DeleteCookiesProc(const url, cookieName: ustring; const callback: TCefDeleteCookiesCallbackProc): Boolean;

View File

@ -70,9 +70,26 @@ type
constructor Create(const visitor: TCefCookieVisitorProc); reintroduce;
end;
TCefCustomCookieVisitor = class(TCefCookieVisitorOwn)
protected
FEvents : Pointer;
FID : integer;
function visit(const name, value, domain, path: ustring; secure, httponly, hasExpires: Boolean; const creation, lastAccess, expires: TDateTime; count, total: Integer; out deleteCookie: Boolean): Boolean; override;
public
constructor Create(const aEvents : IChromiumEvents; aID : integer); reintroduce;
destructor Destroy; override;
end;
implementation
uses
{$IFDEF DELPHI16_UP}
System.SysUtils,
{$ELSE}
SysUtils,
{$ENDIF}
uCEFMiscFunctions, uCEFLibFunctions;
function cef_cookie_visitor_visit(self: PCefCookieVisitor;
@ -148,4 +165,47 @@ begin
creation, lastAccess, expires, count, total, deleteCookie);
end;
// TCefCustomCookieVisitor
constructor TCefCustomCookieVisitor.Create(const aEvents : IChromiumEvents; aID : integer);
begin
inherited Create;
FEvents := Pointer(aEvents);
FID := aID;
end;
destructor TCefCustomCookieVisitor.Destroy;
begin
FEvents := nil;
inherited Destroy;
end;
function TCefCustomCookieVisitor.visit(const name, value, domain, path: ustring;
secure, httponly, hasExpires: Boolean;
const creation, lastAccess, expires: TDateTime;
count, total: Integer;
out deleteCookie: Boolean): Boolean;
var
TempDelete : boolean;
begin
Result := True;
TempDelete := False;
try
try
if (FEvents <> nil) then
IChromiumEvents(FEvents).doOnCookiesVisited(name, value, domain, path, secure, httponly, hasExpires,
creation, lastAccess, expires, count, total, FID, TempDelete, Result);
except
on e : exception do
if CustomExceptionHandler('TCefCustomCookieVisitor.visit', e) then raise;
end;
finally
deleteCookie := TempDelete;
end;
end;
end.

View File

@ -236,6 +236,8 @@ type
FOnHttpAuthCredentialsCleared : TNotifyEvent;
FOnAllConnectionsClosed : TNotifyEvent;
FOnExecuteTaskOnCefThread : TOnExecuteTaskOnCefThread;
FOnCookiesVisited : TOnCookiesVisited;
FOnCookieSet : TOnCookieSet;
{$IFDEF MSWINDOWS}
FOnBrowserCompMsg : TOnCompMsgEvent;
FOnWidgetCompMsg : TOnCompMsgEvent;
@ -469,6 +471,8 @@ type
procedure doHttpAuthCredentialsCleared; virtual;
procedure doAllConnectionsClosed; virtual;
procedure doOnExecuteTaskOnCefThread(aTaskID : cardinal); virtual;
procedure doOnCookiesVisited(const name_, value, domain, path: ustring; secure, httponly, hasExpires: Boolean; const creation, lastAccess, expires: TDateTime; count, total, aID : Integer; var aDeleteCookie, aResult : Boolean); virtual;
procedure doOnCookieSet(aSuccess : boolean; aID : integer); virtual;
function MustCreateLoadHandler : boolean; virtual;
function MustCreateFocusHandler : boolean; virtual;
function MustCreateContextMenuHandler : boolean; virtual;
@ -516,8 +520,6 @@ type
procedure DownloadImage(const imageUrl: ustring; isFavicon: Boolean; maxImageSize: cardinal; bypassCache: Boolean);
procedure SimulateMouseWheel(aDeltaX, aDeltaY : integer);
function DeleteCookies(const url : ustring = ''; const cookieName : ustring = '') : boolean;
function FlushCookieStore(aFlushImmediately : boolean = True) : boolean;
function ClearCertificateExceptions(aClearImmediately : boolean = True) : boolean;
function ClearHttpAuthCredentials(aClearImmediately : boolean = True) : boolean;
function CloseAllConnections(aCloseImmediately : boolean = True) : boolean;
@ -539,6 +541,12 @@ type
function IsSameBrowser(const aBrowser : ICefBrowser) : boolean;
function ExecuteTaskOnCefThread(aCefThreadId : TCefThreadId; aTaskID : cardinal; aDelayMs : Int64 = 0) : boolean;
function DeleteCookies(const url : ustring = ''; const cookieName : ustring = '') : boolean;
function VisitAllCookies(aID : integer = 0) : boolean;
function VisitURLCookies(const url : ustring; includeHttpOnly : boolean = False; aID : integer = 0) : boolean;
function SetCookie(const url: ustring; const name, value, domain, path: ustring; secure, httponly, hasExpires: Boolean; const creation, lastAccess, expires: TDateTime; aSetImmediately : boolean = True; aID : integer = 0): Boolean;
function FlushCookieStore(aFlushImmediately : boolean = True) : boolean;
procedure ShowDevTools(inspectElementAt: TPoint);
procedure CloseDevTools;
@ -678,6 +686,8 @@ type
property OnHttpAuthCredentialsCleared : TNotifyEvent read FOnHttpAuthCredentialsCleared write FOnHttpAuthCredentialsCleared;
property OnAllConnectionsClosed : TNotifyEvent read FOnAllConnectionsClosed write FOnAllConnectionsClosed;
property OnExecuteTaskOnCefThread : TOnExecuteTaskOnCefThread read FOnExecuteTaskOnCefThread write FOnExecuteTaskOnCefThread;
property OnCookiesVisited : TOnCookiesVisited read FOnCookiesVisited write FOnCookiesVisited;
property OnCookieSet : TOnCookieSet read FOnCookieSet write FOnCookieSet;
{$IFDEF MSWINDOWS}
property OnBrowserCompMsg : TOnCompMsgEvent read FOnBrowserCompMsg write FOnBrowserCompMsg;
property OnWidgetCompMsg : TOnCompMsgEvent read FOnWidgetCompMsg write FOnWidgetCompMsg;
@ -826,7 +836,7 @@ uses
uCEFApplication, uCEFProcessMessage, uCEFRequestContext, uCEFCookieManager,
uCEFPDFPrintCallback, uCEFResolveCallback, uCEFDeleteCookiesCallback, uCEFStringVisitor,
uCEFListValue, uCEFNavigationEntryVisitor, uCEFDownloadImageCallBack,
uCEFRequestContextHandler;
uCEFRequestContextHandler, uCEFCookieVisitor, uCEFSetCookieCallback;
constructor TFMXChromium.Create(AOwner: TComponent);
begin
@ -1155,6 +1165,8 @@ begin
FOnHttpAuthCredentialsCleared := nil;
FOnAllConnectionsClosed := nil;
FOnExecuteTaskOnCefThread := nil;
FOnCookiesVisited := nil;
FOnCookieSet := nil;
end;
function TFMXChromium.CreateBrowser(const aWindowName : ustring;
@ -2139,6 +2151,89 @@ begin
end;
end;
// TFMXChromium.VisitAllCookies triggers the TFMXChromium.OnCookiesVisited event for each cookie
// aID is an optional parameter to identify which VisitAllCookies call has triggered the
// OnCookiesVisited event.
function TFMXChromium.VisitAllCookies(aID : integer) : boolean;
var
TempManager : ICefCookieManager;
TempVisitor : ICefCookieVisitor;
begin
Result := False;
if Initialized and (FBrowser.Host <> nil) and (FBrowser.Host.RequestContext <> nil) then
begin
TempManager := FBrowser.Host.RequestContext.GetCookieManager(nil);
if (TempManager <> nil) then
try
TempVisitor := TCefCustomCookieVisitor.Create(self, aID);
Result := TempManager.VisitAllCookies(TempVisitor);
finally
TempVisitor := nil;
end;
end;
end;
// TFMXChromium.VisitURLCookies triggers the TFMXChromium.OnCookiesVisited event for each cookie
// aID is an optional parameter to identify which VisitAllCookies call has triggered the
// OnCookiesVisited event.
function TFMXChromium.VisitURLCookies(const url : ustring; includeHttpOnly : boolean; aID : integer) : boolean;
var
TempManager : ICefCookieManager;
TempVisitor : ICefCookieVisitor;
begin
Result := False;
if Initialized and (FBrowser.Host <> nil) and (FBrowser.Host.RequestContext <> nil) then
begin
TempManager := FBrowser.Host.RequestContext.GetCookieManager(nil);
if (TempManager <> nil) then
try
TempVisitor := TCefCustomCookieVisitor.Create(self, aID);
Result := TempManager.VisitUrlCookies(url, includeHttpOnly, TempVisitor);
finally
TempVisitor := nil;
end;
end;
end;
// TFMXChromium.SetCookie triggers the TFMXChromium.OnCookieSet event when the cookie has been set
// aID is an optional parameter to identify which SetCookie call has triggered the
// OnCookieSet event.
function TFMXChromium.SetCookie(const url, name, value, domain, path: ustring;
secure, httponly, hasExpires: Boolean;
const creation, lastAccess, expires: TDateTime;
aSetImmediately : boolean;
aID : integer): Boolean;
var
TempManager : ICefCookieManager;
TempCallback : ICefSetCookieCallback;
begin
Result := False;
if Initialized and (FBrowser.Host <> nil) and (FBrowser.Host.RequestContext <> nil) then
begin
TempManager := FBrowser.Host.RequestContext.GetCookieManager(nil);
if (TempManager <> nil) then
try
if aSetImmediately then
TempCallback := nil
else
TempCallback := TCefCustomSetCookieCallback.Create(self, aID);
Result := TempManager.SetCookie(url, name, value, domain, path,
secure, httponly, hasExpires,
creation, lastAccess, expires,
TempCallback);
finally
TempCallback := nil;
end;
end;
end;
// If aFlushImmediately is false then OnCookiesFlushed is triggered when the cookies are flushed
function TFMXChromium.FlushCookieStore(aFlushImmediately : boolean) : boolean;
var
@ -3065,6 +3160,25 @@ begin
if assigned(FOnExecuteTaskOnCefThread) then FOnExecuteTaskOnCefThread(self, aTaskID);
end;
procedure TFMXChromium.doOnCookiesVisited(const name_, value, domain, path: ustring;
secure, httponly, hasExpires: Boolean;
const creation, lastAccess, expires: TDateTime;
count, total, aID : Integer;
var aDeleteCookie, aResult : Boolean);
begin
if assigned(FOnCookiesVisited) then
FOnCookiesVisited(self, name, value, domain, path,
secure, httponly, hasExpires,
creation, lastAccess, expires,
count, total, aID,
aDeleteCookie, aResult);
end;
procedure TFMXChromium.doOnCookieSet(aSuccess : boolean; aID : integer);
begin
if assigned(FOnCookieSet) then FOnCookieSet(self, aSuccess, aID);
end;
function TFMXChromium.MustCreateLoadHandler : boolean;
begin
Result := assigned(FOnLoadStart) or

View File

@ -394,6 +394,8 @@ type
procedure doHttpAuthCredentialsCleared;
procedure doAllConnectionsClosed;
procedure doOnExecuteTaskOnCefThread(aTaskID : cardinal);
procedure doOnCookiesVisited(const name_, value, domain, path: ustring; secure, httponly, hasExpires: Boolean; const creation, lastAccess, expires: TDateTime; count, total, aID : Integer; var aDeleteCookie, aResult : Boolean);
procedure doOnCookieSet(aSuccess : boolean; aID : integer);
function MustCreateLoadHandler : boolean;
function MustCreateFocusHandler : boolean;
function MustCreateContextMenuHandler : boolean;
@ -1299,7 +1301,7 @@ type
function VisitAllCookiesProc(const visitor: TCefCookieVisitorProc): Boolean;
function VisitUrlCookies(const url: ustring; includeHttpOnly: Boolean; const visitor: ICefCookieVisitor): Boolean;
function VisitUrlCookiesProc(const url: ustring; includeHttpOnly: Boolean; const visitor: TCefCookieVisitorProc): Boolean;
function SetCookie(const url: ustring; const name, value, domain, path: ustring; secure, httponly, hasExpires: Boolean; const creation, lastAccess, expires: TDateTime; const callback: ICefSetCookieCallback): Boolean;
function SetCookie(const url, name, value, domain, path: ustring; secure, httponly, hasExpires: Boolean; const creation, lastAccess, expires: TDateTime; const callback: ICefSetCookieCallback): Boolean;
function SetCookieProc(const url: ustring; const name, value, domain, path: ustring; secure, httponly, hasExpires: Boolean; const creation, lastAccess, expires: TDateTime; const callback: TCefSetCookieCallbackProc): Boolean;
function DeleteCookies(const url, cookieName: ustring; const callback: ICefDeleteCookiesCallback): Boolean;
function DeleteCookiesProc(const url, cookieName: ustring; const callback: TCefDeleteCookiesCallbackProc): Boolean;

View File

@ -70,9 +70,26 @@ type
constructor Create(const callback: TCefSetCookieCallbackProc); reintroduce;
end;
TCefCustomSetCookieCallback = class(TCefSetCookieCallbackOwn)
protected
FEvents : Pointer;
FID : integer;
procedure OnComplete(success: Boolean); override;
public
constructor Create(const aEvents : IChromiumEvents; aID : integer); reintroduce;
destructor Destroy; override;
end;
implementation
uses
{$IFDEF DELPHI16_UP}
System.SysUtils,
{$ELSE}
SysUtils,
{$ENDIF}
uCEFMiscFunctions, uCEFLibFunctions;
procedure cef_set_cookie_callback_on_complete(self : PCefSetCookieCallback;
@ -108,4 +125,37 @@ begin
FCallback(success);
end;
// TCefCustomSetCookieCallback
constructor TCefCustomSetCookieCallback.Create(const aEvents : IChromiumEvents; aID : integer);
begin
inherited Create;
FEvents := Pointer(aEvents);
FID := aID;
end;
destructor TCefCustomSetCookieCallback.Destroy;
begin
FEvents := nil;
inherited Destroy;
end;
procedure TCefCustomSetCookieCallback.OnComplete(success: Boolean);
begin
try
try
if (FEvents <> nil) then IChromiumEvents(FEvents).doOnCookieSet(success, FID);
except
on e : exception do
if CustomExceptionHandler('TCefCustomSetCookieCallback.OnComplete', e) then raise;
end;
finally
FEvents := nil;
end;
end;
end.

View File

@ -2,7 +2,7 @@
"UpdateLazPackages" : [
{
"ForceNotify" : true,
"InternalVersion" : 50,
"InternalVersion" : 51,
"Name" : "cef4delphi_lazarus.lpk",
"Version" : "77.1.18.0"
}