From 9f3be65def993b007bd77904c8f0276856bb5add Mon Sep 17 00:00:00 2001 From: Schuyler Tan <76160587+SLT-World@users.noreply.github.com> Date: Thu, 25 Jun 2026 17:41:41 +0800 Subject: [PATCH] Core - Expose `IsInterrupted` and `InterruptReason` to DownloadItem. (#5266) * Core - Expose `IsInterrupted` and `InterruptReason` to DownloadItem. --- .../Internals/TypeConversion.h | 2 + CefSharp/DownloadItem.cs | 12 +- CefSharp/Enums/DownloadInterruptReason.cs | 181 ++++++++++++++++++ 3 files changed, 194 insertions(+), 1 deletion(-) create mode 100644 CefSharp/Enums/DownloadInterruptReason.cs diff --git a/CefSharp.Core.Runtime/Internals/TypeConversion.h b/CefSharp.Core.Runtime/Internals/TypeConversion.h index 9c1601e66..7b0752f0e 100644 --- a/CefSharp.Core.Runtime/Internals/TypeConversion.h +++ b/CefSharp.Core.Runtime/Internals/TypeConversion.h @@ -59,6 +59,8 @@ namespace CefSharp item->IsComplete = downloadItem->IsComplete(); item->IsCancelled = downloadItem->IsCanceled(); item->IsPaused = downloadItem->IsPaused(); + item->IsInterrupted = downloadItem->IsInterrupted(); + item->InterruptReason = (DownloadInterruptReason)downloadItem->GetInterruptReason(); item->CurrentSpeed = downloadItem->GetCurrentSpeed(); item->PercentComplete = downloadItem->GetPercentComplete(); item->TotalBytes = downloadItem->GetTotalBytes(); diff --git a/CefSharp/DownloadItem.cs b/CefSharp/DownloadItem.cs index 5b477877c..494d23a24 100644 --- a/CefSharp/DownloadItem.cs +++ b/CefSharp/DownloadItem.cs @@ -27,7 +27,7 @@ namespace CefSharp public bool IsComplete { get; set; } /// - /// Returns true if the download has been canceled or interrupted. + /// Returns true if the download has been canceled. /// public bool IsCancelled { get; set; } @@ -36,6 +36,16 @@ namespace CefSharp /// public bool IsPaused { get; set; } + /// + /// Returns true if the download has been interrupted. + /// + public bool IsInterrupted { get; set; } + + /// + /// Returns the most recent interrupt reason. + /// + public DownloadInterruptReason InterruptReason { get; set; } + /// /// Returns a simple speed estimate in bytes/s. /// diff --git a/CefSharp/Enums/DownloadInterruptReason.cs b/CefSharp/Enums/DownloadInterruptReason.cs new file mode 100644 index 000000000..274db4477 --- /dev/null +++ b/CefSharp/Enums/DownloadInterruptReason.cs @@ -0,0 +1,181 @@ +// Copyright © 2026 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 +{ + /// + /// Download interrupt reasons. + /// + /// For a complete up-to-date list, see the CEF source code + /// (cef_download_interrupt_reason_t in include/internal/cef_types.h) + /// and the Chromium source code (download/public/common/download_interrupt_reason_values.h). + /// + public enum DownloadInterruptReason + { + /// + /// No error occurred. + /// + None = 0, + + /// + /// Generic file operation failure. + /// + FileFailed = 1, + + /// + /// The file cannot be accessed due to security restrictions. + /// + FileAccessDenied = 2, + + /// + /// There is not enough room on the drive. + /// + FileNoSpace = 3, + + /// + /// The directory or file name is too long. + /// + FileNameTooLong = 5, + + /// + /// The file is too large for the file system to handle. + /// + FileTooLarge = 6, + + /// + /// The file contains a virus. + /// + FileVirusInfected = 7, + + /// + /// The file was in use. + /// Too many files are opened at once. + /// We have run out of memory. + /// + FileTransientError = 10, + + /// + /// The file was blocked due to local policy. + /// + FileBlocked = 11, + + /// + /// An attempt to check the safety of the download failed due to unexpected + /// reasons. See http://crbug.com/153212. + /// + FileSecurityCheckFailed = 12, + + /// + /// An attempt was made to seek past the end of a file in opening + /// a file (as part of resuming a previously interrupted download). + /// + FileTooShort = 13, + + /// + /// The partial file didn't match the expected hash. + /// + FileHashMismatch = 14, + + /// + /// The source and the target of the download were the same. + /// + FileSameAsSource = 15, + + /// + /// Generic network failure. + /// + NetworkFailed = 20, + + /// + /// The network operation timed out. + /// + NetworkTimeout = 21, + + /// + /// The network connection has been lost. + /// + NetworkDisconnected = 22, + + /// + /// The server has gone down. + /// + NetworkServerDown = 23, + + /// + /// The network request was invalid. This may be due to the original URL or a + /// redirected URL: + /// - Having an unsupported scheme. + /// - Being an invalid URL. + /// - Being disallowed by policy. + /// + NetworkInvalidRequest = 24, + + /// + /// The server indicates that the operation has failed (generic). + /// + ServerFailed = 30, + + /// + /// The server does not support range requests. + /// Internal use only: must restart from the beginning. + /// + ServerNoRange = 31, + + /// + /// The server does not have the requested data. + /// + ServerBadContent = 33, + + /// + /// Server didn't authorize access to resource. + /// + ServerUnauthorized = 34, + + /// + /// Server certificate problem. + /// + ServerCertProblem = 35, + + /// + /// Server access forbidden. + /// + ServerForbidden = 36, + + /// + /// Unexpected server response. This might indicate that the responding server + /// may not be the intended server. + /// + ServerUnreachable = 37, + + /// + /// The server sent fewer bytes than the content-length header. It may indicate + /// that the connection was closed prematurely, or the Content-Length header was + /// invalid. The download is only interrupted if strong validators are present. + /// Otherwise, it is treated as finished. + /// + ServerContentLengthMismatch = 38, + + /// + /// An unexpected cross-origin redirect happened. + /// + ServerCrossOriginRedirect = 39, + + /// + /// The user canceled the download. + /// + UserCanceled = 40, + + /// + /// The user shut down the browser. + /// Internal use only: resume pending downloads if possible. + /// + UserShutdown = 41, + + /// + /// The browser crashed. + /// Internal use only: resume pending downloads if possible. + /// + Crash = 50 + } +}