Check download item save path before prompting
This commit is contained in:
parent
1de8a0dcf9
commit
cf93e3e713
2 changed files with 28 additions and 19 deletions
|
@ -35,6 +35,17 @@ AtomDownloadManagerDelegate::~AtomDownloadManagerDelegate() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AtomDownloadManagerDelegate::GetItemSavePath(content::DownloadItem* item,
|
||||||
|
base::FilePath* path) {
|
||||||
|
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||||
|
v8::Locker locker(isolate);
|
||||||
|
v8::HandleScope handle_scope(isolate);
|
||||||
|
api::DownloadItem* download = api::DownloadItem::FromWrappedClass(isolate,
|
||||||
|
item);
|
||||||
|
if (download)
|
||||||
|
*path = download->GetSavePath();
|
||||||
|
}
|
||||||
|
|
||||||
void AtomDownloadManagerDelegate::CreateDownloadPath(
|
void AtomDownloadManagerDelegate::CreateDownloadPath(
|
||||||
const GURL& url,
|
const GURL& url,
|
||||||
const std::string& content_disposition,
|
const std::string& content_disposition,
|
||||||
|
@ -77,9 +88,12 @@ void AtomDownloadManagerDelegate::OnDownloadPathGenerated(
|
||||||
window = relay->window.get();
|
window = relay->window.get();
|
||||||
|
|
||||||
base::FilePath path;
|
base::FilePath path;
|
||||||
if (file_dialog::ShowSaveDialog(window, item->GetURL().spec(),
|
GetItemSavePath(item, &path);
|
||||||
"", default_path,
|
// Show save dialog if save path was not set already on item
|
||||||
file_dialog::Filters(), &path)) {
|
if (path.empty() && file_dialog::ShowSaveDialog(window, item->GetURL().spec(),
|
||||||
|
"", default_path,
|
||||||
|
file_dialog::Filters(),
|
||||||
|
&path)) {
|
||||||
// Remember the last selected download directory.
|
// Remember the last selected download directory.
|
||||||
AtomBrowserContext* browser_context = static_cast<AtomBrowserContext*>(
|
AtomBrowserContext* browser_context = static_cast<AtomBrowserContext*>(
|
||||||
download_manager_->GetBrowserContext());
|
download_manager_->GetBrowserContext());
|
||||||
|
@ -122,22 +136,14 @@ bool AtomDownloadManagerDelegate::DetermineDownloadTarget(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to get the save path from JS wrapper.
|
// Try to get the save path from JS wrapper.
|
||||||
{
|
base::FilePath save_path;
|
||||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
GetItemSavePath(download, &save_path);
|
||||||
v8::Locker locker(isolate);
|
if (!save_path.empty()) {
|
||||||
v8::HandleScope handle_scope(isolate);
|
callback.Run(save_path,
|
||||||
api::DownloadItem* download_item = api::DownloadItem::FromWrappedClass(
|
content::DownloadItem::TARGET_DISPOSITION_OVERWRITE,
|
||||||
isolate, download);
|
content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
|
||||||
if (download_item) {
|
save_path);
|
||||||
base::FilePath save_path = download_item->GetSavePath();
|
return true;
|
||||||
if (!save_path.empty()) {
|
|
||||||
callback.Run(save_path,
|
|
||||||
content::DownloadItem::TARGET_DISPOSITION_OVERWRITE,
|
|
||||||
content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
|
|
||||||
save_path);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AtomBrowserContext* browser_context = static_cast<AtomBrowserContext*>(
|
AtomBrowserContext* browser_context = static_cast<AtomBrowserContext*>(
|
||||||
|
|
|
@ -46,6 +46,9 @@ class AtomDownloadManagerDelegate : public content::DownloadManagerDelegate {
|
||||||
void GetNextId(const content::DownloadIdCallback& callback) override;
|
void GetNextId(const content::DownloadIdCallback& callback) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Get the save path set on the associated api::DownloadItem object
|
||||||
|
void GetItemSavePath(content::DownloadItem* item, base::FilePath* path);
|
||||||
|
|
||||||
content::DownloadManager* download_manager_;
|
content::DownloadManager* download_manager_;
|
||||||
base::WeakPtrFactory<AtomDownloadManagerDelegate> weak_ptr_factory_;
|
base::WeakPtrFactory<AtomDownloadManagerDelegate> weak_ptr_factory_;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue