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.

OnGetResourceHandler and Session

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

Re: OnGetResourceHandler and Session

Post by salvadordf »

Hi Jan,

Use this function to download a file using the same session :
ChromiumWindow1.ChromiumBrowser.StartDownload(request.url);

You will also have to add these events :
  • ChromiumWindow1.ChromiumBrowser.OnBeforeDownload
  • ChromiumWindow1.ChromiumBrowser.OnDownloadUpdated
The CEF3 source has these comments about OnBeforeDownload :

Code: Select all

  ///
  // Called before a download begins. |suggested_name| is the suggested name for
  // the download file. By default the download will be canceled. Execute
  // |callback| either asynchronously or in this function to continue the
  // download if desired. Do not keep a reference to |download_item| outside of
  // this function.
  ///
About OnDownloadUpdated :

Code: Select all

  ///
  // Called when a download's status or progress information has been updated.
  // This may be called multiple times before and after on_before_download().
  // Execute |callback| either asynchronously or in this function to cancel the
  // download if desired. Do not keep a reference to |download_item| outside of
  // this function.
  ///
The CEF3 C++ API Docs also have a copy of those comments here :
http://magpcss.org/ceforum/apidocs3/pro ... ndler.html
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: OnGetResourceHandler and Session

Post by salvadordf »

The StartDownload function can be used in any thread inside the browser process. I would use it in the OnBeforeResourceLoad event and return RV_CONTINUE

Code: Select all

procedure TMainForm.Chromium_OnBeforeResourceLoad(...)
begin
if Request.ResourceType = RT_FONT_RESOURCE then
begin
  ChromiumWindow1.ChromiumBrowser.StartDownload(request.url);  
end;

Result := RV_CONTINUE;
end; 
As far as I know, there is no CEF3 function to download a resource in a memory buffer or a stream. However, you can save the file in a temporal directory, read it when it's finished and then delete it.
Post Reply