]> khamidou — GitHub mirrors - electron.git/commitdiff
Allow emitting 'done' event when user cancel the download saving dialog.
authorHaojian Wu <hokein.wu@gmail.com>
Mon, 21 Sep 2015 06:03:36 +0000 (14:03 +0800)
committerHaojian Wu <hokein.wu@gmail.com>
Mon, 21 Sep 2015 13:44:18 +0000 (21:44 +0800)
atom/browser/atom_download_manager_delegate.cc

index 7cc2c171459639a28f6c74233fe8d7df59ab9415..88daec2f4623e61ecff1de27b825d217cfbd726d 100644 (file)
@@ -75,20 +75,24 @@ void AtomDownloadManagerDelegate::OnDownloadPathGenerated(
     window = relay->window.get();
 
   file_dialog::Filters filters;
-  base::FilePath path = default_path;
-  if (open_download_dialog_ &&
-      !file_dialog::ShowSaveDialog(window, item->GetURL().spec(), default_path,
-                                   filters, &path)) {
-    return;
+  base::FilePath path;
+  if (!open_download_dialog_) {
+    // Use default_path if download dialog is disabled.
+    path = default_path;
+  } else {
+    if (file_dialog::ShowSaveDialog(window, item->GetURL().spec(), default_path,
+                                    filters, &path)) {
+      // Remember the last selected download directory.
+      AtomBrowserContext* browser_context = static_cast<AtomBrowserContext*>(
+          download_manager_->GetBrowserContext());
+      browser_context->prefs()->SetFilePath(prefs::kDownloadDefaultDirectory,
+                                            path.DirName());
+    }
   }
 
-  if (open_download_dialog_) {
-    // Remeber the last selected download directory.
-    AtomBrowserContext* browser_context = static_cast<AtomBrowserContext*>(
-        download_manager_->GetBrowserContext());
-    browser_context->prefs()->SetFilePath(prefs::kDownloadDefaultDirectory,
-                                          path.DirName());
-  }
+  // Running the DownloadTargetCallback with an empty FilePath signals that the
+  // download should be cancelled.
+  // If user cancels the file save dialog, run the callback with empty FilePath.
   callback.Run(path,
                content::DownloadItem::TARGET_DISPOSITION_PROMPT,
                content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, path);