feat: add methods to allow customization of save dialog during will-download event (#15497)

* feat: add method to DownloadItem that allows customization of dialog options

* docs: add docs for get/setSaveDialogOptions

* add missing copy constructor for DialogSettings on mac and linux

* fix: don't filter dialog options for mas build, don't return properties

* test: add test for get/setSaveDialogOptions

* fix: remove openDevtools added for debugging

* test: fix failing test because of new event parameter

* docs: use SaveDialogOptions instead of Object
This commit is contained in:
Heilig Benedek 2018-11-08 15:51:06 +01:00 committed by John Kleinschmidt
parent 673004b878
commit ca2d74e118
13 changed files with 203 additions and 49 deletions

View file

@ -70,6 +70,18 @@ void AtomDownloadManagerDelegate::GetItemSavePath(download::DownloadItem* item,
*path = download->GetSavePath();
}
void AtomDownloadManagerDelegate::GetItemSaveDialogOptions(
download::DownloadItem* item,
file_dialog::DialogSettings* options) {
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)
*options = download->GetSaveDialogOptions();
}
void AtomDownloadManagerDelegate::OnDownloadPathGenerated(
uint32_t download_id,
const content::DownloadTargetCallback& callback,
@ -96,10 +108,14 @@ void AtomDownloadManagerDelegate::OnDownloadPathGenerated(
GetItemSavePath(item, &path);
// Show save dialog if save path was not set already on item
file_dialog::DialogSettings settings;
settings.parent_window = window;
GetItemSaveDialogOptions(item, &settings);
if (!settings.parent_window)
settings.parent_window = window;
settings.force_detached = offscreen;
settings.title = item->GetURL().spec();
settings.default_path = default_path;
if (settings.title.size() == 0)
settings.title = item->GetURL().spec();
if (!settings.default_path.empty())
settings.default_path = default_path;
if (path.empty() && file_dialog::ShowSaveDialog(settings, &path)) {
// Remember the last selected download directory.
AtomBrowserContext* browser_context = static_cast<AtomBrowserContext*>(