Add initial support for dataTransferItem.webkitGetAsEntry()
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Aug 2017 17:00:09 +0000 (17:00 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Aug 2017 17:00:09 +0000 (17:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=176038
<rdar://problem/34121095>

Reviewed by Wenson Hsieh.

Source/JavaScriptCore:

Add CommonIdentifier needed by [EnabledAtRuntime].

* runtime/CommonIdentifiers.h:

Source/WebCore:

Add initial support for dataTransferItem.webkitGetAsEntry() as per:
- https://wicg.github.io/entries-api/#html-data

The method works as expected and returns a FileSystemEntry. The entry
can be either a file or a directory. All of the attributes exposed on
the FileSystemEntry return correct values.

What remains to be implemented for this new API to actually be useful:
- directory.getFile() / directory.getDirectory()
- file.file()
- entry.getParent()
- directoryReader.readEntries()

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

* CMakeLists.txt:
* DerivedSources.make:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSBindingsAllInOne.cpp:
Add new files to projects.

* Modules/entriesapi/DOMFileSystem.cpp:
(WebCore::DOMFileSystem::DOMFileSystem):
* Modules/entriesapi/DOMFileSystem.h:
(WebCore::DOMFileSystem::create):
DOMFileSystem factory now takes a name parameter. This name is a UUID, as suggested in
the specification and implemented by Firefox.

* Modules/entriesapi/ErrorCallback.cpp: Added.
* Modules/entriesapi/ErrorCallback.h:
Add scheduleCallback() convenience method as we often need to call this callback
asynchronously.

* Modules/entriesapi/FileSystemDirectoryEntry.cpp:
(WebCore::FileSystemDirectoryEntry::FileSystemDirectoryEntry):
(WebCore::FileSystemDirectoryEntry::createReader):
(WebCore::FileSystemDirectoryEntry::getFile):
(WebCore::FileSystemDirectoryEntry::getDirectory):
* Modules/entriesapi/FileSystemDirectoryEntry.h:
- Add implementation for createReader().
- Update getFile() / getDirectory() to call the error callback for now as they are
  unimplemented.
- Have the factory take the virtual path of the entry so that it can be
  exposed via the fullPath attribute in IDL.

* Modules/entriesapi/FileSystemDirectoryEntry.idl:
Expose createReader() now that we have stubs for FileSystemDirectoryReader.

* Modules/entriesapi/FileSystemDirectoryReader.cpp: Added.
* Modules/entriesapi/FileSystemDirectoryReader.h: Added.
* Modules/entriesapi/FileSystemDirectoryReader.idl: Added.
* Modules/entriesapi/FileSystemEntriesCallback.cpp: Added.
* Modules/entriesapi/FileSystemEntriesCallback.h: Added.
* Modules/entriesapi/FileSystemEntriesCallback.idl: Added.
Land stubs for FileSystemDirectoryReader and its FileSystemEntriesCallback.

* Modules/entriesapi/FileSystemEntry.cpp:
(WebCore::FileSystemEntry::FileSystemEntry):
* Modules/entriesapi/FileSystemEntry.h:
(WebCore::FileSystemEntry::virtualPath const):
* Modules/entriesapi/FileSystemEntry.idl:
Update constructor to take a virtual path, which is exposed via fullPath
attribute in IDL.

* Modules/entriesapi/FileSystemFileEntry.cpp:
(WebCore::FileSystemFileEntry::FileSystemFileEntry):
(WebCore::FileSystemFileEntry::file):
* Modules/entriesapi/FileSystemFileEntry.h:
(isType):
* Modules/entriesapi/FileSystemFileEntry.idl:
- Update file() to call the error callback for now as they are
  unimplemented.
- Have the factory take the virtual path of the entry so that it can be
  exposed via the fullPath attribute in IDL.

* bindings/js/JSFileSystemEntryCustom.cpp: Added.
(WebCore::toJSNewlyCreated):
(WebCore::toJS):
Add custom implementation of FileSystemEntry's toJS() function. This is
needed because FileSystemEntry has 2 subclasses and we need to type check
at runtime to construct the right wrapper.

* dom/DataTransferItem.cpp:
(WebCore::DataTransferItem::getAsEntry const):
* dom/DataTransferItem.h:
* dom/DataTransferItem.idl:
Add initial implementation for getAsEntry(), currently exposed as
webkitGetAsEntry().

* dom/DataTransferItemList.cpp:
(WebCore::DataTransferItemList::ensureItems const):
Construct a DataTransferItem if the file is a directory now that we
support getAsEntry().

* fileapi/File.cpp:
(WebCore::File::isDirectory const):
* fileapi/File.h:
Add convenience method to query if a File is a directory.

Source/WebKit:

Make dataTransfer.items an experimental feature so that it can be easily
turned on from the Develop menu, for testing convenience.

* Shared/WebPreferencesDefinitions.h:

LayoutTests:

* editing/pasteboard/datatransfer-items-drop-getAsEntry-expected.txt: Added.
* editing/pasteboard/datatransfer-items-drop-getAsEntry.html: Added.
Add layout test coverage.

* http/wpt/entries-api/interfaces-expected.txt:
Rebaseline test now that we support more of the API.

* platform/wk2/TestExpectations:
Skip new test on WK2 because it relies on beginDragWithFiles().

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221302 268f45cc-cd09-0410-ab3c-d52691b4dbfc

40 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/pasteboard/datatransfer-items-drop-getAsEntry-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/datatransfer-items-drop-getAsEntry.html [new file with mode: 0644]
LayoutTests/http/wpt/entries-api/interfaces-expected.txt
LayoutTests/platform/wk2/TestExpectations
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/CommonIdentifiers.h
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources.make
Source/WebCore/Modules/entriesapi/DOMFileSystem.cpp
Source/WebCore/Modules/entriesapi/DOMFileSystem.h
Source/WebCore/Modules/entriesapi/ErrorCallback.cpp [new file with mode: 0644]
Source/WebCore/Modules/entriesapi/ErrorCallback.h
Source/WebCore/Modules/entriesapi/FileSystemDirectoryEntry.cpp
Source/WebCore/Modules/entriesapi/FileSystemDirectoryEntry.h
Source/WebCore/Modules/entriesapi/FileSystemDirectoryEntry.idl
Source/WebCore/Modules/entriesapi/FileSystemDirectoryReader.cpp [new file with mode: 0644]
Source/WebCore/Modules/entriesapi/FileSystemDirectoryReader.h [new file with mode: 0644]
Source/WebCore/Modules/entriesapi/FileSystemDirectoryReader.idl [new file with mode: 0644]
Source/WebCore/Modules/entriesapi/FileSystemEntriesCallback.cpp [new file with mode: 0644]
Source/WebCore/Modules/entriesapi/FileSystemEntriesCallback.h [new file with mode: 0644]
Source/WebCore/Modules/entriesapi/FileSystemEntriesCallback.idl [new file with mode: 0644]
Source/WebCore/Modules/entriesapi/FileSystemEntry.cpp
Source/WebCore/Modules/entriesapi/FileSystemEntry.h
Source/WebCore/Modules/entriesapi/FileSystemEntry.idl
Source/WebCore/Modules/entriesapi/FileSystemFileEntry.cpp
Source/WebCore/Modules/entriesapi/FileSystemFileEntry.h
Source/WebCore/Modules/entriesapi/FileSystemFileEntry.idl
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSBindingsAllInOne.cpp
Source/WebCore/bindings/js/JSFileSystemEntryCustom.cpp [new file with mode: 0644]
Source/WebCore/dom/DataTransferItem.cpp
Source/WebCore/dom/DataTransferItem.h
Source/WebCore/dom/DataTransferItem.idl
Source/WebCore/dom/DataTransferItemList.cpp
Source/WebCore/fileapi/File.cpp
Source/WebCore/fileapi/File.h
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebPreferencesDefinitions.h

index 2ab4321..29eb1d4 100644 (file)
@@ -1,3 +1,21 @@
+2017-08-29  Chris Dumez  <cdumez@apple.com>
+
+        Add initial support for dataTransferItem.webkitGetAsEntry()
+        https://bugs.webkit.org/show_bug.cgi?id=176038
+        <rdar://problem/34121095>
+
+        Reviewed by Wenson Hsieh.
+
+        * editing/pasteboard/datatransfer-items-drop-getAsEntry-expected.txt: Added.
+        * editing/pasteboard/datatransfer-items-drop-getAsEntry.html: Added.
+        Add layout test coverage.
+
+        * http/wpt/entries-api/interfaces-expected.txt:
+        Rebaseline test now that we support more of the API.
+
+        * platform/wk2/TestExpectations:
+        Skip new test on WK2 because it relies on beginDragWithFiles().
+
 2017-08-29  Matt Lewis  <jlewis3@apple.com>
 
          Marked media/video-controls-no-display-with-text-track.html and media/video-controls-in-media-document.html as flaky.
diff --git a/LayoutTests/editing/pasteboard/datatransfer-items-drop-getAsEntry-expected.txt b/LayoutTests/editing/pasteboard/datatransfer-items-drop-getAsEntry-expected.txt
new file mode 100644 (file)
index 0000000..6b68de0
--- /dev/null
@@ -0,0 +1,32 @@
+Basic test coverage for dataTransferItem.webkitGetAsEntry()
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS dataTransfer.items.length is 2
+PASS firstDataTransferItem.kind is "file"
+PASS firstDataTransferItem.type is "text/plain"
+PASS firstFile.name is "test.txt"
+PASS firstFile.size is 5
+PASS firstFile.type is "text/plain"
+PASS firstEntry.isDirectory is false
+PASS firstEntry.isFile is true
+PASS firstEntry.name is "test.txt"
+PASS firstEntry.fullPath is "/test.txt"
+PASS secondDataTransferItem.kind is "file"
+PASS secondDataTransferItem.type is ""
+PASS secondFile.name is "testFiles"
+PASS secondFile.size is 204
+PASS secondFile.type is ""
+PASS secondEntry.isDirectory is true
+PASS secondEntry.isFile is false
+PASS secondEntry.name is "testFiles"
+PASS secondEntry.fullPath is "/testFiles"
+PASS fileSystemRoot.isDirectory is true
+PASS fileSystemRoot.isFile is false
+PASS fileSystemRoot.name is ""
+PASS fileSystemRoot.fullPath is "/"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/editing/pasteboard/datatransfer-items-drop-getAsEntry.html b/LayoutTests/editing/pasteboard/datatransfer-items-drop-getAsEntry.html
new file mode 100644 (file)
index 0000000..c0b8356
--- /dev/null
@@ -0,0 +1,81 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test.js"></script>
+</head>
+<body>
+<div id="dropzone" style="width: 200px; height: 200px; background-color: grey;"></div>
+<script>
+description("Basic test coverage for dataTransferItem.webkitGetAsEntry()");
+jsTestIsAsync = true;
+
+function moveMouseToCenterOfElement(element) {
+    var centerX = element.offsetLeft + element.offsetWidth / 2;
+    var centerY = element.offsetTop + element.offsetHeight / 2;
+    eventSender.mouseMoveTo(centerX, centerY);
+}
+
+function dragFilesOntoElement(element, files) {
+    if (!window.eventSender)
+        return;
+
+    eventSender.beginDragWithFiles(files);
+    moveMouseToCenterOfElement(element);
+    eventSender.mouseUp();
+}
+
+var dropzone = document.getElementById('dropzone');
+dropzone.ondrop = function(e) {
+    e.preventDefault();
+    dataTransfer = e.dataTransfer;
+
+    shouldBe("dataTransfer.items.length", "2");
+
+    firstDataTransferItem = dataTransfer.items[0];
+    shouldBeEqualToString("firstDataTransferItem.kind", "file");
+    shouldBeEqualToString("firstDataTransferItem.type", "text/plain");
+    firstFile = firstDataTransferItem.getAsFile();
+    shouldBeEqualToString("firstFile.name", "test.txt");
+    shouldBe("firstFile.size", "5");
+    shouldBeEqualToString("firstFile.type", "text/plain");
+
+    firstEntry = firstDataTransferItem.webkitGetAsEntry();
+    shouldBeFalse("firstEntry.isDirectory");
+    shouldBeTrue("firstEntry.isFile");
+    shouldBeEqualToString("firstEntry.name", "test.txt");
+    shouldBeEqualToString("firstEntry.fullPath", "/test.txt");
+
+    // Second item.
+    secondDataTransferItem = dataTransfer.items[1];
+    shouldBeEqualToString("secondDataTransferItem.kind", "file");
+    shouldBeEqualToString("secondDataTransferItem.type", "");
+    secondFile = secondDataTransferItem.getAsFile();
+    shouldBeEqualToString("secondFile.name", "testFiles");
+    shouldBe("secondFile.size", "204"); // Chrome returns folder size, Firefox returns 0.
+    shouldBeEqualToString("secondFile.type", "");
+
+    secondEntry = secondDataTransferItem.webkitGetAsEntry();
+    shouldBeTrue("secondEntry.isDirectory");
+    shouldBeFalse("secondEntry.isFile");
+    shouldBeEqualToString("secondEntry.name", "testFiles");
+    shouldBeEqualToString("secondEntry.fullPath", "/testFiles");
+
+    fileSystemRoot = secondEntry.filesystem.root;
+    shouldBeTrue("fileSystemRoot.isDirectory");
+    shouldBeFalse("fileSystemRoot.isFile");
+    shouldBeEqualToString("fileSystemRoot.name", "");
+    shouldBeEqualToString("fileSystemRoot.fullPath", "/");
+
+    finishJSTest();
+};
+
+dropzone.ondragover = function(ev) {
+    ev.preventDefault();
+}
+
+onload = function() {
+    dragFilesOntoElement(dropzone, ['../../fast/forms/resources/test.txt', '../../fast/forms/file/resources/testFiles']);
+}
+</script>
+</body>
+</html>
index e505347..e71b9ee 100644 (file)
@@ -21,19 +21,19 @@ PASS FileSystemDirectoryEntry interface object length
 PASS FileSystemDirectoryEntry interface object name 
 PASS FileSystemDirectoryEntry interface: existence and properties of interface prototype object 
 PASS FileSystemDirectoryEntry interface: existence and properties of interface prototype object's "constructor" property 
-FAIL FileSystemDirectoryEntry interface: operation createReader() assert_own_property: interface prototype object missing non-static operation expected property "createReader" missing
+PASS FileSystemDirectoryEntry interface: operation createReader() 
 PASS FileSystemDirectoryEntry interface: operation getFile(USVString,FileSystemFlags,FileSystemEntryCallback,ErrorCallback) 
 PASS FileSystemDirectoryEntry interface: operation getDirectory(USVString,FileSystemFlags,FileSystemEntryCallback,ErrorCallback) 
 PASS FileSystemEntryCallback interface: existence and properties of interface object 
 PASS FileSystemEntryCallback interface: existence and properties of interface prototype object 
 PASS FileSystemEntryCallback interface: existence and properties of interface prototype object's "constructor" property 
 PASS FileSystemEntryCallback interface: operation handleEvent(FileSystemEntry) 
-FAIL FileSystemDirectoryReader interface: existence and properties of interface object assert_own_property: self does not have own property "FileSystemDirectoryReader" expected property "FileSystemDirectoryReader" missing
-FAIL FileSystemDirectoryReader interface object length assert_own_property: self does not have own property "FileSystemDirectoryReader" expected property "FileSystemDirectoryReader" missing
-FAIL FileSystemDirectoryReader interface object name assert_own_property: self does not have own property "FileSystemDirectoryReader" expected property "FileSystemDirectoryReader" missing
-FAIL FileSystemDirectoryReader interface: existence and properties of interface prototype object assert_own_property: self does not have own property "FileSystemDirectoryReader" expected property "FileSystemDirectoryReader" missing
-FAIL FileSystemDirectoryReader interface: existence and properties of interface prototype object's "constructor" property assert_own_property: self does not have own property "FileSystemDirectoryReader" expected property "FileSystemDirectoryReader" missing
-FAIL FileSystemDirectoryReader interface: operation readEntries(FileSystemEntriesCallback,ErrorCallback) assert_own_property: self does not have own property "FileSystemDirectoryReader" expected property "FileSystemDirectoryReader" missing
+PASS FileSystemDirectoryReader interface: existence and properties of interface object 
+PASS FileSystemDirectoryReader interface object length 
+PASS FileSystemDirectoryReader interface object name 
+PASS FileSystemDirectoryReader interface: existence and properties of interface prototype object 
+PASS FileSystemDirectoryReader interface: existence and properties of interface prototype object's "constructor" property 
+PASS FileSystemDirectoryReader interface: operation readEntries(FileSystemEntriesCallback,ErrorCallback) 
 PASS FileSystemEntriesCallback interface: existence and properties of interface object 
 PASS FileSystemEntriesCallback interface: existence and properties of interface prototype object 
 PASS FileSystemEntriesCallback interface: existence and properties of interface prototype object's "constructor" property 
@@ -65,5 +65,5 @@ PASS HTMLInputElement must be primary interface of file_input
 PASS Stringification of file_input 
 PASS HTMLInputElement interface: file_input must inherit property "webkitdirectory" with the proper type (0) 
 FAIL HTMLInputElement interface: file_input must inherit property "webkitEntries" with the proper type (1) assert_inherits: property "webkitEntries" not found in prototype chain
-FAIL DataTransferItem interface: operation webkitGetAsEntry() assert_own_property: interface prototype object missing non-static operation expected property "webkitGetAsEntry" missing
+PASS DataTransferItem interface: operation webkitGetAsEntry() 
 
index 5ed55e3..f84fa81 100644 (file)
@@ -563,6 +563,7 @@ platform/mac/fast/events/objc-event-api.html
 
 # WebKitTestRunner needs an implementation of eventSender.beginDragWithFiles
 # https://bugs.webkit.org/show_bug.cgi?id=64285
+editing/pasteboard/datatransfer-items-drop-getAsEntry.html
 editing/pasteboard/datatransfer-items-drop-plaintext-file.html
 editing/pasteboard/file-drag-to-editable.html [ Skip ]
 editing/pasteboard/file-input-files-access.html
index 494cd95..40ae6d2 100644 (file)
@@ -1,3 +1,15 @@
+2017-08-29  Chris Dumez  <cdumez@apple.com>
+
+        Add initial support for dataTransferItem.webkitGetAsEntry()
+        https://bugs.webkit.org/show_bug.cgi?id=176038
+        <rdar://problem/34121095>
+
+        Reviewed by Wenson Hsieh.
+
+        Add CommonIdentifier needed by [EnabledAtRuntime].
+
+        * runtime/CommonIdentifiers.h:
+
 2017-08-27  Devin Rousso  <webkit@devinrousso.com>
 
         Web Inspector: Record actions performed on WebGLRenderingContext
index 2e7828f..df3f05d 100644 (file)
@@ -51,6 +51,7 @@
     macro(FederatedCredential) \
     macro(FileSystem) \
     macro(FileSystemDirectoryEntry) \
+    macro(FileSystemDirectoryReader) \
     macro(FileSystemEntry) \
     macro(FileSystemFileEntry) \
     macro(Function) \
index 53a9b28..6f67c47 100644 (file)
@@ -204,6 +204,8 @@ set(WebCore_NON_SVG_IDL_FILES
     Modules/entriesapi/ErrorCallback.idl
     Modules/entriesapi/FileCallback.idl
     Modules/entriesapi/FileSystemDirectoryEntry.idl
+    Modules/entriesapi/FileSystemDirectoryReader.idl
+    Modules/entriesapi/FileSystemEntriesCallback.idl
     Modules/entriesapi/FileSystemEntry.idl
     Modules/entriesapi/FileSystemEntryCallback.idl
     Modules/entriesapi/FileSystemFileEntry.idl
@@ -919,8 +921,11 @@ set(WebCore_SOURCES
     Modules/credentials/NavigatorCredentials.cpp
     Modules/credentials/PasswordCredential.cpp
 
+    Modules/entriesapi/ErrorCallback.cpp
     Modules/entriesapi/DOMFileSystem.cpp
     Modules/entriesapi/FileSystemDirectoryEntry.cpp
+    Modules/entriesapi/FileSystemDirectoryReader.cpp
+    Modules/entriesapi/FileSystemEntriesCallback.cpp
     Modules/entriesapi/FileSystemEntry.cpp
     Modules/entriesapi/FileSystemFileEntry.cpp
 
@@ -1230,6 +1235,7 @@ set(WebCore_SOURCES
     bindings/js/JSEventCustom.cpp
     bindings/js/JSEventListener.cpp
     bindings/js/JSEventTargetCustom.cpp
+    bindings/js/JSFileSystemEntryCustom.cpp
     bindings/js/JSHTMLCollectionCustom.cpp
     bindings/js/JSHTMLDocumentCustom.cpp
     bindings/js/JSHTMLElementCustom.cpp
index ad80921..fc55277 100644 (file)
@@ -1,3 +1,110 @@
+2017-08-29  Chris Dumez  <cdumez@apple.com>
+
+        Add initial support for dataTransferItem.webkitGetAsEntry()
+        https://bugs.webkit.org/show_bug.cgi?id=176038
+        <rdar://problem/34121095>
+
+        Reviewed by Wenson Hsieh.
+
+        Add initial support for dataTransferItem.webkitGetAsEntry() as per:
+        - https://wicg.github.io/entries-api/#html-data
+
+        The method works as expected and returns a FileSystemEntry. The entry
+        can be either a file or a directory. All of the attributes exposed on
+        the FileSystemEntry return correct values.
+
+        What remains to be implemented for this new API to actually be useful:
+        - directory.getFile() / directory.getDirectory()
+        - file.file()
+        - entry.getParent()
+        - directoryReader.readEntries()
+
+        Test: editing/pasteboard/datatransfer-items-drop-getAsEntry.html
+
+        * CMakeLists.txt:
+        * DerivedSources.make:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/JSBindingsAllInOne.cpp:
+        Add new files to projects.
+
+        * Modules/entriesapi/DOMFileSystem.cpp:
+        (WebCore::DOMFileSystem::DOMFileSystem):
+        * Modules/entriesapi/DOMFileSystem.h:
+        (WebCore::DOMFileSystem::create):
+        DOMFileSystem factory now takes a name parameter. This name is a UUID, as suggested in
+        the specification and implemented by Firefox.
+
+        * Modules/entriesapi/ErrorCallback.cpp: Added.
+        * Modules/entriesapi/ErrorCallback.h:
+        Add scheduleCallback() convenience method as we often need to call this callback
+        asynchronously.
+
+        * Modules/entriesapi/FileSystemDirectoryEntry.cpp:
+        (WebCore::FileSystemDirectoryEntry::FileSystemDirectoryEntry):
+        (WebCore::FileSystemDirectoryEntry::createReader):
+        (WebCore::FileSystemDirectoryEntry::getFile):
+        (WebCore::FileSystemDirectoryEntry::getDirectory):
+        * Modules/entriesapi/FileSystemDirectoryEntry.h:
+        - Add implementation for createReader().
+        - Update getFile() / getDirectory() to call the error callback for now as they are
+          unimplemented.
+        - Have the factory take the virtual path of the entry so that it can be
+          exposed via the fullPath attribute in IDL.
+
+        * Modules/entriesapi/FileSystemDirectoryEntry.idl:
+        Expose createReader() now that we have stubs for FileSystemDirectoryReader.
+
+        * Modules/entriesapi/FileSystemDirectoryReader.cpp: Added.
+        * Modules/entriesapi/FileSystemDirectoryReader.h: Added.
+        * Modules/entriesapi/FileSystemDirectoryReader.idl: Added.
+        * Modules/entriesapi/FileSystemEntriesCallback.cpp: Added.
+        * Modules/entriesapi/FileSystemEntriesCallback.h: Added.
+        * Modules/entriesapi/FileSystemEntriesCallback.idl: Added.
+        Land stubs for FileSystemDirectoryReader and its FileSystemEntriesCallback.
+
+        * Modules/entriesapi/FileSystemEntry.cpp:
+        (WebCore::FileSystemEntry::FileSystemEntry):
+        * Modules/entriesapi/FileSystemEntry.h:
+        (WebCore::FileSystemEntry::virtualPath const):
+        * Modules/entriesapi/FileSystemEntry.idl:
+        Update constructor to take a virtual path, which is exposed via fullPath
+        attribute in IDL.
+
+        * Modules/entriesapi/FileSystemFileEntry.cpp:
+        (WebCore::FileSystemFileEntry::FileSystemFileEntry):
+        (WebCore::FileSystemFileEntry::file):
+        * Modules/entriesapi/FileSystemFileEntry.h:
+        (isType):
+        * Modules/entriesapi/FileSystemFileEntry.idl:
+        - Update file() to call the error callback for now as they are
+          unimplemented.
+        - Have the factory take the virtual path of the entry so that it can be
+          exposed via the fullPath attribute in IDL.
+
+        * bindings/js/JSFileSystemEntryCustom.cpp: Added.
+        (WebCore::toJSNewlyCreated):
+        (WebCore::toJS):
+        Add custom implementation of FileSystemEntry's toJS() function. This is
+        needed because FileSystemEntry has 2 subclasses and we need to type check
+        at runtime to construct the right wrapper.
+
+        * dom/DataTransferItem.cpp:
+        (WebCore::DataTransferItem::getAsEntry const):
+        * dom/DataTransferItem.h:
+        * dom/DataTransferItem.idl:
+        Add initial implementation for getAsEntry(), currently exposed as
+        webkitGetAsEntry().
+
+        * dom/DataTransferItemList.cpp:
+        (WebCore::DataTransferItemList::ensureItems const):
+        Construct a DataTransferItem if the file is a directory now that we
+        support getAsEntry().
+
+        * fileapi/File.cpp:
+        (WebCore::File::isDirectory const):
+        * fileapi/File.h:
+        Add convenience method to query if a File is a directory.
+
 2017-08-29  Zan Dobersek  <zdobersek@igalia.com>
 
         [WebCrypto] Push WorkQueue dispatches for HKDF, HMAC, PBKDF2 algorithms into shared code
index 1068288..6e74777 100644 (file)
@@ -138,6 +138,8 @@ JS_BINDING_IDLS = \
     $(WebCore)/Modules/entriesapi/ErrorCallback.idl \
     $(WebCore)/Modules/entriesapi/FileCallback.idl \
     $(WebCore)/Modules/entriesapi/FileSystemDirectoryEntry.idl \
+    $(WebCore)/Modules/entriesapi/FileSystemDirectoryReader.idl \
+    $(WebCore)/Modules/entriesapi/FileSystemEntriesCallback.idl \
     $(WebCore)/Modules/entriesapi/FileSystemEntry.idl \
     $(WebCore)/Modules/entriesapi/FileSystemEntryCallback.idl \
     $(WebCore)/Modules/entriesapi/FileSystemFileEntry.idl \
index 8174aa7..a839a52 100644 (file)
@@ -30,8 +30,9 @@
 
 namespace WebCore {
 
-DOMFileSystem::DOMFileSystem()
-    : m_root(FileSystemDirectoryEntry::create(*this))
+DOMFileSystem::DOMFileSystem(const String& name)
+    : m_name(name)
+    , m_root(FileSystemDirectoryEntry::create(*this, ASCIILiteral("/")))
 {
 }
 
index 485cd05..f368c0d 100644 (file)
 namespace WebCore {
 
 class FileSystemDirectoryEntry;
+class FileSystemEntry;
 
 class DOMFileSystem : public ScriptWrappable, public RefCounted<DOMFileSystem> {
 public:
-    static Ref<DOMFileSystem> create()
+    static Ref<DOMFileSystem> create(const String& name)
     {
-        return adoptRef(*new DOMFileSystem);
+        return adoptRef(*new DOMFileSystem(name));
     }
 
     ~DOMFileSystem();
@@ -46,7 +47,7 @@ public:
     FileSystemDirectoryEntry& root() const { return m_root; }
 
 private:
-    DOMFileSystem();
+    explicit DOMFileSystem(const String& name);
 
     String m_name;
     Ref<FileSystemDirectoryEntry> m_root;
diff --git a/Source/WebCore/Modules/entriesapi/ErrorCallback.cpp b/Source/WebCore/Modules/entriesapi/ErrorCallback.cpp
new file mode 100644 (file)
index 0000000..80f96e5
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ErrorCallback.h"
+
+#include "DOMException.h"
+#include "ScriptExecutionContext.h"
+
+namespace WebCore {
+
+void ErrorCallback::scheduleCallback(ScriptExecutionContext& context, Ref<DOMException>&& exception)
+{
+    context.postTask([protectedThis = makeRef(*this), exception = WTFMove(exception)] (ScriptExecutionContext&) {
+        protectedThis->handleEvent(exception);
+    });
+}
+
+}
index 9b203cc..8c1eaff 100644 (file)
@@ -39,6 +39,9 @@ public:
     using ActiveDOMCallback::ActiveDOMCallback;
 
     virtual CallbackResult<void> handleEvent(DOMException&) = 0;
+
+    // Helper to post callback task.
+    void scheduleCallback(ScriptExecutionContext&, Ref<DOMException>&&);
 };
 
 } // namespace WebCore
index df95982..d70d2d0 100644 (file)
 #include "config.h"
 #include "FileSystemDirectoryEntry.h"
 
+#include "DOMException.h"
+#include "ErrorCallback.h"
+#include "FileSystemDirectoryReader.h"
+
 namespace WebCore {
 
-FileSystemDirectoryEntry::FileSystemDirectoryEntry(DOMFileSystem& filesystem)
-    : FileSystemEntry(filesystem)
+FileSystemDirectoryEntry::FileSystemDirectoryEntry(DOMFileSystem& filesystem, const String& virtualPath)
+    : FileSystemEntry(filesystem, virtualPath)
 {
 }
 
-void FileSystemDirectoryEntry::getFile(const String&, const Flags&, RefPtr<FileSystemEntryCallback>&&, RefPtr<ErrorCallback>&&)
+Ref<FileSystemDirectoryReader> FileSystemDirectoryEntry::createReader()
 {
+    return FileSystemDirectoryReader::create(*this);
 }
 
-void FileSystemDirectoryEntry::getDirectory(const String&, const Flags&, RefPtr<FileSystemEntryCallback>&&, RefPtr<ErrorCallback>&&)
+void FileSystemDirectoryEntry::getFile(ScriptExecutionContext& context, const String&, const Flags&, RefPtr<FileSystemEntryCallback>&&, RefPtr<ErrorCallback>&& errorCallback)
 {
+    if (errorCallback)
+        errorCallback->scheduleCallback(context, DOMException::create(NotSupportedError));
+}
 
+void FileSystemDirectoryEntry::getDirectory(ScriptExecutionContext& context, const String&, const Flags&, RefPtr<FileSystemEntryCallback>&&, RefPtr<ErrorCallback>&& errorCallback)
+{
+    if (errorCallback)
+        errorCallback->scheduleCallback(context, DOMException::create(NotSupportedError));
 }
 
 } // namespace WebCore
index 13299e7..f474c69 100644 (file)
 namespace WebCore {
 
 class ErrorCallback;
+class FileSystemDirectoryReader;
 class FileSystemEntryCallback;
+class ScriptExecutionContext;
 
 class FileSystemDirectoryEntry final : public FileSystemEntry {
 public:
-    static Ref<FileSystemDirectoryEntry> create(DOMFileSystem& filesystem)
+    static Ref<FileSystemDirectoryEntry> create(DOMFileSystem& filesystem, const String& virtualPath)
     {
-        return adoptRef(*new FileSystemDirectoryEntry(filesystem));
+        return adoptRef(*new FileSystemDirectoryEntry(filesystem, virtualPath));
     }
 
+    Ref<FileSystemDirectoryReader> createReader();
+
     struct Flags {
         bool create { false };
         bool exclusive { false };
     };
 
-    void getFile(const String& path, const Flags& options, RefPtr<FileSystemEntryCallback>&&, RefPtr<ErrorCallback>&&);
-    void getDirectory(const String& path, const Flags& options, RefPtr<FileSystemEntryCallback>&&, RefPtr<ErrorCallback>&&);
+    void getFile(ScriptExecutionContext&, const String& path, const Flags& options, RefPtr<FileSystemEntryCallback>&&, RefPtr<ErrorCallback>&&);
+    void getDirectory(ScriptExecutionContext&, const String& path, const Flags& options, RefPtr<FileSystemEntryCallback>&&, RefPtr<ErrorCallback>&&);
 
 private:
     bool isDirectory() const final { return true; }
 
-    explicit FileSystemDirectoryEntry(DOMFileSystem&);
+    FileSystemDirectoryEntry(DOMFileSystem&, const String& virtualPath);
 };
 
 } // namespace WebCore
+
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::FileSystemDirectoryEntry)
+    static bool isType(const WebCore::FileSystemEntry& entry) { return entry.isDirectory(); }
+SPECIALIZE_TYPE_TRAITS_END()
index 2e68dcb..28bdfc7 100644 (file)
 [
     EnabledAtRuntime=DirectoryUpload,
 ] interface FileSystemDirectoryEntry : FileSystemEntry {
-    // FileSystemDirectoryReader createReader();
+    FileSystemDirectoryReader createReader();
 
-    void getFile(optional USVString? path,
+    [CallWith=ScriptExecutionContext] void getFile(optional USVString? path,
         optional FileSystemFlags options,
         optional FileSystemEntryCallback? successCallback,
         optional ErrorCallback? errorCallback);
 
-    void getDirectory(optional USVString? path,
+    [CallWith=ScriptExecutionContext] void getDirectory(optional USVString? path,
         optional FileSystemFlags options,
         optional FileSystemEntryCallback? successCallback,
         optional ErrorCallback? errorCallback);
diff --git a/Source/WebCore/Modules/entriesapi/FileSystemDirectoryReader.cpp b/Source/WebCore/Modules/entriesapi/FileSystemDirectoryReader.cpp
new file mode 100644 (file)
index 0000000..ed9ee63
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "FileSystemDirectoryReader.h"
+
+#include "DOMException.h"
+#include "ErrorCallback.h"
+#include "FileSystemDirectoryEntry.h"
+#include "FileSystemEntriesCallback.h"
+
+namespace WebCore {
+
+FileSystemDirectoryReader::FileSystemDirectoryReader(FileSystemDirectoryEntry& directory)
+    : m_directory(directory)
+{
+}
+
+FileSystemDirectoryReader::~FileSystemDirectoryReader()
+{
+}
+
+void FileSystemDirectoryReader::readEntries(ScriptExecutionContext& context, Ref<FileSystemEntriesCallback>&&, RefPtr<ErrorCallback>&& errorCallback)
+{
+    if (errorCallback)
+        errorCallback->scheduleCallback(context, DOMException::create(NotSupportedError));
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/Modules/entriesapi/FileSystemDirectoryReader.h b/Source/WebCore/Modules/entriesapi/FileSystemDirectoryReader.h
new file mode 100644 (file)
index 0000000..8a09944
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "ScriptWrappable.h"
+#include <wtf/RefCounted.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class ErrorCallback;
+class FileSystemDirectoryEntry;
+class FileSystemEntriesCallback;
+class ScriptExecutionContext;
+
+class FileSystemDirectoryReader : public ScriptWrappable, public RefCounted<FileSystemDirectoryReader> {
+public:
+    static Ref<FileSystemDirectoryReader> create(FileSystemDirectoryEntry& directory)
+    {
+        return adoptRef(*new FileSystemDirectoryReader(directory));
+    }
+
+    ~FileSystemDirectoryReader();
+
+    void readEntries(ScriptExecutionContext&, Ref<FileSystemEntriesCallback>&&, RefPtr<ErrorCallback>&&);
+
+private:
+    explicit FileSystemDirectoryReader(FileSystemDirectoryEntry&);
+
+    Ref<FileSystemDirectoryEntry> m_directory;
+};
+
+}
diff --git a/Source/WebCore/Modules/entriesapi/FileSystemDirectoryReader.idl b/Source/WebCore/Modules/entriesapi/FileSystemDirectoryReader.idl
new file mode 100644 (file)
index 0000000..dd0cb04
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+[
+    EnabledAtRuntime=DirectoryUpload,
+    ImplementationLacksVTable,
+] interface FileSystemDirectoryReader {
+    [CallWith=ScriptExecutionContext] void readEntries(FileSystemEntriesCallback successCallback, optional ErrorCallback? errorCallback);
+};
diff --git a/Source/WebCore/Modules/entriesapi/FileSystemEntriesCallback.cpp b/Source/WebCore/Modules/entriesapi/FileSystemEntriesCallback.cpp
new file mode 100644 (file)
index 0000000..955c943
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "FileSystemEntriesCallback.h"
+
+#include "FileSystemEntry.h"
+#include "ScriptExecutionContext.h"
+
+namespace WebCore {
+
+static Vector<Ref<FileSystemEntry>> copyVector(const Vector<Ref<FileSystemEntry>>& entries)
+{
+    Vector<Ref<FileSystemEntry>> entriesCopy;
+    entriesCopy.reserveInitialCapacity(entries.size());
+    for (auto& entry : entries)
+        entriesCopy.uncheckedAppend(entry.copyRef());
+    return entriesCopy;
+}
+
+void FileSystemEntriesCallback::scheduleCallback(ScriptExecutionContext& context, const Vector<Ref<FileSystemEntry>>& entries)
+{
+    context.postTask([protectedThis = makeRef(*this), entries = copyVector(entries)] (ScriptExecutionContext&) {
+        protectedThis->handleEvent(entries);
+    });
+}
+
+}
diff --git a/Source/WebCore/Modules/entriesapi/FileSystemEntriesCallback.h b/Source/WebCore/Modules/entriesapi/FileSystemEntriesCallback.h
new file mode 100644 (file)
index 0000000..36578eb
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "ActiveDOMCallback.h"
+#include "CallbackResult.h"
+#include <wtf/Forward.h>
+#include <wtf/RefCounted.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+class FileSystemEntry;
+
+class FileSystemEntriesCallback : public RefCounted<FileSystemEntriesCallback>, public ActiveDOMCallback {
+public:
+    using ActiveDOMCallback::ActiveDOMCallback;
+
+    virtual CallbackResult<void> handleEvent(const Vector<Ref<FileSystemEntry>>&) = 0;
+
+    // Helper to post callback task.
+    void scheduleCallback(ScriptExecutionContext&, const Vector<Ref<FileSystemEntry>>&);
+};
+
+} // namespace WebCore
diff --git a/Source/WebCore/Modules/entriesapi/FileSystemEntriesCallback.idl b/Source/WebCore/Modules/entriesapi/FileSystemEntriesCallback.idl
new file mode 100644 (file)
index 0000000..eb37b49
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+callback FileSystemEntriesCallback = void (sequence<FileSystemEntry> entries);
index 8c8ffe1..b04963c 100644 (file)
 #include "config.h"
 #include "FileSystemEntry.h"
 
+#include "FileSystem.h"
+
 namespace WebCore {
 
-FileSystemEntry::FileSystemEntry(DOMFileSystem& filesystem)
+FileSystemEntry::FileSystemEntry(DOMFileSystem& filesystem, const String& virtualPath)
     : m_filesystem(filesystem)
+    , m_name(pathGetFileName(virtualPath))
+    , m_virtualPath(virtualPath)
 {
 }
 
index 4155bb0..031dc27 100644 (file)
@@ -41,16 +41,16 @@ public:
     virtual bool isDirectory() const { return false; }
 
     const String& name() const { return m_name; }
-    const String& fullPath() const { return m_fullPath; }
+    const String& virtualPath() const { return m_virtualPath; }
     DOMFileSystem& filesystem() const { return m_filesystem; }
 
 protected:
-    explicit FileSystemEntry(DOMFileSystem&);
+    FileSystemEntry(DOMFileSystem&, const String& virtualPath);
 
 private:
-    String m_name;
-    String m_fullPath;
     DOMFileSystem& m_filesystem;
+    String m_name;
+    String m_virtualPath;
 };
 
 } // namespace WebCore
index b946de3..f716401 100644 (file)
  */
 
 [
+    CustomToJSObject,
     EnabledAtRuntime=DirectoryUpload,
 ] interface FileSystemEntry {
     readonly attribute boolean isFile;
     readonly attribute boolean isDirectory;
     readonly attribute USVString name;
-    readonly attribute USVString fullPath;
+    [ImplementedAs=virtualPath] readonly attribute USVString fullPath;
     readonly attribute DOMFileSystem filesystem;
 
     // void getParent(optional FileSystemEntryCallback successCallback, optional ErrorCallback errorCallback);
index 13b415e..780a5f0 100644 (file)
 #include "config.h"
 #include "FileSystemFileEntry.h"
 
+#include "DOMException.h"
+#include "ErrorCallback.h"
+
 namespace WebCore {
 
-FileSystemFileEntry::FileSystemFileEntry(DOMFileSystem& filesystem)
-    : FileSystemEntry(filesystem)
+FileSystemFileEntry::FileSystemFileEntry(DOMFileSystem& filesystem, const String& virtualPath)
+    : FileSystemEntry(filesystem, virtualPath)
 {
 }
 
-void FileSystemFileEntry::file(RefPtr<FileCallback>&&, RefPtr<ErrorCallback>&&)
+void FileSystemFileEntry::file(ScriptExecutionContext& context, RefPtr<FileCallback>&&, RefPtr<ErrorCallback>&& errorCallback)
 {
+    if (errorCallback)
+        errorCallback->scheduleCallback(context, DOMException::create(NotSupportedError));
 }
 
 } // namespace WebCore
index 04e2c31..1fa3acc 100644 (file)
@@ -31,20 +31,25 @@ namespace WebCore {
 
 class ErrorCallback;
 class FileCallback;
+class ScriptExecutionContext;
 
 class FileSystemFileEntry final : public FileSystemEntry {
 public:
-    static Ref<FileSystemFileEntry> create(DOMFileSystem& filesystem)
+    static Ref<FileSystemFileEntry> create(DOMFileSystem& filesystem, const String& virtualPath)
     {
-        return adoptRef(*new FileSystemFileEntry(filesystem));
+        return adoptRef(*new FileSystemFileEntry(filesystem, virtualPath));
     }
 
-    void file(RefPtr<FileCallback>&&, RefPtr<ErrorCallback>&& = nullptr);
+    void file(ScriptExecutionContext&, RefPtr<FileCallback>&&, RefPtr<ErrorCallback>&& = nullptr);
 
 private:
     bool isFile() const final { return true; }
 
-    explicit FileSystemFileEntry(DOMFileSystem&);
+    FileSystemFileEntry(DOMFileSystem&, const String& virtualPath);
 };
 
 } // namespace WebCore
+
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::FileSystemFileEntry)
+    static bool isType(const WebCore::FileSystemEntry& entry) { return entry.isFile(); }
+SPECIALIZE_TYPE_TRAITS_END()
index 1d8ec78..13253c7 100644 (file)
@@ -26,5 +26,5 @@
 [
     EnabledAtRuntime=DirectoryUpload,
 ] interface FileSystemFileEntry : FileSystemEntry {
-    void file(FileCallback? successCallback, optional ErrorCallback? errorCallback);
+    [CallWith=ScriptExecutionContext] void file(FileCallback? successCallback, optional ErrorCallback? errorCallback);
 };
index 02d72a8..e9d25ea 100644 (file)
                830030F51B7D33B500ED3AAC /* GenericCachedHTMLCollection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 830030F31B7D33A600ED3AAC /* GenericCachedHTMLCollection.cpp */; };
                830030F61B7D33B500ED3AAC /* GenericCachedHTMLCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 830030F41B7D33A600ED3AAC /* GenericCachedHTMLCollection.h */; };
                830030F81B7D3B7800ED3AAC /* CachedHTMLCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 830030F71B7D398800ED3AAC /* CachedHTMLCollection.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               830335011F549057004DF707 /* FileSystemDirectoryReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 830334FB1F549052004DF707 /* FileSystemDirectoryReader.cpp */; };
+               830335021F549057004DF707 /* FileSystemDirectoryReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 830334FC1F549052004DF707 /* FileSystemDirectoryReader.h */; };
+               830335031F54905A004DF707 /* FileSystemEntriesCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 830334FE1F549052004DF707 /* FileSystemEntriesCallback.h */; };
                830519951BB0F11000F3772E /* HTMLTimeElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 830519921BB0F0E700F3772E /* HTMLTimeElement.cpp */; };
                830519961BB0F11000F3772E /* HTMLTimeElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 830519931BB0F0E700F3772E /* HTMLTimeElement.h */; };
                8306EFF11B8BCEA50031D032 /* NativeNodeFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8306EFF01B8BCE7C0031D032 /* NativeNodeFilter.cpp */; };
                835657C71ECAB10700CDE72D /* JSDOMMatrixInit.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 835657C61ECAB0E800CDE72D /* JSDOMMatrixInit.cpp */; };
                8358CB6F1C53277200E0C2D8 /* JSXMLDocument.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 83F570AE1C53268E007FD6CB /* JSXMLDocument.cpp */; };
                8358CB701C53277500E0C2D8 /* JSXMLDocument.h in Headers */ = {isa = PBXBuildFile; fileRef = 83F570AD1C53268E007FD6CB /* JSXMLDocument.h */; };
