Changeset 221540 in webkit
- Timestamp:
- Sep 2, 2017 2:31:49 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r221512 r221540 1 2017-09-02 Chris Dumez <cdumez@apple.com> 2 3 Implement FileSystemDirectoryEntry.getDirectory() 4 https://bugs.webkit.org/show_bug.cgi?id=176168 5 <rdar://problem/34187787> 6 7 Reviewed by Darin Adler. 8 9 Add layout test coverage. 10 11 * editing/pasteboard/datatransfer-items-drop-getDirectory-expected.txt: Added. 12 * editing/pasteboard/datatransfer-items-drop-getDirectory.html: Added. 13 * platform/wk2/TestExpectations: 14 1 15 2017-09-01 Sam Weinig <sam@webkit.org> 2 16 -
trunk/LayoutTests/platform/wk2/TestExpectations
r221510 r221540 568 568 editing/pasteboard/datatransfer-items-drop-directoryReader-root.html 569 569 editing/pasteboard/datatransfer-items-drop-getAsEntry.html 570 editing/pasteboard/datatransfer-items-drop-getDirectory.html 570 571 editing/pasteboard/datatransfer-items-drop-getFile.html 571 572 editing/pasteboard/datatransfer-items-drop-getParent-root.html -
trunk/Source/WebCore/ChangeLog
r221539 r221540 1 2017-09-02 Chris Dumez <cdumez@apple.com> 2 3 Implement FileSystemDirectoryEntry.getDirectory() 4 https://bugs.webkit.org/show_bug.cgi?id=176168 5 <rdar://problem/34187787> 6 7 Reviewed by Darin Adler. 8 9 Implement FileSystemDirectoryEntry.getDirectory() as per: 10 - https://wicg.github.io/entries-api/#dom-filesystemdirectoryentry-getdirectory 11 12 Test: editing/pasteboard/datatransfer-items-drop-getDirectory.html 13 14 * Modules/entriesapi/DOMFileSystem.cpp: 15 (WebCore::isValidVirtualPath): 16 (WebCore::resolveRelativeVirtualPath): 17 (WebCore::DOMFileSystem::getEntry): 18 * Modules/entriesapi/DOMFileSystem.h: 19 * Modules/entriesapi/FileSystemDirectoryEntry.cpp: 20 (WebCore::FileSystemDirectoryEntry::getEntry): 21 (WebCore::FileSystemDirectoryEntry::getFile): 22 (WebCore::FileSystemDirectoryEntry::getDirectory): 23 * Modules/entriesapi/FileSystemDirectoryEntry.h: 24 1 25 2017-09-02 Joseph Pecoraro <pecoraro@apple.com> 2 26 -
trunk/Source/WebCore/Modules/entriesapi/DOMFileSystem.cpp
r221510 r221540 131 131 return false; 132 132 if (virtualPath[0] == '/') 133 return isValidRelativeVirtualPath(virtualPath.substring(1));133 return virtualPath.length() == 1 || isValidRelativeVirtualPath(virtualPath.substring(1)); 134 134 return isValidRelativeVirtualPath(virtualPath); 135 135 } … … 165 165 ASSERT(baseVirtualPath[0] == '/'); 166 166 if (relativeVirtualPath[0] == '/') 167 return re solveRelativeVirtualPath(ASCIILiteral("/"), relativeVirtualPath.substring(1));167 return relativeVirtualPath.length() == 1 ? relativeVirtualPath.toString() : resolveRelativeVirtualPath(ASCIILiteral("/"), relativeVirtualPath.substring(1)); 168 168 169 169 auto virtualPathSegments = baseVirtualPath.split('/'); … … 262 262 } 263 263 264 static ExceptionOr<String> validatePathIsFile(const String& fullPath, String&& virtualPath)265 {266 ASSERT(!isMainThread());267 268 FileMetadata metadata;269 if (!getFileMetadata(fullPath, metadata, ShouldFollowSymbolicLinks::No))270 return Exception { NotFoundError, ASCIILiteral("File does not exist") };271 272 if (metadata.type != FileMetadata::TypeFile)273 return Exception { TypeMismatchError, ASCIILiteral("Entry at path is not a file") };274 275 return WTFMove(virtualPath);276 }277 278 264 // https://wicg.github.io/entries-api/#dom-filesystemdirectoryentry-getfile 279 void DOMFileSystem::getFile(ScriptExecutionContext& context, FileSystemDirectoryEntry& directory, const String& virtualPath, const FileSystemDirectoryEntry::Flags& flags, GetFileCallback&& completionCallback) 265 // https://wicg.github.io/entries-api/#dom-filesystemdirectoryentry-getdirectory 266 void DOMFileSystem::getEntry(ScriptExecutionContext& context, FileSystemDirectoryEntry& directory, const String& virtualPath, const FileSystemDirectoryEntry::Flags& flags, GetEntryCallback&& completionCallback) 280 267 { 281 268 ASSERT(&directory.filesystem() == this); … … 298 285 ASSERT(resolvedVirtualPath[0] == '/'); 299 286 String fullPath = evaluatePath(resolvedVirtualPath); 287 if (fullPath == m_rootPath) { 288 callOnMainThread([this, context = makeRef(context), completionCallback = WTFMove(completionCallback)]() mutable { 289 completionCallback(Ref<FileSystemEntry> { root(context) }); 290 }); 291 return; 292 } 293 300 294 m_workQueue->dispatch([this, context = makeRef(context), fullPath = crossThreadCopy(fullPath), resolvedVirtualPath = crossThreadCopy(resolvedVirtualPath), completionCallback = WTFMove(completionCallback)]() mutable { 301 auto validatedVirtualPath = validatePathIsFile(fullPath, WTFMove(resolvedVirtualPath)); 302 callOnMainThread([this, context = WTFMove(context), validatedVirtualPath = crossThreadCopy(validatedVirtualPath), completionCallback = WTFMove(completionCallback)]() mutable { 303 if (validatedVirtualPath.hasException()) 304 completionCallback(validatedVirtualPath.releaseException()); 305 else 306 completionCallback(FileSystemFileEntry::create(context, *this, validatedVirtualPath.releaseReturnValue())); 295 FileMetadata metadata; 296 getFileMetadata(fullPath, metadata, ShouldFollowSymbolicLinks::No); 297 callOnMainThread([this, context = WTFMove(context), resolvedVirtualPath = crossThreadCopy(resolvedVirtualPath), entryType = metadata.type, completionCallback = WTFMove(completionCallback)]() mutable { 298 switch (entryType) { 299 case FileMetadata::TypeDirectory: 300 completionCallback(Ref<FileSystemEntry> { FileSystemDirectoryEntry::create(context, *this, resolvedVirtualPath) }); 301 break; 302 case FileMetadata::TypeFile: 303 completionCallback(Ref<FileSystemEntry> { FileSystemFileEntry::create(context, *this, resolvedVirtualPath) }); 304 break; 305 default: 306 completionCallback(Exception { NotFoundError, ASCIILiteral("Cannot find entry at given path") }); 307 break; 308 } 307 309 }); 308 310 }); -
trunk/Source/WebCore/Modules/entriesapi/DOMFileSystem.h
r221510 r221540 59 59 void getParent(ScriptExecutionContext&, FileSystemEntry&, GetParentCallback&&); 60 60 61 using Get FileCallback = WTF::Function<void(ExceptionOr<Ref<FileSystemFileEntry>>&&)>;62 void get File(ScriptExecutionContext&, FileSystemDirectoryEntry&, const String& virtualPath, const FileSystemDirectoryEntry::Flags&, GetFileCallback&&);61 using GetEntryCallback = WTF::Function<void(ExceptionOr<Ref<FileSystemEntry>>&&)>; 62 void getEntry(ScriptExecutionContext&, FileSystemDirectoryEntry&, const String& virtualPath, const FileSystemDirectoryEntry::Flags&, GetEntryCallback&&); 63 63 64 64 private: -
trunk/Source/WebCore/Modules/entriesapi/FileSystemDirectoryEntry.cpp
r221510 r221540 47 47 } 48 48 49 void FileSystemDirectoryEntry::get File(ScriptExecutionContext& context, const String& path, const Flags& flags, RefPtr<FileSystemEntryCallback>&& successCallback, RefPtr<ErrorCallback>&& errorCallback)49 void FileSystemDirectoryEntry::getEntry(ScriptExecutionContext& context, const String& path, const Flags& flags, EntryMatchingFunction&& matches, RefPtr<FileSystemEntryCallback>&& successCallback, RefPtr<ErrorCallback>&& errorCallback) 50 50 { 51 51 if (!successCallback && !errorCallback) 52 52 return; 53 53 54 filesystem().get File(context, *this, path, flags, [this, pendingActivity = makePendingActivity(*this), successCallback = WTFMove(successCallback), errorCallback = WTFMove(errorCallback)](auto&& result) {54 filesystem().getEntry(context, *this, path, flags, [this, pendingActivity = makePendingActivity(*this), matches = WTFMove(matches), successCallback = WTFMove(successCallback), errorCallback = WTFMove(errorCallback)](auto&& result) { 55 55 if (result.hasException()) { 56 56 if (errorCallback) … … 58 58 return; 59 59 } 60 auto entry = result.releaseReturnValue(); 61 if (!matches(entry)) { 62 if (errorCallback) 63 errorCallback->handleEvent(DOMException::create(Exception { TypeMismatchError, ASCIILiteral("Entry at given path does not match expected type") })); 64 return; 65 } 60 66 if (successCallback) 61 successCallback->handleEvent( result.releaseReturnValue());67 successCallback->handleEvent(WTFMove(entry)); 62 68 }); 63 69 } 64 70 65 void FileSystemDirectoryEntry::get Directory(ScriptExecutionContext& context, const String&, const Flags&, RefPtr<FileSystemEntryCallback>&&, RefPtr<ErrorCallback>&& errorCallback)71 void FileSystemDirectoryEntry::getFile(ScriptExecutionContext& context, const String& path, const Flags& flags, RefPtr<FileSystemEntryCallback>&& successCallback, RefPtr<ErrorCallback>&& errorCallback) 66 72 { 67 if (errorCallback) 68 errorCallback->scheduleCallback(context, DOMException::create(NotSupportedError)); 73 getEntry(context, path, flags, [](auto& entry) { return entry.isFile(); }, WTFMove(successCallback), WTFMove(errorCallback)); 74 } 75 76 void FileSystemDirectoryEntry::getDirectory(ScriptExecutionContext& context, const String& path, const Flags& flags, RefPtr<FileSystemEntryCallback>&& successCallback, RefPtr<ErrorCallback>&& errorCallback) 77 { 78 getEntry(context, path, flags, [](auto& entry) { return entry.isDirectory(); }, WTFMove(successCallback), WTFMove(errorCallback)); 69 79 } 70 80 -
trunk/Source/WebCore/Modules/entriesapi/FileSystemDirectoryEntry.h
r221481 r221540 54 54 private: 55 55 bool isDirectory() const final { return true; } 56 using EntryMatchingFunction = WTF::Function<bool(const FileSystemEntry&)>; 57 void getEntry(ScriptExecutionContext&, const String& path, const Flags& options, EntryMatchingFunction&&, RefPtr<FileSystemEntryCallback>&&, RefPtr<ErrorCallback>&&); 56 58 57 59 FileSystemDirectoryEntry(ScriptExecutionContext&, DOMFileSystem&, const String& virtualPath);
Note: See TracChangeset
for help on using the changeset viewer.