| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/chromeos/fileapi/file_system_backend.h" | 5 #include "chrome/browser/chromeos/fileapi/file_system_backend.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "chrome/browser/chromeos/fileapi/file_access_permissions.h" | 10 #include "chrome/browser/chromeos/fileapi/file_access_permissions.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 url.type() == storage::kFileSystemTypeRestrictedNativeLocal || | 32 url.type() == storage::kFileSystemTypeRestrictedNativeLocal || |
| 33 url.type() == storage::kFileSystemTypeDrive || | 33 url.type() == storage::kFileSystemTypeDrive || |
| 34 url.type() == storage::kFileSystemTypeProvided || | 34 url.type() == storage::kFileSystemTypeProvided || |
| 35 url.type() == storage::kFileSystemTypeDeviceMediaAsFileStorage; | 35 url.type() == storage::kFileSystemTypeDeviceMediaAsFileStorage; |
| 36 } | 36 } |
| 37 | 37 |
| 38 FileSystemBackend::FileSystemBackend( | 38 FileSystemBackend::FileSystemBackend( |
| 39 FileSystemBackendDelegate* drive_delegate, | 39 FileSystemBackendDelegate* drive_delegate, |
| 40 FileSystemBackendDelegate* file_system_provider_delegate, | 40 FileSystemBackendDelegate* file_system_provider_delegate, |
| 41 FileSystemBackendDelegate* mtp_delegate, | 41 FileSystemBackendDelegate* mtp_delegate, |
| 42 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy, | |
| 43 scoped_refptr<storage::ExternalMountPoints> mount_points, | 42 scoped_refptr<storage::ExternalMountPoints> mount_points, |
| 44 storage::ExternalMountPoints* system_mount_points) | 43 storage::ExternalMountPoints* system_mount_points) |
| 45 : special_storage_policy_(special_storage_policy), | 44 : file_access_permissions_(new FileAccessPermissions()), |
| 46 file_access_permissions_(new FileAccessPermissions()), | |
| 47 local_file_util_(storage::AsyncFileUtil::CreateForLocalFileSystem()), | 45 local_file_util_(storage::AsyncFileUtil::CreateForLocalFileSystem()), |
| 48 drive_delegate_(drive_delegate), | 46 drive_delegate_(drive_delegate), |
| 49 file_system_provider_delegate_(file_system_provider_delegate), | 47 file_system_provider_delegate_(file_system_provider_delegate), |
| 50 mtp_delegate_(mtp_delegate), | 48 mtp_delegate_(mtp_delegate), |
| 51 mount_points_(mount_points), | 49 mount_points_(mount_points), |
| 52 system_mount_points_(system_mount_points) { | 50 system_mount_points_(system_mount_points) { |
| 53 } | 51 } |
| 54 | 52 |
| 55 FileSystemBackend::~FileSystemBackend() { | 53 FileSystemBackend::~FileSystemBackend() { |
| 56 } | 54 } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 return true; | 176 return true; |
| 179 | 177 |
| 180 std::string extension_id = url.origin().host(); | 178 std::string extension_id = url.origin().host(); |
| 181 // TODO(mtomasz): Temporarily whitelist TimeScapes. Remove this in M-31. | 179 // TODO(mtomasz): Temporarily whitelist TimeScapes. Remove this in M-31. |
| 182 // See: crbug.com/271946 | 180 // See: crbug.com/271946 |
| 183 if (extension_id == "mlbmkoenclnokonejhlfakkeabdlmpek" && | 181 if (extension_id == "mlbmkoenclnokonejhlfakkeabdlmpek" && |
| 184 url.type() == storage::kFileSystemTypeRestrictedNativeLocal) { | 182 url.type() == storage::kFileSystemTypeRestrictedNativeLocal) { |
| 185 return true; | 183 return true; |
| 186 } | 184 } |
| 187 | 185 |
| 188 // Check first to make sure this extension has fileBrowserHander permissions. | |
| 189 if (!special_storage_policy_.get() || | |
| 190 !special_storage_policy_->IsFileHandler(extension_id)) | |
| 191 return false; | |
| 192 | |
| 193 return file_access_permissions_->HasAccessPermission(extension_id, | 186 return file_access_permissions_->HasAccessPermission(extension_id, |
| 194 url.virtual_path()); | 187 url.virtual_path()); |
| 195 } | 188 } |
| 196 | 189 |
| 197 void FileSystemBackend::GrantFileAccessToExtension( | 190 void FileSystemBackend::GrantFileAccessToExtension( |
| 198 const std::string& extension_id, const base::FilePath& virtual_path) { | 191 const std::string& extension_id, const base::FilePath& virtual_path) { |
| 199 if (!special_storage_policy_.get()) | |
| 200 return; | |
| 201 // All we care about here is access from extensions for now. | |
| 202 if (!special_storage_policy_->IsFileHandler(extension_id)) { | |
| 203 NOTREACHED(); | |
| 204 return; | |
| 205 } | |
| 206 | |
| 207 std::string id; | 192 std::string id; |
| 208 storage::FileSystemType type; | 193 storage::FileSystemType type; |
| 209 std::string cracked_id; | 194 std::string cracked_id; |
| 210 base::FilePath path; | 195 base::FilePath path; |
| 211 storage::FileSystemMountOption option; | 196 storage::FileSystemMountOption option; |
| 212 if (!mount_points_->CrackVirtualPath(virtual_path, &id, &type, &cracked_id, | 197 if (!mount_points_->CrackVirtualPath(virtual_path, &id, &type, &cracked_id, |
| 213 &path, &option) && | 198 &path, &option) && |
| 214 !system_mount_points_->CrackVirtualPath(virtual_path, &id, &type, | 199 !system_mount_points_->CrackVirtualPath(virtual_path, &id, &type, |
| 215 &cracked_id, &path, &option)) { | 200 &cracked_id, &path, &option)) { |
| 216 return; | 201 return; |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 const base::FilePath& entry_path) const { | 414 const base::FilePath& entry_path) const { |
| 430 base::FilePath virtual_path; | 415 base::FilePath virtual_path; |
| 431 if (!GetVirtualPath(entry_path, &virtual_path)) | 416 if (!GetVirtualPath(entry_path, &virtual_path)) |
| 432 return storage::FileSystemURL(); | 417 return storage::FileSystemURL(); |
| 433 | 418 |
| 434 return context->CreateCrackedFileSystemURL( | 419 return context->CreateCrackedFileSystemURL( |
| 435 GURL() /* origin */, storage::kFileSystemTypeExternal, virtual_path); | 420 GURL() /* origin */, storage::kFileSystemTypeExternal, virtual_path); |
| 436 } | 421 } |
| 437 | 422 |
| 438 } // namespace chromeos | 423 } // namespace chromeos |
| OLD | NEW |