2017-01-27 17:29:37 +01:00
|
|
|
|
// ************************************************************************
|
|
|
|
|
// ***************************** CEF4Delphi *******************************
|
|
|
|
|
// ************************************************************************
|
|
|
|
|
//
|
2019-10-19 10:58:34 +02:00
|
|
|
|
// CEF4Delphi is based on DCEF3 which uses CEF to embed a chromium-based
|
2017-01-27 17:29:37 +01:00
|
|
|
|
// browser in Delphi applications.
|
|
|
|
|
//
|
|
|
|
|
// The original license of DCEF3 still applies to CEF4Delphi.
|
|
|
|
|
//
|
|
|
|
|
// For more information about CEF4Delphi visit :
|
|
|
|
|
// https://www.briskbard.com/index.php?lang=en&pageid=cef
|
|
|
|
|
//
|
2021-01-01 11:11:30 +01:00
|
|
|
|
// Copyright <20> 2021 Salvador Diaz Fau. All rights reserved.
|
2017-01-27 17:29:37 +01:00
|
|
|
|
//
|
|
|
|
|
// ************************************************************************
|
|
|
|
|
// ************ vvvv Original license and comments below vvvv *************
|
|
|
|
|
// ************************************************************************
|
|
|
|
|
(*
|
|
|
|
|
* Delphi Chromium Embedded 3
|
|
|
|
|
*
|
|
|
|
|
* Usage allowed under the restrictions of the Lesser GNU General Public License
|
|
|
|
|
* or alternatively the restrictions of the Mozilla Public License 1.1
|
|
|
|
|
*
|
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
|
|
|
|
|
* the specific language governing rights and limitations under the License.
|
|
|
|
|
*
|
|
|
|
|
* Unit owner : Henri Gourvest <hgourvest@gmail.com>
|
|
|
|
|
* Web site : http://www.progdigy.com
|
|
|
|
|
* Repository : http://code.google.com/p/delphichromiumembedded/
|
|
|
|
|
* Group : http://groups.google.com/group/delphichromiumembedded
|
|
|
|
|
*
|
|
|
|
|
* Embarcadero Technologies, Inc is not permitted to use or redistribute
|
|
|
|
|
* this source code without explicit permission.
|
|
|
|
|
*
|
|
|
|
|
*)
|
|
|
|
|
|
|
|
|
|
unit uCEFCookieManager;
|
|
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
|
{$IFDEF FPC}
|
|
|
|
|
{$MODE OBJFPC}{$H+}
|
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
2018-11-22 15:02:21 +01:00
|
|
|
|
{$IFNDEF CPUX64}{$ALIGN ON}{$ENDIF}
|
|
|
|
|
{$MINENUMSIZE 4}
|
2017-01-27 17:29:37 +01:00
|
|
|
|
|
2017-02-05 20:56:46 +01:00
|
|
|
|
{$I cef.inc}
|
|
|
|
|
|
2017-01-27 17:29:37 +01:00
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
uses
|
2017-02-05 20:56:46 +01:00
|
|
|
|
{$IFDEF DELPHI16_UP}
|
2018-02-26 18:40:51 +01:00
|
|
|
|
System.Classes, System.SysUtils,
|
2017-02-05 20:56:46 +01:00
|
|
|
|
{$ELSE}
|
2018-02-26 18:40:51 +01:00
|
|
|
|
Classes, SysUtils,
|
2017-02-05 20:56:46 +01:00
|
|
|
|
{$ENDIF}
|
2019-09-16 11:28:48 +02:00
|
|
|
|
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes, uCEFCompletionCallback;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
|
|
|
|
|
type
|
2017-03-16 19:09:42 +01:00
|
|
|
|
TCefCookieManagerRef = class(TCefBaseRefCountedRef, ICefCookieManager)
|
2017-01-27 17:29:37 +01:00
|
|
|
|
protected
|
2018-02-27 10:23:45 +01:00
|
|
|
|
function VisitAllCookies(const visitor: ICefCookieVisitor): Boolean;
|
|
|
|
|
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;
|
2020-05-23 15:00:44 +02:00
|
|
|
|
function SetCookie(const url, name, value, domain, path: ustring; secure, httponly, hasExpires: Boolean; const creation, lastAccess, expires: TDateTime; same_site : TCefCookieSameSite; priority : TCefCookiePriority; const callback: ICefSetCookieCallback): Boolean;
|
|
|
|
|
function SetCookieProc(const url: ustring; const name, value, domain, path: ustring; secure, httponly, hasExpires: Boolean; const creation, lastAccess, expires: TDateTime; same_site : TCefCookieSameSite; priority : TCefCookiePriority; const callback: TCefSetCookieCallbackProc): Boolean;
|
2018-02-27 10:23:45 +01:00
|
|
|
|
function DeleteCookies(const url, cookieName: ustring; const callback: ICefDeleteCookiesCallback): Boolean;
|
|
|
|
|
function DeleteCookiesProc(const url, cookieName: ustring; const callback: TCefDeleteCookiesCallbackProc): Boolean;
|
2019-11-20 10:45:46 +01:00
|
|
|
|
function FlushStore(const callback: ICefCompletionCallback): Boolean;
|
2018-02-27 10:23:45 +01:00
|
|
|
|
function FlushStoreProc(const proc: TCefCompletionCallbackProc): Boolean;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
|
|
|
|
|
public
|
|
|
|
|
class function UnWrap(data: Pointer): ICefCookieManager;
|
|
|
|
|
class function Global(const callback: ICefCompletionCallback): ICefCookieManager;
|
|
|
|
|
class function GlobalProc(const callback: TCefCompletionCallbackProc): ICefCookieManager;
|
|
|
|
|
end;
|
|
|
|
|
|
2019-09-16 11:28:48 +02:00
|
|
|
|
TCefFlushStoreCompletionCallback = class(TCefCustomCompletionCallback)
|
|
|
|
|
protected
|
|
|
|
|
procedure OnComplete; override;
|
|
|
|
|
end;
|
|
|
|
|
|
2017-01-27 17:29:37 +01:00
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
uses
|
2019-09-16 11:28:48 +02:00
|
|
|
|
uCEFMiscFunctions, uCEFLibFunctions, uCEFDeleteCookiesCallback,
|
2018-03-29 20:02:04 +02:00
|
|
|
|
uCEFSetCookieCallback, uCEFCookieVisitor, uCEFStringList;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
|
|
|
|
|
|
2018-02-27 10:23:45 +01:00
|
|
|
|
function TCefCookieManagerRef.DeleteCookies(const url : ustring;
|
|
|
|
|
const cookieName : ustring;
|
|
|
|
|
const callback : ICefDeleteCookiesCallback): Boolean;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
var
|
2018-05-12 14:50:54 +02:00
|
|
|
|
TempURL, TempName : TCefString;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
|
TempURL := CefString(url);
|
|
|
|
|
TempName := CefString(cookieName);
|
|
|
|
|
Result := PCefCookieManager(FData)^.delete_cookies(PCefCookieManager(FData), @TempURL, @TempName, CefGetData(callback)) <> 0;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2018-02-27 10:23:45 +01:00
|
|
|
|
function TCefCookieManagerRef.DeleteCookiesProc(const url : ustring;
|
|
|
|
|
const cookieName : ustring;
|
|
|
|
|
const callback : TCefDeleteCookiesCallbackProc): Boolean;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
begin
|
|
|
|
|
Result := DeleteCookies(url, cookieName, TCefFastDeleteCookiesCallback.Create(callback));
|
|
|
|
|
end;
|
|
|
|
|
|
2019-11-20 10:45:46 +01:00
|
|
|
|
function TCefCookieManagerRef.FlushStore(const callback: ICefCompletionCallback): Boolean;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
begin
|
2019-11-20 10:45:46 +01:00
|
|
|
|
Result := PCefCookieManager(FData)^.flush_store(PCefCookieManager(FData), CefGetData(callback)) <> 0;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2018-02-27 10:23:45 +01:00
|
|
|
|
function TCefCookieManagerRef.FlushStoreProc(const proc: TCefCompletionCallbackProc): Boolean;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
begin
|
|
|
|
|
Result := FlushStore(TCefFastCompletionCallback.Create(proc))
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
class function TCefCookieManagerRef.Global(const callback: ICefCompletionCallback): ICefCookieManager;
|
|
|
|
|
begin
|
|
|
|
|
Result := UnWrap(cef_cookie_manager_get_global_manager(CefGetData(callback)));
|
|
|
|
|
end;
|
|
|
|
|
|
2018-02-27 10:23:45 +01:00
|
|
|
|
class function TCefCookieManagerRef.GlobalProc(const callback: TCefCompletionCallbackProc): ICefCookieManager;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
begin
|
|
|
|
|
Result := Global(TCefFastCompletionCallback.Create(callback));
|
|
|
|
|
end;
|
|
|
|
|
|
2018-02-27 10:23:45 +01:00
|
|
|
|
function TCefCookieManagerRef.SetCookie(const url, name, value, domain, path: ustring;
|
|
|
|
|
secure, httponly, hasExpires: Boolean;
|
|
|
|
|
const creation, lastAccess, expires: TDateTime;
|
2020-05-23 15:00:44 +02:00
|
|
|
|
same_site : TCefCookieSameSite;
|
|
|
|
|
priority : TCefCookiePriority;
|
2018-02-27 10:23:45 +01:00
|
|
|
|
const callback: ICefSetCookieCallback): Boolean;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
var
|
2019-11-20 10:45:46 +01:00
|
|
|
|
TempURL : TCefString;
|
|
|
|
|
TempCookie : TCefCookie;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
begin
|
2019-11-20 10:45:46 +01:00
|
|
|
|
TempURL := CefString(url);
|
|
|
|
|
TempCookie.name := CefString(name);
|
|
|
|
|
TempCookie.value := CefString(value);
|
|
|
|
|
TempCookie.domain := CefString(domain);
|
|
|
|
|
TempCookie.path := CefString(path);
|
|
|
|
|
TempCookie.secure := Ord(secure);
|
|
|
|
|
TempCookie.httponly := Ord(httponly);
|
|
|
|
|
TempCookie.creation := DateTimeToCefTime(creation);
|
|
|
|
|
TempCookie.last_access := DateTimeToCefTime(lastAccess);
|
|
|
|
|
TempCookie.has_expires := Ord(hasExpires);
|
2020-05-23 15:00:44 +02:00
|
|
|
|
TempCookie.same_site := same_site;
|
|
|
|
|
TempCookie.priority := priority;
|
2018-02-27 10:23:45 +01:00
|
|
|
|
|
2017-01-27 17:29:37 +01:00
|
|
|
|
if hasExpires then
|
2019-11-20 10:45:46 +01:00
|
|
|
|
TempCookie.expires := DateTimeToCefTime(expires)
|
2018-02-27 10:23:45 +01:00
|
|
|
|
else
|
2019-11-20 10:45:46 +01:00
|
|
|
|
FillChar(TempCookie.expires, SizeOf(TCefTime), 0);
|
2018-02-27 10:23:45 +01:00
|
|
|
|
|
2019-11-20 10:45:46 +01:00
|
|
|
|
Result := PCefCookieManager(FData)^.set_cookie(PCefCookieManager(FData), @TempURL, @TempCookie, CefGetData(callback)) <> 0;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2018-02-27 10:23:45 +01:00
|
|
|
|
function TCefCookieManagerRef.SetCookieProc(const url, name, value, domain, path: ustring;
|
|
|
|
|
secure, httponly, hasExpires: Boolean;
|
|
|
|
|
const creation, lastAccess, expires: TDateTime;
|
2020-05-23 15:00:44 +02:00
|
|
|
|
same_site : TCefCookieSameSite;
|
|
|
|
|
priority : TCefCookiePriority;
|
2018-02-27 10:23:45 +01:00
|
|
|
|
const callback: TCefSetCookieCallbackProc): Boolean;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
begin
|
2018-02-27 10:23:45 +01:00
|
|
|
|
Result := SetCookie(url, name, value, domain, path,
|
|
|
|
|
secure, httponly, hasExpires,
|
|
|
|
|
creation, lastAccess, expires,
|
2020-05-23 15:00:44 +02:00
|
|
|
|
same_site, priority,
|
2018-02-27 10:23:45 +01:00
|
|
|
|
TCefFastSetCookieCallback.Create(callback));
|
2017-01-27 17:29:37 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
class function TCefCookieManagerRef.UnWrap(data: Pointer): ICefCookieManager;
|
|
|
|
|
begin
|
2018-02-27 10:23:45 +01:00
|
|
|
|
if (data <> nil) then
|
|
|
|
|
Result := Create(data) as ICefCookieManager
|
|
|
|
|
else
|
2017-01-27 17:29:37 +01:00
|
|
|
|
Result := nil;
|
|
|
|
|
end;
|
|
|
|
|
|
2018-02-27 10:23:45 +01:00
|
|
|
|
function TCefCookieManagerRef.VisitAllCookies(const visitor: ICefCookieVisitor): Boolean;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
|
Result := PCefCookieManager(FData)^.visit_all_cookies(PCefCookieManager(FData), CefGetData(visitor)) <> 0;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2018-02-27 10:23:45 +01:00
|
|
|
|
function TCefCookieManagerRef.VisitAllCookiesProc(const visitor: TCefCookieVisitorProc): Boolean;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
begin
|
2018-02-27 10:23:45 +01:00
|
|
|
|
Result := VisitAllCookies(TCefFastCookieVisitor.Create(visitor) as ICefCookieVisitor);
|
2017-01-27 17:29:37 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2018-02-27 10:23:45 +01:00
|
|
|
|
function TCefCookieManagerRef.VisitUrlCookies(const url : ustring;
|
|
|
|
|
includeHttpOnly : Boolean;
|
|
|
|
|
const visitor : ICefCookieVisitor): Boolean;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
var
|
2018-05-12 14:50:54 +02:00
|
|
|
|
TempURL : TCefString;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
|
TempURL := CefString(url);
|
|
|
|
|
Result := PCefCookieManager(FData)^.visit_url_cookies(PCefCookieManager(FData), @TempURL, Ord(includeHttpOnly), CefGetData(visitor)) <> 0;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2018-02-27 10:23:45 +01:00
|
|
|
|
function TCefCookieManagerRef.VisitUrlCookiesProc(const url : ustring;
|
|
|
|
|
includeHttpOnly : Boolean;
|
|
|
|
|
const visitor : TCefCookieVisitorProc): Boolean;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
begin
|
2018-02-27 10:23:45 +01:00
|
|
|
|
Result := VisitUrlCookies(url, includeHttpOnly, TCefFastCookieVisitor.Create(visitor) as ICefCookieVisitor);
|
2017-01-27 17:29:37 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2019-09-16 11:28:48 +02:00
|
|
|
|
|
|
|
|
|
// TCefFlushStoreCompletionCallback
|
|
|
|
|
|
|
|
|
|
procedure TCefFlushStoreCompletionCallback.OnComplete;
|
|
|
|
|
begin
|
|
|
|
|
try
|
|
|
|
|
try
|
|
|
|
|
if (FEvents <> nil) then IChromiumEvents(FEvents).doOnCookiesStoreFlushed;
|
|
|
|
|
except
|
|
|
|
|
on e : exception do
|
|
|
|
|
if CustomExceptionHandler('TCefFlushStoreCompletionCallback.OnComplete', e) then raise;
|
|
|
|
|
end;
|
|
|
|
|
finally
|
|
|
|
|
FEvents := nil;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
2017-01-27 17:29:37 +01:00
|
|
|
|
end.
|