| 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 "webkit/chromeos/fileapi/cros_mount_point_provider.h" | 5 #include "webkit/chromeos/fileapi/cros_mount_point_provider.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/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 base::AutoLock locker(lock_); | 71 base::AutoLock locker(lock_); |
| 72 // Check if this root mount point is exposed by this provider. | 72 // Check if this root mount point is exposed by this provider. |
| 73 MountPointMap::iterator iter = mount_point_map_.find(components[0]); | 73 MountPointMap::iterator iter = mount_point_map_.find(components[0]); |
| 74 if (iter == mount_point_map_.end()) { | 74 if (iter == mount_point_map_.end()) { |
| 75 return false; | 75 return false; |
| 76 } | 76 } |
| 77 *root_path = iter->second; | 77 *root_path = iter->second; |
| 78 return true; | 78 return true; |
| 79 } | 79 } |
| 80 | 80 |
| 81 void CrosMountPointProvider::ValidateFileSystemRootAndGetURL( | 81 void CrosMountPointProvider::ValidateFileSystemRoot( |
| 82 const GURL& origin_url, | 82 const GURL& origin_url, |
| 83 fileapi::FileSystemType type, | 83 fileapi::FileSystemType type, |
| 84 bool create, | 84 bool create, |
| 85 const GetRootPathCallback& callback) { | 85 const ValidateFileSystemCallback& callback) { |
| 86 // Nothing to validate for external filesystem. |
| 86 DCHECK(type == fileapi::kFileSystemTypeExternal); | 87 DCHECK(type == fileapi::kFileSystemTypeExternal); |
| 87 std::string name(GetOriginIdentifierFromURL(origin_url)); | 88 callback.Run(base::PLATFORM_FILE_OK); |
| 88 name += ':'; | |
| 89 name += fileapi::kExternalName; | |
| 90 FilePath root_path; | |
| 91 root_path = FilePath(fileapi::kExternalDir); | |
| 92 callback.Run(true, root_path, name); | |
| 93 } | 89 } |
| 94 | 90 |
| 95 FilePath CrosMountPointProvider::ValidateFileSystemRootAndGetPathOnFileThread( | 91 FilePath CrosMountPointProvider::GetFileSystemRootPathOnFileThread( |
| 96 const GURL& origin_url, | 92 const GURL& origin_url, |
| 97 fileapi::FileSystemType type, | 93 fileapi::FileSystemType type, |
| 98 const FilePath& virtual_path, | 94 const FilePath& virtual_path, |
| 99 bool create) { | 95 bool create) { |
| 100 DCHECK(type == fileapi::kFileSystemTypeExternal); | 96 DCHECK(type == fileapi::kFileSystemTypeExternal); |
| 101 FilePath root_path; | 97 FilePath root_path; |
| 102 if (!GetRootForVirtualPath(virtual_path, &root_path)) | 98 if (!GetRootForVirtualPath(virtual_path, &root_path)) |
| 103 return FilePath(); | 99 return FilePath(); |
| 104 | 100 |
| 105 return root_path; | 101 return root_path; |
| 106 } | 102 } |
| 107 | 103 |
| 108 // TODO(zelidrag): Share this code with SandboxMountPointProvider impl. | |
| 109 bool CrosMountPointProvider::IsRestrictedFileName(const FilePath& path) const { | |
| 110 return false; | |
| 111 } | |
| 112 | |
| 113 bool CrosMountPointProvider::IsAccessAllowed(const GURL& origin_url, | 104 bool CrosMountPointProvider::IsAccessAllowed(const GURL& origin_url, |
| 114 fileapi::FileSystemType type, | 105 fileapi::FileSystemType type, |
| 115 const FilePath& virtual_path) { | 106 const FilePath& virtual_path) { |
| 116 if (type != fileapi::kFileSystemTypeExternal) | 107 if (type != fileapi::kFileSystemTypeExternal) |
| 117 return false; | 108 return false; |
| 118 | 109 |
| 119 // Permit access to mount points from internal WebUI. | 110 // Permit access to mount points from internal WebUI. |
| 120 if (origin_url.SchemeIs(kChromeUIScheme)) | 111 if (origin_url.SchemeIs(kChromeUIScheme)) |
| 121 return true; | 112 return true; |
| 122 | 113 |
| 123 std::string extension_id = origin_url.host(); | 114 std::string extension_id = origin_url.host(); |
| 124 // Check first to make sure this extension has fileBrowserHander permissions. | 115 // Check first to make sure this extension has fileBrowserHander permissions. |
| 125 if (!special_storage_policy_->IsFileHandler(extension_id)) | 116 if (!special_storage_policy_->IsFileHandler(extension_id)) |
| 126 return false; | 117 return false; |
| 127 | 118 |
| 128 return file_access_permissions_->HasAccessPermission(extension_id, | 119 return file_access_permissions_->HasAccessPermission(extension_id, |
| 129 virtual_path); | 120 virtual_path); |
| 130 } | 121 } |
| 131 | 122 |
| 123 // TODO(zelidrag): Share this code with SandboxMountPointProvider impl. |
| 124 bool CrosMountPointProvider::IsRestrictedFileName(const FilePath& path) const { |
| 125 return false; |
| 126 } |
| 127 |
| 132 void CrosMountPointProvider::AddMountPoint(FilePath mount_point) { | 128 void CrosMountPointProvider::AddMountPoint(FilePath mount_point) { |
| 133 base::AutoLock locker(lock_); | 129 base::AutoLock locker(lock_); |
| 134 mount_point_map_.erase(mount_point.BaseName().value()); | 130 mount_point_map_.erase(mount_point.BaseName().value()); |
| 135 mount_point_map_.insert(std::pair<std::string, FilePath>( | 131 mount_point_map_.insert(std::pair<std::string, FilePath>( |
| 136 mount_point.BaseName().value(), mount_point.DirName())); | 132 mount_point.BaseName().value(), mount_point.DirName())); |
| 137 } | 133 } |
| 138 | 134 |
| 139 void CrosMountPointProvider::RemoveMountPoint(FilePath mount_point) { | 135 void CrosMountPointProvider::RemoveMountPoint(FilePath mount_point) { |
| 140 base::AutoLock locker(lock_); | 136 base::AutoLock locker(lock_); |
| 141 mount_point_map_.erase(mount_point.BaseName().value()); | 137 mount_point_map_.erase(mount_point.BaseName().value()); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 } else if (mount_prefix == filesystem_path) { | 189 } else if (mount_prefix == filesystem_path) { |
| 194 FilePath root = FilePath(FILE_PATH_LITERAL("/")); | 190 FilePath root = FilePath(FILE_PATH_LITERAL("/")); |
| 195 *virtual_path = root.Append(iter->first); | 191 *virtual_path = root.Append(iter->first); |
| 196 return true; | 192 return true; |
| 197 } | 193 } |
| 198 } | 194 } |
| 199 return false; | 195 return false; |
| 200 } | 196 } |
| 201 | 197 |
| 202 } // namespace chromeos | 198 } // namespace chromeos |
| OLD | NEW |