|
@@ -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(
|
|
|
const GURL& url,
|
|
|
const std::string& content_disposition,
|
|
@@ -77,9 +88,12 @@ void AtomDownloadManagerDelegate::OnDownloadPathGenerated(
|
|
|
window = relay->window.get();
|
|
|
|
|
|
base::FilePath path;
|
|
|
- if (file_dialog::ShowSaveDialog(window, item->GetURL().spec(),
|
|
|
- "", default_path,
|
|
|
- file_dialog::Filters(), &path)) {
|
|
|
+ GetItemSavePath(item, &path);
|
|
|
+ // Show save dialog if save path was not set already on item
|
|
|
+ if (path.empty() && file_dialog::ShowSaveDialog(window, item->GetURL().spec(),
|
|
|
+ "", default_path,
|
|
|
+ file_dialog::Filters(),
|
|
|
+ &path)) {
|
|
|
// Remember the last selected download directory.
|
|
|
AtomBrowserContext* browser_context = static_cast<AtomBrowserContext*>(
|
|
|
download_manager_->GetBrowserContext());
|
|
@@ -122,22 +136,14 @@ bool AtomDownloadManagerDelegate::DetermineDownloadTarget(
|
|
|
}
|
|
|
|
|
|
// Try to get the save path from JS wrapper.
|
|
|
- {
|
|
|
- v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
|
|
- v8::Locker locker(isolate);
|
|
|
- v8::HandleScope handle_scope(isolate);
|
|
|
- api::DownloadItem* download_item = api::DownloadItem::FromWrappedClass(
|
|
|
- isolate, download);
|
|
|
- if (download_item) {
|
|
|
- base::FilePath save_path = download_item->GetSavePath();
|
|
|
- if (!save_path.empty()) {
|
|
|
- callback.Run(save_path,
|
|
|
- content::DownloadItem::TARGET_DISPOSITION_OVERWRITE,
|
|
|
- content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
|
|
|
- save_path);
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
+ base::FilePath save_path;
|
|
|
+ GetItemSavePath(download, &save_path);
|
|
|
+ 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*>(
|