Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

delete cache

Post Reply
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: delete cache

Post by salvadordf »

Set GlobalCEFApp.DeleteCache to TRUE before the GlobalCEFApp.StartMainProcess call in the DPR file and CEF4Delphi will delete the cache before CEF is initialized.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: delete cache

Post by salvadordf »

I'm sorry but CEF3 doesn't allow to delete the cache while the browser is fully initialized. That's why I added the "GlobalCEFApp.DeleteCache" property.

Read this thread for more information :
https://www.briskbard.com/forum/viewtopic.php?f=8&t=594
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: delete cache

Post by salvadordf »

beryindo wrote: Thu Jan 10, 2019 8:43 amMDIBrowser can create and delete so can GlobalCEFApp.DeleteCache := True before Browser Create ?
You need to set GlobalCEFApp.DeleteCache before the GlobalCEFApp.StartMainProcess call in the DPR file.

MDIBrowser can be configured to create browsers with different "contexts", which means that they can use different cache directories. This is just a workaround to avoid closing your app each time you need to clear the cache with "GlobalCEFApp.DeleteCache".
beryindo wrote: Thu Jan 10, 2019 8:43 ambut can MDIBrowser delete cookies and set user agent ?
Yes. That demo can delete cookies and you can modify the request headers to set a new user agent.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: delete cache

Post by salvadordf »

You also need to call TempManager.VisitAllCookies(FVisitor) after you assign TempManager := TCefCookieManagerRef.Global(nil);

The CookieVisitor demo do that in the TCookieVisitorFrm.Chromium1ContextMenuCommand procedure but you can call VisitAllCookies in any browser thread or procedure.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: delete cache

Post by salvadordf »

Put a breakpoint in CookieVisitorProc and check that ChildForm exists and has a valid handle.

Also check that ChildForm receives the SHOWCOOKIES message.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: delete cache

Post by salvadordf »

Build the CookieVisitor demo and check that it works in your computer. Then add your code to that demo incrementally.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: delete cache

Post by salvadordf »

If you create different request contexts for each child browser in the MDIBrowser demo then each child browser will also have a different cookie manager.

You will need to use those cookie managers to call "VisitAllCookies" and not the global cookie manager that's used in the CookieVisitor demo.

Let's say you create a custom request context for a new child browser in the MDIBrowser demo and you call it "NewChildContext". To get the cookie manager for that browser you only have to call :

Code: Select all

TempManager := NewChildContext.GetDefaultCookieManager(nil);
Then you can call TempManager.VisitAllCookies(FVisitor) to get the cookies.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: delete cache

Post by salvadordf »

Right now I'm very busy. I'll try to take a look at this over the weekend.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: delete cache

Post by salvadordf »

Sorry for the delay.

You need to declare "NewChildContext : ICefRequestContext;" in the class, not in a procedure.

Assign NewChildContext in TChildForm.FormShow like this :

Code: Select all

procedure TChildForm.FormShow(Sender: TObject);
begin
  NewChildContext := TCefRequestContextRef.New('', '', False, False, False, False);
  Chromium1.CreateBrowser(CEFWindowParent1, '', TempContext);
end;
Then modify TChildForm.Button2Click like this :

Code: Select all

procedure TChildForm.Button2Click(Sender: TObject);
var
  TempManager : ICefCookieManager;
begin
    TempManager := NewChildContext.GetDefaultCookieManager(nil);
    TempManager.VisitAllCookies(FVisitor);
end;
You will also have to set NewChildContext to NIL in the FormCloseQuery procedure

Code: Select all

procedure TChildForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  CanClose := FCanClose;
  NewChildContext := nil;

  if not(FClosing) and Panel1.Enabled then
    begin
      FClosing       := True;
      Panel1.Enabled := False;
      Chromium1.CloseBrowser(True);
    end;
end;
Post Reply