diff --git a/atom/browser/api/atom_api_download_item.cc b/atom/browser/api/atom_api_download_item.cc index 84d285dc1fc..81107abceac 100644 --- a/atom/browser/api/atom_api_download_item.cc +++ b/atom/browser/api/atom_api_download_item.cc @@ -102,10 +102,18 @@ void DownloadItem::Pause() { download_item_->Pause(); } +bool DownloadItem::IsPaused() const { + return download_item_->IsPaused(); +} + void DownloadItem::Resume() { download_item_->Resume(); } +bool DownloadItem::CanResume() const { + return download_item_->CanResume(); +} + void DownloadItem::Cancel() { download_item_->Cancel(true); download_item_->Remove(); @@ -148,6 +156,10 @@ content::DownloadItem::DownloadState DownloadItem::GetState() const { return download_item_->GetState(); } +bool DownloadItem::IsDone() const { + return download_item_->IsDone(); +} + void DownloadItem::SetSavePath(const base::FilePath& path) { save_path_ = path; } @@ -162,7 +174,9 @@ void DownloadItem::BuildPrototype(v8::Isolate* isolate, mate::ObjectTemplateBuilder(isolate, prototype) .MakeDestroyable() .SetMethod("pause", &DownloadItem::Pause) + .SetMethod("isPaused", &DownloadItem::IsPaused) .SetMethod("resume", &DownloadItem::Resume) + .SetMethod("canResume", &DownloadItem::CanResume) .SetMethod("cancel", &DownloadItem::Cancel) .SetMethod("getReceivedBytes", &DownloadItem::GetReceivedBytes) .SetMethod("getTotalBytes", &DownloadItem::GetTotalBytes) @@ -172,6 +186,7 @@ void DownloadItem::BuildPrototype(v8::Isolate* isolate, .SetMethod("getContentDisposition", &DownloadItem::GetContentDisposition) .SetMethod("getURL", &DownloadItem::GetURL) .SetMethod("getState", &DownloadItem::GetState) + .SetMethod("isDone", &DownloadItem::IsDone) .SetMethod("setSavePath", &DownloadItem::SetSavePath) .SetMethod("getSavePath", &DownloadItem::GetSavePath); } diff --git a/atom/browser/api/atom_api_download_item.h b/atom/browser/api/atom_api_download_item.h index e57fd04cb98..fa330b90a0e 100644 --- a/atom/browser/api/atom_api_download_item.h +++ b/atom/browser/api/atom_api_download_item.h @@ -27,7 +27,9 @@ class DownloadItem : public mate::TrackableObject, v8::Local prototype); void Pause(); + bool IsPaused() const; void Resume(); + bool CanResume() const; void Cancel(); int64_t GetReceivedBytes() const; int64_t GetTotalBytes() const; @@ -37,6 +39,7 @@ class DownloadItem : public mate::TrackableObject, std::string GetContentDisposition() const; const GURL& GetURL() const; content::DownloadItem::DownloadState GetState() const; + bool IsDone() const; void SetSavePath(const base::FilePath& path); base::FilePath GetSavePath() const; diff --git a/docs/api/download-item.md b/docs/api/download-item.md index 02160f5f5f8..826d856be4f 100644 --- a/docs/api/download-item.md +++ b/docs/api/download-item.md @@ -78,10 +78,18 @@ routine to determine the save path(Usually prompts a save dialog). Pauses the download. +### `downloadItem.isPaused()` + +Returns whether the download is paused. + ### `downloadItem.resume()` Resumes the download that has been paused. +### `downloadItem.canResume()` + +Resumes whether the download can resume. + ### `downloadItem.cancel()` Cancels the download operation.