OnBeforeDownload and OnDownloadUpdated when to act?

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

OnBeforeDownload and OnDownloadUpdated when to act?

Postby Czarek » Wed Jan 17, 2024 11:01 am

Hello,

According to documentation OnDownloadUpdated may be called multiple times before and after OnBeforeDownload. I must act upon file download being complete and saved to disk. I do it in OnDownloadUpdated, however I am wondering if it is possible for file being already with "complete" status when OnBeforeDownload is called? Since download really begins before this callback is called. Is it guaranteed that there will be at least one call to OnDownloadUpdated after OnBeforeDownload? Or should I handle possible complete status in OnBeforeDownload and act with the saved file after calling CefBeforeDownloadCallback.Continue?

Thank you for your help.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: OnBeforeDownload and OnDownloadUpdated when to act?

Postby magreenblatt » Wed Jan 17, 2024 11:27 am

Is it guaranteed that there will be at least one call to OnDownloadUpdated after OnBeforeDownload?

Did you test it? For example, download a very small file that will complete quickly.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: OnBeforeDownload and OnDownloadUpdated when to act?

Postby Czarek » Wed Jan 17, 2024 12:30 pm

For a small zip file (20 KB) there are 5 calls to OnDownloadUpdated after OnBeforeDownload, so looks like update should always be called after. Logs below:

Code: Select all
[0117/182648.478153:INFO:browser_process_client.cpp(909)] Page generated download allowed: https://www.dwsamplefiles.com/?dl_id=560
[0117/182648.478822:INFO:browser_process_client.cpp(971)] Page generated download updated (inprogress): https://www.dwsamplefiles.com/?dl_id=560
[0117/182648.478877:INFO:browser_process_client.cpp(931)] Page generated download begins (inprogress): https://www.dwsamplefiles.com/?dl_id=560
[0117/182648.478889:INFO:browser_process_client.cpp(935)] Download suggested name is: dwsample2-zip.zip
[0117/182648.479064:INFO:browser_process_client.cpp(971)] Page generated download updated (inprogress): https://www.dwsamplefiles.com/?dl_id=560
[0117/182648.479100:INFO:browser_process_client.cpp(971)] Page generated download updated (inprogress): https://www.dwsamplefiles.com/?dl_id=560
[0117/182648.479846:INFO:browser_process_client.cpp(971)] Page generated download updated (inprogress): https://www.dwsamplefiles.com/?dl_id=560
[0117/182648.479942:INFO:browser_process_client.cpp(971)] Page generated download updated (inprogress): https://www.dwsamplefiles.com/?dl_id=560
[0117/182648.480053:INFO:browser_process_client.cpp(971)] Page generated download updated (complete): https://www.dwsamplefiles.com/?dl_id=560


Thank you.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 189 guests