Implement FileSystemDirectoryReader.readEntries()
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 31 Aug 2017 03:48:21 +0000 (03:48 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 31 Aug 2017 03:48:21 +0000 (03:48 +0000)
commit10c7fafca6c15a7205ea85a126d32fc388bdaaaf
tree4487c1c865c9472afc710af7137078c0c300a4e3
parentdfa8f2d873be92de349aae539ec19db20a675d89
Implement FileSystemDirectoryReader.readEntries()
https://bugs.webkit.org/show_bug.cgi?id=176091
<rdar://problem/34168015>

Reviewed by Andreas Kling.

Source/WebCore:

Tests: editing/pasteboard/datatransfer-items-drop-directoryReader-error.html
       editing/pasteboard/datatransfer-items-drop-directoryReader-root.html
       editing/pasteboard/datatransfer-items-drop-directoryReader.html

* Modules/entriesapi/DOMFileSystem.cpp:
(WebCore::ListedChild::isolatedCopy const):
(WebCore::listDirectoryWithMetadata):
(WebCore::toFileSystemEntries):
(WebCore::DOMFileSystem::DOMFileSystem):
(WebCore::DOMFileSystem::root):
(WebCore::DOMFileSystem::fileAsEntry):
(WebCore::DOMFileSystem::evaluatePath):
(WebCore::DOMFileSystem::listDirectory):
* Modules/entriesapi/DOMFileSystem.h:
(WebCore::DOMFileSystem::createEntryForFile):
* Modules/entriesapi/DOMFileSystem.idl:
- Implement directory listing operation for supporting
  FileSystemDirectoryReader::readEntries().
- Implement evaluatePath() operation as per:
  - https://wicg.github.io/entries-api/#evaluate-a-path
- DOMFileSystem should no longer hold a strong reference to
  the root entry and FileSystemEntry now holds a strong
  reference to the DOMFileSystem and this would create a
  cycle.

* Modules/entriesapi/FileSystemDirectoryEntry.cpp:
(WebCore::FileSystemDirectoryEntry::createReader):
* Modules/entriesapi/FileSystemDirectoryEntry.h:
* Modules/entriesapi/FileSystemDirectoryEntry.idl:
Have createReader() take a ScriptExecutionContext, which is needed
to construct a FileSystemDirectoryReader, now that FileSystemDirectoryReader
is an ActiveDOMObject.

* Modules/entriesapi/FileSystemDirectoryReader.cpp:
(WebCore::FileSystemDirectoryReader::FileSystemDirectoryReader):
(WebCore::FileSystemDirectoryReader::activeDOMObjectName const):
(WebCore::FileSystemDirectoryReader::canSuspendForDocumentSuspension const):
(WebCore::FileSystemDirectoryReader::readEntries):
* Modules/entriesapi/FileSystemDirectoryReader.h:
* Modules/entriesapi/FileSystemDirectoryReader.idl:
Provide implementation for FileSystemDirectoryReader.readEntries() as per:
- https://wicg.github.io/entries-api/#dom-filesystemdirectoryreader-readentries
For the actual directory listing operation, we ask the DOMFileSystem, which is
where all filesystem operations should live.
Also made the FileSystemDirectoryReader an ActiveDOMObject to keep it and its
wrapper alive while a file system operation is pending.

* Modules/entriesapi/FileSystemEntry.cpp:
(WebCore::FileSystemEntry::~FileSystemEntry):
(WebCore::FileSystemEntry::filesystem const):
* Modules/entriesapi/FileSystemEntry.h:
Make FileSystemEntry keep a strong reference to its DOMFileSystem object.
Previously, the DOMFileSystem was kept alive by the DataTransferItem but
this was unsafe because FileSystemEntry may outlive the DataTransferItem.

* dom/ActiveDOMObject.h:
(WebCore::ActiveDOMObject::PendingActivity::PendingActivity):
(WebCore::ActiveDOMObject::PendingActivity::~PendingActivity):
(WebCore::ActiveDOMObject::makePendingActivity):
Add PendingActivity / makePendingActivity() as a less error-prone
replacement for setPendingActivity() / unsetPendingActivity().

* dom/DOMException.cpp:
(WebCore::DOMException::create):
* dom/DOMException.h:
Add factory to construct a DOMException from an Exception.

* dom/DataTransferItem.cpp:
(WebCore::DataTransferItem::getAsEntry const):
* dom/DataTransferItem.h:

* dom/Exception.h:
(WebCore::Exception::isolatedCopy const):
* dom/ExceptionOr.h:
Make ExceptionOr<> / Exception work with CrossThreadCopier for convenience.

* html/FileListCreator.cpp:
(WebCore::FileListCreator::FileListCreator):
Use crossThreadCopy() instead of longer form.

* platform/FileSystem.h:
* platform/glib/FileSystemGlib.cpp:
(WebCore::pathByAppendingComponents):
* platform/posix/FileSystemPOSIX.cpp:
(WebCore::pathByAppendingComponents):
* platform/win/FileSystemWin.cpp:
(WebCore::pathByAppendingComponents):
Add pathByAppendingComponents() utility function, which is similar to
pathByAppendingComponent() but supports appending multiple components
in an efficient fashion.

Source/WTF:

* wtf/CrossThreadCopier.h:
(WTF::crossThreadCopy):
* wtf/CrossThreadTask.h:
Move crossThreadCopy() from CrossThreadTask.h to CrossThreadCopier.h and
add "using WTF::crossThreadCopy" statement to make it more easily usable
from WebCore.

LayoutTests:

Add layout test coverage.

* editing/editing.js:
(moveMouseToCenterOfElement):
(dragFilesOntoElement):
* editing/pasteboard/datatransfer-items-drop-directoryReader-error-expected.txt: Added.
* editing/pasteboard/datatransfer-items-drop-directoryReader-error.html: Added.
* editing/pasteboard/datatransfer-items-drop-directoryReader-expected.txt: Added.
* editing/pasteboard/datatransfer-items-drop-directoryReader-root-expected.txt: Added.
* editing/pasteboard/datatransfer-items-drop-directoryReader-root.html: Added.
* editing/pasteboard/datatransfer-items-drop-directoryReader.html: Added.
* editing/pasteboard/datatransfer-items-drop-getAsEntry.html:
* platform/wk2/TestExpectations:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221414 268f45cc-cd09-0410-ab3c-d52691b4dbfc
37 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/editing.js
LayoutTests/editing/pasteboard/datatransfer-items-drop-directoryReader-error-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/datatransfer-items-drop-directoryReader-error.html [new file with mode: 0644]
LayoutTests/editing/pasteboard/datatransfer-items-drop-directoryReader-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/datatransfer-items-drop-directoryReader-root-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/datatransfer-items-drop-directoryReader-root.html [new file with mode: 0644]
LayoutTests/editing/pasteboard/datatransfer-items-drop-directoryReader.html [new file with mode: 0644]
LayoutTests/editing/pasteboard/datatransfer-items-drop-getAsEntry.html
LayoutTests/platform/wk2/TestExpectations
Source/WTF/ChangeLog
Source/WTF/wtf/CrossThreadCopier.h
Source/WTF/wtf/CrossThreadTask.h
Source/WebCore/ChangeLog
Source/WebCore/Modules/entriesapi/DOMFileSystem.cpp
Source/WebCore/Modules/entriesapi/DOMFileSystem.h
Source/WebCore/Modules/entriesapi/DOMFileSystem.idl
Source/WebCore/Modules/entriesapi/FileSystemDirectoryEntry.cpp
Source/WebCore/Modules/entriesapi/FileSystemDirectoryEntry.h
Source/WebCore/Modules/entriesapi/FileSystemDirectoryEntry.idl
Source/WebCore/Modules/entriesapi/FileSystemDirectoryReader.cpp
Source/WebCore/Modules/entriesapi/FileSystemDirectoryReader.h
Source/WebCore/Modules/entriesapi/FileSystemDirectoryReader.idl
Source/WebCore/Modules/entriesapi/FileSystemEntry.cpp
Source/WebCore/Modules/entriesapi/FileSystemEntry.h
Source/WebCore/dom/ActiveDOMObject.h
Source/WebCore/dom/DOMException.cpp
Source/WebCore/dom/DOMException.h
Source/WebCore/dom/DataTransferItem.cpp
Source/WebCore/dom/DataTransferItem.h
Source/WebCore/dom/Exception.h
Source/WebCore/dom/ExceptionOr.h
Source/WebCore/html/FileListCreator.cpp
Source/WebCore/platform/FileSystem.h
Source/WebCore/platform/glib/FileSystemGlib.cpp
Source/WebCore/platform/posix/FileSystemPOSIX.cpp
Source/WebCore/platform/win/FileSystemWin.cpp