-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathWebView.InternalDownloadHandler.cs
More file actions
37 lines (30 loc) · 1.59 KB
/
WebView.InternalDownloadHandler.cs
File metadata and controls
37 lines (30 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using Xilium.CefGlue;
using Xilium.CefGlue.Common.Handlers;
namespace WebViewControl {
partial class WebView {
private class InternalDownloadHandler : DownloadHandler {
private WebView OwnerWebView { get; }
public InternalDownloadHandler(WebView owner) {
OwnerWebView = owner;
}
protected override void OnBeforeDownload(CefBrowser browser, CefDownloadItem downloadItem, string suggestedName, CefBeforeDownloadCallback callback) {
callback.Continue(downloadItem.SuggestedFileName, showDialog: true);
}
protected override void OnDownloadUpdated(CefBrowser browser, CefDownloadItem downloadItem, CefDownloadItemCallback callback) {
if (downloadItem.IsComplete) {
if (OwnerWebView.DownloadCompleted != null) {
OwnerWebView.AsyncExecuteInUI(() => OwnerWebView.DownloadCompleted?.Invoke(downloadItem.FullPath));
}
} else if (downloadItem.IsCanceled) {
if (OwnerWebView.DownloadCancelled != null) {
OwnerWebView.AsyncExecuteInUI(() => OwnerWebView.DownloadCancelled?.Invoke(downloadItem.FullPath));
}
} else {
if (OwnerWebView.DownloadProgressChanged != null) {
OwnerWebView.AsyncExecuteInUI(() => OwnerWebView.DownloadProgressChanged?.Invoke(downloadItem.FullPath, downloadItem.ReceivedBytes, downloadItem.TotalBytes));
}
}
}
}
}
}