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 "chrome/browser/extensions/shell_window_registry.h" | 10 #include "chrome/browser/extensions/shell_window_registry.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 std::string filesystem_name; | 100 std::string filesystem_name; |
101 std::string filesystem_path; | 101 std::string filesystem_path; |
102 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &filesystem_name)); | 102 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &filesystem_name)); |
103 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_path)); | 103 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_path)); |
104 | 104 |
105 FilePath file_path; | 105 FilePath file_path; |
106 if (!GetFilePathOfFileEntry(filesystem_name, filesystem_path, | 106 if (!GetFilePathOfFileEntry(filesystem_name, filesystem_path, |
107 render_view_host_, &file_path, &error_)) | 107 render_view_host_, &file_path, &error_)) |
108 return false; | 108 return false; |
109 | 109 |
110 result_.reset(base::Value::CreateStringValue(file_path.value())); | 110 SetSingleResult(base::Value::CreateStringValue(file_path.value())); |
111 return true; | 111 return true; |
112 } | 112 } |
113 | 113 |
114 bool FileSystemEntryFunction::HasFileSystemWritePermission() { | 114 bool FileSystemEntryFunction::HasFileSystemWritePermission() { |
115 const extensions::Extension* extension = GetExtension(); | 115 const extensions::Extension* extension = GetExtension(); |
116 if (!extension) | 116 if (!extension) |
117 return false; | 117 return false; |
118 | 118 |
119 return extension->HasAPIPermission(APIPermission::kFileSystemWrite); | 119 return extension->HasAPIPermission(APIPermission::kFileSystemWrite); |
120 } | 120 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 else | 152 else |
153 policy->GrantReadFileSystem(renderer_id, filesystem_id); | 153 policy->GrantReadFileSystem(renderer_id, filesystem_id); |
154 | 154 |
155 // We only need file level access for reading FileEntries. Saving FileEntries | 155 // We only need file level access for reading FileEntries. Saving FileEntries |
156 // just needs the file system to have read/write access, which is granted | 156 // just needs the file system to have read/write access, which is granted |
157 // above if required. | 157 // above if required. |
158 if (!policy->CanReadFile(renderer_id, path)) | 158 if (!policy->CanReadFile(renderer_id, path)) |
159 policy->GrantReadFile(renderer_id, path); | 159 policy->GrantReadFile(renderer_id, path); |
160 | 160 |
161 DictionaryValue* dict = new DictionaryValue(); | 161 DictionaryValue* dict = new DictionaryValue(); |
162 result_.reset(dict); | 162 SetSingleResult(dict); |
163 dict->SetString("fileSystemId", filesystem_id); | 163 dict->SetString("fileSystemId", filesystem_id); |
164 dict->SetString("baseName", path.BaseName().AsUTF8Unsafe()); | 164 dict->SetString("baseName", path.BaseName().AsUTF8Unsafe()); |
165 SendResponse(true); | 165 SendResponse(true); |
166 } | 166 } |
167 | 167 |
168 void FileSystemEntryFunction::HandleWritableFileError() { | 168 void FileSystemEntryFunction::HandleWritableFileError() { |
169 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 169 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
170 error_ = kWritableFileError; | 170 error_ = kWritableFileError; |
171 SendResponse(false); | 171 SendResponse(false); |
172 } | 172 } |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 | 348 |
349 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { | 349 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { |
350 error_ = kRequiresFileSystemWriteError; | 350 error_ = kRequiresFileSystemWriteError; |
351 return false; | 351 return false; |
352 } | 352 } |
353 | 353 |
354 return ShowPicker(FilePath(), picker_type, entry_type); | 354 return ShowPicker(FilePath(), picker_type, entry_type); |
355 } | 355 } |
356 | 356 |
357 } // namespace extensions | 357 } // namespace extensions |
OLD | NEW |