+               835B68101F548BE10071F7F6 /* JSFileSystemEntryCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 835B680E1F548BDE0071F7F6 /* JSFileSystemEntryCustom.cpp */; };
                835D363719FF6193004C93AB /* StyleBuilderCustom.h in Headers */ = {isa = PBXBuildFile; fileRef = 835D363619FF6193004C93AB /* StyleBuilderCustom.h */; };
                835D54C41F4DE53800E60671 /* FileListCreator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 835D54C11F4DE53400E60671 /* FileListCreator.cpp */; };
                835D54C51F4DE53800E60671 /* FileListCreator.h in Headers */ = {isa = PBXBuildFile; fileRef = 835D54C21F4DE53400E60671 /* FileListCreator.h */; };
+               836589DD1F54A76600DC31F4 /* JSFileSystemDirectoryReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 836589DB1F54A76200DC31F4 /* JSFileSystemDirectoryReader.cpp */; };
+               836589DE1F54A76900DC31F4 /* JSFileSystemDirectoryReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 836589D91F54A76200DC31F4 /* JSFileSystemDirectoryReader.h */; };
+               836589DF1F54A76C00DC31F4 /* JSFileSystemEntriesCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 836589DA1F54A76200DC31F4 /* JSFileSystemEntriesCallback.cpp */; };
+               836589E01F54A76E00DC31F4 /* JSFileSystemEntriesCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 836589D81F54A76200DC31F4 /* JSFileSystemEntriesCallback.h */; };
                8367587E1C56E99B008A1087 /* JSHTMLDataElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 834B86A91C56E93E00F3F0E3 /* JSHTMLDataElement.cpp */; };
                8367587F1C56E99B008A1087 /* JSHTMLDataElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 834B86A81C56E93E00F3F0E3 /* JSHTMLDataElement.h */; };
                836ACEC21ECA62C8004BD012 /* DOMMatrixReadOnly.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 836ACEBF1ECA62B0004BD012 /* DOMMatrixReadOnly.cpp */; };
                837056901F50915C00D93425 /* JSFileSystemEntryCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 837056891F50915000D93425 /* JSFileSystemEntryCallback.h */; };
                8371AC3B1F509BE400FBF284 /* ErrorCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 8371AC391F509BDD00FBF284 /* ErrorCallback.h */; };
                8372DB311A6780A800C697C5 /* DiagnosticLoggingResultType.h in Headers */ = {isa = PBXBuildFile; fileRef = 8372DB301A6780A800C697C5 /* DiagnosticLoggingResultType.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               837609CA1F54CC18000C122D /* ErrorCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 837609C81F54CC13000C122D /* ErrorCallback.cpp */; };
                83765F951DAC522F00C06537 /* MouseEventInit.h in Headers */ = {isa = PBXBuildFile; fileRef = 83765F941DAC521800C06537 /* MouseEventInit.h */; settings = {ATTRIBUTES = (Private, ); }; };
                837A80131E1E127300026B9F /* Localizable.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = 837A80111E1E127300026B9F /* Localizable.stringsdict */; };
                837B7D201DC3F55000D051FC /* ValidationBubbleIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 837B7D1F1DC3F54C00D051FC /* ValidationBubbleIOS.mm */; };
                838EF53C1DC14A7C008F0C39 /* JSIDBTransactionMode.h in Headers */ = {isa = PBXBuildFile; fileRef = 838EF53A1DC14A75008F0C39 /* JSIDBTransactionMode.h */; };
                838F86DA1F509E7400E8CFC5 /* FileCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 838F86D81F509E6C00E8CFC5 /* FileCallback.h */; };
                838F86DB1F509E7B00E8CFC5 /* FileSystemEntryCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 838F86D71F509E6C00E8CFC5 /* FileSystemEntryCallback.h */; };
