| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 std::string filesystem_path; | 143 std::string filesystem_path; |
| 144 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &filesystem_name)); | 144 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &filesystem_name)); |
| 145 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_path)); | 145 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_path)); |
| 146 | 146 |
| 147 FilePath file_path; | 147 FilePath file_path; |
| 148 if (!GetFilePathOfFileEntry(filesystem_name, filesystem_path, | 148 if (!GetFilePathOfFileEntry(filesystem_name, filesystem_path, |
| 149 render_view_host_, &file_path, &error_)) | 149 render_view_host_, &file_path, &error_)) |
| 150 return false; | 150 return false; |
| 151 | 151 |
| 152 file_path = PrettifyPath(file_path); | 152 file_path = PrettifyPath(file_path); |
| 153 result_.reset(base::Value::CreateStringValue(file_path.value())); | 153 SetResult(base::Value::CreateStringValue(file_path.value())); |
| 154 return true; | 154 return true; |
| 155 } | 155 } |
| 156 | 156 |
| 157 bool FileSystemEntryFunction::HasFileSystemWritePermission() { | 157 bool FileSystemEntryFunction::HasFileSystemWritePermission() { |
| 158 const extensions::Extension* extension = GetExtension(); | 158 const extensions::Extension* extension = GetExtension(); |
| 159 if (!extension) | 159 if (!extension) |
| 160 return false; | 160 return false; |
| 161 | 161 |
| 162 return extension->HasAPIPermission(APIPermission::kFileSystemWrite); | 162 return extension->HasAPIPermission(APIPermission::kFileSystemWrite); |
| 163 } | 163 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 else | 195 else |
| 196 policy->GrantReadFileSystem(renderer_id, filesystem_id); | 196 policy->GrantReadFileSystem(renderer_id, filesystem_id); |
| 197 | 197 |
| 198 // We only need file level access for reading FileEntries. Saving FileEntries | 198 // We only need file level access for reading FileEntries. Saving FileEntries |
| 199 // just needs the file system to have read/write access, which is granted | 199 // just needs the file system to have read/write access, which is granted |
| 200 // above if required. | 200 // above if required. |
| 201 if (!policy->CanReadFile(renderer_id, path)) | 201 if (!policy->CanReadFile(renderer_id, path)) |
| 202 policy->GrantReadFile(renderer_id, path); | 202 policy->GrantReadFile(renderer_id, path); |
| 203 | 203 |
| 204 DictionaryValue* dict = new DictionaryValue(); | 204 DictionaryValue* dict = new DictionaryValue(); |
| 205 result_.reset(dict); | 205 SetResult(dict); |
| 206 dict->SetString("fileSystemId", filesystem_id); | 206 dict->SetString("fileSystemId", filesystem_id); |
| 207 dict->SetString("baseName", registered_name); | 207 dict->SetString("baseName", registered_name); |
| 208 SendResponse(true); | 208 SendResponse(true); |
| 209 } | 209 } |
| 210 | 210 |
| 211 void FileSystemEntryFunction::HandleWritableFileError() { | 211 void FileSystemEntryFunction::HandleWritableFileError() { |
| 212 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 212 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 213 error_ = kWritableFileError; | 213 error_ = kWritableFileError; |
| 214 SendResponse(false); | 214 SendResponse(false); |
| 215 } | 215 } |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 | 391 |
| 392 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { | 392 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { |
| 393 error_ = kRequiresFileSystemWriteError; | 393 error_ = kRequiresFileSystemWriteError; |
| 394 return false; | 394 return false; |
| 395 } | 395 } |
| 396 | 396 |
| 397 return ShowPicker(FilePath(), picker_type, entry_type); | 397 return ShowPicker(FilePath(), picker_type, entry_type); |
| 398 } | 398 } |
| 399 | 399 |
| 400 } // namespace extensions | 400 } // namespace extensions |
| OLD | NEW |