| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 else if (type == kFileSystemTypeExternal) | 101 else if (type == kFileSystemTypeExternal) |
| 102 type_string = kExternalPathPrefix; | 102 type_string = kExternalPathPrefix; |
| 103 else | 103 else |
| 104 return KURL(); | 104 return KURL(); |
| 105 | 105 |
| 106 String result = "filesystem:" + origin + "/" + type_string + "/"; | 106 String result = "filesystem:" + origin + "/" + type_string + "/"; |
| 107 return KURL(kParsedURLString, result); | 107 return KURL(kParsedURLString, result); |
| 108 } | 108 } |
| 109 | 109 |
| 110 bool DOMFileSystemBase::SupportsToURL() const { | 110 bool DOMFileSystemBase::SupportsToURL() const { |
| 111 ASSERT(IsValidType(type_)); | 111 DCHECK(IsValidType(type_)); |
| 112 return type_ != kFileSystemTypeIsolated; | 112 return type_ != kFileSystemTypeIsolated; |
| 113 } | 113 } |
| 114 | 114 |
| 115 KURL DOMFileSystemBase::CreateFileSystemURL(const EntryBase* entry) const { | 115 KURL DOMFileSystemBase::CreateFileSystemURL(const EntryBase* entry) const { |
| 116 return CreateFileSystemURL(entry->fullPath()); | 116 return CreateFileSystemURL(entry->fullPath()); |
| 117 } | 117 } |
| 118 | 118 |
| 119 KURL DOMFileSystemBase::CreateFileSystemURL(const String& full_path) const { | 119 KURL DOMFileSystemBase::CreateFileSystemURL(const String& full_path) const { |
| 120 ASSERT(DOMFilePath::IsAbsolute(full_path)); | 120 DCHECK(DOMFilePath::IsAbsolute(full_path)); |
| 121 | 121 |
| 122 if (GetType() == kFileSystemTypeExternal) { | 122 if (GetType() == kFileSystemTypeExternal) { |
| 123 // For external filesystem originString could be different from what we have | 123 // For external filesystem originString could be different from what we have |
| 124 // in m_filesystemRootURL. | 124 // in m_filesystemRootURL. |
| 125 StringBuilder result; | 125 StringBuilder result; |
| 126 result.Append("filesystem:"); | 126 result.Append("filesystem:"); |
| 127 result.Append(GetSecurityOrigin()->ToString()); | 127 result.Append(GetSecurityOrigin()->ToString()); |
| 128 result.Append('/'); | 128 result.Append('/'); |
| 129 result.Append(kExternalPathPrefix); | 129 result.Append(kExternalPathPrefix); |
| 130 result.Append(filesystem_root_url_.GetPath()); | 130 result.Append(filesystem_root_url_.GetPath()); |
| 131 // Remove the extra leading slash. | 131 // Remove the extra leading slash. |
| 132 result.Append(EncodeWithURLEscapeSequences(full_path.Substring(1))); | 132 result.Append(EncodeWithURLEscapeSequences(full_path.Substring(1))); |
| 133 return KURL(kParsedURLString, result.ToString()); | 133 return KURL(kParsedURLString, result.ToString()); |
| 134 } | 134 } |
| 135 | 135 |
| 136 // For regular types we can just append the entry's fullPath to the | 136 // For regular types we can just append the entry's fullPath to the |
| 137 // m_filesystemRootURL that should look like | 137 // m_filesystemRootURL that should look like |
| 138 // 'filesystem:<origin>/<typePrefix>'. | 138 // 'filesystem:<origin>/<typePrefix>'. |
| 139 ASSERT(!filesystem_root_url_.IsEmpty()); | 139 DCHECK(!filesystem_root_url_.IsEmpty()); |
| 140 KURL url = filesystem_root_url_; | 140 KURL url = filesystem_root_url_; |
| 141 // Remove the extra leading slash. | 141 // Remove the extra leading slash. |
| 142 url.SetPath(url.GetPath() + | 142 url.SetPath(url.GetPath() + |
| 143 EncodeWithURLEscapeSequences(full_path.Substring(1))); | 143 EncodeWithURLEscapeSequences(full_path.Substring(1))); |
| 144 return url; | 144 return url; |
| 145 } | 145 } |
| 146 | 146 |
| 147 bool DOMFileSystemBase::PathToAbsolutePath(FileSystemType type, | 147 bool DOMFileSystemBase::PathToAbsolutePath(FileSystemType type, |
| 148 const EntryBase* base, | 148 const EntryBase* base, |
| 149 String path, | 149 String path, |
| 150 String& absolute_path) { | 150 String& absolute_path) { |
| 151 ASSERT(base); | 151 DCHECK(base); |
| 152 | 152 |
| 153 if (!DOMFilePath::IsAbsolute(path)) | 153 if (!DOMFilePath::IsAbsolute(path)) |
| 154 path = DOMFilePath::Append(base->fullPath(), path); | 154 path = DOMFilePath::Append(base->fullPath(), path); |
| 155 absolute_path = DOMFilePath::RemoveExtraParentReferences(path); | 155 absolute_path = DOMFilePath::RemoveExtraParentReferences(path); |
| 156 | 156 |
| 157 return (type != kFileSystemTypeTemporary && | 157 return (type != kFileSystemTypeTemporary && |
| 158 type != kFileSystemTypePersistent) || | 158 type != kFileSystemTypePersistent) || |
| 159 DOMFilePath::IsValidPath(absolute_path); | 159 DOMFilePath::IsValidPath(absolute_path); |
| 160 } | 160 } |
| 161 | 161 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(MetadataCallbacks::Create( | 220 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(MetadataCallbacks::Create( |
| 221 success_callback, error_callback, context_, this)); | 221 success_callback, error_callback, context_, this)); |
| 222 callbacks->SetShouldBlockUntilCompletion(synchronous_type == kSynchronous); | 222 callbacks->SetShouldBlockUntilCompletion(synchronous_type == kSynchronous); |
| 223 FileSystem()->ReadMetadata(CreateFileSystemURL(entry), std::move(callbacks)); | 223 FileSystem()->ReadMetadata(CreateFileSystemURL(entry), std::move(callbacks)); |
| 224 } | 224 } |
| 225 | 225 |
| 226 static bool VerifyAndGetDestinationPathForCopyOrMove(const EntryBase* source, | 226 static bool VerifyAndGetDestinationPathForCopyOrMove(const EntryBase* source, |
| 227 EntryBase* parent, | 227 EntryBase* parent, |
| 228 const String& new_name, | 228 const String& new_name, |
| 229 String& destination_path) { | 229 String& destination_path) { |
| 230 ASSERT(source); | 230 DCHECK(source); |
| 231 | 231 |
| 232 if (!parent || !parent->isDirectory()) | 232 if (!parent || !parent->isDirectory()) |
| 233 return false; | 233 return false; |
| 234 | 234 |
| 235 if (!new_name.IsEmpty() && !DOMFilePath::IsValidName(new_name)) | 235 if (!new_name.IsEmpty() && !DOMFilePath::IsValidName(new_name)) |
| 236 return false; | 236 return false; |
| 237 | 237 |
| 238 const bool is_same_file_system = | 238 const bool is_same_file_system = |
| 239 (*source->filesystem() == *parent->filesystem()); | 239 (*source->filesystem() == *parent->filesystem()); |
| 240 | 240 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 | 320 |
| 321 void DOMFileSystemBase::Remove(const EntryBase* entry, | 321 void DOMFileSystemBase::Remove(const EntryBase* entry, |
| 322 VoidCallback* success_callback, | 322 VoidCallback* success_callback, |
| 323 ErrorCallbackBase* error_callback, | 323 ErrorCallbackBase* error_callback, |
| 324 SynchronousType synchronous_type) { | 324 SynchronousType synchronous_type) { |
| 325 if (!FileSystem()) { | 325 if (!FileSystem()) { |
| 326 ReportError(error_callback, FileError::kAbortErr); | 326 ReportError(error_callback, FileError::kAbortErr); |
| 327 return; | 327 return; |
| 328 } | 328 } |
| 329 | 329 |
| 330 ASSERT(entry); | 330 DCHECK(entry); |
| 331 // We don't allow calling remove() on the root directory. | 331 // We don't allow calling remove() on the root directory. |
| 332 if (entry->fullPath() == String(DOMFilePath::kRoot)) { | 332 if (entry->fullPath() == String(DOMFilePath::kRoot)) { |
| 333 ReportError(error_callback, FileError::kInvalidModificationErr); | 333 ReportError(error_callback, FileError::kInvalidModificationErr); |
| 334 return; | 334 return; |
| 335 } | 335 } |
| 336 | 336 |
| 337 std::unique_ptr<AsyncFileSystemCallbacks> callbacks( | 337 std::unique_ptr<AsyncFileSystemCallbacks> callbacks( |
| 338 VoidCallbacks::Create(success_callback, error_callback, context_, this)); | 338 VoidCallbacks::Create(success_callback, error_callback, context_, this)); |
| 339 callbacks->SetShouldBlockUntilCompletion(synchronous_type == kSynchronous); | 339 callbacks->SetShouldBlockUntilCompletion(synchronous_type == kSynchronous); |
| 340 | 340 |
| 341 FileSystem()->Remove(CreateFileSystemURL(entry), std::move(callbacks)); | 341 FileSystem()->Remove(CreateFileSystemURL(entry), std::move(callbacks)); |
| 342 } | 342 } |
| 343 | 343 |
| 344 void DOMFileSystemBase::RemoveRecursively(const EntryBase* entry, | 344 void DOMFileSystemBase::RemoveRecursively(const EntryBase* entry, |
| 345 VoidCallback* success_callback, | 345 VoidCallback* success_callback, |
| 346 ErrorCallbackBase* error_callback, | 346 ErrorCallbackBase* error_callback, |
| 347 SynchronousType synchronous_type) { | 347 SynchronousType synchronous_type) { |
| 348 if (!FileSystem()) { | 348 if (!FileSystem()) { |
| 349 ReportError(error_callback, FileError::kAbortErr); | 349 ReportError(error_callback, FileError::kAbortErr); |
| 350 return; | 350 return; |
| 351 } | 351 } |
| 352 | 352 |
| 353 ASSERT(entry && entry->isDirectory()); | 353 DCHECK(entry); |
| 354 DCHECK(entry->isDirectory()); |
| 354 // We don't allow calling remove() on the root directory. | 355 // We don't allow calling remove() on the root directory. |
| 355 if (entry->fullPath() == String(DOMFilePath::kRoot)) { | 356 if (entry->fullPath() == String(DOMFilePath::kRoot)) { |
| 356 ReportError(error_callback, FileError::kInvalidModificationErr); | 357 ReportError(error_callback, FileError::kInvalidModificationErr); |
| 357 return; | 358 return; |
| 358 } | 359 } |
| 359 | 360 |
| 360 std::unique_ptr<AsyncFileSystemCallbacks> callbacks( | 361 std::unique_ptr<AsyncFileSystemCallbacks> callbacks( |
| 361 VoidCallbacks::Create(success_callback, error_callback, context_, this)); | 362 VoidCallbacks::Create(success_callback, error_callback, context_, this)); |
| 362 callbacks->SetShouldBlockUntilCompletion(synchronous_type == kSynchronous); | 363 callbacks->SetShouldBlockUntilCompletion(synchronous_type == kSynchronous); |
| 363 | 364 |
| 364 FileSystem()->RemoveRecursively(CreateFileSystemURL(entry), | 365 FileSystem()->RemoveRecursively(CreateFileSystemURL(entry), |
| 365 std::move(callbacks)); | 366 std::move(callbacks)); |
| 366 } | 367 } |
| 367 | 368 |
| 368 void DOMFileSystemBase::GetParent(const EntryBase* entry, | 369 void DOMFileSystemBase::GetParent(const EntryBase* entry, |
| 369 EntryCallback* success_callback, | 370 EntryCallback* success_callback, |
| 370 ErrorCallbackBase* error_callback) { | 371 ErrorCallbackBase* error_callback) { |
| 371 if (!FileSystem()) { | 372 if (!FileSystem()) { |
| 372 ReportError(error_callback, FileError::kAbortErr); | 373 ReportError(error_callback, FileError::kAbortErr); |
| 373 return; | 374 return; |
| 374 } | 375 } |
| 375 | 376 |
| 376 ASSERT(entry); | 377 DCHECK(entry); |
| 377 String path = DOMFilePath::GetDirectory(entry->fullPath()); | 378 String path = DOMFilePath::GetDirectory(entry->fullPath()); |
| 378 | 379 |
| 379 FileSystem()->DirectoryExists( | 380 FileSystem()->DirectoryExists( |
| 380 CreateFileSystemURL(path), | 381 CreateFileSystemURL(path), |
| 381 EntryCallbacks::Create(success_callback, error_callback, context_, this, | 382 EntryCallbacks::Create(success_callback, error_callback, context_, this, |
| 382 path, true)); | 383 path, true)); |
| 383 } | 384 } |
| 384 | 385 |
| 385 void DOMFileSystemBase::GetFile(const EntryBase* entry, | 386 void DOMFileSystemBase::GetFile(const EntryBase* entry, |
| 386 const String& path, | 387 const String& path, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 int DOMFileSystemBase::ReadDirectory(DirectoryReaderBase* reader, | 444 int DOMFileSystemBase::ReadDirectory(DirectoryReaderBase* reader, |
| 444 const String& path, | 445 const String& path, |
| 445 EntriesCallback* success_callback, | 446 EntriesCallback* success_callback, |
| 446 ErrorCallbackBase* error_callback, | 447 ErrorCallbackBase* error_callback, |
| 447 SynchronousType synchronous_type) { | 448 SynchronousType synchronous_type) { |
| 448 if (!FileSystem()) { | 449 if (!FileSystem()) { |
| 449 ReportError(error_callback, FileError::kAbortErr); | 450 ReportError(error_callback, FileError::kAbortErr); |
| 450 return 0; | 451 return 0; |
| 451 } | 452 } |
| 452 | 453 |
| 453 ASSERT(DOMFilePath::IsAbsolute(path)); | 454 DCHECK(DOMFilePath::IsAbsolute(path)); |
| 454 | 455 |
| 455 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntriesCallbacks::Create( | 456 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntriesCallbacks::Create( |
| 456 success_callback, error_callback, context_, reader, path)); | 457 success_callback, error_callback, context_, reader, path)); |
| 457 callbacks->SetShouldBlockUntilCompletion(synchronous_type == kSynchronous); | 458 callbacks->SetShouldBlockUntilCompletion(synchronous_type == kSynchronous); |
| 458 | 459 |
| 459 return FileSystem()->ReadDirectory(CreateFileSystemURL(path), | 460 return FileSystem()->ReadDirectory(CreateFileSystemURL(path), |
| 460 std::move(callbacks)); | 461 std::move(callbacks)); |
| 461 } | 462 } |
| 462 | 463 |
| 463 bool DOMFileSystemBase::WaitForAdditionalResult(int callbacks_id) { | 464 bool DOMFileSystemBase::WaitForAdditionalResult(int callbacks_id) { |
| 464 if (!FileSystem()) | 465 if (!FileSystem()) |
| 465 return false; | 466 return false; |
| 466 return FileSystem()->WaitForAdditionalResult(callbacks_id); | 467 return FileSystem()->WaitForAdditionalResult(callbacks_id); |
| 467 } | 468 } |
| 468 | 469 |
| 469 } // namespace blink | 470 } // namespace blink |
| OLD | NEW |