+               839680B41F54C6AD00752690 /* FileSystemEntriesCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 839680B21F54C6A800752690 /* FileSystemEntriesCallback.cpp */; };
                8399470B1F50B63E00E9D86B /* DOMFileSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 839947091F50B63800E9D86B /* DOMFileSystem.cpp */; };
                8399470C1F50B63E00E9D86B /* DOMFileSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 839947071F50B63800E9D86B /* DOMFileSystem.h */; };
                8399470F1F50B6FA00E9D86B /* JSDOMFileSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8399470D1F50B6F300E9D86B /* JSDOMFileSystem.cpp */; };
                830030F31B7D33A600ED3AAC /* GenericCachedHTMLCollection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GenericCachedHTMLCollection.cpp; sourceTree = "<group>"; };
                830030F41B7D33A600ED3AAC /* GenericCachedHTMLCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GenericCachedHTMLCollection.h; sourceTree = "<group>"; };
                830030F71B7D398800ED3AAC /* CachedHTMLCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CachedHTMLCollection.h; sourceTree = "<group>"; };
+               830334FB1F549052004DF707 /* FileSystemDirectoryReader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FileSystemDirectoryReader.cpp; sourceTree = "<group>"; };
+               830334FC1F549052004DF707 /* FileSystemDirectoryReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileSystemDirectoryReader.h; sourceTree = "<group>"; };
+               830334FD1F549052004DF707 /* FileSystemEntriesCallback.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = FileSystemEntriesCallback.idl; sourceTree = "<group>"; };
+               830334FE1F549052004DF707 /* FileSystemEntriesCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileSystemEntriesCallback.h; sourceTree = "<group>"; };
+               830334FF1F549052004DF707 /* FileSystemDirectoryReader.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = FileSystemDirectoryReader.idl; sourceTree = "<group>"; };
                830519921BB0F0E700F3772E /* HTMLTimeElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLTimeElement.cpp; sourceTree = "<group>"; };
                830519931BB0F0E700F3772E /* HTMLTimeElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLTimeElement.h; sourceTree = "<group>"; };
                830519941BB0F0E700F3772E /* HTMLTimeElement.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = HTMLTimeElement.idl; sourceTree = "<group>"; };
                8350C3E81DA59B6200356446 /* ScrollToOptions.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ScrollToOptions.idl; sourceTree = "<group>"; };
                83520C7D1A71BFCC006BD2AA /* CSSFontFamily.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSFontFamily.h; sourceTree = "<group>"; };
                835657C61ECAB0E800CDE72D /* JSDOMMatrixInit.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMMatrixInit.cpp; sourceTree = "<group>"; };
+               835B680E1F548BDE0071F7F6 /* JSFileSystemEntryCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSFileSystemEntryCustom.cpp; sourceTree = "<group>"; };
                835D363619FF6193004C93AB /* StyleBuilderCustom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleBuilderCustom.h; sourceTree = "<group>"; };
                835D54C11F4DE53400E60671 /* FileListCreator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FileListCreator.cpp; sourceTree = "<group>"; };
                835D54C21F4DE53400E60671 /* FileListCreator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileListCreator.h; sourceTree = "<group>"; };
                835F8B261D2D90BA00E408EC /* Slotable.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Slotable.idl; sourceTree = "<group>"; };
+               836589D81F54A76200DC31F4 /* JSFileSystemEntriesCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSFileSystemEntriesCallback.h; sourceTree = "<group>"; };
+               836589D91F54A76200DC31F4 /* JSFileSystemDirectoryReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSFileSystemDirectoryReader.h; sourceTree = "<group>"; };
+               836589DA1F54A76200DC31F4 /* JSFileSystemEntriesCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSFileSystemEntriesCallback.cpp; sourceTree = "<group>"; };
+               836589DB1F54A76200DC31F4 /* JSFileSystemDirectoryReader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSFileSystemDirectoryReader.cpp; sourceTree = "<group>"; };
                8369E58F1AFDD0300087DF68 /* NonDocumentTypeChildNode.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = NonDocumentTypeChildNode.idl; sourceTree = "<group>"; };
                836ACEBF1ECA62B0004BD012 /* DOMMatrixReadOnly.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DOMMatrixReadOnly.cpp; sourceTree = "<group>"; };
                836ACEC01ECA62B0004BD012 /* DOMMatrixReadOnly.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMMatrixReadOnly.h; sourceTree = "<group>"; };
                8371AC381F509BDD00FBF284 /* FileCallback.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = FileCallback.idl; sourceTree = "<group>"; };
                8371AC391F509BDD00FBF284 /* ErrorCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ErrorCallback.h; sourceTree = "<group>"; };
                8372DB301A6780A800C697C5 /* DiagnosticLoggingResultType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DiagnosticLoggingResultType.h; sourceTree = "<group>"; };
+               837609C81F54CC13000C122D /* ErrorCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ErrorCallback.cpp; sourceTree = "<group>"; };
                83765F931DAC521800C06537 /* MouseEventInit.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = MouseEventInit.idl; sourceTree = "<group>"; };
                83765F941DAC521800C06537 /* MouseEventInit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MouseEventInit.h; sourceTree = "<group>"; };
                837A80121E1E127300026B9F /* English */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = English; path = English.lproj/Localizable.stringsdict; sourceTree = SOURCE_ROOT; };
                838EF53A1DC14A75008F0C39 /* JSIDBTransactionMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSIDBTransactionMode.h; sourceTree = "<group>"; };
                838F86D71F509E6C00E8CFC5 /* FileSystemEntryCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileSystemEntryCallback.h; sourceTree = "<group>"; };
                838F86D81F509E6C00E8CFC5 /* FileCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileCallback.h; sourceTree = "<group>"; };
+               839680B21F54C6A800752690 /* FileSystemEntriesCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FileSystemEntriesCallback.cpp; sourceTree = "<group>"; };
                839947071F50B63800E9D86B /* DOMFileSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMFileSystem.h; sourceTree = "<group>"; };
                839947081F50B63800E9D86B /* DOMFileSystem.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DOMFileSystem.idl; sourceTree = "<group>"; };
                839947091F50B63800E9D86B /* DOMFileSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DOMFileSystem.cpp; sourceTree = "<group>"; };
                                E34EE49F1DC2D57500EAA9D3 /* JSEventCustom.h */,
                                BC60901E0E91B8EC000C68B5 /* JSEventTargetCustom.cpp */,
                                46B63F6B1C6E8CDF002E914B /* JSEventTargetCustom.h */,
