// Copyright © 2021 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
namespace CefSharp.Handler
{
///
/// Class used to handle file downloads.
/// The methods of this class will called on the CEF UI thread.
///
public class DownloadHandler : IDownloadHandler
{
///
bool IDownloadHandler.CanDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, string url, string requestMethod)
{
return CanDownload(chromiumWebBrowser, browser, url, requestMethod);
}
///
/// Called before a download begins in response to a user-initiated action
/// (e.g. alt + link click or link click that returns a `Content-Disposition:
/// attachment` response from the server).
///
/// the ChromiumWebBrowser control
/// The browser instance
/// is the target download URL
/// is the target method (GET, POST, etc)
/// Return true to proceed with the download or false to cancel the download.
protected virtual bool CanDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, string url, string requestMethod)
{
return true;
}
///
bool IDownloadHandler.OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
{
return OnBeforeDownload(chromiumWebBrowser, browser, downloadItem, callback);
}
///
/// Called before a download begins.
///
/// the ChromiumWebBrowser control
/// The browser instance
/// Represents the file being downloaded.
/// Callback interface used to asynchronously continue a download.
/// Return true and execute either
/// asynchronously or in this method to continue or cancel the download.
/// Return false to proceed with default handling (cancel with Alloy style,
/// download shelf with Chrome style).
protected virtual bool OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
{
return false;
}
///
/// Called when a download's status or progress information has been updated. This may be called multiple times before and after .
///
/// the ChromiumWebBrowser control
/// The browser instance
/// Represents the file being downloaded.
/// The callback used to Cancel/Pause/Resume the process
void IDownloadHandler.OnDownloadUpdated(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback)
{
OnDownloadUpdated(chromiumWebBrowser, browser, downloadItem, callback);
}
///
/// Called when a download's status or progress information has been updated. This may be called multiple times before and after .
///
/// the ChromiumWebBrowser control
/// The browser instance
/// Represents the file being downloaded.
/// The callback used to Cancel/Pause/Resume the process
protected virtual void OnDownloadUpdated(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback)
{
}
}
}