Page 1 of 1

Re: OnGetResourceHandler and Session

Posted: Tue Dec 12, 2017 8:32 am
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

Re: OnGetResourceHandler and Session

Posted: Tue Dec 12, 2017 11:23 am
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.