+                               835B680E1F548BDE0071F7F6 /* JSFileSystemEntryCustom.cpp */,
                                BCCBAD3A0C18BFF800CE890F /* JSHTMLCollectionCustom.cpp */,
                                BC51580A0C03D404008BB0EE /* JSHTMLDocumentCustom.cpp */,
                                D6F7960C166FFECE0076DD18 /* JSHTMLTemplateElementCustom.cpp */,
                                839947091F50B63800E9D86B /* DOMFileSystem.cpp */,
                                839947071F50B63800E9D86B /* DOMFileSystem.h */,
                                839947081F50B63800E9D86B /* DOMFileSystem.idl */,
+                               837609C81F54CC13000C122D /* ErrorCallback.cpp */,
                                8371AC391F509BDD00FBF284 /* ErrorCallback.h */,
                                8371AC371F509BDD00FBF284 /* ErrorCallback.idl */,
                                838F86D81F509E6C00E8CFC5 /* FileCallback.h */,
                                83FB336B1F508A4E00986E54 /* FileSystemDirectoryEntry.cpp */,
                                83FB336D1F508A4E00986E54 /* FileSystemDirectoryEntry.h */,
                                83FB336A1F508A4E00986E54 /* FileSystemDirectoryEntry.idl */,
+                               830334FB1F549052004DF707 /* FileSystemDirectoryReader.cpp */,
+                               830334FC1F549052004DF707 /* FileSystemDirectoryReader.h */,
+                               830334FF1F549052004DF707 /* FileSystemDirectoryReader.idl */,
+                               839680B21F54C6A800752690 /* FileSystemEntriesCallback.cpp */,
+                               830334FE1F549052004DF707 /* FileSystemEntriesCallback.h */,
+                               830334FD1F549052004DF707 /* FileSystemEntriesCallback.idl */,
                                83FB336E1F508A4E00986E54 /* FileSystemEntry.cpp */,
                                83FB336F1F508A4E00986E54 /* FileSystemEntry.h */,
                                83FB33681F508A4E00986E54 /* FileSystemEntry.idl */,
                                8370568B1F50915000D93425 /* JSFileCallback.h */,
                                833B9E2B1F508D8000E0E428 /* JSFileSystemDirectoryEntry.cpp */,
                                833B9E2F1F508D8000E0E428 /* JSFileSystemDirectoryEntry.h */,
