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/developer_private/developer_private_api. h" | 5 #include "chrome/browser/extensions/api/developer_private/developer_private_api. h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 #include "webkit/fileapi/file_system_context.h" | 49 #include "webkit/fileapi/file_system_context.h" |
| 50 #include "webkit/fileapi/file_system_operation.h" | 50 #include "webkit/fileapi/file_system_operation.h" |
| 51 #include "webkit/fileapi/syncable/syncable_file_system_util.h" | 51 #include "webkit/fileapi/syncable/syncable_file_system_util.h" |
| 52 | 52 |
| 53 using content::RenderViewHost; | 53 using content::RenderViewHost; |
| 54 | 54 |
| 55 namespace extensions { | 55 namespace extensions { |
| 56 | 56 |
| 57 namespace { | 57 namespace { |
| 58 | 58 |
| 59 char kUnpackedAppsFolder[] = "apps_target"; | |
| 60 | |
| 59 ExtensionUpdater* GetExtensionUpdater(Profile* profile) { | 61 ExtensionUpdater* GetExtensionUpdater(Profile* profile) { |
| 60 return profile->GetExtensionService()->updater(); | 62 return profile->GetExtensionService()->updater(); |
| 61 } | 63 } |
| 62 | 64 |
| 63 GURL ToDataURL(const base::FilePath& path) { | 65 GURL ToDataURL(const base::FilePath& path) { |
| 64 std::string contents; | 66 std::string contents; |
| 65 if (!file_util::ReadFileToString(path, &contents)) | 67 if (!file_util::ReadFileToString(path, &contents)) |
| 66 return GURL(); | 68 return GURL(); |
| 67 | 69 |
| 68 std::string contents_base64; | 70 std::string contents_base64; |
| (...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 809 | 811 |
| 810 for (size_t i = 0; i < file_list.size(); ++i) { | 812 for (size_t i = 0; i < file_list.size(); ++i) { |
| 811 std::string origin_url( | 813 std::string origin_url( |
| 812 Extension::GetBaseURLFromExtensionId(extension_id()).spec()); | 814 Extension::GetBaseURLFromExtensionId(extension_id()).spec()); |
| 813 fileapi::FileSystemURL url(sync_file_system::CreateSyncableFileSystemURL( | 815 fileapi::FileSystemURL url(sync_file_system::CreateSyncableFileSystemURL( |
| 814 GURL(origin_url), | 816 GURL(origin_url), |
| 815 sync_file_system::DriveFileSyncService::kServiceName, | 817 sync_file_system::DriveFileSyncService::kServiceName, |
| 816 base::FilePath(file_list[i].name))); | 818 base::FilePath(file_list[i].name))); |
| 817 base::FilePath target_path(profile()->GetPath()); | 819 base::FilePath target_path(profile()->GetPath()); |
| 818 target_path = | 820 target_path = |
| 819 target_path.Append(FILE_PATH_LITERAL("apps_target")); | 821 target_path.Append(FILE_PATH_LITERAL(kUnpackedAppsFolder)); |
| 820 target_path = target_path.Append(project_name); | 822 target_path = target_path.Append(project_name); |
| 821 target_path = target_path.Append(file_list[i].name); | 823 target_path = target_path.Append(file_list[i].name); |
| 822 | 824 |
| 823 base::PlatformFileError error_code; | 825 base::PlatformFileError error_code; |
| 824 fileapi::FileSystemOperation* op = | 826 fileapi::FileSystemOperation* op = |
| 825 context_->CreateFileSystemOperation(url, &error_code); | 827 context_->CreateFileSystemOperation(url, &error_code); |
| 826 DCHECK(op); | 828 DCHECK(op); |
| 827 | 829 |
| 828 if (error_code != base::PLATFORM_FILE_OK) { | 830 if (error_code != base::PLATFORM_FILE_OK) { |
| 829 DLOG(ERROR) << "Error in copying files from sync filesystem."; | 831 DLOG(ERROR) << "Error in copying files from sync filesystem."; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 870 file_util::CopyFile(src_path, target_path); | 872 file_util::CopyFile(src_path, target_path); |
| 871 } | 873 } |
| 872 | 874 |
| 873 DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: | 875 DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: |
| 874 DeveloperPrivateExportSyncfsFolderToLocalfsFunction() | 876 DeveloperPrivateExportSyncfsFolderToLocalfsFunction() |
| 875 {} | 877 {} |
| 876 | 878 |
| 877 DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: | 879 DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: |
| 878 ~DeveloperPrivateExportSyncfsFolderToLocalfsFunction() {} | 880 ~DeveloperPrivateExportSyncfsFolderToLocalfsFunction() {} |
| 879 | 881 |
| 882 bool DeveloperPrivateLoadProjectToSyncfsFunction::RunImpl() { | |
| 883 // TODO(grv) : implement | |
| 884 return true; | |
| 885 } | |
| 886 | |
| 887 DeveloperPrivateLoadProjectToSyncfsFunction:: | |
| 888 DeveloperPrivateLoadProjectToSyncfsFunction() {} | |
| 889 | |
| 890 DeveloperPrivateLoadProjectToSyncfsFunction:: | |
| 891 ~DeveloperPrivateLoadProjectToSyncfsFunction() {} | |
| 892 | |
| 893 bool DeveloperPrivateGetProjectsInfoFunction::RunImpl() { | |
| 894 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, | |
| 895 base::Bind(&DeveloperPrivateGetProjectsInfoFunction::ReadFolder, | |
| 896 this)); | |
| 897 | |
| 898 // Released by ReadFolder | |
| 899 AddRef(); | |
| 900 return true; | |
| 901 } | |
| 902 | |
| 903 void DeveloperPrivateGetProjectsInfoFunction::ReadFolder() { | |
| 904 base::FilePath path(profile()->GetPath()); | |
| 905 path = path.Append(FILE_PATH_LITERAL(kUnpackedAppsFolder)); | |
| 906 | |
| 907 file_util::FileEnumerator files( | |
| 908 path, false, file_util::FileEnumerator::DIRECTORIES); | |
| 909 ProjectInfoList info_list; | |
| 910 for (base::FilePath current_path = files.Next(); !current_path.empty(); | |
| 911 current_path = files.Next()) { | |
| 912 scoped_ptr<developer::ProjectInfo> info(new developer::ProjectInfo()); | |
| 913 info->name = current_path.BaseName().MaybeAsASCII(); | |
| 914 info_list.push_back( | |
| 915 make_linked_ptr<developer::ProjectInfo>(info.release())); | |
| 916 } | |
| 917 results_ = developer::GetProjectsInfo::Results::Create(info_list); | |
| 918 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | |
| 919 base::Bind(&DeveloperPrivateGetProjectsInfoFunction::SendResponse, | |
| 920 this, | |
| 921 true)); | |
| 922 Release(); | |
| 923 } | |
| 924 | |
| 925 DeveloperPrivateGetProjectsInfoFunction:: | |
| 926 DeveloperPrivateGetProjectsInfoFunction() {} | |
| 927 | |
| 928 DeveloperPrivateGetProjectsInfoFunction:: | |
| 929 ~DeveloperPrivateGetProjectsInfoFunction() {} | |
| 930 | |
| 931 bool DeveloperPrivateLoadProjectFunction::RunImpl() { | |
| 932 std::string project_name; | |
| 933 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &project_name)); | |
| 934 base::FilePath path(profile()->GetPath()); | |
| 935 path = path.Append(FILE_PATH_LITERAL(kUnpackedAppsFolder)); | |
| 936 path = path.Append(project_name); | |
|
miket_OOO
2013/04/18 03:12:00
Please add a TODO to sanitize this value, and furt
Gaurav
2013/04/18 17:24:06
Done.
miket_OOO
2013/04/23 17:02:47
This didn't happen. What's going on?
Gaurav
2013/04/23 18:08:33
Added the checks for folder name validation (was t
| |
| 937 ExtensionService* service = profile()->GetExtensionService(); | |
| 938 UnpackedInstaller::Create(service)->Load(path); | |
| 939 SendResponse(true); | |
| 940 return true; | |
| 941 } | |
| 942 | |
| 943 DeveloperPrivateLoadProjectFunction::DeveloperPrivateLoadProjectFunction() {} | |
| 944 | |
| 945 DeveloperPrivateLoadProjectFunction::~DeveloperPrivateLoadProjectFunction() {} | |
| 946 | |
| 880 bool DeveloperPrivateChoosePathFunction::RunImpl() { | 947 bool DeveloperPrivateChoosePathFunction::RunImpl() { |
| 881 | 948 |
| 882 scoped_ptr<developer::ChoosePath::Params> params( | 949 scoped_ptr<developer::ChoosePath::Params> params( |
| 883 developer::ChoosePath::Params::Create(*args_)); | 950 developer::ChoosePath::Params::Create(*args_)); |
| 884 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 951 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
| 885 | 952 |
| 886 ui::SelectFileDialog::Type type = ui::SelectFileDialog::SELECT_FOLDER; | 953 ui::SelectFileDialog::Type type = ui::SelectFileDialog::SELECT_FOLDER; |
| 887 ui::SelectFileDialog::FileTypeInfo info; | 954 ui::SelectFileDialog::FileTypeInfo info; |
| 888 if (params->select_type == developer::SELECT_TYPE_FILE) { | 955 if (params->select_type == developer::SELECT_TYPE_FILE) { |
| 889 type = ui::SelectFileDialog::SELECT_OPEN_FILE; | 956 type = ui::SelectFileDialog::SELECT_OPEN_FILE; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1009 | 1076 |
| 1010 #undef SET_STRING | 1077 #undef SET_STRING |
| 1011 return true; | 1078 return true; |
| 1012 } | 1079 } |
| 1013 | 1080 |
| 1014 DeveloperPrivateGetStringsFunction::~DeveloperPrivateGetStringsFunction() {} | 1081 DeveloperPrivateGetStringsFunction::~DeveloperPrivateGetStringsFunction() {} |
| 1015 | 1082 |
| 1016 } // namespace api | 1083 } // namespace api |
| 1017 | 1084 |
| 1018 } // namespace extensions | 1085 } // namespace extensions |
| OLD | NEW |