Changeset 221544 in webkit


Ignore:
Timestamp:
Sep 2, 2017 9:02:05 PM (7 years ago)
Author:
Chris Dumez
Message:

Implement FileSystemFileEntry.file()
https://bugs.webkit.org/show_bug.cgi?id=176166
<rdar://problem/34187756>

Reviewed by Sam Weinig.

Source/WebCore:

Implement FileSystemFileEntry.file():

Test: editing/pasteboard/datatransfer-items-drop-fileEntry-file.html

  • Modules/entriesapi/DOMFileSystem.cpp:

(WebCore::validatePathIsExpectedType):
(WebCore::DOMFileSystem::listDirectory):
(WebCore::DOMFileSystem::getParent):
(WebCore::DOMFileSystem::getFile):

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

(WebCore::FileSystemFileEntry::file):

LayoutTests:

Add layout test coverage. I have verified that this test passes in Chrome as well.

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

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r221540 r221544  
     12017-09-02  Chris Dumez  <cdumez@apple.com>
     2
     3        Implement FileSystemFileEntry.file()
     4        https://bugs.webkit.org/show_bug.cgi?id=176166
     5        <rdar://problem/34187756>
     6
     7        Reviewed by Sam Weinig.
     8
     9        Add layout test coverage. I have verified that this test passes in Chrome as well.
     10
     11        * editing/pasteboard/datatransfer-items-drop-fileEntry-file-expected.txt: Added.
     12        * editing/pasteboard/datatransfer-items-drop-fileEntry-file.html: Added.
     13        * platform/wk2/TestExpectations:
     14
    1152017-09-02  Chris Dumez  <cdumez@apple.com>
    216
  • trunk/LayoutTests/platform/wk2/TestExpectations

    r221540 r221544  
    567567editing/pasteboard/datatransfer-items-drop-directoryReader-error.html
    568568editing/pasteboard/datatransfer-items-drop-directoryReader-root.html
     569editing/pasteboard/datatransfer-items-drop-fileEntry-file.html
    569570editing/pasteboard/datatransfer-items-drop-getAsEntry.html
    570571editing/pasteboard/datatransfer-items-drop-getDirectory.html
  • trunk/Source/WebCore/ChangeLog

    r221543 r221544  
     12017-09-02  Chris Dumez  <cdumez@apple.com>
     2
     3        Implement FileSystemFileEntry.file()
     4        https://bugs.webkit.org/show_bug.cgi?id=176166
     5        <rdar://problem/34187756>
     6
     7        Reviewed by Sam Weinig.
     8
     9        Implement FileSystemFileEntry.file():
     10        - https://wicg.github.io/entries-api/#dom-filesystemfileentry-file
     11
     12        Test: editing/pasteboard/datatransfer-items-drop-fileEntry-file.html
     13
     14        * Modules/entriesapi/DOMFileSystem.cpp:
     15        (WebCore::validatePathIsExpectedType):
     16        (WebCore::DOMFileSystem::listDirectory):
     17        (WebCore::DOMFileSystem::getParent):
     18        (WebCore::DOMFileSystem::getFile):
     19        * Modules/entriesapi/DOMFileSystem.h:
     20        * Modules/entriesapi/FileSystemFileEntry.cpp:
     21        (WebCore::FileSystemFileEntry::file):
     22
    1232017-09-02  Andy Estes  <aestes@apple.com>
    224
  • trunk/Source/WebCore/Modules/entriesapi/DOMFileSystem.cpp

    r221540 r221544  
    160160}
    161161
     162static ExceptionOr<String> validatePathIsExpectedType(const String& fullPath, String&& virtualPath, FileMetadata::Type expectedType)
     163{
     164    ASSERT(!isMainThread());
     165
     166    FileMetadata metadata;
     167    if (!getFileMetadata(fullPath, metadata, ShouldFollowSymbolicLinks::No))
     168        return Exception { NotFoundError, ASCIILiteral("Path does not exist") };
     169
     170    if (metadata.type != expectedType)
     171        return Exception { TypeMismatchError, "Entry at path does not have expected type" };
     172
     173    return WTFMove(virtualPath);
     174}
     175
    162176// https://wicg.github.io/entries-api/#resolve-a-relative-path
    163177static String resolveRelativeVirtualPath(const String& baseVirtualPath, StringView relativeVirtualPath)
     
    218232    ASSERT(&directory.filesystem() == this);
    219233
    220     String directoryVirtualPath = directory.virtualPath();
    221     String fullPath = evaluatePath(directoryVirtualPath);
     234    auto directoryVirtualPath = directory.virtualPath();
     235    auto fullPath = evaluatePath(directoryVirtualPath);
    222236    if (fullPath == m_rootPath) {
    223237        Vector<Ref<FileSystemEntry>> children;
     
    227241    }
    228242
    229     m_workQueue->dispatch([this, context = makeRef(context), completionHandler = WTFMove(completionHandler), fullPath = fullPath.isolatedCopy(), directoryVirtualPath = directoryVirtualPath.isolatedCopy()]() mutable {
     243    m_workQueue->dispatch([this, context = makeRef(context), completionHandler = WTFMove(completionHandler), fullPath = crossThreadCopy(fullPath), directoryVirtualPath = crossThreadCopy(directoryVirtualPath)]() mutable {
    230244        auto listedChildren = listDirectoryWithMetadata(fullPath);
    231245        callOnMainThread([this, context = WTFMove(context), completionHandler = WTFMove(completionHandler), listedChildren = crossThreadCopy(listedChildren), directoryVirtualPath = directoryVirtualPath.isolatedCopy()]() mutable {
     
    235249}
    236250
    237 static ExceptionOr<String> validatePathIsDirectory(const String& fullPath, String&& virtualPath)
    238 {
    239     ASSERT(!isMainThread());
    240 
    241     if (!fileIsDirectory(fullPath, ShouldFollowSymbolicLinks::No))
    242         return Exception { NotFoundError, "Path no longer exists or is no longer a directory" };
    243     return WTFMove(virtualPath);
    244 }
    245 
    246251void DOMFileSystem::getParent(ScriptExecutionContext& context, FileSystemEntry& entry, GetParentCallback&& completionCallback)
    247252{
    248253    ASSERT(&entry.filesystem() == this);
    249254
    250     String virtualPath = resolveRelativeVirtualPath(entry.virtualPath(), "..");
     255    auto virtualPath = resolveRelativeVirtualPath(entry.virtualPath(), "..");
    251256    ASSERT(virtualPath[0] == '/');
    252     String fullPath = evaluatePath(virtualPath);
     257    auto fullPath = evaluatePath(virtualPath);
    253258    m_workQueue->dispatch([this, context = makeRef(context), fullPath = crossThreadCopy(fullPath), virtualPath = crossThreadCopy(virtualPath), completionCallback = WTFMove(completionCallback)]() mutable {
    254         auto validatedVirtualPath = validatePathIsDirectory(fullPath, WTFMove(virtualPath));
     259        auto validatedVirtualPath = validatePathIsExpectedType(fullPath, WTFMove(virtualPath), FileMetadata::TypeDirectory);
    255260        callOnMainThread([this, context = WTFMove(context), validatedVirtualPath = crossThreadCopy(validatedVirtualPath), completionCallback = WTFMove(completionCallback)]() mutable {
    256261            if (validatedVirtualPath.hasException())
     
    282287    }
    283288
    284     String resolvedVirtualPath = resolveRelativeVirtualPath(directory.virtualPath(), virtualPath);
     289    auto resolvedVirtualPath = resolveRelativeVirtualPath(directory.virtualPath(), virtualPath);
    285290    ASSERT(resolvedVirtualPath[0] == '/');
    286     String fullPath = evaluatePath(resolvedVirtualPath);
     291    auto fullPath = evaluatePath(resolvedVirtualPath);
    287292    if (fullPath == m_rootPath) {
    288293        callOnMainThread([this, context = makeRef(context), completionCallback = WTFMove(completionCallback)]() mutable {
     
    311316}
    312317
     318void DOMFileSystem::getFile(ScriptExecutionContext& context, FileSystemFileEntry& fileEntry, GetFileCallback&& completionCallback)
     319{
     320    auto virtualPath = fileEntry.virtualPath();
     321    auto fullPath = evaluatePath(virtualPath);
     322    m_workQueue->dispatch([this, context = makeRef(context), fullPath = crossThreadCopy(fullPath), virtualPath = crossThreadCopy(virtualPath), completionCallback = WTFMove(completionCallback)]() mutable {
     323        auto validatedVirtualPath = validatePathIsExpectedType(fullPath, WTFMove(virtualPath), FileMetadata::TypeFile);
     324        callOnMainThread([this, context = WTFMove(context), fullPath = crossThreadCopy(fullPath), validatedVirtualPath = crossThreadCopy(validatedVirtualPath), completionCallback = WTFMove(completionCallback)]() mutable {
     325            if (validatedVirtualPath.hasException())
     326                completionCallback(validatedVirtualPath.releaseException());
     327            else
     328                completionCallback(File::create(fullPath));
     329        });
     330    });
     331}
     332
    313333} // namespace WebCore
  • trunk/Source/WebCore/Modules/entriesapi/DOMFileSystem.h

    r221540 r221544  
    6262    void getEntry(ScriptExecutionContext&, FileSystemDirectoryEntry&, const String& virtualPath, const FileSystemDirectoryEntry::Flags&, GetEntryCallback&&);
    6363
     64    using GetFileCallback = WTF::Function<void(ExceptionOr<Ref<File>>&&)>;
     65    void getFile(ScriptExecutionContext&, FileSystemFileEntry&, GetFileCallback&&);
     66
    6467private:
    6568    explicit DOMFileSystem(Ref<File>&&);
  • trunk/Source/WebCore/Modules/entriesapi/FileSystemFileEntry.cpp

    r221481 r221544  
    2828
    2929#include "DOMException.h"
     30#include "DOMFileSystem.h"
    3031#include "ErrorCallback.h"
     32#include "FileCallback.h"
    3133
    3234namespace WebCore {
     
    3739}
    3840
    39 void FileSystemFileEntry::file(ScriptExecutionContext& context, RefPtr<FileCallback>&&, RefPtr<ErrorCallback>&& errorCallback)
     41void FileSystemFileEntry::file(ScriptExecutionContext& context, Ref<FileCallback>&& successCallback, RefPtr<ErrorCallback>&& errorCallback)
    4042{
    41     if (errorCallback)
    42         errorCallback->scheduleCallback(context, DOMException::create(NotSupportedError));
     43    filesystem().getFile(context, *this, [successCallback = WTFMove(successCallback), errorCallback = WTFMove(errorCallback)](auto&& result) {
     44        if (result.hasException()) {
     45            if (errorCallback)
     46                errorCallback->handleEvent(DOMException::create(result.releaseException()));
     47            return;
     48        }
     49        successCallback->handleEvent(result.releaseReturnValue());
     50    });
    4351}
    4452
  • trunk/Source/WebCore/Modules/entriesapi/FileSystemFileEntry.h

    r221481 r221544  
    4141    }
    4242
    43     void file(ScriptExecutionContext&, RefPtr<FileCallback>&&, RefPtr<ErrorCallback>&& = nullptr);
     43    void file(ScriptExecutionContext&, Ref<FileCallback>&&, RefPtr<ErrorCallback>&& = nullptr);
    4444
    4545private:
  • trunk/Source/WebCore/Modules/entriesapi/FileSystemFileEntry.idl

    r221302 r221544  
    2727    EnabledAtRuntime=DirectoryUpload,
    2828] interface FileSystemFileEntry : FileSystemEntry {
    29     [CallWith=ScriptExecutionContext] void file(FileCallback? successCallback, optional ErrorCallback? errorCallback);
     29    [CallWith=ScriptExecutionContext] void file(FileCallback successCallback, optional ErrorCallback? errorCallback);
    3030};
Note: See TracChangeset for help on using the changeset viewer.