diff --git a/include/capi/cef_download_item_capi.h b/include/capi/cef_download_item_capi.h index d6986eb03..366e223f9 100644 --- a/include/capi/cef_download_item_capi.h +++ b/include/capi/cef_download_item_capi.h @@ -33,7 +33,7 @@ // by hand. See the translator.README.txt file in the tools directory for // more information. // -// $hash=332b9cb62b9c85573dc705aba4c9db3b34177e20$ +// $hash=d9e9f4b914ae2d3b1ed83ae0d9e2e46e9e736af5$ // #ifndef CEF_INCLUDE_CAPI_CEF_DOWNLOAD_ITEM_CAPI_H_ @@ -72,10 +72,21 @@ typedef struct _cef_download_item_t { int(CEF_CALLBACK* is_complete)(struct _cef_download_item_t* self); /// - /// Returns true (1) if the download has been canceled or interrupted. + /// Returns true (1) if the download has been canceled. /// int(CEF_CALLBACK* is_canceled)(struct _cef_download_item_t* self); + /// + /// Returns true (1) if the download has been interrupted. + /// + int(CEF_CALLBACK* is_interrupted)(struct _cef_download_item_t* self); + + /// + /// Returns the most recent interrupt reason. + /// + cef_download_interrupt_reason_t(CEF_CALLBACK* get_interrupt_reason)( + struct _cef_download_item_t* self); + /// /// Returns a simple speed estimate in bytes/s. /// diff --git a/include/cef_api_hash.h b/include/cef_api_hash.h index ec82f69a7..6f5bfbdef 100644 --- a/include/cef_api_hash.h +++ b/include/cef_api_hash.h @@ -42,13 +42,13 @@ // way that may cause binary incompatibility with other builds. The universal // hash value will change if any platform is affected whereas the platform hash // values will change only if that particular platform is affected. -#define CEF_API_HASH_UNIVERSAL "05ddbcd7ae86396372d24639bcf383c0c3186a48" +#define CEF_API_HASH_UNIVERSAL "defb610a3c797b3636da085bd008fb24c46c8242" #if defined(OS_WIN) -#define CEF_API_HASH_PLATFORM "210d3a785a0386b734504366f461a4ff435cd8f0" +#define CEF_API_HASH_PLATFORM "b47966e88841b7aa5546ead8a2021892d51886b1" #elif defined(OS_MAC) -#define CEF_API_HASH_PLATFORM "d0197836c7828d704fe6d5b7a4f9434a06419143" +#define CEF_API_HASH_PLATFORM "da69054d32deecf2476aeb30607036e074413730" #elif defined(OS_LINUX) -#define CEF_API_HASH_PLATFORM "188b94c939b73aa00e382b1d4967c69364247d54" +#define CEF_API_HASH_PLATFORM "00ed1b02f30b01ed1c841e1ef515f1b77f9832e6" #endif #ifdef __cplusplus diff --git a/include/cef_download_item.h b/include/cef_download_item.h index bde3ac534..671f32f16 100644 --- a/include/cef_download_item.h +++ b/include/cef_download_item.h @@ -66,11 +66,23 @@ class CefDownloadItem : public virtual CefBaseRefCounted { virtual bool IsComplete() = 0; /// - /// Returns true if the download has been canceled or interrupted. + /// Returns true if the download has been canceled. /// /*--cef()--*/ virtual bool IsCanceled() = 0; + /// + /// Returns true if the download has been interrupted. + /// + /*--cef()--*/ + virtual bool IsInterrupted() = 0; + + /// + /// Returns the most recent interrupt reason. + /// + /*--cef(default_retval=CEF_DOWNLOAD_INTERRUPT_REASON_NONE)--*/ + virtual cef_download_interrupt_reason_t GetInterruptReason() = 0; + /// /// Returns a simple speed estimate in bytes/s. /// diff --git a/include/internal/cef_types.h b/include/internal/cef_types.h index d007d5ad0..2ca9d7d1a 100644 --- a/include/internal/cef_types.h +++ b/include/internal/cef_types.h @@ -3488,6 +3488,123 @@ typedef enum { CEF_PREFERENCES_TYPE_REQUEST_CONTEXT, } cef_preferences_type_t; +/// +/// Download interrupt reasons. Should be kept in sync with +/// Chromium's download::DownloadInterruptReason type. +/// +typedef enum { + CEF_DOWNLOAD_INTERRUPT_REASON_NONE = 0, + + /// Generic file operation failure. + CEF_DOWNLOAD_INTERRUPT_REASON_FILE_FAILED = 1, + + /// The file cannot be accessed due to security restrictions. + CEF_DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED = 2, + + /// There is not enough room on the drive. + CEF_DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE = 3, + + /// The directory or file name is too long. + CEF_DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG = 5, + + /// The file is too large for the file system to handle. + CEF_DOWNLOAD_INTERRUPT_REASON_FILE_TOO_LARGE = 6, + + /// The file contains a virus. + CEF_DOWNLOAD_INTERRUPT_REASON_FILE_VIRUS_INFECTED = 7, + + /// The file was in use. Too many files are opened at once. We have run out of + /// memory. + CEF_DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR = 10, + + /// The file was blocked due to local policy. + CEF_DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED = 11, + + /// An attempt to check the safety of the download failed due to unexpected + /// reasons. See http://crbug.com/153212. + CEF_DOWNLOAD_INTERRUPT_REASON_FILE_SECURITY_CHECK_FAILED = 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). + CEF_DOWNLOAD_INTERRUPT_REASON_FILE_TOO_SHORT = 13, + + /// The partial file didn't match the expected hash. + CEF_DOWNLOAD_INTERRUPT_REASON_FILE_HASH_MISMATCH = 14, + + /// The source and the target of the download were the same. + CEF_DOWNLOAD_INTERRUPT_REASON_FILE_SAME_AS_SOURCE = 15, + + // Network errors. + + /// Generic network failure. + CEF_DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED = 20, + + /// The network operation timed out. + CEF_DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT = 21, + + /// The network connection has been lost. + CEF_DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED = 22, + + /// The server has gone down. + CEF_DOWNLOAD_INTERRUPT_REASON_NETWORK_SERVER_DOWN = 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. + CEF_DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST = 24, + + // Server responses. + + /// The server indicates that the operation has failed (generic). + CEF_DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED = 30, + + /// The server does not support range requests. + /// Internal use only: must restart from the beginning. + CEF_DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE = 31, + + /// The server does not have the requested data. + CEF_DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT = 33, + + /// Server didn't authorize access to resource. + CEF_DOWNLOAD_INTERRUPT_REASON_SERVER_UNAUTHORIZED = 34, + + /// Server certificate problem. + CEF_DOWNLOAD_INTERRUPT_REASON_SERVER_CERT_PROBLEM = 35, + + /// Server access forbidden. + CEF_DOWNLOAD_INTERRUPT_REASON_SERVER_FORBIDDEN = 36, + + /// Unexpected server response. This might indicate that the responding server + /// may not be the intended server. + CEF_DOWNLOAD_INTERRUPT_REASON_SERVER_UNREACHABLE = 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. + CEF_DOWNLOAD_INTERRUPT_REASON_SERVER_CONTENT_LENGTH_MISMATCH = 38, + + /// An unexpected cross-origin redirect happened. + CEF_DOWNLOAD_INTERRUPT_REASON_SERVER_CROSS_ORIGIN_REDIRECT = 39, + + // User input. + + /// The user canceled the download. + CEF_DOWNLOAD_INTERRUPT_REASON_USER_CANCELED = 40, + + /// The user shut down the browser. + /// Internal use only: resume pending downloads if possible. + CEF_DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN = 41, + + // Crash. + + /// The browser crashed. + /// Internal use only: resume pending downloads if possible. + CEF_DOWNLOAD_INTERRUPT_REASON_CRASH = 50, +} cef_download_interrupt_reason_t; + #ifdef __cplusplus } #endif diff --git a/libcef/browser/download_item_impl.cc b/libcef/browser/download_item_impl.cc index d5e63981d..f997f1b02 100644 --- a/libcef/browser/download_item_impl.cc +++ b/libcef/browser/download_item_impl.cc @@ -39,6 +39,17 @@ bool CefDownloadItemImpl::IsCanceled() { return const_value().GetState() == download::DownloadItem::CANCELLED; } +bool CefDownloadItemImpl::IsInterrupted() { + CEF_VALUE_VERIFY_RETURN(false, false); + return const_value().GetState() == download::DownloadItem::INTERRUPTED; +} + +cef_download_interrupt_reason_t CefDownloadItemImpl::GetInterruptReason() { + CEF_VALUE_VERIFY_RETURN(false, CEF_DOWNLOAD_INTERRUPT_REASON_NONE); + return static_cast( + const_value().GetLastReason()); +} + int64 CefDownloadItemImpl::GetCurrentSpeed() { CEF_VALUE_VERIFY_RETURN(false, 0); return const_value().CurrentSpeed(); diff --git a/libcef/browser/download_item_impl.h b/libcef/browser/download_item_impl.h index 8a02e629a..0dbef9d61 100644 --- a/libcef/browser/download_item_impl.h +++ b/libcef/browser/download_item_impl.h @@ -27,6 +27,8 @@ class CefDownloadItemImpl bool IsInProgress() override; bool IsComplete() override; bool IsCanceled() override; + bool IsInterrupted() override; + cef_download_interrupt_reason_t GetInterruptReason() override; int64 GetCurrentSpeed() override; int GetPercentComplete() override; int64 GetTotalBytes() override; diff --git a/libcef_dll/cpptoc/download_item_cpptoc.cc b/libcef_dll/cpptoc/download_item_cpptoc.cc index 47f988c90..8232d48ee 100644 --- a/libcef_dll/cpptoc/download_item_cpptoc.cc +++ b/libcef_dll/cpptoc/download_item_cpptoc.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=cb94a7a2bc730d84808942098434a9fa482e348d$ +// $hash=45f5c5ca3629966c785faf3785144c18f7fe14f0$ // #include "libcef_dll/cpptoc/download_item_cpptoc.h" @@ -88,6 +88,43 @@ int CEF_CALLBACK download_item_is_canceled(struct _cef_download_item_t* self) { return _retval; } +int CEF_CALLBACK +download_item_is_interrupted(struct _cef_download_item_t* self) { + shutdown_checker::AssertNotShutdown(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) { + return 0; + } + + // Execute + bool _retval = CefDownloadItemCppToC::Get(self)->IsInterrupted(); + + // Return type: bool + return _retval; +} + +cef_download_interrupt_reason_t CEF_CALLBACK +download_item_get_interrupt_reason(struct _cef_download_item_t* self) { + shutdown_checker::AssertNotShutdown(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) { + return CEF_DOWNLOAD_INTERRUPT_REASON_NONE; + } + + // Execute + cef_download_interrupt_reason_t _retval = + CefDownloadItemCppToC::Get(self)->GetInterruptReason(); + + // Return type: simple + return _retval; +} + int64 CEF_CALLBACK download_item_get_current_speed(struct _cef_download_item_t* self) { shutdown_checker::AssertNotShutdown(); @@ -330,6 +367,8 @@ CefDownloadItemCppToC::CefDownloadItemCppToC() { GetStruct()->is_in_progress = download_item_is_in_progress; GetStruct()->is_complete = download_item_is_complete; GetStruct()->is_canceled = download_item_is_canceled; + GetStruct()->is_interrupted = download_item_is_interrupted; + GetStruct()->get_interrupt_reason = download_item_get_interrupt_reason; GetStruct()->get_current_speed = download_item_get_current_speed; GetStruct()->get_percent_complete = download_item_get_percent_complete; GetStruct()->get_total_bytes = download_item_get_total_bytes; diff --git a/libcef_dll/ctocpp/download_item_ctocpp.cc b/libcef_dll/ctocpp/download_item_ctocpp.cc index 752c5aac7..86c606e0f 100644 --- a/libcef_dll/ctocpp/download_item_ctocpp.cc +++ b/libcef_dll/ctocpp/download_item_ctocpp.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=4ce3ee0a560c692db5902828ffd856ac1a3f4b19$ +// $hash=fc5e810c3fe740f341ed8f5387fff35f101d6461$ // #include "libcef_dll/ctocpp/download_item_ctocpp.h" @@ -85,6 +85,42 @@ NO_SANITIZE("cfi-icall") bool CefDownloadItemCToCpp::IsCanceled() { return _retval ? true : false; } +NO_SANITIZE("cfi-icall") bool CefDownloadItemCToCpp::IsInterrupted() { + shutdown_checker::AssertNotShutdown(); + + cef_download_item_t* _struct = GetStruct(); + if (CEF_MEMBER_MISSING(_struct, is_interrupted)) { + return false; + } + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int _retval = _struct->is_interrupted(_struct); + + // Return type: bool + return _retval ? true : false; +} + +NO_SANITIZE("cfi-icall") +cef_download_interrupt_reason_t CefDownloadItemCToCpp::GetInterruptReason() { + shutdown_checker::AssertNotShutdown(); + + cef_download_item_t* _struct = GetStruct(); + if (CEF_MEMBER_MISSING(_struct, get_interrupt_reason)) { + return CEF_DOWNLOAD_INTERRUPT_REASON_NONE; + } + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_download_interrupt_reason_t _retval = + _struct->get_interrupt_reason(_struct); + + // Return type: simple + return _retval; +} + NO_SANITIZE("cfi-icall") int64 CefDownloadItemCToCpp::GetCurrentSpeed() { shutdown_checker::AssertNotShutdown(); diff --git a/libcef_dll/ctocpp/download_item_ctocpp.h b/libcef_dll/ctocpp/download_item_ctocpp.h index 8c93039e0..b22ba37a7 100644 --- a/libcef_dll/ctocpp/download_item_ctocpp.h +++ b/libcef_dll/ctocpp/download_item_ctocpp.h @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=d0295aa7dbc39993e62486a20a1ef8123d0648b2$ +// $hash=8db814c52f72368cb7dd612ed3d2efaccddb865c$ // #ifndef CEF_LIBCEF_DLL_CTOCPP_DOWNLOAD_ITEM_CTOCPP_H_ @@ -38,6 +38,8 @@ class CefDownloadItemCToCpp : public CefCToCppRefCountedIsInProgress()); EXPECT_FALSE(download_item->IsComplete()); EXPECT_FALSE(download_item->IsCanceled()); + EXPECT_FALSE(download_item->IsInterrupted()); + EXPECT_EQ(CEF_DOWNLOAD_INTERRUPT_REASON_NONE, + download_item->GetInterruptReason()); EXPECT_EQ(static_cast(sizeof(kTestContent) - 1), download_item->GetTotalBytes()); EXPECT_EQ(0UL, download_item->GetFullPath().length()); @@ -415,6 +418,9 @@ class DownloadTestHandler : public TestHandler { EXPECT_TRUE(download_item->IsValid()); EXPECT_FALSE(download_item->IsCanceled()); + EXPECT_FALSE(download_item->IsInterrupted()); + EXPECT_EQ(CEF_DOWNLOAD_INTERRUPT_REASON_NONE, + download_item->GetInterruptReason()); EXPECT_STREQ(kTestDownloadUrl, download_item->GetURL().ToString().c_str()); EXPECT_STREQ(kTestContentDisposition, download_item->GetContentDisposition().ToString().c_str());