CefDownloadItem
Header: cef_download_item.h
Category: Core APIs
Overview
Foundational interfaces: process bootstrap, browser lifecycle, frames, DOM, requests, and data objects.
CefDownloadItem
Source File: include/cef_download_item.h
Process / Thread Context: Threading not specified in header. Typically obtained from CefDownloadHandler::OnDownloadUpdated callbacks on the browser process UI thread.
Purpose: USER-CALLED library interface representing an in-progress or completed download. Provides state, progress, timing, source/target file info, and metadata.
Methods
bool IsValid()
Return Value: True if object is valid. Do not call other methods if false.
Threading Constraint: Threading constraint not specified in source.
bool IsInProgress()
Return Value: True if download is currently in progress.
Threading Constraint: Threading constraint not specified in source.
bool IsComplete()
Return Value: True if the download has finished successfully.
Threading Constraint: Threading constraint not specified in source.
bool IsCanceled()
Return Value: True if the download was canceled.
Threading Constraint: Threading constraint not specified in source.
bool IsInterrupted()
Return Value: True if the download was interrupted.
Threading Constraint: Threading constraint not specified in source.
cef_download_interrupt_reason_t GetInterruptReason()
Return Value: Most recent interrupt reason. Default CEF_DOWNLOAD_INTERRUPT_REASON_NONE.
Threading Constraint: Threading constraint not specified in source.
int64_t GetCurrentSpeed()
Return Value: Simple speed estimate in bytes/s.
Threading Constraint: Threading constraint not specified in source.
int GetPercentComplete()
Return Value: Rough percent complete, or -1 if total size unknown.
Threading Constraint: Threading constraint not specified in source.
int64_t GetTotalBytes()
Return Value: Total expected bytes.
Threading Constraint: Threading constraint not specified in source.
int64_t GetReceivedBytes()
Return Value: Number of bytes received so far.
Threading Constraint: Threading constraint not specified in source.
CefBaseTime GetStartTime()
Return Value: Time the download started.
Threading Constraint: Threading constraint not specified in source.
CefBaseTime GetEndTime()
Return Value: Time the download ended.
Threading Constraint: Threading constraint not specified in source.
CefString GetFullPath()
Return Value: Full path to the downloaded (or downloading) file.
Threading Constraint: Threading constraint not specified in source.
uint32_t GetId()
Return Value: Unique download identifier.
Threading Constraint: Threading constraint not specified in source.
CefString GetURL()
Return Value: Final URL (after redirects).
Threading Constraint: Threading constraint not specified in source.
CefString GetOriginalUrl()
Return Value: URL before any redirects.
Threading Constraint: Threading constraint not specified in source.
CefString GetSuggestedFileName()
Return Value: Suggested file name.
Threading Constraint: Threading constraint not specified in source.
CefString GetContentDisposition()
Return Value: Content-Disposition header value.
Threading Constraint: Threading constraint not specified in source.
CefString GetMimeType()
Return Value: MIME type of the download.
Threading Constraint: Threading constraint not specified in source.
Usage Example
// CefDownloadHandler::OnDownloadUpdated:
void OnDownloadUpdated(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDownloadItem> item,
CefRefPtr<CefDownloadItemCallback> callback) override {
if (!item->IsValid()) return;
if (item->IsComplete()) {
Log("Downloaded %s (%lld bytes)", item->GetFullPath().ToString().c_str(),
item->GetReceivedBytes());
} else if (item->IsInterrupted()) {
Log("Interrupted: %d", item->GetInterruptReason());
} else {
Log("%d%% (%lld / %lld)", item->GetPercentComplete(),
item->GetReceivedBytes(), item->GetTotalBytes());
}
}