interface ICoreWebView2DownloadOperation
interface ICoreWebView2DownloadOperation
: public IUnknown
Represents a download operation.
Summary
Members | Descriptions |
---|---|
add_BytesReceivedChanged | Add an event handler for the BytesReceivedChanged event. |
add_EstimatedEndTimeChanged | Add an event handler for the EstimatedEndTimeChanged event. |
add_StateChanged | Add an event handler for the StateChanged event. |
Cancel | Cancels the download. |
get_BytesReceived | The number of bytes that have been written to the download file. |
get_CanResume | Returns true if an interrupted download can be resumed. |
get_ContentDisposition | The Content-Disposition header value from the download's HTTP response. |
get_EstimatedEndTime | The estimated end time in ISO 8601 Date and Time Format. |
get_InterruptReason | The reason why connection with file host was broken. |
get_MimeType | MIME type of the downloaded content. |
get_ResultFilePath | The absolute path to the download file, including file name. |
get_State | The state of the download. |
get_TotalBytesToReceive | The expected size of the download in total number of bytes based on the HTTP Content-Length header. |
get_Uri | The URI of the download. |
Pause | Pauses the download. |
remove_BytesReceivedChanged | Remove an event handler previously added with add_BytesReceivedChanged . |
remove_EstimatedEndTimeChanged | Remove an event handler previously added with add_EstimatedEndTimeChanged . |
remove_StateChanged | Remove an event handler previously added with add_StateChanged . |
Resume | Resumes a paused download. |
Gives access to the download's metadata and supports a user canceling, pausing, or resuming the download.
Applies to
Product | Introduced |
---|---|
WebView2 Win32 | 1.0.902.49 |
WebView2 Win32 Prerelease | 1.0.902 |
Members
add_BytesReceivedChanged
Add an event handler for the BytesReceivedChanged
event.
public HRESULT add_BytesReceivedChanged(ICoreWebView2BytesReceivedChangedEventHandler * eventHandler, EventRegistrationToken * token)
CHECK_FAILURE(download->add_BytesReceivedChanged(
Callback<ICoreWebView2BytesReceivedChangedEventHandler>(
[this](ICoreWebView2DownloadOperation* download, IUnknown* args) -> HRESULT {
// Here developer can update UI to show progress of a download using
// `download->get_BytesReceived` and
// `download->get_TotalBytesToReceive`.
return S_OK;
})
.Get(),
&m_bytesReceivedChangedToken));
add_EstimatedEndTimeChanged
Add an event handler for the EstimatedEndTimeChanged
event.
public HRESULT add_EstimatedEndTimeChanged(ICoreWebView2EstimatedEndTimeChangedEventHandler * eventHandler, EventRegistrationToken * token)
add_StateChanged
Add an event handler for the StateChanged
event.
public HRESULT add_StateChanged(ICoreWebView2StateChangedEventHandler * eventHandler, EventRegistrationToken * token)
CHECK_FAILURE(download->add_StateChanged(
Callback<ICoreWebView2StateChangedEventHandler>(
[this](ICoreWebView2DownloadOperation* download,
IUnknown* args) -> HRESULT {
COREWEBVIEW2_DOWNLOAD_STATE downloadState;
CHECK_FAILURE(download->get_State(&downloadState));
switch (downloadState)
{
case COREWEBVIEW2_DOWNLOAD_STATE_IN_PROGRESS:
break;
case COREWEBVIEW2_DOWNLOAD_STATE_INTERRUPTED:
// Here developer can take different actions based on `download->InterruptReason`.
// For example, show an error message to the end user.
CompleteDownload(download);
break;
case COREWEBVIEW2_DOWNLOAD_STATE_COMPLETED:
CompleteDownload(download);
break;
}
return S_OK;
})
.Get(),
&m_stateChangedToken));
Cancel
Cancels the download.
public HRESULT Cancel()
If canceled, the default download dialog shows that the download was canceled. Host should set the Cancel
property from ICoreWebView2SDownloadStartingEventArgs
if the download should be canceled without displaying the default download dialog.
get_BytesReceived
The number of bytes that have been written to the download file.
public HRESULT get_BytesReceived(INT64 * bytesReceived)
get_CanResume
Returns true if an interrupted download can be resumed.
public HRESULT get_CanResume(BOOL * canResume)
Downloads with the following interrupt reasons may automatically resume without you calling any methods: COREWEBVIEW2_DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE
, COREWEBVIEW2_DOWNLOAD_INTERRUPT_REASON_FILE_HASH_MISMATCH
, COREWEBVIEW2_DOWNLOAD_INTERRUPT_REASON_FILE_TOO_SHORT
. In these cases download progress may be restarted with BytesReceived
reset to 0.
get_ContentDisposition
The Content-Disposition header value from the download's HTTP response.
public HRESULT get_ContentDisposition(LPWSTR * contentDisposition)
The caller must free the returned string with CoTaskMemFree
. See API Conventions.
get_EstimatedEndTime
The estimated end time in ISO 8601 Date and Time Format.
public HRESULT get_EstimatedEndTime(LPWSTR * estimatedEndTime)
The caller must free the returned string with CoTaskMemFree
. See API Conventions.
get_InterruptReason
The reason why connection with file host was broken.
public HRESULT get_InterruptReason(COREWEBVIEW2_DOWNLOAD_INTERRUPT_REASON * interruptReason)
get_MimeType
MIME type of the downloaded content.
public HRESULT get_MimeType(LPWSTR * mimeType)
The caller must free the returned string with CoTaskMemFree
. See API Conventions.
get_ResultFilePath
The absolute path to the download file, including file name.
public HRESULT get_ResultFilePath(LPWSTR * resultFilePath)
Host can change this from ICoreWebView2DownloadStartingEventArgs.
The caller must free the returned string with CoTaskMemFree
. See API Conventions.
get_State
The state of the download.
public HRESULT get_State(COREWEBVIEW2_DOWNLOAD_STATE * downloadState)
A download can be in progress, interrupted, or completed. See COREWEBVIEW2_DOWNLOAD_STATE
for descriptions of states.
get_TotalBytesToReceive
The expected size of the download in total number of bytes based on the HTTP Content-Length header.
public HRESULT get_TotalBytesToReceive(INT64 * totalBytesToReceive)
Returns -1 if the size is unknown.
get_Uri
The URI of the download.
public HRESULT get_Uri(LPWSTR * uri)
The caller must free the returned string with CoTaskMemFree
. See API Conventions.
Pause
Pauses the download.
public HRESULT Pause()
If paused, the default download dialog shows that the download is paused. No effect if download is already paused. Pausing a download changes the state to COREWEBVIEW2_DOWNLOAD_STATE_INTERRUPTED
with InterruptReason
set to COREWEBVIEW2_DOWNLOAD_INTERRUPT_REASON_USER_PAUSED
.
remove_BytesReceivedChanged
Remove an event handler previously added with add_BytesReceivedChanged
.
public HRESULT remove_BytesReceivedChanged(EventRegistrationToken token)
remove_EstimatedEndTimeChanged
Remove an event handler previously added with add_EstimatedEndTimeChanged
.
public HRESULT remove_EstimatedEndTimeChanged(EventRegistrationToken token)
remove_StateChanged
Remove an event handler previously added with add_StateChanged
.
public HRESULT remove_StateChanged(EventRegistrationToken token)
Resume
Resumes a paused download.
public HRESULT Resume()
May also resume a download that was interrupted for another reason, if CanResume
returns true. Resuming a download changes the state from COREWEBVIEW2_DOWNLOAD_STATE_INTERRUPTED
to COREWEBVIEW2_DOWNLOAD_STATE_IN_PROGRESS
.