| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 } | 467 } |
| 468 | 468 |
| 469 #endif | 469 #endif |
| 470 | 470 |
| 471 } // namespace file_system_api | 471 } // namespace file_system_api |
| 472 | 472 |
| 473 #if defined(OS_CHROMEOS) | 473 #if defined(OS_CHROMEOS) |
| 474 using file_system_api::ConsentProvider; | 474 using file_system_api::ConsentProvider; |
| 475 #endif | 475 #endif |
| 476 | 476 |
| 477 bool FileSystemGetDisplayPathFunction::RunSync() { | 477 ExtensionFunction::ResponseAction FileSystemGetDisplayPathFunction::Run() { |
| 478 std::string filesystem_name; | 478 std::string filesystem_name; |
| 479 std::string filesystem_path; | 479 std::string filesystem_path; |
| 480 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &filesystem_name)); | 480 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &filesystem_name)); |
| 481 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_path)); | 481 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_path)); |
| 482 | 482 |
| 483 base::FilePath file_path; | 483 base::FilePath file_path; |
| 484 std::string error; |
| 484 if (!app_file_handler_util::ValidateFileEntryAndGetPath( | 485 if (!app_file_handler_util::ValidateFileEntryAndGetPath( |
| 485 filesystem_name, filesystem_path, | 486 filesystem_name, filesystem_path, |
| 486 render_frame_host()->GetProcess()->GetID(), &file_path, &error_)) | 487 render_frame_host()->GetProcess()->GetID(), &file_path, &error)) { |
| 487 return false; | 488 return RespondNow(Error(error)); |
| 489 } |
| 488 | 490 |
| 489 file_path = path_util::PrettifyPath(file_path); | 491 file_path = path_util::PrettifyPath(file_path); |
| 490 SetResult(base::MakeUnique<base::StringValue>(file_path.value())); | 492 return RespondNow( |
| 491 return true; | 493 OneArgument(base::MakeUnique<base::StringValue>(file_path.value()))); |
| 492 } | 494 } |
| 493 | 495 |
| 494 FileSystemEntryFunction::FileSystemEntryFunction() | 496 FileSystemEntryFunction::FileSystemEntryFunction() |
| 495 : multiple_(false), is_directory_(false) {} | 497 : multiple_(false), is_directory_(false) {} |
| 496 | 498 |
| 497 void FileSystemEntryFunction::PrepareFilesForWritableApp( | 499 void FileSystemEntryFunction::PrepareFilesForWritableApp( |
| 498 const std::vector<base::FilePath>& paths) { | 500 const std::vector<base::FilePath>& paths) { |
| 499 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 501 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 500 // TODO(cmihail): Path directory set should be initialized only with the | 502 // TODO(cmihail): Path directory set should be initialized only with the |
| 501 // paths that are actually directories, but for now we will consider | 503 // paths that are actually directories, but for now we will consider |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 PrepareFilesForWritableApp(paths); | 606 PrepareFilesForWritableApp(paths); |
| 605 } | 607 } |
| 606 | 608 |
| 607 void FileSystemGetWritableEntryFunction::SetIsDirectoryOnFileThread() { | 609 void FileSystemGetWritableEntryFunction::SetIsDirectoryOnFileThread() { |
| 608 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); | 610 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
| 609 if (base::DirectoryExists(path_)) { | 611 if (base::DirectoryExists(path_)) { |
| 610 is_directory_ = true; | 612 is_directory_ = true; |
| 611 } | 613 } |
| 612 } | 614 } |
| 613 | 615 |
| 614 bool FileSystemIsWritableEntryFunction::RunSync() { | 616 ExtensionFunction::ResponseAction FileSystemIsWritableEntryFunction::Run() { |
| 615 std::string filesystem_name; | 617 std::string filesystem_name; |
| 616 std::string filesystem_path; | 618 std::string filesystem_path; |
| 617 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &filesystem_name)); | 619 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &filesystem_name)); |
| 618 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_path)); | 620 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_path)); |
| 619 | 621 |
| 620 std::string filesystem_id; | 622 std::string filesystem_id; |
| 621 if (!storage::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id)) { | 623 if (!storage::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id)) |
| 622 error_ = app_file_handler_util::kInvalidParameters; | 624 return RespondNow(Error(app_file_handler_util::kInvalidParameters)); |
| 623 return false; | |
| 624 } | |
| 625 | 625 |
| 626 content::ChildProcessSecurityPolicy* policy = | 626 content::ChildProcessSecurityPolicy* policy = |
| 627 content::ChildProcessSecurityPolicy::GetInstance(); | 627 content::ChildProcessSecurityPolicy::GetInstance(); |
| 628 int renderer_id = render_frame_host()->GetProcess()->GetID(); | 628 int renderer_id = render_frame_host()->GetProcess()->GetID(); |
| 629 bool is_writable = policy->CanReadWriteFileSystem(renderer_id, | 629 bool is_writable = policy->CanReadWriteFileSystem(renderer_id, |
| 630 filesystem_id); | 630 filesystem_id); |
| 631 | 631 |
| 632 SetResult(base::MakeUnique<base::FundamentalValue>(is_writable)); | 632 return RespondNow( |
| 633 return true; | 633 OneArgument(base::MakeUnique<base::FundamentalValue>(is_writable))); |
| 634 } | 634 } |
| 635 | 635 |
| 636 // Handles showing a dialog to the user to ask for the filename for a file to | 636 // Handles showing a dialog to the user to ask for the filename for a file to |
| 637 // save or open. | 637 // save or open. |
| 638 class FileSystemChooseEntryFunction::FilePicker | 638 class FileSystemChooseEntryFunction::FilePicker |
| 639 : public ui::SelectFileDialog::Listener { | 639 : public ui::SelectFileDialog::Listener { |
| 640 public: | 640 public: |
| 641 FilePicker(FileSystemChooseEntryFunction* function, | 641 FilePicker(FileSystemChooseEntryFunction* function, |
| 642 content::WebContents* web_contents, | 642 content::WebContents* web_contents, |
| 643 const base::FilePath& suggested_name, | 643 const base::FilePath& suggested_name, |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1185 return; | 1185 return; |
| 1186 } | 1186 } |
| 1187 | 1187 |
| 1188 SavedFilesService* saved_files_service = SavedFilesService::Get(GetProfile()); | 1188 SavedFilesService* saved_files_service = SavedFilesService::Get(GetProfile()); |
| 1189 saved_files_service->RegisterFileEntry( | 1189 saved_files_service->RegisterFileEntry( |
| 1190 extension_->id(), entry_id, path, file_info->is_directory); | 1190 extension_->id(), entry_id, path, file_info->is_directory); |
| 1191 saved_files_service->EnqueueFileEntry(extension_->id(), entry_id); | 1191 saved_files_service->EnqueueFileEntry(extension_->id(), entry_id); |
| 1192 SendResponse(true); | 1192 SendResponse(true); |
| 1193 } | 1193 } |
| 1194 | 1194 |
| 1195 bool FileSystemIsRestorableFunction::RunSync() { | 1195 ExtensionFunction::ResponseAction FileSystemIsRestorableFunction::Run() { |
| 1196 std::string entry_id; | 1196 std::string entry_id; |
| 1197 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &entry_id)); | 1197 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &entry_id)); |
| 1198 SetResult(base::MakeUnique<base::FundamentalValue>( | 1198 return RespondNow(OneArgument(base::MakeUnique<base::FundamentalValue>( |
| 1199 SavedFilesService::Get(GetProfile()) | 1199 SavedFilesService::Get(Profile::FromBrowserContext(browser_context())) |
| 1200 ->IsRegistered(extension_->id(), entry_id))); | 1200 ->IsRegistered(extension_->id(), entry_id)))); |
| 1201 return true; | |
| 1202 } | 1201 } |
| 1203 | 1202 |
| 1204 bool FileSystemRestoreEntryFunction::RunAsync() { | 1203 bool FileSystemRestoreEntryFunction::RunAsync() { |
| 1205 std::string entry_id; | 1204 std::string entry_id; |
| 1206 bool needs_new_entry; | 1205 bool needs_new_entry; |
| 1207 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &entry_id)); | 1206 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &entry_id)); |
| 1208 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &needs_new_entry)); | 1207 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &needs_new_entry)); |
| 1209 const SavedFileEntry* file_entry = SavedFilesService::Get( | 1208 const SavedFileEntry* file_entry = SavedFilesService::Get( |
| 1210 GetProfile())->GetFileEntry(extension_->id(), entry_id); | 1209 GetProfile())->GetFileEntry(extension_->id(), entry_id); |
| 1211 if (!file_entry) { | 1210 if (!file_entry) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1222 if (needs_new_entry) { | 1221 if (needs_new_entry) { |
| 1223 is_directory_ = file_entry->is_directory; | 1222 is_directory_ = file_entry->is_directory; |
| 1224 std::unique_ptr<base::DictionaryValue> result = CreateResult(); | 1223 std::unique_ptr<base::DictionaryValue> result = CreateResult(); |
| 1225 AddEntryToResult(file_entry->path, file_entry->id, result.get()); | 1224 AddEntryToResult(file_entry->path, file_entry->id, result.get()); |
| 1226 SetResult(std::move(result)); | 1225 SetResult(std::move(result)); |
| 1227 } | 1226 } |
| 1228 SendResponse(true); | 1227 SendResponse(true); |
| 1229 return true; | 1228 return true; |
| 1230 } | 1229 } |
| 1231 | 1230 |
| 1232 bool FileSystemObserveDirectoryFunction::RunSync() { | 1231 ExtensionFunction::ResponseAction FileSystemObserveDirectoryFunction::Run() { |
| 1233 NOTIMPLEMENTED(); | 1232 NOTIMPLEMENTED(); |
| 1234 error_ = kUnknownIdError; | 1233 return RespondNow(Error(kUnknownIdError)); |
| 1235 return false; | |
| 1236 } | 1234 } |
| 1237 | 1235 |
| 1238 bool FileSystemUnobserveEntryFunction::RunSync() { | 1236 ExtensionFunction::ResponseAction FileSystemUnobserveEntryFunction::Run() { |
| 1239 NOTIMPLEMENTED(); | 1237 NOTIMPLEMENTED(); |
| 1240 error_ = kUnknownIdError; | 1238 return RespondNow(Error(kUnknownIdError)); |
| 1241 return false; | |
| 1242 } | 1239 } |
| 1243 | 1240 |
| 1244 bool FileSystemGetObservedEntriesFunction::RunSync() { | 1241 ExtensionFunction::ResponseAction FileSystemGetObservedEntriesFunction::Run() { |
| 1245 NOTIMPLEMENTED(); | 1242 NOTIMPLEMENTED(); |
| 1246 error_ = kUnknownIdError; | 1243 return RespondNow(Error(kUnknownIdError)); |
| 1247 return false; | |
| 1248 } | 1244 } |
| 1249 | 1245 |
| 1250 #if !defined(OS_CHROMEOS) | 1246 #if !defined(OS_CHROMEOS) |
| 1251 ExtensionFunction::ResponseAction FileSystemRequestFileSystemFunction::Run() { | 1247 ExtensionFunction::ResponseAction FileSystemRequestFileSystemFunction::Run() { |
| 1252 using api::file_system::RequestFileSystem::Params; | 1248 using api::file_system::RequestFileSystem::Params; |
| 1253 const std::unique_ptr<Params> params(Params::Create(*args_)); | 1249 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 1254 EXTENSION_FUNCTION_VALIDATE(params); | 1250 EXTENSION_FUNCTION_VALIDATE(params); |
| 1255 | 1251 |
| 1256 NOTIMPLEMENTED(); | 1252 NOTIMPLEMENTED(); |
| 1257 return RespondNow(Error(kNotSupportedOnCurrentPlatformError)); | 1253 return RespondNow(Error(kNotSupportedOnCurrentPlatformError)); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1446 return RespondNow(Error(kNotSupportedOnNonKioskSessionError)); | 1442 return RespondNow(Error(kNotSupportedOnNonKioskSessionError)); |
| 1447 std::vector<api::file_system::Volume> result_volume_list; | 1443 std::vector<api::file_system::Volume> result_volume_list; |
| 1448 FillVolumeList(chrome_details_.GetProfile(), &result_volume_list); | 1444 FillVolumeList(chrome_details_.GetProfile(), &result_volume_list); |
| 1449 | 1445 |
| 1450 return RespondNow(ArgumentList( | 1446 return RespondNow(ArgumentList( |
| 1451 api::file_system::GetVolumeList::Results::Create(result_volume_list))); | 1447 api::file_system::GetVolumeList::Results::Create(result_volume_list))); |
| 1452 } | 1448 } |
| 1453 #endif | 1449 #endif |
| 1454 | 1450 |
| 1455 } // namespace extensions | 1451 } // namespace extensions |
| OLD | NEW |