Changeset 221540 in webkit


Ignore:
Timestamp:
Sep 2, 2017 2:31:49 PM (7 years ago)
Author:
Chris Dumez
Message:

Implement FileSystemDirectoryEntry.getDirectory()
https://bugs.webkit.org/show_bug.cgi?id=176168
<rdar://problem/34187787>

Reviewed by Darin Adler.

Source/WebCore:

Implement FileSystemDirectoryEntry.getDirectory() as per:

Test: editing/pasteboard/datatransfer-items-drop-getDirectory.html

  • Modules/entriesapi/DOMFileSystem.cpp:

(WebCore::isValidVirtualPath):
(WebCore::resolveRelativeVirtualPath):
(WebCore::DOMFileSystem::getEntry):

  • Modules/entriesapi/DOMFileSystem.h:
  • Modules/entriesapi/FileSystemDirectoryEntry.cpp:

(WebCore::FileSystemDirectoryEntry::getEntry):
(WebCore::FileSystemDirectoryEntry::getFile):
(WebCore::FileSystemDirectoryEntry::getDirectory):

  • Modules/entriesapi/FileSystemDirectoryEntry.h:

LayoutTests:

Add layout test coverage.

  • editing/pasteboard/datatransfer-items-drop-getDirectory-expected.txt: Added.
  • editing/pasteboard/datatransfer-items-drop-getDirectory.html: Added.
  • platform/wk2/TestExpectations:
Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r221512 r221540  
     12017-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
    1152017-09-01  Sam Weinig  <sam@webkit.org>
    216
  • trunk/LayoutTests/platform/wk2/TestExpectations

    r221510 r221540  
    568568editing/pasteboard/datatransfer-items-drop-directoryReader-root.html
    569569editing/pasteboard/datatransfer-items-drop-getAsEntry.html
     570editing/pasteboard/datatransfer-items-drop-getDirectory.html
    570571editing/pasteboard/datatransfer-items-drop-getFile.html
    571572editing/pasteboard/datatransfer-items-drop-getParent-root.html
  • trunk/Source/WebCore/ChangeLog

    r221539 r221540  
     12017-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
    1252017-09-02  Joseph Pecoraro  <pecoraro@apple.com>
    226
  • trunk/Source/WebCore/Modules/entriesapi/DOMFileSystem.cpp

    r221510 r221540  
    131131        return false;
    132132    if (virtualPath[0] == '/')
    133         return isValidRelativeVirtualPath(virtualPath.substring(1));
     133        return virtualPath.length() == 1 || isValidRelativeVirtualPath(virtualPath.substring(1));
    134134    return isValidRelativeVirtualPath(virtualPath);
    135135}
     
    165165    ASSERT(baseVirtualPath[0] == '/');
    166166    if (relativeVirtualPath[0] == '/')
    167         return resolveRelativeVirtualPath(ASCIILiteral("/"), relativeVirtualPath.substring(1));
     167        return relativeVirtualPath.length() == 1 ? relativeVirtualPath.toString() : resolveRelativeVirtualPath(ASCIILiteral("/"), relativeVirtualPath.substring(1));
    168168
    169169    auto virtualPathSegments = baseVirtualPath.split('/');
     
    262262}
    263263
    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 
    278264// 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
     266void DOMFileSystem::getEntry(ScriptExecutionContext& context, FileSystemDirectoryEntry& directory, const String& virtualPath, const FileSystemDirectoryEntry::Flags& flags, GetEntryCallback&& completionCallback)
    280267{
    281268    ASSERT(&directory.filesystem() == this);
     
    298285    ASSERT(resolvedVirtualPath[0] == '/');
    299286    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
    300294    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            }
    307309        });
    308310    });
  • trunk/Source/WebCore/Modules/entriesapi/DOMFileSystem.h

    r221510 r221540  
    5959    void getParent(ScriptExecutionContext&, FileSystemEntry&, GetParentCallback&&);
    6060
    61     using GetFileCallback = WTF::Function<void(ExceptionOr<Ref<FileSystemFileEntry>>&&)>;
    62     void getFile(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&&);
    6363
    6464private:
  • trunk/Source/WebCore/Modules/entriesapi/FileSystemDirectoryEntry.cpp

    r221510 r221540  
    4747}
    4848
    49 void FileSystemDirectoryEntry::getFile(ScriptExecutionContext& context, const String& path, const Flags& flags, RefPtr<FileSystemEntryCallback>&& successCallback, RefPtr<ErrorCallback>&& errorCallback)
     49void FileSystemDirectoryEntry::getEntry(ScriptExecutionContext& context, const String& path, const Flags& flags, EntryMatchingFunction&& matches, RefPtr<FileSystemEntryCallback>&& successCallback, RefPtr<ErrorCallback>&& errorCallback)
    5050{
    5151    if (!successCallback && !errorCallback)
    5252        return;
    5353
    54     filesystem().getFile(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) {
    5555        if (result.hasException()) {
    5656            if (errorCallback)
     
    5858            return;
    5959        }
     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        }
    6066        if (successCallback)
    61             successCallback->handleEvent(result.releaseReturnValue());
     67            successCallback->handleEvent(WTFMove(entry));
    6268    });
    6369}
    6470
    65 void FileSystemDirectoryEntry::getDirectory(ScriptExecutionContext& context, const String&, const Flags&, RefPtr<FileSystemEntryCallback>&&, RefPtr<ErrorCallback>&& errorCallback)
     71void FileSystemDirectoryEntry::getFile(ScriptExecutionContext& context, const String& path, const Flags& flags, RefPtr<FileSystemEntryCallback>&& successCallback, RefPtr<ErrorCallback>&& errorCallback)
    6672{
    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
     76void 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));
    6979}
    7080
  • trunk/Source/WebCore/Modules/entriesapi/FileSystemDirectoryEntry.h

    r221481 r221540  
    5454private:
    5555    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>&&);
    5658
    5759    FileSystemDirectoryEntry(ScriptExecutionContext&, DOMFileSystem&, const String& virtualPath);
Note: See TracChangeset for help on using the changeset viewer.