| 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 "apps/app_load_service.h" | 7 #include "apps/app_load_service.h" |
| 8 #include "apps/app_window.h" | 8 #include "apps/app_window.h" |
| 9 #include "apps/app_window_registry.h" | 9 #include "apps/app_window_registry.h" |
| 10 #include "apps/saved_files_service.h" | 10 #include "apps/saved_files_service.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 #include "extensions/common/manifest_handlers/offline_enabled_info.h" | 66 #include "extensions/common/manifest_handlers/offline_enabled_info.h" |
| 67 #include "extensions/common/permissions/permissions_data.h" | 67 #include "extensions/common/permissions/permissions_data.h" |
| 68 #include "extensions/common/switches.h" | 68 #include "extensions/common/switches.h" |
| 69 #include "grit/chromium_strings.h" | 69 #include "grit/chromium_strings.h" |
| 70 #include "grit/generated_resources.h" | 70 #include "grit/generated_resources.h" |
| 71 #include "grit/theme_resources.h" | 71 #include "grit/theme_resources.h" |
| 72 #include "net/base/net_util.h" | 72 #include "net/base/net_util.h" |
| 73 #include "ui/base/l10n/l10n_util.h" | 73 #include "ui/base/l10n/l10n_util.h" |
| 74 #include "ui/base/resource/resource_bundle.h" | 74 #include "ui/base/resource/resource_bundle.h" |
| 75 #include "ui/base/webui/web_ui_util.h" | 75 #include "ui/base/webui/web_ui_util.h" |
| 76 #include "webkit/browser/fileapi/external_mount_points.h" | 76 #include "storage/browser/fileapi/external_mount_points.h" |
| 77 #include "webkit/browser/fileapi/file_system_context.h" | 77 #include "storage/browser/fileapi/file_system_context.h" |
| 78 #include "webkit/browser/fileapi/file_system_operation.h" | 78 #include "storage/browser/fileapi/file_system_operation.h" |
| 79 #include "webkit/browser/fileapi/file_system_operation_runner.h" | 79 #include "storage/browser/fileapi/file_system_operation_runner.h" |
| 80 #include "webkit/browser/fileapi/isolated_context.h" | 80 #include "storage/browser/fileapi/isolated_context.h" |
| 81 #include "webkit/common/blob/shareable_file_reference.h" | 81 #include "storage/common/blob/shareable_file_reference.h" |
| 82 | 82 |
| 83 using apps::AppWindow; | 83 using apps::AppWindow; |
| 84 using apps::AppWindowRegistry; | 84 using apps::AppWindowRegistry; |
| 85 using content::RenderViewHost; | 85 using content::RenderViewHost; |
| 86 | 86 |
| 87 namespace extensions { | 87 namespace extensions { |
| 88 | 88 |
| 89 namespace developer_private = api::developer_private; | 89 namespace developer_private = api::developer_private; |
| 90 | 90 |
| 91 namespace { | 91 namespace { |
| (...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1065 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &filesystem_name)); | 1065 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &filesystem_name)); |
| 1066 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_path)); | 1066 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_path)); |
| 1067 EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &directory_url_str)); | 1067 EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &directory_url_str)); |
| 1068 | 1068 |
| 1069 context_ = content::BrowserContext::GetStoragePartition( | 1069 context_ = content::BrowserContext::GetStoragePartition( |
| 1070 GetProfile(), render_view_host()->GetSiteInstance()) | 1070 GetProfile(), render_view_host()->GetSiteInstance()) |
| 1071 ->GetFileSystemContext(); | 1071 ->GetFileSystemContext(); |
| 1072 | 1072 |
| 1073 // Directory url is non empty only for syncfilesystem. | 1073 // Directory url is non empty only for syncfilesystem. |
| 1074 if (directory_url_str != "") { | 1074 if (directory_url_str != "") { |
| 1075 fileapi::FileSystemURL directory_url = | 1075 storage::FileSystemURL directory_url = |
| 1076 context_->CrackURL(GURL(directory_url_str)); | 1076 context_->CrackURL(GURL(directory_url_str)); |
| 1077 if (!directory_url.is_valid() || | 1077 if (!directory_url.is_valid() || |
| 1078 directory_url.type() != fileapi::kFileSystemTypeSyncable) { | 1078 directory_url.type() != storage::kFileSystemTypeSyncable) { |
| 1079 SetError("DirectoryEntry of unsupported filesystem."); | 1079 SetError("DirectoryEntry of unsupported filesystem."); |
| 1080 return false; | 1080 return false; |
| 1081 } | 1081 } |
| 1082 return LoadByFileSystemAPI(directory_url); | 1082 return LoadByFileSystemAPI(directory_url); |
| 1083 } else { | 1083 } else { |
| 1084 // Check if the DirecotryEntry is the instance of chrome filesystem. | 1084 // Check if the DirecotryEntry is the instance of chrome filesystem. |
| 1085 if (!app_file_handler_util::ValidateFileEntryAndGetPath(filesystem_name, | 1085 if (!app_file_handler_util::ValidateFileEntryAndGetPath(filesystem_name, |
| 1086 filesystem_path, | 1086 filesystem_path, |
| 1087 render_view_host_, | 1087 render_view_host_, |
| 1088 &project_base_path_, | 1088 &project_base_path_, |
| 1089 &error_)) { | 1089 &error_)) { |
| 1090 SetError("DirectoryEntry of unsupported filesystem."); | 1090 SetError("DirectoryEntry of unsupported filesystem."); |
| 1091 return false; | 1091 return false; |
| 1092 } | 1092 } |
| 1093 | 1093 |
| 1094 // Try to load using the FileSystem API backend, in case the filesystem | 1094 // Try to load using the FileSystem API backend, in case the filesystem |
| 1095 // points to a non-native local directory. | 1095 // points to a non-native local directory. |
| 1096 std::string filesystem_id; | 1096 std::string filesystem_id; |
| 1097 bool cracked = | 1097 bool cracked = |
| 1098 fileapi::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id); | 1098 storage::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id); |
| 1099 CHECK(cracked); | 1099 CHECK(cracked); |
| 1100 base::FilePath virtual_path = | 1100 base::FilePath virtual_path = |
| 1101 fileapi::IsolatedContext::GetInstance() | 1101 storage::IsolatedContext::GetInstance() |
| 1102 ->CreateVirtualRootPath(filesystem_id) | 1102 ->CreateVirtualRootPath(filesystem_id) |
| 1103 .Append(base::FilePath::FromUTF8Unsafe(filesystem_path)); | 1103 .Append(base::FilePath::FromUTF8Unsafe(filesystem_path)); |
| 1104 fileapi::FileSystemURL directory_url = context_->CreateCrackedFileSystemURL( | 1104 storage::FileSystemURL directory_url = context_->CreateCrackedFileSystemURL( |
| 1105 extensions::Extension::GetBaseURLFromExtensionId(extension_id()), | 1105 extensions::Extension::GetBaseURLFromExtensionId(extension_id()), |
| 1106 fileapi::kFileSystemTypeIsolated, | 1106 storage::kFileSystemTypeIsolated, |
| 1107 virtual_path); | 1107 virtual_path); |
| 1108 | 1108 |
| 1109 if (directory_url.is_valid() && | 1109 if (directory_url.is_valid() && |
| 1110 directory_url.type() != fileapi::kFileSystemTypeNativeLocal && | 1110 directory_url.type() != storage::kFileSystemTypeNativeLocal && |
| 1111 directory_url.type() != fileapi::kFileSystemTypeRestrictedNativeLocal && | 1111 directory_url.type() != storage::kFileSystemTypeRestrictedNativeLocal && |
| 1112 directory_url.type() != fileapi::kFileSystemTypeDragged) { | 1112 directory_url.type() != storage::kFileSystemTypeDragged) { |
| 1113 return LoadByFileSystemAPI(directory_url); | 1113 return LoadByFileSystemAPI(directory_url); |
| 1114 } | 1114 } |
| 1115 | 1115 |
| 1116 Load(); | 1116 Load(); |
| 1117 } | 1117 } |
| 1118 | 1118 |
| 1119 return true; | 1119 return true; |
| 1120 } | 1120 } |
| 1121 | 1121 |
| 1122 bool DeveloperPrivateLoadDirectoryFunction::LoadByFileSystemAPI( | 1122 bool DeveloperPrivateLoadDirectoryFunction::LoadByFileSystemAPI( |
| 1123 const fileapi::FileSystemURL& directory_url) { | 1123 const storage::FileSystemURL& directory_url) { |
| 1124 std::string directory_url_str = directory_url.ToGURL().spec(); | 1124 std::string directory_url_str = directory_url.ToGURL().spec(); |
| 1125 | 1125 |
| 1126 size_t pos = 0; | 1126 size_t pos = 0; |
| 1127 // Parse the project directory name from the project url. The project url is | 1127 // Parse the project directory name from the project url. The project url is |
| 1128 // expected to have project name as the suffix. | 1128 // expected to have project name as the suffix. |
| 1129 if ((pos = directory_url_str.rfind("/")) == std::string::npos) { | 1129 if ((pos = directory_url_str.rfind("/")) == std::string::npos) { |
| 1130 SetError("Invalid Directory entry."); | 1130 SetError("Invalid Directory entry."); |
| 1131 return false; | 1131 return false; |
| 1132 } | 1132 } |
| 1133 | 1133 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, | 1171 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, |
| 1172 base::Bind(&DeveloperPrivateLoadDirectoryFunction:: | 1172 base::Bind(&DeveloperPrivateLoadDirectoryFunction:: |
| 1173 ReadDirectoryByFileSystemAPI, | 1173 ReadDirectoryByFileSystemAPI, |
| 1174 this, project_path, project_path.BaseName())); | 1174 this, project_path, project_path.BaseName())); |
| 1175 } | 1175 } |
| 1176 | 1176 |
| 1177 void DeveloperPrivateLoadDirectoryFunction::ReadDirectoryByFileSystemAPI( | 1177 void DeveloperPrivateLoadDirectoryFunction::ReadDirectoryByFileSystemAPI( |
| 1178 const base::FilePath& project_path, | 1178 const base::FilePath& project_path, |
| 1179 const base::FilePath& destination_path) { | 1179 const base::FilePath& destination_path) { |
| 1180 GURL project_url = GURL(project_base_url_ + destination_path.AsUTF8Unsafe()); | 1180 GURL project_url = GURL(project_base_url_ + destination_path.AsUTF8Unsafe()); |
| 1181 fileapi::FileSystemURL url = context_->CrackURL(project_url); | 1181 storage::FileSystemURL url = context_->CrackURL(project_url); |
| 1182 | 1182 |
| 1183 context_->operation_runner()->ReadDirectory( | 1183 context_->operation_runner()->ReadDirectory( |
| 1184 url, base::Bind(&DeveloperPrivateLoadDirectoryFunction:: | 1184 url, base::Bind(&DeveloperPrivateLoadDirectoryFunction:: |
| 1185 ReadDirectoryByFileSystemAPICb, | 1185 ReadDirectoryByFileSystemAPICb, |
| 1186 this, project_path, destination_path)); | 1186 this, project_path, destination_path)); |
| 1187 } | 1187 } |
| 1188 | 1188 |
| 1189 void DeveloperPrivateLoadDirectoryFunction::ReadDirectoryByFileSystemAPICb( | 1189 void DeveloperPrivateLoadDirectoryFunction::ReadDirectoryByFileSystemAPICb( |
| 1190 const base::FilePath& project_path, | 1190 const base::FilePath& project_path, |
| 1191 const base::FilePath& destination_path, | 1191 const base::FilePath& destination_path, |
| 1192 base::File::Error status, | 1192 base::File::Error status, |
| 1193 const fileapi::FileSystemOperation::FileEntryList& file_list, | 1193 const storage::FileSystemOperation::FileEntryList& file_list, |
| 1194 bool has_more) { | 1194 bool has_more) { |
| 1195 | |
| 1196 if (status != base::File::FILE_OK) { | 1195 if (status != base::File::FILE_OK) { |
| 1197 DLOG(ERROR) << "Error in copying files from sync filesystem."; | 1196 DLOG(ERROR) << "Error in copying files from sync filesystem."; |
| 1198 return; | 1197 return; |
| 1199 } | 1198 } |
| 1200 | 1199 |
| 1201 // We add 1 to the pending copy operations for both files and directories. We | 1200 // We add 1 to the pending copy operations for both files and directories. We |
| 1202 // release the directory copy operation once all the files under the directory | 1201 // release the directory copy operation once all the files under the directory |
| 1203 // are added for copying. We do that to ensure that pendingCopyOperationsCount | 1202 // are added for copying. We do that to ensure that pendingCopyOperationsCount |
| 1204 // does not become zero before all copy operations are finished. | 1203 // does not become zero before all copy operations are finished. |
| 1205 // In case the directory happens to be executing the last copy operation it | 1204 // In case the directory happens to be executing the last copy operation it |
| 1206 // will call SendResponse to send the response to the API. The pending copy | 1205 // will call SendResponse to send the response to the API. The pending copy |
| 1207 // operations of files are released by the CopyFile function. | 1206 // operations of files are released by the CopyFile function. |
| 1208 pending_copy_operations_count_ += file_list.size(); | 1207 pending_copy_operations_count_ += file_list.size(); |
| 1209 | 1208 |
| 1210 for (size_t i = 0; i < file_list.size(); ++i) { | 1209 for (size_t i = 0; i < file_list.size(); ++i) { |
| 1211 if (file_list[i].is_directory) { | 1210 if (file_list[i].is_directory) { |
| 1212 ReadDirectoryByFileSystemAPI(project_path.Append(file_list[i].name), | 1211 ReadDirectoryByFileSystemAPI(project_path.Append(file_list[i].name), |
| 1213 destination_path.Append(file_list[i].name)); | 1212 destination_path.Append(file_list[i].name)); |
| 1214 continue; | 1213 continue; |
| 1215 } | 1214 } |
| 1216 | 1215 |
| 1217 GURL project_url = GURL(project_base_url_ + | 1216 GURL project_url = GURL(project_base_url_ + |
| 1218 destination_path.Append(file_list[i].name).AsUTF8Unsafe()); | 1217 destination_path.Append(file_list[i].name).AsUTF8Unsafe()); |
| 1219 fileapi::FileSystemURL url = context_->CrackURL(project_url); | 1218 storage::FileSystemURL url = context_->CrackURL(project_url); |
| 1220 | 1219 |
| 1221 base::FilePath target_path = project_path; | 1220 base::FilePath target_path = project_path; |
| 1222 target_path = target_path.Append(file_list[i].name); | 1221 target_path = target_path.Append(file_list[i].name); |
| 1223 | 1222 |
| 1224 context_->operation_runner()->CreateSnapshotFile( | 1223 context_->operation_runner()->CreateSnapshotFile( |
| 1225 url, | 1224 url, |
| 1226 base::Bind(&DeveloperPrivateLoadDirectoryFunction::SnapshotFileCallback, | 1225 base::Bind(&DeveloperPrivateLoadDirectoryFunction::SnapshotFileCallback, |
| 1227 this, | 1226 this, |
| 1228 target_path)); | 1227 target_path)); |
| 1229 } | 1228 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1240 success_)); | 1239 success_)); |
| 1241 } | 1240 } |
| 1242 } | 1241 } |
| 1243 } | 1242 } |
| 1244 | 1243 |
| 1245 void DeveloperPrivateLoadDirectoryFunction::SnapshotFileCallback( | 1244 void DeveloperPrivateLoadDirectoryFunction::SnapshotFileCallback( |
| 1246 const base::FilePath& target_path, | 1245 const base::FilePath& target_path, |
| 1247 base::File::Error result, | 1246 base::File::Error result, |
| 1248 const base::File::Info& file_info, | 1247 const base::File::Info& file_info, |
| 1249 const base::FilePath& src_path, | 1248 const base::FilePath& src_path, |
| 1250 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { | 1249 const scoped_refptr<storage::ShareableFileReference>& file_ref) { |
| 1251 if (result != base::File::FILE_OK) { | 1250 if (result != base::File::FILE_OK) { |
| 1252 SetError("Error in copying files from sync filesystem."); | 1251 SetError("Error in copying files from sync filesystem."); |
| 1253 success_ = false; | 1252 success_ = false; |
| 1254 return; | 1253 return; |
| 1255 } | 1254 } |
| 1256 | 1255 |
| 1257 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, | 1256 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, |
| 1258 base::Bind(&DeveloperPrivateLoadDirectoryFunction::CopyFile, | 1257 base::Bind(&DeveloperPrivateLoadDirectoryFunction::CopyFile, |
| 1259 this, | 1258 this, |
| 1260 src_path, | 1259 src_path, |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1399 } | 1398 } |
| 1400 | 1399 |
| 1401 error_ui_util::HandleOpenDevTools(dict); | 1400 error_ui_util::HandleOpenDevTools(dict); |
| 1402 | 1401 |
| 1403 return true; | 1402 return true; |
| 1404 } | 1403 } |
| 1405 | 1404 |
| 1406 } // namespace api | 1405 } // namespace api |
| 1407 | 1406 |
| 1408 } // namespace extensions | 1407 } // namespace extensions |
| OLD | NEW |