Add DownloadItem.getState

This commit is contained in:
Cheng Zhao 2016-06-09 19:42:32 +09:00
parent 2ec5406ca6
commit 0321e23c7a
2 changed files with 10 additions and 1 deletions

View file

@ -25,6 +25,9 @@ struct Converter<content::DownloadItem::DownloadState> {
content::DownloadItem::DownloadState state) { content::DownloadItem::DownloadState state) {
std::string download_state; std::string download_state;
switch (state) { switch (state) {
case content::DownloadItem::IN_PROGRESS:
download_state = "progressing";
break;
case content::DownloadItem::COMPLETE: case content::DownloadItem::COMPLETE:
download_state = "completed"; download_state = "completed";
break; break;
@ -85,7 +88,7 @@ void DownloadItem::OnDownloadUpdated(content::DownloadItem* item) {
// Destroy the item once item is downloaded. // Destroy the item once item is downloaded.
base::MessageLoop::current()->PostTask(FROM_HERE, GetDestroyClosure()); base::MessageLoop::current()->PostTask(FROM_HERE, GetDestroyClosure());
} else { } else {
Emit("updated"); Emit("updated", item->GetState());
} }
} }
@ -141,6 +144,10 @@ const GURL& DownloadItem::GetURL() const {
return download_item_->GetURL(); return download_item_->GetURL();
} }
content::DownloadItem::DownloadState DownloadItem::GetState() const {
return download_item_->GetState();
}
void DownloadItem::SetSavePath(const base::FilePath& path) { void DownloadItem::SetSavePath(const base::FilePath& path) {
save_path_ = path; save_path_ = path;
} }
@ -164,6 +171,7 @@ void DownloadItem::BuildPrototype(v8::Isolate* isolate,
.SetMethod("getFilename", &DownloadItem::GetFilename) .SetMethod("getFilename", &DownloadItem::GetFilename)
.SetMethod("getContentDisposition", &DownloadItem::GetContentDisposition) .SetMethod("getContentDisposition", &DownloadItem::GetContentDisposition)
.SetMethod("getURL", &DownloadItem::GetURL) .SetMethod("getURL", &DownloadItem::GetURL)
.SetMethod("getState", &DownloadItem::GetState)
.SetMethod("setSavePath", &DownloadItem::SetSavePath) .SetMethod("setSavePath", &DownloadItem::SetSavePath)
.SetMethod("getSavePath", &DownloadItem::GetSavePath); .SetMethod("getSavePath", &DownloadItem::GetSavePath);
} }

View file

@ -36,6 +36,7 @@ class DownloadItem : public mate::TrackableObject<DownloadItem>,
std::string GetFilename() const; std::string GetFilename() const;
std::string GetContentDisposition() const; std::string GetContentDisposition() const;
const GURL& GetURL() const; const GURL& GetURL() const;
content::DownloadItem::DownloadState GetState() const;
void SetSavePath(const base::FilePath& path); void SetSavePath(const base::FilePath& path);
base::FilePath GetSavePath() const; base::FilePath GetSavePath() const;