+                               836589DB1F54A76200DC31F4 /* JSFileSystemDirectoryReader.cpp */,
+                               836589D91F54A76200DC31F4 /* JSFileSystemDirectoryReader.h */,
+                               836589DA1F54A76200DC31F4 /* JSFileSystemEntriesCallback.cpp */,
+                               836589D81F54A76200DC31F4 /* JSFileSystemEntriesCallback.h */,
                                833B9E2E1F508D8000E0E428 /* JSFileSystemEntry.cpp */,
                                833B9E2A1F508D8000E0E428 /* JSFileSystemEntry.h */,
                                8370568A1F50915000D93425 /* JSFileSystemEntryCallback.cpp */,
                                2EF1BFF9121CB0CE00C27627 /* FileStreamClient.h in Headers */,
                                514B3F730C722047000530DF /* FileSystem.h in Headers */,
                                83FB33711F508A5400986E54 /* FileSystemDirectoryEntry.h in Headers */,
+                               830335021F549057004DF707 /* FileSystemDirectoryReader.h in Headers */,
+                               830335031F54905A004DF707 /* FileSystemEntriesCallback.h in Headers */,
                                83FB33731F508A5800986E54 /* FileSystemEntry.h in Headers */,
                                838F86DB1F509E7B00E8CFC5 /* FileSystemEntryCallback.h in Headers */,
                                83FB33751F508A5B00986E54 /* FileSystemFileEntry.h in Headers */,
                                2E94F43C119207DA00B7F75D /* JSFileReader.h in Headers */,
                                898785F5122E1EAC003AABDA /* JSFileReaderSync.h in Headers */,
                                833B9E321F508D8500E0E428 /* JSFileSystemDirectoryEntry.h in Headers */,
