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/fileapi/isolated_context.h" | 5 #include "webkit/fileapi/isolated_context.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 for (; component_iter != components.end(); ++component_iter) | 294 for (; component_iter != components.end(); ++component_iter) |
295 cracked_path = cracked_path.Append(*component_iter); | 295 cracked_path = cracked_path.Append(*component_iter); |
296 *path = cracked_path; | 296 *path = cracked_path; |
297 return true; | 297 return true; |
298 } | 298 } |
299 | 299 |
300 FileSystemURL IsolatedContext::CrackURL(const GURL& url) const { | 300 FileSystemURL IsolatedContext::CrackURL(const GURL& url) const { |
301 FileSystemURL filesystem_url = FileSystemURL(url); | 301 FileSystemURL filesystem_url = FileSystemURL(url); |
302 if (!filesystem_url.is_valid()) | 302 if (!filesystem_url.is_valid()) |
303 return FileSystemURL(); | 303 return FileSystemURL(); |
304 return CreateCrackedFileSystemURL(filesystem_url.origin(), | 304 return CrackFileSystemURL(filesystem_url); |
305 filesystem_url.mount_type(), | 305 } |
306 filesystem_url.path()); | 306 |
| 307 FileSystemURL IsolatedContext::CrackFileSystemURL( |
| 308 const FileSystemURL& url) const { |
| 309 if (!HandlesFileSystemMountType(url.type())) |
| 310 return FileSystemURL(); |
| 311 |
| 312 std::string mount_name; |
| 313 FileSystemType cracked_type; |
| 314 base::FilePath cracked_path; |
| 315 if (!CrackVirtualPath(url.path(), &mount_name, &cracked_type, &cracked_path)) |
| 316 return FileSystemURL(); |
| 317 |
| 318 return FileSystemURL( |
| 319 url.origin(), url.mount_type(), url.virtual_path(), |
| 320 !url.filesystem_id().empty() ? url.filesystem_id() : mount_name, |
| 321 cracked_type, cracked_path, mount_name); |
307 } | 322 } |
308 | 323 |
309 FileSystemURL IsolatedContext::CreateCrackedFileSystemURL( | 324 FileSystemURL IsolatedContext::CreateCrackedFileSystemURL( |
310 const GURL& origin, | 325 const GURL& origin, |
311 FileSystemType type, | 326 FileSystemType type, |
312 const base::FilePath& path) const { | 327 const base::FilePath& path) const { |
313 if (!HandlesFileSystemMountType(type)) | 328 return CrackFileSystemURL(FileSystemURL(origin, type, path)); |
314 return FileSystemURL(); | |
315 | |
316 std::string mount_name; | |
317 FileSystemType cracked_type; | |
318 base::FilePath cracked_path; | |
319 if (!CrackVirtualPath(path, &mount_name, &cracked_type, &cracked_path)) | |
320 return FileSystemURL(); | |
321 | |
322 return FileSystemURL(origin, type, path, | |
323 mount_name, cracked_type, cracked_path); | |
324 } | 329 } |
325 | 330 |
326 void IsolatedContext::RevokeFileSystemByPath(const base::FilePath& path_in) { | 331 void IsolatedContext::RevokeFileSystemByPath(const base::FilePath& path_in) { |
327 base::AutoLock locker(lock_); | 332 base::AutoLock locker(lock_); |
328 base::FilePath path(path_in.NormalizePathSeparators()); | 333 base::FilePath path(path_in.NormalizePathSeparators()); |
329 PathToID::iterator ids_iter = path_to_id_map_.find(path); | 334 PathToID::iterator ids_iter = path_to_id_map_.find(path); |
330 if (ids_iter == path_to_id_map_.end()) | 335 if (ids_iter == path_to_id_map_.end()) |
331 return; | 336 return; |
332 std::set<std::string>& ids = ids_iter->second; | 337 std::set<std::string>& ids = ids_iter->second; |
333 for (std::set<std::string>::iterator iter = ids.begin(); | 338 for (std::set<std::string>::iterator iter = ids.begin(); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 uint32 random_data[4]; | 420 uint32 random_data[4]; |
416 std::string id; | 421 std::string id; |
417 do { | 422 do { |
418 base::RandBytes(random_data, sizeof(random_data)); | 423 base::RandBytes(random_data, sizeof(random_data)); |
419 id = base::HexEncode(random_data, sizeof(random_data)); | 424 id = base::HexEncode(random_data, sizeof(random_data)); |
420 } while (instance_map_.find(id) != instance_map_.end()); | 425 } while (instance_map_.find(id) != instance_map_.end()); |
421 return id; | 426 return id; |
422 } | 427 } |
423 | 428 |
424 } // namespace fileapi | 429 } // namespace fileapi |
OLD | NEW |