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

Commit

Permalink
DROPME - Merge pull request #508 from brave/browser-laptop-issue-13229
Browse files Browse the repository at this point in the history
Using `DIR_DEFAULT_DOWNLOADS_SAFE`
  • Loading branch information
bsclifton committed Mar 1, 2018
1 parent d9484d7 commit 8611af9
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion atom/browser/api/atom_api_dialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "atom/common/native_mate_converters/file_path_converter.h"
#include "atom/common/native_mate_converters/image_converter.h"
#include "base/bind.h"
#include "base/files/file_util.h"
#include "base/path_service.h"
#include "chrome/browser/extensions/api/file_system/file_entry_picker.h"
#include "chrome/common/chrome_paths.h"
Expand Down Expand Up @@ -86,6 +87,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 +169,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 8611af9

Please sign in to comment.