+                               836589DE1F54A76900DC31F4 /* JSFileSystemDirectoryReader.h in Headers */,
+                               836589E01F54A76E00DC31F4 /* JSFileSystemEntriesCallback.h in Headers */,
                                833B9E341F508D8500E0E428 /* JSFileSystemEntry.h in Headers */,
                                837056901F50915C00D93425 /* JSFileSystemEntryCallback.h in Headers */,
                                833B9E361F508D8500E0E428 /* JSFileSystemFileEntry.h in Headers */,
                                F52AD5E41534245F0059FBE6 /* EmptyClients.cpp in Sources */,
                                515BE18F1D54F5FB00DD7C68 /* EmptyGamepadProvider.cpp in Sources */,
                                FD31609212B026F700C1A359 /* EqualPowerPanner.cpp in Sources */,
+                               837609CA1F54CC18000C122D /* ErrorCallback.cpp in Sources */,
                                2ECF7AE110162B5800427DE7 /* ErrorEvent.cpp in Sources */,
                                85031B410A44EFC700F992E0 /* Event.cpp in Sources */,
                                4138D3361244054800323D33 /* EventContext.cpp in Sources */,
                                5160306C0CC4362300C8AC25 /* FileSystemCF.cpp in Sources */,
                                514B3F760C722055000530DF /* FileSystemCocoa.mm in Sources */,
                                83FB33701F508A5400986E54 /* FileSystemDirectoryEntry.cpp in Sources */,
