Commit dc881dc0 authored by hshi@chromium.org's avatar hshi@chromium.org

File system API: whitelist the Downloads dir on Chrome OS.

Due to crrev.com/203393 we now blacklist the user data dir in
DoCheckWritableFile(). However, on Chrome OS the user Downloads
folder (~/Downloads) is a subdirectory of the user data dir and
serves the role of local storage. This should be writable for
file system API.

BUG=246339
TEST=verified Downloads folder is writable by v2 apps on Chrome OS.

Review URL: https://chromiumcodereview.appspot.com/15896035

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@203919 0039d316-1c4b-4281-b951-d872f2087c98
parent 719fbaa3
......@@ -73,6 +73,14 @@ const int kBlacklistedPaths[] = {
chrome::DIR_USER_DATA,
};
#if defined(OS_CHROMEOS)
// On Chrome OS, the default downloads directory is a subdirectory of user data
// directory, and should be whitelisted.
const int kWhitelistedPaths[] = {
chrome::DIR_DEFAULT_DOWNLOADS_SAFE,
};
#endif
#if defined(OS_MACOSX)
// Retrieves the localized display name for the base name of the given path.
// If the path is not localized, this will just return the base name.
......@@ -211,11 +219,26 @@ bool DoCheckWritableFile(const base::FilePath& path,
if (extension_directory == path || extension_directory.IsParent(path))
return false;
for (size_t i = 0; i < arraysize(kBlacklistedPaths); i++) {
base::FilePath blacklisted_path;
if (PathService::Get(kBlacklistedPaths[i], &blacklisted_path) &&
(blacklisted_path == path || blacklisted_path.IsParent(path))) {
return false;
bool is_whitelisted_path = false;
#if defined(OS_CHROMEOS)
for (size_t i = 0; i < arraysize(kWhitelistedPaths); i++) {
base::FilePath whitelisted_path;
if (PathService::Get(kWhitelistedPaths[i], &whitelisted_path) &&
(whitelisted_path == path || whitelisted_path.IsParent(path))) {
is_whitelisted_path = true;
break;
}
}
#endif
if (!is_whitelisted_path) {
for (size_t i = 0; i < arraysize(kBlacklistedPaths); i++) {
base::FilePath blacklisted_path;
if (PathService::Get(kBlacklistedPaths[i], &blacklisted_path) &&
(blacklisted_path == path || blacklisted_path.IsParent(path))) {
return false;
}
}
}
......
......@@ -454,6 +454,24 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
"api_test/file_system/open_writable_existing_non_writable")) << message_;
}
#if defined(OS_CHROMEOS)
// In Chrome OS the download directory is whitelisted for write.
IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
FileSystemApiOpenInDownloadDirForWrite) {
base::FilePath test_file =
base::MakeAbsoluteFilePath(TempFilePath("writable.txt", true));
ASSERT_FALSE(test_file.empty());
ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
chrome::DIR_USER_DATA, test_file.DirName(), false));
ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
chrome::DIR_DEFAULT_DOWNLOADS_SAFE, test_file.DirName(), false));
FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
&test_file);
ASSERT_TRUE(RunPlatformAppTest(
"api_test/file_system/is_writable_file_entry")) << message_;
}
#endif
IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
FileSystemApiOpenInChromeDirForWrite) {
base::FilePath test_file =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment