by pssgcsim » Sun Jun 16, 2013 2:50 pm
Downloading do not wait for OnBeforeDownload and still downloading. Can i prevent it and wait for user response ?
- Code: Select all
protected override void OnBeforeDownload(CefBrowser browser, CefDownloadItem downloadItem, string suggestedName, CefBeforeDownloadCallback callback)
{
var question = Prompts.ShowQuestion("Do you want to download file \"" + suggestedName + "\"\nfrom url \"" + downloadItem.Url + "\" ?", MessageBoxButtons.YesNoCancel);
bool canContinue = false;
if (question == DialogResult.Yes)
{
string dir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
canContinue = true;
callback.Continue(dir + "\\" + suggestedName, true);
}
_core.OnDownload(browser, downloadItem, suggestedName, callback, canContinue);
}
protected override void OnDownloadUpdated(CefBrowser browser, CefDownloadItem downloadItem, CefDownloadItemCallback callback)
{
_core.OnDownloadUpdated(browser, downloadItem, callback);
}
- Code: Select all
bool isReady = false;
bool canContinue = true;
string suggestedName = "";
browser.DownloadStarted += (s, e) =>
{
canContinue = e.CanContinue;
suggestedName = e.SuggestedName;
isReady = true;
};
browser.DownloadUpdated += (s, e) =>
{
if (isReady)
{
if (e.DownloadItem.IsComplete || e.DownloadItem.IsCanceled)
{
_statusLabel.Text = "Ready ...";
_statusLabel.Visible = false;
canContinue = true;
suggestedName = "";
isReady = false;
}
else
{
if (canContinue == false)
{
e.Callback.Cancel();
_statusLabel.Visible = false;
canContinue = true;
suggestedName = "";
isReady = false;
}
else
{
_statusLabel.Text = "Downloading file " + suggestedName +
"... Downloaded " + e.DownloadItem.PercentComplete + "% " +
StringTools.byteToMegabyte(e.DownloadItem.ReceivedBytes) +
" / " + StringTools.byteToMegabyte(e.DownloadItem.TotalBytes) + " ...";
_statusLabel.Visible = true;
}
}
}
};