2017-01-27 18:29:37 +02:00
|
|
|
// ************************************************************************
|
|
|
|
// ***************************** CEF4Delphi *******************************
|
|
|
|
// ************************************************************************
|
|
|
|
//
|
|
|
|
// CEF4Delphi is based on DCEF3 which uses CEF3 to embed a chromium-based
|
|
|
|
// 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
|
|
|
|
//
|
2018-01-06 16:25:32 +02:00
|
|
|
// Copyright � 2018 Salvador D�az Fau. All rights reserved.
|
2017-01-27 18:29:37 +02: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;
|
|
|
|
|
|
|
|
{$IFNDEF CPUX64}
|
|
|
|
{$ALIGN ON}
|
|
|
|
{$MINENUMSIZE 4}
|
|
|
|
{$ENDIF}
|
|
|
|
|
2017-02-05 21:56:46 +02:00
|
|
|
{$I cef.inc}
|
|
|
|
|
2017-01-27 18:29:37 +02:00
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2017-02-05 21:56:46 +02:00
|
|
|
{$IFDEF DELPHI16_UP}
|
2018-02-26 19:40:51 +02:00
|
|
|
System.Classes, System.SysUtils,
|
2017-02-05 21:56:46 +02:00
|
|
|
{$ELSE}
|
2018-02-26 19:40:51 +02:00
|
|
|
Classes, SysUtils,
|
2017-02-05 21:56:46 +02:00
|
|
|
{$ENDIF}
|
2017-03-16 20:09:42 +02:00
|
|
|
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes;
|
2017-01-27 18:29:37 +02:00
|
|
|
|
|
|
|
type
|
2017-03-16 20:09:42 +02:00
|
|
|
TCefCookieManagerRef = class(TCefBaseRefCountedRef, ICefCookieManager)
|
2017-01-27 18:29:37 +02:00
|
|
|
protected
|
2018-02-26 19:40:51 +02:00
|
|
|
procedure SetSupportedSchemes(const schemes: TStrings; const callback: ICefCompletionCallback);
|
|
|
|
procedure SetSupportedSchemesProc(const schemes: TStrings; const callback: TCefCompletionCallbackProc);
|
2018-02-27 11:23:45 +02: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;
|
|
|
|
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 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;
|
|
|
|
function SetStoragePath(const path: ustring; persistSessionCookies: Boolean; const callback: ICefCompletionCallback): Boolean;
|
|
|
|
function SetStoragePathProc(const path: ustring; persistSessionCookies: Boolean; const callback: TCefCompletionCallbackProc): Boolean;
|
|
|
|
function FlushStore(const handler: ICefCompletionCallback): Boolean;
|
|
|
|
function FlushStoreProc(const proc: TCefCompletionCallbackProc): Boolean;
|
2017-01-27 18:29:37 +02:00
|
|
|
|
|
|
|
public
|
|
|
|
class function UnWrap(data: Pointer): ICefCookieManager;
|
|
|
|
class function Global(const callback: ICefCompletionCallback): ICefCookieManager;
|
|
|
|
class function GlobalProc(const callback: TCefCompletionCallbackProc): ICefCookieManager;
|
2018-03-17 12:12:03 +02:00
|
|
|
class function Blocking : ICefCookieManager;
|
2017-01-27 18:29:37 +02:00
|
|
|
class function New(const path: ustring; persistSessionCookies: Boolean; const callback: ICefCompletionCallback): ICefCookieManager;
|
|
|
|
class function NewProc(const path: ustring; persistSessionCookies: Boolean; const callback: TCefCompletionCallbackProc): ICefCookieManager;
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
|
|
|
uCEFMiscFunctions, uCEFLibFunctions, uCEFCompletionCallback, uCEFDeleteCookiesCallback,
|
2018-03-29 20:02:04 +02:00
|
|
|
uCEFSetCookieCallback, uCEFCookieVisitor, uCEFStringList;
|
2017-01-27 18:29:37 +02:00
|
|
|
|
2018-02-27 11:23:45 +02:00
|
|
|
class function TCefCookieManagerRef.New(const path : ustring;
|
|
|
|
persistSessionCookies : Boolean;
|
|
|
|
const callback : ICefCompletionCallback): ICefCookieManager;
|
2017-01-27 18:29:37 +02:00
|
|
|
var
|
|
|
|
pth: TCefString;
|
|
|
|
begin
|
|
|
|
pth := CefString(path);
|
|
|
|
Result := UnWrap(cef_cookie_manager_create_manager(@pth, Ord(persistSessionCookies), CefGetData(callback)));
|
|
|
|
end;
|
|
|
|
|
2018-02-27 11:23:45 +02:00
|
|
|
class function TCefCookieManagerRef.NewProc(const path : ustring;
|
|
|
|
persistSessionCookies : Boolean;
|
|
|
|
const callback : TCefCompletionCallbackProc): ICefCookieManager;
|
2017-01-27 18:29:37 +02:00
|
|
|
begin
|
|
|
|
Result := New(path, persistSessionCookies, TCefFastCompletionCallback.Create(callback));
|
|
|
|
end;
|
|
|
|
|
2018-02-27 11:23:45 +02:00
|
|
|
function TCefCookieManagerRef.DeleteCookies(const url : ustring;
|
|
|
|
const cookieName : ustring;
|
|
|
|
const callback : ICefDeleteCookiesCallback): Boolean;
|
2017-01-27 18:29:37 +02:00
|
|
|
var
|
|
|
|
u, n: TCefString;
|
|
|
|
begin
|
2018-02-27 11:23:45 +02:00
|
|
|
u := CefString(url);
|
|
|
|
n := CefString(cookieName);
|
|
|
|
Result := PCefCookieManager(FData).delete_cookies(PCefCookieManager(FData), @u, @n, CefGetData(callback)) <> 0;
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
|
2018-02-27 11:23:45 +02:00
|
|
|
function TCefCookieManagerRef.DeleteCookiesProc(const url : ustring;
|
|
|
|
const cookieName : ustring;
|
|
|
|
const callback : TCefDeleteCookiesCallbackProc): Boolean;
|
2017-01-27 18:29:37 +02:00
|
|
|
begin
|
|
|
|
Result := DeleteCookies(url, cookieName, TCefFastDeleteCookiesCallback.Create(callback));
|
|
|
|
end;
|
|
|
|
|
2018-02-27 11:23:45 +02:00
|
|
|
function TCefCookieManagerRef.FlushStore(const handler: ICefCompletionCallback): Boolean;
|
2017-01-27 18:29:37 +02:00
|
|
|
begin
|
2018-02-27 11:23:45 +02:00
|
|
|
Result := PCefCookieManager(FData).flush_store(PCefCookieManager(FData), CefGetData(handler)) <> 0;
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
|
2018-02-27 11:23:45 +02:00
|
|
|
function TCefCookieManagerRef.FlushStoreProc(const proc: TCefCompletionCallbackProc): Boolean;
|
2017-01-27 18:29:37 +02: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-03-17 12:12:03 +02:00
|
|
|
class function TCefCookieManagerRef.Blocking : ICefCookieManager;
|
|
|
|
begin
|
|
|
|
Result := UnWrap(cef_cookie_manager_get_blocking_manager);
|
|
|
|
end;
|
|
|
|
|
2018-02-27 11:23:45 +02:00
|
|
|
class function TCefCookieManagerRef.GlobalProc(const callback: TCefCompletionCallbackProc): ICefCookieManager;
|
2017-01-27 18:29:37 +02:00
|
|
|
begin
|
|
|
|
Result := Global(TCefFastCompletionCallback.Create(callback));
|
|
|
|
end;
|
|
|
|
|
2018-02-27 11:23:45 +02:00
|
|
|
function TCefCookieManagerRef.SetCookie(const url, name, value, domain, path: ustring;
|
|
|
|
secure, httponly, hasExpires: Boolean;
|
|
|
|
const creation, lastAccess, expires: TDateTime;
|
|
|
|
const callback: ICefSetCookieCallback): Boolean;
|
2017-01-27 18:29:37 +02:00
|
|
|
var
|
2018-02-27 11:23:45 +02:00
|
|
|
str : TCefString;
|
|
|
|
cook : TCefCookie;
|
2017-01-27 18:29:37 +02:00
|
|
|
begin
|
2018-02-27 11:23:45 +02:00
|
|
|
str := CefString(url);
|
|
|
|
cook.name := CefString(name);
|
|
|
|
cook.value := CefString(value);
|
|
|
|
cook.domain := CefString(domain);
|
|
|
|
cook.path := CefString(path);
|
|
|
|
cook.secure := Ord(secure);
|
|
|
|
cook.httponly := Ord(httponly);
|
|
|
|
cook.creation := DateTimeToCefTime(creation);
|
2017-01-27 18:29:37 +02:00
|
|
|
cook.last_access := DateTimeToCefTime(lastAccess);
|
|
|
|
cook.has_expires := Ord(hasExpires);
|
2018-02-27 11:23:45 +02:00
|
|
|
|
2017-01-27 18:29:37 +02:00
|
|
|
if hasExpires then
|
2018-02-27 11:23:45 +02:00
|
|
|
cook.expires := DateTimeToCefTime(expires)
|
|
|
|
else
|
2017-01-27 18:29:37 +02:00
|
|
|
FillChar(cook.expires, SizeOf(TCefTime), 0);
|
2018-02-27 11:23:45 +02:00
|
|
|
|
|
|
|
Result := PCefCookieManager(FData).set_cookie(PCefCookieManager(FData), @str, @cook, CefGetData(callback)) <> 0;
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
|
2018-02-27 11:23:45 +02:00
|
|
|
function TCefCookieManagerRef.SetCookieProc(const url, name, value, domain, path: ustring;
|
|
|
|
secure, httponly, hasExpires: Boolean;
|
|
|
|
const creation, lastAccess, expires: TDateTime;
|
|
|
|
const callback: TCefSetCookieCallbackProc): Boolean;
|
2017-01-27 18:29:37 +02:00
|
|
|
begin
|
2018-02-27 11:23:45 +02:00
|
|
|
Result := SetCookie(url, name, value, domain, path,
|
|
|
|
secure, httponly, hasExpires,
|
|
|
|
creation, lastAccess, expires,
|
|
|
|
TCefFastSetCookieCallback.Create(callback));
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
|
2018-02-27 11:23:45 +02:00
|
|
|
function TCefCookieManagerRef.SetStoragePath(const path : ustring;
|
|
|
|
persistSessionCookies : Boolean;
|
|
|
|
const callback : ICefCompletionCallback): Boolean;
|
2017-01-27 18:29:37 +02:00
|
|
|
var
|
|
|
|
p: TCefString;
|
|
|
|
begin
|
2018-02-27 11:23:45 +02:00
|
|
|
p := CefString(path);
|
|
|
|
Result := PCefCookieManager(FData)^.set_storage_path(PCefCookieManager(FData), @p, Ord(persistSessionCookies), CefGetData(callback)) <> 0;
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
|
2018-02-27 11:23:45 +02:00
|
|
|
function TCefCookieManagerRef.SetStoragePathProc(const path : ustring;
|
|
|
|
persistSessionCookies : Boolean;
|
|
|
|
const callback : TCefCompletionCallbackProc): Boolean;
|
2017-01-27 18:29:37 +02:00
|
|
|
begin
|
|
|
|
Result := SetStoragePath(path, persistSessionCookies, TCefFastCompletionCallback.Create(callback));
|
|
|
|
end;
|
|
|
|
|
2018-02-26 19:40:51 +02:00
|
|
|
procedure TCefCookieManagerRef.SetSupportedSchemes(const schemes: TStrings; const callback: ICefCompletionCallback);
|
2017-01-27 18:29:37 +02:00
|
|
|
var
|
2018-03-29 20:02:04 +02:00
|
|
|
TempSL : ICefStringList;
|
2017-01-27 18:29:37 +02:00
|
|
|
begin
|
2018-02-26 19:40:51 +02:00
|
|
|
try
|
2018-03-29 20:02:04 +02:00
|
|
|
TempSL := TCefStringListOwn.Create;
|
|
|
|
TempSL.AddStrings(schemes);
|
|
|
|
|
|
|
|
PCefCookieManager(FData).set_supported_schemes(PCefCookieManager(FData),
|
|
|
|
TempSL.Handle,
|
|
|
|
CefGetData(callback));
|
2017-01-27 18:29:37 +02:00
|
|
|
finally
|
2018-03-29 20:02:04 +02:00
|
|
|
TempSL := nil;
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2018-02-26 19:40:51 +02:00
|
|
|
procedure TCefCookieManagerRef.SetSupportedSchemesProc(const schemes: TStrings; const callback: TCefCompletionCallbackProc);
|
2017-01-27 18:29:37 +02:00
|
|
|
begin
|
|
|
|
SetSupportedSchemes(schemes, TCefFastCompletionCallback.Create(callback));
|
|
|
|
end;
|
|
|
|
|
|
|
|
class function TCefCookieManagerRef.UnWrap(data: Pointer): ICefCookieManager;
|
|
|
|
begin
|
2018-02-27 11:23:45 +02:00
|
|
|
if (data <> nil) then
|
|
|
|
Result := Create(data) as ICefCookieManager
|
|
|
|
else
|
2017-01-27 18:29:37 +02:00
|
|
|
Result := nil;
|
|
|
|
end;
|
|
|
|
|
2018-02-27 11:23:45 +02:00
|
|
|
function TCefCookieManagerRef.VisitAllCookies(const visitor: ICefCookieVisitor): Boolean;
|
2017-01-27 18:29:37 +02:00
|
|
|
begin
|
2018-02-27 11:23:45 +02:00
|
|
|
Result := PCefCookieManager(FData).visit_all_cookies(PCefCookieManager(FData), CefGetData(visitor)) <> 0;
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
|
2018-02-27 11:23:45 +02:00
|
|
|
function TCefCookieManagerRef.VisitAllCookiesProc(const visitor: TCefCookieVisitorProc): Boolean;
|
2017-01-27 18:29:37 +02:00
|
|
|
begin
|
2018-02-27 11:23:45 +02:00
|
|
|
Result := VisitAllCookies(TCefFastCookieVisitor.Create(visitor) as ICefCookieVisitor);
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
|
2018-02-27 11:23:45 +02:00
|
|
|
function TCefCookieManagerRef.VisitUrlCookies(const url : ustring;
|
|
|
|
includeHttpOnly : Boolean;
|
|
|
|
const visitor : ICefCookieVisitor): Boolean;
|
2017-01-27 18:29:37 +02:00
|
|
|
var
|
2018-02-27 11:23:45 +02:00
|
|
|
str : TCefString;
|
2017-01-27 18:29:37 +02:00
|
|
|
begin
|
2018-02-27 11:23:45 +02:00
|
|
|
str := CefString(url);
|
2017-01-27 18:29:37 +02:00
|
|
|
Result := PCefCookieManager(FData).visit_url_cookies(PCefCookieManager(FData), @str, Ord(includeHttpOnly), CefGetData(visitor)) <> 0;
|
|
|
|
end;
|
|
|
|
|
2018-02-27 11:23:45 +02:00
|
|
|
function TCefCookieManagerRef.VisitUrlCookiesProc(const url : ustring;
|
|
|
|
includeHttpOnly : Boolean;
|
|
|
|
const visitor : TCefCookieVisitorProc): Boolean;
|
2017-01-27 18:29:37 +02:00
|
|
|
begin
|
2018-02-27 11:23:45 +02:00
|
|
|
Result := VisitUrlCookies(url, includeHttpOnly, TCefFastCookieVisitor.Create(visitor) as ICefCookieVisitor);
|
2017-01-27 18:29:37 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|