Chromium Code Reviews| 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_handlers/app_file_handler_util.h" | 5 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "chrome/browser/extensions/extension_prefs.h" | 9 #include "chrome/browser/extensions/extension_prefs.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 return true; | 57 return true; |
| 58 } | 58 } |
| 59 return false; | 59 return false; |
| 60 } | 60 } |
| 61 | 61 |
| 62 bool DoCheckWritableFile(const base::FilePath& path) { | 62 bool DoCheckWritableFile(const base::FilePath& path) { |
| 63 // Don't allow links. | 63 // Don't allow links. |
| 64 if (base::PathExists(path) && file_util::IsLink(path)) | 64 if (base::PathExists(path) && file_util::IsLink(path)) |
| 65 return false; | 65 return false; |
| 66 | 66 |
| 67 if (base::DirectoryExists(path)) | |
| 68 return base::PathIsWritable(path); | |
|
Matt Giuca
2013/08/27 04:30:53
Do you handle the case of trying to write to a fil
Sam McNally
2013/08/27 05:16:37
That would cause getFile/getDirectory to fail in t
| |
| 69 | |
| 67 // Create the file if it doesn't already exist. | 70 // Create the file if it doesn't already exist. |
| 68 base::PlatformFileError error = base::PLATFORM_FILE_OK; | 71 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
| 69 int creation_flags = base::PLATFORM_FILE_CREATE | | 72 int creation_flags = base::PLATFORM_FILE_CREATE | |
| 70 base::PLATFORM_FILE_READ | | 73 base::PLATFORM_FILE_READ | |
| 71 base::PLATFORM_FILE_WRITE; | 74 base::PLATFORM_FILE_WRITE; |
| 72 base::PlatformFile file = base::CreatePlatformFile(path, creation_flags, | 75 base::PlatformFile file = base::CreatePlatformFile(path, creation_flags, |
| 73 NULL, &error); | 76 NULL, &error); |
| 74 // Close the file so we don't keep a lock open. | 77 // Close the file so we don't keep a lock open. |
| 75 if (file != base::kInvalidPlatformFileValue) | 78 if (file != base::kInvalidPlatformFileValue) |
| 76 base::ClosePlatformFile(file); | 79 base::ClosePlatformFile(file); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 const std::string& mime_type, | 286 const std::string& mime_type, |
| 284 const base::FilePath& path) { | 287 const base::FilePath& path) { |
| 285 return FileHandlerCanHandleFileWithMimeType(handler, mime_type) || | 288 return FileHandlerCanHandleFileWithMimeType(handler, mime_type) || |
| 286 FileHandlerCanHandleFileWithExtension(handler, path); | 289 FileHandlerCanHandleFileWithExtension(handler, path); |
| 287 } | 290 } |
| 288 | 291 |
| 289 GrantedFileEntry CreateFileEntry( | 292 GrantedFileEntry CreateFileEntry( |
| 290 Profile* profile, | 293 Profile* profile, |
| 291 const Extension* extension, | 294 const Extension* extension, |
| 292 int renderer_id, | 295 int renderer_id, |
| 293 const base::FilePath& path) { | 296 const base::FilePath& path, |
| 297 bool is_directory) { | |
| 294 GrantedFileEntry result; | 298 GrantedFileEntry result; |
| 295 fileapi::IsolatedContext* isolated_context = | 299 fileapi::IsolatedContext* isolated_context = |
| 296 fileapi::IsolatedContext::GetInstance(); | 300 fileapi::IsolatedContext::GetInstance(); |
| 297 DCHECK(isolated_context); | 301 DCHECK(isolated_context); |
| 298 | 302 |
| 299 result.filesystem_id = isolated_context->RegisterFileSystemForPath( | 303 result.filesystem_id = isolated_context->RegisterFileSystemForPath( |
| 300 fileapi::kFileSystemTypeNativeForPlatformApp, path, | 304 fileapi::kFileSystemTypeNativeForPlatformApp, path, |
| 301 &result.registered_name); | 305 &result.registered_name); |
| 302 | 306 |
| 303 content::ChildProcessSecurityPolicy* policy = | 307 content::ChildProcessSecurityPolicy* policy = |
| 304 content::ChildProcessSecurityPolicy::GetInstance(); | 308 content::ChildProcessSecurityPolicy::GetInstance(); |
| 305 policy->GrantReadFileSystem(renderer_id, result.filesystem_id); | 309 policy->GrantReadFileSystem(renderer_id, result.filesystem_id); |
| 306 if (HasFileSystemWritePermission(extension)) | 310 if (HasFileSystemWritePermission(extension)) { |
| 307 policy->GrantWriteFileSystem(renderer_id, result.filesystem_id); | 311 policy->GrantWriteFileSystem(renderer_id, result.filesystem_id); |
| 312 if (is_directory) | |
| 313 policy->GrantCreateFileForFileSystem(renderer_id, result.filesystem_id); | |
| 314 } | |
| 308 | 315 |
| 309 result.id = result.filesystem_id + ":" + result.registered_name; | 316 result.id = result.filesystem_id + ":" + result.registered_name; |
| 310 return result; | 317 return result; |
| 311 } | 318 } |
| 312 | 319 |
| 313 void CheckWritableFiles( | 320 void CheckWritableFiles( |
| 314 const std::vector<base::FilePath>& paths, | 321 const std::vector<base::FilePath>& paths, |
| 315 Profile* profile, | 322 Profile* profile, |
| 316 const base::Closure& on_success, | 323 const base::Closure& on_success, |
| 317 const base::Callback<void(const base::FilePath&)>& on_failure) { | 324 const base::Callback<void(const base::FilePath&)>& on_failure) { |
| 318 scoped_refptr<WritableFileChecker> checker( | 325 scoped_refptr<WritableFileChecker> checker( |
| 319 new WritableFileChecker(paths, profile, on_success, on_failure)); | 326 new WritableFileChecker(paths, profile, on_success, on_failure)); |
| 320 checker->Check(); | 327 checker->Check(); |
| 321 } | 328 } |
| 322 | 329 |
| 330 GrantedFileEntry::GrantedFileEntry() {} | |
| 331 | |
| 323 bool HasFileSystemWritePermission(const Extension* extension) { | 332 bool HasFileSystemWritePermission(const Extension* extension) { |
| 324 return extension->HasAPIPermission(APIPermission::kFileSystemWrite); | 333 return extension->HasAPIPermission(APIPermission::kFileSystemWrite); |
| 325 } | 334 } |
| 326 | 335 |
| 327 } // namespace app_file_handler_util | 336 } // namespace app_file_handler_util |
| 328 | 337 |
| 329 } // namespace extensions | 338 } // namespace extensions |
| OLD | NEW |