Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
Using DIR_DEFAULT_DOWNLOADS_SAFE when DIR_DEFAULT_DOWNLOADS got home
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdh committed Feb 23, 2018
1 parent 82d523c commit 588042a
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion atom/browser/api/atom_api_dialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ struct Converter<file_dialog::DialogSettings> {

namespace {

// Consider downloads 'dangerous' if they go to the home directory on Linux and
// to the desktop on any platform.
bool DownloadPathIsDangerous(const base::FilePath& download_path) {
#if defined(OS_LINUX)
base::FilePath home_dir = base::GetHomeDir();
if (download_path == home_dir) {
return true;
}
#endif
base::FilePath desktop_dir;
if (!PathService::Get(base::DIR_USER_DESKTOP, &desktop_dir)) {
NOTREACHED();
return false;
}
return (download_path == desktop_dir);
}

void ShowMessageBox(int type,
const std::vector<std::string>& buttons,
int default_id,
Expand Down Expand Up @@ -151,7 +168,16 @@ void ShowDialog(const file_dialog::DialogSettings& settings,

base::FilePath default_path = settings.default_path;
if (default_path.empty()) {
PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &default_path);
if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &default_path)) {
NOTREACHED();
}
}
if (DownloadPathIsDangerous(default_path)) {
// This is only useful on platforms that support
// DIR_DEFAULT_DOWNLOADS_SAFE.
if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS_SAFE, &default_path)) {
NOTREACHED();
}
}
file_type_info.include_all_files = settings.include_all_files;
file_type_info.extension_description_overrides =
Expand Down

0 comments on commit 588042a

Please sign in to comment.