OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/api/file_system/file_system_api.h" | 5 #include "chrome/browser/extensions/api/file_system/file_system_api.h" |
6 | 6 |
7 #include "apps/saved_files_service.h" | 7 #include "apps/saved_files_service.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 namespace file_system = extensions::api::file_system; | 66 namespace file_system = extensions::api::file_system; |
67 namespace ChooseEntry = file_system::ChooseEntry; | 67 namespace ChooseEntry = file_system::ChooseEntry; |
68 | 68 |
69 namespace { | 69 namespace { |
70 | 70 |
71 const int kBlacklistedPaths[] = { | 71 const int kBlacklistedPaths[] = { |
72 chrome::DIR_APP, | 72 chrome::DIR_APP, |
73 chrome::DIR_USER_DATA, | 73 chrome::DIR_USER_DATA, |
74 }; | 74 }; |
75 | 75 |
| 76 #if defined(OS_CHROMEOS) |
| 77 // On Chrome OS, the default downloads directory is a subdirectory of user data |
| 78 // directory, and should be whitelisted. |
| 79 const int kWhitelistedPaths[] = { |
| 80 chrome::DIR_DEFAULT_DOWNLOADS_SAFE, |
| 81 }; |
| 82 #endif |
| 83 |
76 #if defined(OS_MACOSX) | 84 #if defined(OS_MACOSX) |
77 // Retrieves the localized display name for the base name of the given path. | 85 // Retrieves the localized display name for the base name of the given path. |
78 // If the path is not localized, this will just return the base name. | 86 // If the path is not localized, this will just return the base name. |
79 std::string GetDisplayBaseName(const base::FilePath& path) { | 87 std::string GetDisplayBaseName(const base::FilePath& path) { |
80 base::mac::ScopedCFTypeRef<CFURLRef> url( | 88 base::mac::ScopedCFTypeRef<CFURLRef> url( |
81 CFURLCreateFromFileSystemRepresentation( | 89 CFURLCreateFromFileSystemRepresentation( |
82 NULL, | 90 NULL, |
83 (const UInt8*)path.value().c_str(), | 91 (const UInt8*)path.value().c_str(), |
84 path.value().length(), | 92 path.value().length(), |
85 true)); | 93 true)); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 212 |
205 bool DoCheckWritableFile(const base::FilePath& path, | 213 bool DoCheckWritableFile(const base::FilePath& path, |
206 const base::FilePath& extension_directory) { | 214 const base::FilePath& extension_directory) { |
207 // Don't allow links. | 215 // Don't allow links. |
208 if (file_util::PathExists(path) && file_util::IsLink(path)) | 216 if (file_util::PathExists(path) && file_util::IsLink(path)) |
209 return false; | 217 return false; |
210 | 218 |
211 if (extension_directory == path || extension_directory.IsParent(path)) | 219 if (extension_directory == path || extension_directory.IsParent(path)) |
212 return false; | 220 return false; |
213 | 221 |
214 for (size_t i = 0; i < arraysize(kBlacklistedPaths); i++) { | 222 bool is_whitelisted_path = false; |
215 base::FilePath blacklisted_path; | 223 |
216 if (PathService::Get(kBlacklistedPaths[i], &blacklisted_path) && | 224 #if defined(OS_CHROMEOS) |
217 (blacklisted_path == path || blacklisted_path.IsParent(path))) { | 225 for (size_t i = 0; i < arraysize(kWhitelistedPaths); i++) { |
218 return false; | 226 base::FilePath whitelisted_path; |
| 227 if (PathService::Get(kWhitelistedPaths[i], &whitelisted_path) && |
| 228 (whitelisted_path == path || whitelisted_path.IsParent(path))) { |
| 229 is_whitelisted_path = true; |
| 230 break; |
| 231 } |
| 232 } |
| 233 #endif |
| 234 |
| 235 if (!is_whitelisted_path) { |
| 236 for (size_t i = 0; i < arraysize(kBlacklistedPaths); i++) { |
| 237 base::FilePath blacklisted_path; |
| 238 if (PathService::Get(kBlacklistedPaths[i], &blacklisted_path) && |
| 239 (blacklisted_path == path || blacklisted_path.IsParent(path))) { |
| 240 return false; |
| 241 } |
219 } | 242 } |
220 } | 243 } |
221 | 244 |
222 // Create the file if it doesn't already exist. | 245 // Create the file if it doesn't already exist. |
223 base::PlatformFileError error = base::PLATFORM_FILE_OK; | 246 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
224 int creation_flags = base::PLATFORM_FILE_CREATE | | 247 int creation_flags = base::PLATFORM_FILE_CREATE | |
225 base::PLATFORM_FILE_READ | | 248 base::PLATFORM_FILE_READ | |
226 base::PLATFORM_FILE_WRITE; | 249 base::PLATFORM_FILE_WRITE; |
227 base::PlatformFile file = base::CreatePlatformFile(path, creation_flags, | 250 base::PlatformFile file = base::CreatePlatformFile(path, creation_flags, |
228 NULL, &error); | 251 NULL, &error); |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 // ID that was passed to restoreEntry. | 841 // ID that was passed to restoreEntry. |
819 RegisterFileSystemAndSendResponseWithIdOverride( | 842 RegisterFileSystemAndSendResponseWithIdOverride( |
820 file_entry->path, | 843 file_entry->path, |
821 file_entry->writable ? WRITABLE : READ_ONLY, | 844 file_entry->writable ? WRITABLE : READ_ONLY, |
822 file_entry->id); | 845 file_entry->id); |
823 } | 846 } |
824 return true; | 847 return true; |
825 } | 848 } |
826 | 849 |
827 } // namespace extensions | 850 } // namespace extensions |
OLD | NEW |