+                               830335011F549057004DF707 /* FileSystemDirectoryReader.cpp in Sources */,
+                               839680B41F54C6AD00752690 /* FileSystemEntriesCallback.cpp in Sources */,
                                83FB33721F508A5800986E54 /* FileSystemEntry.cpp in Sources */,
                                83FB33741F508A5B00986E54 /* FileSystemFileEntry.cpp in Sources */,
                                26C17A3F1491D2D400D12BA2 /* FileSystemIOS.mm in Sources */,
                                2E94F43B119207DA00B7F75D /* JSFileReader.cpp in Sources */,
                                898785F4122E1EAC003AABDA /* JSFileReaderSync.cpp in Sources */,
                                833B9E311F508D8500E0E428 /* JSFileSystemDirectoryEntry.cpp in Sources */,
+                               836589DD1F54A76600DC31F4 /* JSFileSystemDirectoryReader.cpp in Sources */,
+                               836589DF1F54A76C00DC31F4 /* JSFileSystemEntriesCallback.cpp in Sources */,
                                833B9E331F508D8500E0E428 /* JSFileSystemEntry.cpp in Sources */,
                                8370568F1F50915900D93425 /* JSFileSystemEntryCallback.cpp in Sources */,
+                               835B68101F548BE10071F7F6 /* JSFileSystemEntryCustom.cpp in Sources */,
                                833B9E351F508D8500E0E428 /* JSFileSystemFileEntry.cpp in Sources */,
                                B6D9D27C14EAC0860090D75E /* JSFocusEvent.cpp in Sources */,
                                C28083401C6DC275001451B6 /* JSFontFace.cpp in Sources */,
