| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "webkit/browser/fileapi/external_mount_points.h" | 5 #include "webkit/browser/fileapi/external_mount_points.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 if (found == instance_map_.end()) | 142 if (found == instance_map_.end()) |
| 143 return false; | 143 return false; |
| 144 *path = found->second->path(); | 144 *path = found->second->path(); |
| 145 return true; | 145 return true; |
| 146 } | 146 } |
| 147 | 147 |
| 148 bool ExternalMountPoints::CrackVirtualPath( | 148 bool ExternalMountPoints::CrackVirtualPath( |
| 149 const base::FilePath& virtual_path, | 149 const base::FilePath& virtual_path, |
| 150 std::string* mount_name, | 150 std::string* mount_name, |
| 151 FileSystemType* type, | 151 FileSystemType* type, |
| 152 std::string* cracked_id, |
| 152 base::FilePath* path, | 153 base::FilePath* path, |
| 153 FileSystemMountOption* mount_option) const { | 154 FileSystemMountOption* mount_option) const { |
| 154 DCHECK(mount_name); | 155 DCHECK(mount_name); |
| 155 DCHECK(path); | 156 DCHECK(path); |
| 156 | 157 |
| 157 // The path should not contain any '..' references. | 158 // The path should not contain any '..' references. |
| 158 if (virtual_path.ReferencesParent()) | 159 if (virtual_path.ReferencesParent()) |
| 159 return false; | 160 return false; |
| 160 | 161 |
| 161 // The virtual_path should comprise of <mount_name> and <relative_path> parts. | 162 // The virtual_path should comprise of <mount_name> and <relative_path> parts. |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 // On other OS, it is simply a native local path. | 288 // On other OS, it is simply a native local path. |
| 288 return FileSystemURL( | 289 return FileSystemURL( |
| 289 url.origin(), url.mount_type(), url.virtual_path(), | 290 url.origin(), url.mount_type(), url.virtual_path(), |
| 290 url.mount_filesystem_id(), kFileSystemTypeNativeLocal, | 291 url.mount_filesystem_id(), kFileSystemTypeNativeLocal, |
| 291 url.path(), url.filesystem_id(), url.mount_option()); | 292 url.path(), url.filesystem_id(), url.mount_option()); |
| 292 #endif | 293 #endif |
| 293 } | 294 } |
| 294 | 295 |
| 295 std::string mount_name; | 296 std::string mount_name; |
| 296 FileSystemType cracked_type; | 297 FileSystemType cracked_type; |
| 298 std::string cracked_id; |
| 297 base::FilePath cracked_path; | 299 base::FilePath cracked_path; |
| 298 FileSystemMountOption cracked_mount_option; | 300 FileSystemMountOption cracked_mount_option; |
| 299 | 301 |
| 300 if (!CrackVirtualPath(virtual_path, &mount_name, &cracked_type, | 302 if (!CrackVirtualPath(virtual_path, &mount_name, &cracked_type, |
| 301 &cracked_path, &cracked_mount_option)) { | 303 &cracked_id, &cracked_path, &cracked_mount_option)) { |
| 302 return FileSystemURL(); | 304 return FileSystemURL(); |
| 303 } | 305 } |
| 304 | 306 |
| 305 return FileSystemURL( | 307 return FileSystemURL( |
| 306 url.origin(), url.mount_type(), url.virtual_path(), | 308 url.origin(), url.mount_type(), url.virtual_path(), |
| 307 !url.filesystem_id().empty() ? url.filesystem_id() : mount_name, | 309 !url.filesystem_id().empty() ? url.filesystem_id() : mount_name, |
| 308 cracked_type, cracked_path, mount_name, cracked_mount_option); | 310 cracked_type, cracked_path, |
| 311 cracked_id.empty() ? mount_name : cracked_id, cracked_mount_option); |
| 309 } | 312 } |
| 310 | 313 |
| 311 bool ExternalMountPoints::ValidateNewMountPoint(const std::string& mount_name, | 314 bool ExternalMountPoints::ValidateNewMountPoint(const std::string& mount_name, |
| 312 FileSystemType type, | 315 FileSystemType type, |
| 313 const base::FilePath& path) { | 316 const base::FilePath& path) { |
| 314 lock_.AssertAcquired(); | 317 lock_.AssertAcquired(); |
| 315 | 318 |
| 316 // Mount name must not be empty. | 319 // Mount name must not be empty. |
| 317 if (mount_name.empty()) | 320 if (mount_name.empty()) |
| 318 return false; | 321 return false; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 348 path.IsParent(potential_child->first)) { | 351 path.IsParent(potential_child->first)) { |
| 349 return false; | 352 return false; |
| 350 } | 353 } |
| 351 } | 354 } |
| 352 } | 355 } |
| 353 | 356 |
| 354 return true; | 357 return true; |
| 355 } | 358 } |
| 356 | 359 |
| 357 } // namespace fileapi | 360 } // namespace fileapi |
| OLD | NEW |