How to get cookies in Delphi app?

Do not post support requests, bug reports or feature requests. Discuss CEF here. Non-CEF related discussion goes in General Discussion!

How to get cookies in Delphi app?

Postby lisha » Thu Nov 17, 2011 7:38 am

I need to get cookies in my Delphi application. When the page is loaded i tried to get cookies.

var visitor: TCefCookieVisitorOwn;
begin
if crm.Browser <> nil then begin
vis := TCefCookieVisitorOwn.Create;
CefVisitAllCookies(vis);
...
end;
...
end;

And after calling CefVisitAllCookies I don't know what to do next. Please, help.
lisha
Newbie
 
Posts: 5
Joined: Thu Nov 17, 2011 5:56 am

Re: How to get cookies in Delphi app?

Postby lisha » Mon Nov 21, 2011 3:26 am

As I understand I have to implement class TCefCookieVisitorOwn. Am I right?
What class-method then I could use to get cookies access?
lisha
Newbie
 
Posts: 5
Joined: Thu Nov 17, 2011 5:56 am

Re: How to get cookies in Delphi app?

Postby lisha » Wed Nov 23, 2011 4:23 am

I solved my problem.. Maybe someone will need this solution.
(to developers) Delphi wrapper needs DateTimeToCefTime in public section.

Code: Select all
  TCustomVisitor = class (TCefCookieVisitorOwn)
    private
      fcookie: PCefCookie;
      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
      pEvent: TEvent;
      function getCookies: PCefCookie;
      constructor Create; override;
  end;

constructor TCustomVisitor.Create;
begin
  inherited;
  pEvent := TEvent.Create(nil, False, False, 'ev.chromium');
  new(fcookie);
end;

function TCustomVisitor.getCookies;
begin
  Result := fcookie;
end;

function TCustomVisitor.visit(const name, value, domain, path: ustring; secure, httponly,
            hasExpires: Boolean; const creation, lastAccess, expires: TDateTime;
            count, total: Integer; out deleteCookie: Boolean): Boolean;
begin
    fcookie.name := CefString(name);
    fcookie.value := CefString(value);
    fcookie.domain := CefString(domain);
    fcookie.path := CefString(path);
    fcookie.secure := secure;
    fcookie.httponly := httponly;
    fcookie.has_expires := hasExpires;
    //fcookie.creation := DateTimeToCefTime(creation);
    //fcookie.last_access := DateTimeToCefTime(lastAccess);
    //fcookie.expires  := DateTimeToCefTime(expires);

    SetEvent(pEvent.Handle);
end;


procedure TfrmAuth.bt_okClick(Sender: TObject);
var
  vis: TCustomVisitor;
  cname, cvalue: uString;
  ccookie: PCefCookie;
begin
  if crm.Browser<>nil then begin
    vis := TCustomVisitor.Create;
    try
      CefVisitUrlCookies(ed_url.Text, true, vis);

      if WaitForSingleObject(vis.pEvent.Handle, INFINITE) = WAIT_OBJECT_0 then begin
        ccookie := vis.getCookies;
        cname := CefString(@ccookie.name);
        cvalue := CefString(@ccookie.value);
      end;
    finally
      vis.Free;
    end;
  end;
end;
lisha
Newbie
 
Posts: 5
Joined: Thu Nov 17, 2011 5:56 am


Return to CEF Discussion

Who is online

Users browsing this forum: No registered users and 133 guests