index d90142e..e366c56 100644 (file)
@@ -63,6 +63,7 @@
 #include "JSEventCustom.cpp"
 #include "JSEventListener.cpp"
 #include "JSEventTargetCustom.cpp"
+#include "JSFileSystemEntryCustom.cpp"
 #include "JSHTMLCollectionCustom.cpp"
 #include "JSHTMLDocumentCustom.cpp"
 #include "JSHTMLElementCustom.cpp"
diff --git a/Source/WebCore/bindings/js/JSFileSystemEntryCustom.cpp b/Source/WebCore/bindings/js/JSFileSystemEntryCustom.cpp
new file mode 100644 (file)
index 0000000..546f751
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSFileSystemEntry.h"
+
+#include "FileSystemDirectoryEntry.h"
+#include "FileSystemFileEntry.h"
+#include "JSDOMBinding.h"
+#include "JSFileSystemDirectoryEntry.h"
+#include "JSFileSystemFileEntry.h"
+
+using namespace JSC;
+
+namespace WebCore {
+
+JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<FileSystemEntry>&& entry)
+{
+    if (is<FileSystemDirectoryEntry>(entry))
+        return createWrapper<FileSystemDirectoryEntry>(globalObject, WTFMove(entry));
+    return createWrapper<FileSystemFileEntry>(globalObject, WTFMove(entry));
+}
+
+JSValue toJS(ExecState* state, JSDOMGlobalObject* globalObject, FileSystemEntry& entry)
+{
+    return wrap(state, globalObject, entry);
+}
+
+} // namespace WebCore
index 1232e81..6b5d7a5 100644 (file)
 #include "config.h"
 #include "DataTransferItem.h"
 
+#include "DOMFileSystem.h"
 #include "DataTransferItemList.h"
 #include "File.h"
+#include "FileSystem.h"
+#include "FileSystemDirectoryEntry.h"
+#include "FileSystemFileEntry.h"
 #include "ScriptExecutionContext.h"
 #include "StringCallback.h"
+#include <wtf/UUID.h>
 
 namespace WebCore {
 
@@ -101,4 +106,19 @@ RefPtr<File> DataTransferItem::getAsFile() const
     return m_file.copyRef();
 }
 
+RefPtr<FileSystemEntry> DataTransferItem::getAsEntry() const
+{
+    auto file = getAsFile();
+    if (!file)
+        return nullptr;
+
+    if (!m_fileSystem)
+        m_fileSystem = DOMFileSystem::create(createCanonicalUUIDString());
+
+    String virtualPath = "/" + file->name();
+    if (file->isDirectory())
+        return FileSystemDirectoryEntry::create(*m_fileSystem, virtualPath);
+    return FileSystemFileEntry::create(*m_fileSystem, virtualPath);
+}
+
 } // namespace WebCore
index d8b84a1..bea1cf1 100644 (file)
 
 namespace WebCore {
 
+class DOMFileSystem;
 class DataTransferListItem;
 class File;
+class FileSystemEntry;
 class ScriptExecutionContext;
 class StringCallback;
 
@@ -59,6 +61,7 @@ public:
     String type() const;
     void getAsString(ScriptExecutionContext&, RefPtr<StringCallback>&&) const;
     RefPtr<File> getAsFile() const;
+    RefPtr<FileSystemEntry> getAsEntry() const;
 
 private:
     DataTransferItem(WeakPtr<DataTransferItemList>&&, const String&);
@@ -69,6 +72,7 @@ private:
     WeakPtr<DataTransferItemList> m_list;
     const String m_type;
     RefPtr<File> m_file;
+    mutable RefPtr<DOMFileSystem> m_fileSystem;
 };
 
 }
index 7397a7f..cd52f50 100644 (file)
@@ -38,5 +38,8 @@
 
     [CallWith=ScriptExecutionContext] void getAsString(StringCallback? callback);
     File getAsFile();
+
+    // https://wicg.github.io/entries-api/#html-data
+    [ImplementedAs=getAsEntry] FileSystemEntry? webkitGetAsEntry();
 };
 
index 2c909e0..fdfda27 100644 (file)
@@ -134,7 +134,7 @@ Vector<Ref<DataTransferItem>>& DataTransferItemList::ensureItems() const
     for (unsigned i = 0, length = files.length(); i < length; ++i) {
         File& file = *files.item(i);
         String type = File::contentTypeForFile(file.path()).convertToASCIILowercase();
-        if (isSupportedType(type))
+        if (isSupportedType(type) || file.isDirectory())
             items.append(DataTransferItem::create(m_weakPtrFactory.createWeakPtr(), type, file));
     }
 
index e56500a..b508abf 100644 (file)
@@ -127,4 +127,11 @@ String File::contentTypeForFile(const String& path)
     return type;
 }
 
+bool File::isDirectory() const
+{
+    if (!m_isDirectory)
+        m_isDirectory = fileIsDirectory(m_path);
+    return *m_isDirectory;
+}
+
 } // namespace WebCore
index 226af8c..a9601f5 100644 (file)
@@ -81,6 +81,8 @@ public:
     static bool shouldReplaceFile(const String& path);
 #endif
 
+    bool isDirectory() const;
+
 private:
     WEBCORE_EXPORT explicit File(const String& path);
     File(const String& path, const String& nameOverride);
@@ -98,6 +100,7 @@ private:
     String m_name;
 
     std::optional<int64_t> m_overrideLastModifiedDate;
+    mutable std::optional<bool> m_isDirectory;
 };
 
 } // namespace WebCore
index fab7e86..863a97d 100644 (file)
@@ -1,3 +1,16 @@
+2017-08-29  Chris Dumez  <cdumez@apple.com>
+
+        Add initial support for dataTransferItem.webkitGetAsEntry()
+        https://bugs.webkit.org/show_bug.cgi?id=176038
+        <rdar://problem/34121095>
+
+        Reviewed by Wenson Hsieh.
+
+        Make dataTransfer.items an experimental feature so that it can be easily
+        turned on from the Develop menu, for testing convenience.
+
+        * Shared/WebPreferencesDefinitions.h:
+
 2017-08-29  Andy Estes  <aestes@apple.com>
 
         [Mac] Upstream WKSetMetadataURL() from WebKitSystemInterface
index 18cb26a..1b92dd6 100644 (file)
     macro(LargeImageAsyncDecodingEnabled, largeImageAsyncDecodingEnabled, Bool, bool, true, "", "") \
     macro(AnimatedImageAsyncDecodingEnabled, animatedImageAsyncDecodingEnabled, Bool, bool, true, "", "") \
     macro(CustomElementsEnabled, customElementsEnabled, Bool, bool, true, "", "") \
-    macro(DataTransferItemsEnabled, dataTransferItemsEnabled, Bool, bool, false, "Data Transfer Items", "Enables DataTransferItem in the clipboard API") \
     macro(EncryptedMediaAPIEnabled, encryptedMediaAPIEnabled, Bool, bool, false, "", "") \
     macro(MediaPreloadingEnabled, mediaPreloadingEnabled, Bool, bool, false, "", "") \
     macro(IntersectionObserverEnabled, intersectionObserverEnabled, Bool, bool, false, "Intersection Observer", "Enable Intersection Observer support") \
     macro(WebGL2Enabled, webGL2Enabled, Bool, bool, false, "WebGL 2.0", "WebGL 2 prototype") \
     macro(WebGPUEnabled, webGPUEnabled, Bool, bool, false, "WebGPU", "WebGPU prototype") \
     macro(DirectoryUploadEnabled, directoryUploadEnabled, Bool, bool, false, "Directory Upload", "input.webkitdirectory") \
+    macro(DataTransferItemsEnabled, dataTransferItemsEnabled, Bool, bool, false, "Data Transfer Items", "Enables DataTransferItem in the clipboard API") \
     macro(AsyncFrameScrollingEnabled, asyncFrameScrollingEnabled, Bool, bool, false, "Async Frame Scrolling", "Perform frame scrolling in a dedicated thread or process") \
     \