Title: [263214] branches/safari-610.1.17-branch/Source/WebCore
Revision
263214
Author
alanc...@apple.com
Date
2020-06-18 09:52:12 -0700 (Thu, 18 Jun 2020)

Log Message

Cherry-pick r263129. rdar://problem/64492826

    FileListCreator should only be used for resolving directories
    https://bugs.webkit.org/show_bug.cgi?id=213259
    <rdar://problem/64375709>

    Reviewed by David Kilzer.

    Depending on whether directories should be resolved, FileListCreator::create would either
    synchronously execute its completion handler then return nullptr or asynchronously dispatch
    its completion handler then return a non-null RefPtr. Interfaces with sometimes-synchronous
    callbacks can be hard to use correctly; e.g., r262962 fixes a problem where
    FileInputType::m_fileListCreator was being modified in an unexpected order.

    This patch makes the interface between FileInputType and FileListCreator less error-prone
    and more explicit by renaming FileListCreator to DirectoryFileListCreator, making its job
    solely to create directory FileLists on a background queue, and giving it an explicit start
    member function. For non-directories, FileInputType::filesChosen now bypasses
    DirectoryFileListCreator and directly converts from Vector<FileChooserFileInfo> to FileList.

    Covered by existing tests.

    * Sources.txt:
    * WebCore.xcodeproj/project.pbxproj:

    * html/DirectoryFileListCreator.cpp: Renamed from html/FileListCreator.cpp.
    (WebCore::createFileList): Removed the template and ShouldResolveDirectories parameter.
    (WebCore::DirectoryFileListCreator::DirectoryFileListCreator): Moved the work queue
    dispatching to DirectoryFileListCreator::start.
    (WebCore::DirectoryFileListCreator::start): Added; moved the work queue dispatching here
    from the ctor.

    * html/DirectoryFileListCreator.h: Renamed from html/FileListCreator.h.
    (WebCore::DirectoryFileListCreator::create): Stopped performing non-directory creation and
    changed the return value back to Ref<>.

    * html/FileInputType.cpp:
    (WebCore::FileInputType::filesChosen): Moved most of the work done in the FileListCreator
    completion handler to didCreateFileList. When !FileInputType::allowsDirectories, used
    Vector::map to convert paths to a Vector<Ref<File>>, used that to create a FileList, then
    called didCreateFileList. Otherwise, created and started a DirectoryFileListCreator that
    calls didCreateFileList in its completion handler.
    (WebCore::FileInputType::didCreateFileList): Added; sets the new file list and icon and
    clears m_directoryFileListCreator.

    * html/FileInputType.h:

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

Modified Paths

Added Paths

Removed Paths

Diff

Modified: branches/safari-610.1.17-branch/Source/WebCore/ChangeLog (263213 => 263214)


--- branches/safari-610.1.17-branch/Source/WebCore/ChangeLog	2020-06-18 16:52:08 UTC (rev 263213)
+++ branches/safari-610.1.17-branch/Source/WebCore/ChangeLog	2020-06-18 16:52:12 UTC (rev 263214)
@@ -1,5 +1,104 @@
 2020-06-18  Alan Coon  <alanc...@apple.com>
 
+        Cherry-pick r263129. rdar://problem/64492826
+
+    FileListCreator should only be used for resolving directories
+    https://bugs.webkit.org/show_bug.cgi?id=213259
+    <rdar://problem/64375709>
+    
+    Reviewed by David Kilzer.
+    
+    Depending on whether directories should be resolved, FileListCreator::create would either
+    synchronously execute its completion handler then return nullptr or asynchronously dispatch
+    its completion handler then return a non-null RefPtr. Interfaces with sometimes-synchronous
+    callbacks can be hard to use correctly; e.g., r262962 fixes a problem where
+    FileInputType::m_fileListCreator was being modified in an unexpected order.
+    
+    This patch makes the interface between FileInputType and FileListCreator less error-prone
+    and more explicit by renaming FileListCreator to DirectoryFileListCreator, making its job
+    solely to create directory FileLists on a background queue, and giving it an explicit start
+    member function. For non-directories, FileInputType::filesChosen now bypasses
+    DirectoryFileListCreator and directly converts from Vector<FileChooserFileInfo> to FileList.
+    
+    Covered by existing tests.
+    
+    * Sources.txt:
+    * WebCore.xcodeproj/project.pbxproj:
+    
+    * html/DirectoryFileListCreator.cpp: Renamed from html/FileListCreator.cpp.
+    (WebCore::createFileList): Removed the template and ShouldResolveDirectories parameter.
+    (WebCore::DirectoryFileListCreator::DirectoryFileListCreator): Moved the work queue
+    dispatching to DirectoryFileListCreator::start.
+    (WebCore::DirectoryFileListCreator::start): Added; moved the work queue dispatching here
+    from the ctor.
+    
+    * html/DirectoryFileListCreator.h: Renamed from html/FileListCreator.h.
+    (WebCore::DirectoryFileListCreator::create): Stopped performing non-directory creation and
+    changed the return value back to Ref<>.
+    
+    * html/FileInputType.cpp:
+    (WebCore::FileInputType::filesChosen): Moved most of the work done in the FileListCreator
+    completion handler to didCreateFileList. When !FileInputType::allowsDirectories, used
+    Vector::map to convert paths to a Vector<Ref<File>>, used that to create a FileList, then
+    called didCreateFileList. Otherwise, created and started a DirectoryFileListCreator that
+    calls didCreateFileList in its completion handler.
+    (WebCore::FileInputType::didCreateFileList): Added; sets the new file list and icon and
+    clears m_directoryFileListCreator.
+    
+    * html/FileInputType.h:
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@263129 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-06-16  Andy Estes  <aes...@apple.com>
+
+            FileListCreator should only be used for resolving directories
+            https://bugs.webkit.org/show_bug.cgi?id=213259
+            <rdar://problem/64375709>
+
+            Reviewed by David Kilzer.
+
+            Depending on whether directories should be resolved, FileListCreator::create would either
+            synchronously execute its completion handler then return nullptr or asynchronously dispatch
+            its completion handler then return a non-null RefPtr. Interfaces with sometimes-synchronous
+            callbacks can be hard to use correctly; e.g., r262962 fixes a problem where
+            FileInputType::m_fileListCreator was being modified in an unexpected order.
+
+            This patch makes the interface between FileInputType and FileListCreator less error-prone
+            and more explicit by renaming FileListCreator to DirectoryFileListCreator, making its job
+            solely to create directory FileLists on a background queue, and giving it an explicit start
+            member function. For non-directories, FileInputType::filesChosen now bypasses
+            DirectoryFileListCreator and directly converts from Vector<FileChooserFileInfo> to FileList.
+
+            Covered by existing tests.
+
+            * Sources.txt:
+            * WebCore.xcodeproj/project.pbxproj:
+
+            * html/DirectoryFileListCreator.cpp: Renamed from html/FileListCreator.cpp.
+            (WebCore::createFileList): Removed the template and ShouldResolveDirectories parameter.
+            (WebCore::DirectoryFileListCreator::DirectoryFileListCreator): Moved the work queue
+            dispatching to DirectoryFileListCreator::start.
+            (WebCore::DirectoryFileListCreator::start): Added; moved the work queue dispatching here
+            from the ctor.
+
+            * html/DirectoryFileListCreator.h: Renamed from html/FileListCreator.h.
+            (WebCore::DirectoryFileListCreator::create): Stopped performing non-directory creation and
+            changed the return value back to Ref<>.
+
+            * html/FileInputType.cpp:
+            (WebCore::FileInputType::filesChosen): Moved most of the work done in the FileListCreator
+            completion handler to didCreateFileList. When !FileInputType::allowsDirectories, used
+            Vector::map to convert paths to a Vector<Ref<File>>, used that to create a FileList, then
+            called didCreateFileList. Otherwise, created and started a DirectoryFileListCreator that
+            calls didCreateFileList in its completion handler.
+            (WebCore::FileInputType::didCreateFileList): Added; sets the new file list and icon and
+            clears m_directoryFileListCreator.
+
+            * html/FileInputType.h:
+
+2020-06-18  Alan Coon  <alanc...@apple.com>
+
         Cherry-pick r263128. rdar://problem/64492837
 
     REGRESSION (r262643): DumpRenderTree at com.apple.WebCore: WebCore::Document::prepareCanvasesForDisplayIfNeeded

Modified: branches/safari-610.1.17-branch/Source/WebCore/Sources.txt (263213 => 263214)


--- branches/safari-610.1.17-branch/Source/WebCore/Sources.txt	2020-06-18 16:52:08 UTC (rev 263213)
+++ branches/safari-610.1.17-branch/Source/WebCore/Sources.txt	2020-06-18 16:52:12 UTC (rev 263214)
@@ -1134,10 +1134,10 @@
 html/DateInputType.cpp
 html/DateTimeInputType.cpp
 html/DateTimeLocalInputType.cpp
+html/DirectoryFileListCreator.cpp
 html/EmailInputType.cpp
 html/EnterKeyHint.cpp
 html/FTPDirectoryDocument.cpp
-html/FileListCreator.cpp
 html/FeaturePolicy.cpp
 html/FileInputType.cpp
 html/FormAssociatedElement.cpp

Modified: branches/safari-610.1.17-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj (263213 => 263214)


--- branches/safari-610.1.17-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-06-18 16:52:08 UTC (rev 263213)
+++ branches/safari-610.1.17-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-06-18 16:52:12 UTC (rev 263214)
@@ -2431,7 +2431,7 @@
 		8358CB701C53277500E0C2D8 /* JSXMLDocument.h in Headers */ = {isa = PBXBuildFile; fileRef = 83F570AD1C53268E007FD6CB /* JSXMLDocument.h */; };
 		835D2D781F5F1FBD00141DED /* HTMLInputElementEntriesAPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 835D2D751F5F1FB800141DED /* HTMLInputElementEntriesAPI.h */; };
 		835D363719FF6193004C93AB /* StyleBuilderCustom.h in Headers */ = {isa = PBXBuildFile; fileRef = 835D363619FF6193004C93AB /* StyleBuilderCustom.h */; };
-		835D54C51F4DE53800E60671 /* FileListCreator.h in Headers */ = {isa = PBXBuildFile; fileRef = 835D54C21F4DE53400E60671 /* FileListCreator.h */; };
+		835D54C51F4DE53800E60671 /* DirectoryFileListCreator.h in Headers */ = {isa = PBXBuildFile; fileRef = 835D54C21F4DE53400E60671 /* DirectoryFileListCreator.h */; };
 		8362E8C120CEF9CB00245886 /* ShouldTreatAsContinuingLoad.h in Headers */ = {isa = PBXBuildFile; fileRef = 8362E8BF20CEF9CB00245886 /* ShouldTreatAsContinuingLoad.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		836589DE1F54A76900DC31F4 /* JSFileSystemDirectoryReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 836589D91F54A76200DC31F4 /* JSFileSystemDirectoryReader.h */; };
 		836589E01F54A76E00DC31F4 /* JSFileSystemEntriesCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 836589D81F54A76200DC31F4 /* JSFileSystemEntriesCallback.h */; };
@@ -10358,8 +10358,8 @@
 		835D2D751F5F1FB800141DED /* HTMLInputElementEntriesAPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLInputElementEntriesAPI.h; sourceTree = "<group>"; };
 		835D2D761F5F1FB800141DED /* HTMLInputElementEntriesAPI.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLInputElementEntriesAPI.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>"; };
+		835D54C11F4DE53400E60671 /* DirectoryFileListCreator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DirectoryFileListCreator.cpp; sourceTree = "<group>"; };
+		835D54C21F4DE53400E60671 /* DirectoryFileListCreator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DirectoryFileListCreator.h; sourceTree = "<group>"; };
 		835F8B261D2D90BA00E408EC /* Slotable.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Slotable.idl; sourceTree = "<group>"; };
 		8362E8BF20CEF9CB00245886 /* ShouldTreatAsContinuingLoad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShouldTreatAsContinuingLoad.h; sourceTree = "<group>"; };
 		836589D81F54A76200DC31F4 /* JSFileSystemEntriesCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSFileSystemEntriesCallback.h; sourceTree = "<group>"; };
@@ -22257,6 +22257,8 @@
 				F55B3D841251F12D003EF269 /* DateTimeInputType.h */,
 				F55B3D851251F12D003EF269 /* DateTimeLocalInputType.cpp */,
 				F55B3D861251F12D003EF269 /* DateTimeLocalInputType.h */,
+				835D54C11F4DE53400E60671 /* DirectoryFileListCreator.cpp */,
+				835D54C21F4DE53400E60671 /* DirectoryFileListCreator.h */,
 				2ED609BA1145B07100C8684E /* DOMFormData.cpp */,
 				2ED609BB1145B07100C8684E /* DOMFormData.h */,
 				2E0888C3114883A900AF4265 /* DOMFormData.idl */,
@@ -22274,8 +22276,6 @@
 				41A0829922932EF4008426E0 /* FeaturePolicy.h */,
 				F55B3D891251F12D003EF269 /* FileInputType.cpp */,
 				F55B3D8A1251F12D003EF269 /* FileInputType.h */,
-				835D54C11F4DE53400E60671 /* FileListCreator.cpp */,
-				835D54C21F4DE53400E60671 /* FileListCreator.h */,
 				4A0DA2FC129B241900AB61E1 /* FormAssociatedElement.cpp */,
 				4A0DA2FD129B241900AB61E1 /* FormAssociatedElement.h */,
 				F50664F5157F52DC00AC226F /* FormController.cpp */,
@@ -29992,6 +29992,7 @@
 				EDE3A5000C7A430600956A37 /* ColorMac.h in Headers */,
 				7CAC6AE9247F082F00E61D59 /* ColorMatrix.h in Headers */,
 				9382DF5810A8D5C900925652 /* ColorSpace.h in Headers */,
+				7C029C6E2493C8F800268204 /* ColorTypes.h in Headers */,
 				0FEAF66B23BFC39E004030DA /* ColorUtilities.h in Headers */,
 				BCDD454E1236C95C009A7985 /* ColumnInfo.h in Headers */,
 				43EDD67F1B485DBF00640E75 /* CombinedFiltersAlphabet.h in Headers */,
@@ -30356,6 +30357,7 @@
 				937FF3D51A1012D6008EBA31 /* DictionaryLookup.h in Headers */,
 				2D5646B01B8F8493003C4994 /* DictionaryPopupInfo.h in Headers */,
 				FDAF19991513D131008DB0C3 /* DirectConvolver.h in Headers */,
+				835D54C51F4DE53800E60671 /* DirectoryFileListCreator.h in Headers */,
 				F47A09D120A93A9700240FAE /* DisabledAdaptations.h in Headers */,
 				7EDAAFC919A2CCDC0034DFD1 /* DiskCacheMonitorCocoa.h in Headers */,
 				1199FA5B208E3C7F002358CC /* DisplayBox.h in Headers */,
@@ -30588,7 +30590,6 @@
 				1A88A90517553CD7000C74F9 /* FileIconLoader.h in Headers */,
 				F55B3DBE1251F12D003EF269 /* FileInputType.h in Headers */,
 				976D6C86122B8A3D001FD1F7 /* FileList.h in Headers */,
-				835D54C51F4DE53800E60671 /* FileListCreator.h in Headers */,
 				7A09CEF11F02069B00E93BDB /* FileMonitor.h in Headers */,
 				976D6C89122B8A3D001FD1F7 /* FileReader.h in Headers */,
 				2E75841E12779ADA0062628B /* FileReaderLoader.h in Headers */,
@@ -33110,7 +33111,6 @@
 				FE36FD1816C7826500F887C1 /* SQLTransactionState.h in Headers */,
 				FE36FD1716C7826500F887C1 /* SQLTransactionStateMachine.h in Headers */,
 				1A2E6E5A0CC55213004A2062 /* SQLValue.h in Headers */,
-				7C029C6E2493C8F800268204 /* ColorTypes.h in Headers */,
 				93F1996308245E59001E9ABC /* SSLKeyGenerator.h in Headers */,
 				26B999911803B3C900D01121 /* StackAllocator.h in Headers */,
 				BC7FA62D0D1F0EFF00DB22A9 /* StaticNodeList.h in Headers */,

Copied: branches/safari-610.1.17-branch/Source/WebCore/html/DirectoryFileListCreator.cpp (from rev 263213, branches/safari-610.1.17-branch/Source/WebCore/html/FileListCreator.cpp) (0 => 263214)


--- branches/safari-610.1.17-branch/Source/WebCore/html/DirectoryFileListCreator.cpp	                        (rev 0)
+++ branches/safari-610.1.17-branch/Source/WebCore/html/DirectoryFileListCreator.cpp	2020-06-18 16:52:12 UTC (rev 263214)
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2017-2020 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 "DirectoryFileListCreator.h"
+
+#include "FileChooser.h"
+#include "FileList.h"
+#include <wtf/CrossThreadCopier.h>
+#include <wtf/FileMetadata.h>
+#include <wtf/FileSystem.h>
+
+namespace WebCore {
+
+DirectoryFileListCreator::~DirectoryFileListCreator()
+{
+    ASSERT(!m_completionHandler);
+}
+
+static void appendDirectoryFiles(const String& directory, const String& relativePath, Vector<Ref<File>>& fileObjects)
+{
+    for (auto& childPath : FileSystem::listDirectory(directory, "*")) {
+        auto metadata = FileSystem::fileMetadata(childPath);
+        if (!metadata)
+            continue;
+
+        if (metadata.value().isHidden)
+            continue;
+
+        String childRelativePath = relativePath + "/" + FileSystem::pathGetFileName(childPath);
+        if (metadata.value().type == FileMetadata::Type::Directory)
+            appendDirectoryFiles(childPath, childRelativePath, fileObjects);
+        else if (metadata.value().type == FileMetadata::Type::File)
+            fileObjects.append(File::createWithRelativePath(childPath, childRelativePath));
+    }
+}
+
+static Ref<FileList> createFileList(const Vector<FileChooserFileInfo>& paths)
+{
+    Vector<Ref<File>> fileObjects;
+    for (auto& info : paths) {
+        if (FileSystem::fileIsDirectory(info.path, FileSystem::ShouldFollowSymbolicLinks::No))
+            appendDirectoryFiles(info.path, FileSystem::pathGetFileName(info.path), fileObjects);
+        else
+            fileObjects.append(File::create(info.path, info.displayName));
+    }
+    return FileList::create(WTFMove(fileObjects));
+}
+
+DirectoryFileListCreator::DirectoryFileListCreator(CompletionHandler&& completionHandler)
+    : m_workQueue(WorkQueue::create("DirectoryFileListCreator Work Queue"))
+    , m_completionHandler(WTFMove(completionHandler))
+{
+}
+
+void DirectoryFileListCreator::start(const Vector<FileChooserFileInfo>& paths)
+{
+    // Resolve directories on a background thread to avoid blocking the main thread.
+    m_workQueue->dispatch([this, protectedThis = makeRef(*this), paths = crossThreadCopy(paths)]() mutable {
+        callOnMainThread([this, protectedThis = WTFMove(protectedThis), fileList = createFileList(paths)]() mutable {
+            if (auto completionHandler = std::exchange(m_completionHandler, nullptr))
+                completionHandler(WTFMove(fileList));
+        });
+    });
+}
+
+void DirectoryFileListCreator::cancel()
+{
+    m_completionHandler = nullptr;
+    m_workQueue = nullptr;
+}
+
+} // namespace WebCore

Copied: branches/safari-610.1.17-branch/Source/WebCore/html/DirectoryFileListCreator.h (from rev 263213, branches/safari-610.1.17-branch/Source/WebCore/html/FileListCreator.h) (0 => 263214)


--- branches/safari-610.1.17-branch/Source/WebCore/html/DirectoryFileListCreator.h	                        (rev 0)
+++ branches/safari-610.1.17-branch/Source/WebCore/html/DirectoryFileListCreator.h	2020-06-18 16:52:12 UTC (rev 263214)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2017-2020 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 <wtf/Forward.h>
+#include <wtf/Function.h>
+#include <wtf/Ref.h>
+#include <wtf/ThreadSafeRefCounted.h>
+#include <wtf/WorkQueue.h>
+
+namespace WebCore {
+
+struct FileChooserFileInfo;
+class FileList;
+
+class DirectoryFileListCreator : public ThreadSafeRefCounted<DirectoryFileListCreator> {
+public:
+    using CompletionHandler = Function<void(Ref<FileList>&&)>;
+
+    static Ref<DirectoryFileListCreator> create(CompletionHandler&& completionHandler)
+    {
+        return adoptRef(*new DirectoryFileListCreator(WTFMove(completionHandler)));
+    }
+
+    ~DirectoryFileListCreator();
+
+    void start(const Vector<FileChooserFileInfo>&);
+    void cancel();
+
+private:
+    explicit DirectoryFileListCreator(CompletionHandler&&);
+
+    RefPtr<WorkQueue> m_workQueue;
+    CompletionHandler m_completionHandler;
+};
+
+}

Modified: branches/safari-610.1.17-branch/Source/WebCore/html/FileInputType.cpp (263213 => 263214)


--- branches/safari-610.1.17-branch/Source/WebCore/html/FileInputType.cpp	2020-06-18 16:52:08 UTC (rev 263213)
+++ branches/safari-610.1.17-branch/Source/WebCore/html/FileInputType.cpp	2020-06-18 16:52:12 UTC (rev 263214)
@@ -24,12 +24,12 @@
 
 #include "Chrome.h"
 #include "DOMFormData.h"
+#include "DirectoryFileListCreator.h"
 #include "DragData.h"
 #include "ElementChildIterator.h"
 #include "Event.h"
 #include "File.h"
 #include "FileList.h"
-#include "FileListCreator.h"
 #include "FormController.h"
 #include "Frame.h"
 #include "HTMLInputElement.h"
@@ -409,21 +409,38 @@
     if (!displayString.isEmpty())
         m_displayString = displayString;
 
-    if (m_fileListCreator)
-        m_fileListCreator->cancel();
+    if (m_directoryFileListCreator)
+        m_directoryFileListCreator->cancel();
 
-    auto shouldResolveDirectories = allowsDirectories() ? FileListCreator::ShouldResolveDirectories::Yes : FileListCreator::ShouldResolveDirectories::No;
-    m_fileListCreator = FileListCreator::create(paths, shouldResolveDirectories, [this, weakThis = makeWeakPtr(*this), icon = makeRefPtr(icon)](Ref<FileList>&& fileList) mutable {
-        auto protectedThis = makeRefPtr(weakThis.get());
-        if (!protectedThis)
+    if (!allowsDirectories()) {
+        auto files = paths.map([](auto& fileInfo) {
+            return File::create(fileInfo.path, fileInfo.displayName);
+        });
+        didCreateFileList(FileList::create(WTFMove(files)), icon);
+        return;
+    }
+
+    m_directoryFileListCreator = DirectoryFileListCreator::create([this, weakThis = makeWeakPtr(*this), icon = makeRefPtr(icon)](Ref<FileList>&& fileList) mutable {
+        ASSERT(isMainThread());
+        if (!weakThis)
             return;
-        setFiles(WTFMove(fileList), icon ? RequestIcon::Yes : RequestIcon::No);
-        if (icon && !m_fileList->isEmpty() && element())
-            iconLoaded(WTFMove(icon));
-        m_fileListCreator = nullptr;
+        didCreateFileList(WTFMove(fileList), WTFMove(icon));
     });
+    m_directoryFileListCreator->start(paths);
 }
 
+void FileInputType::didCreateFileList(Ref<FileList>&& fileList, RefPtr<Icon>&& icon)
+{
+    auto protectedThis = makeRef(*this);
+
+    ASSERT(!allowsDirectories() || m_directoryFileListCreator);
+    m_directoryFileListCreator = nullptr;
+
+    setFiles(WTFMove(fileList), icon ? RequestIcon::Yes : RequestIcon::No);
+    if (icon && !m_fileList->isEmpty() && element())
+        iconLoaded(WTFMove(icon));
+}
+
 String FileInputType::displayString() const
 {
     return m_displayString;

Modified: branches/safari-610.1.17-branch/Source/WebCore/html/FileInputType.h (263213 => 263214)


--- branches/safari-610.1.17-branch/Source/WebCore/html/FileInputType.h	2020-06-18 16:52:08 UTC (rev 263213)
+++ branches/safari-610.1.17-branch/Source/WebCore/html/FileInputType.h	2020-06-18 16:52:12 UTC (rev 263214)
@@ -39,9 +39,9 @@
 
 namespace WebCore {
 
+class DirectoryFileListCreator;
 class DragData;
 class FileList;
-class FileListCreator;
 class Icon;
 
 class FileInputType final : public BaseClickableWithKeyInputType, private FileChooserClient, private FileIconLoaderClient, public CanMakeWeakPtr<FileInputType> {
@@ -86,10 +86,10 @@
     // FileIconLoaderClient implementation.
     void iconLoaded(RefPtr<Icon>&&) final;
 
+    void applyFileChooserSettings(const FileChooserSettings&);
+    void didCreateFileList(Ref<FileList>&&, RefPtr<Icon>&&);
     void requestIcon(const Vector<String>&);
 
-    void applyFileChooserSettings(const FileChooserSettings&);
-
     bool allowsDirectories() const;
 
     RefPtr<FileChooser> m_fileChooser;
@@ -96,7 +96,7 @@
     std::unique_ptr<FileIconLoader> m_fileIconLoader;
 
     Ref<FileList> m_fileList;
-    RefPtr<FileListCreator> m_fileListCreator;
+    RefPtr<DirectoryFileListCreator> m_directoryFileListCreator;
     RefPtr<Icon> m_icon;
     String m_displayString;
 };

Deleted: branches/safari-610.1.17-branch/Source/WebCore/html/FileListCreator.cpp (263213 => 263214)


--- branches/safari-610.1.17-branch/Source/WebCore/html/FileListCreator.cpp	2020-06-18 16:52:08 UTC (rev 263213)
+++ branches/safari-610.1.17-branch/Source/WebCore/html/FileListCreator.cpp	2020-06-18 16:52:12 UTC (rev 263214)
@@ -1,103 +0,0 @@
-/*
- * Copyright (C) 2017-2020 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 "FileListCreator.h"
-
-#include "FileChooser.h"
-#include "FileList.h"
-#include <wtf/CrossThreadCopier.h>
-#include <wtf/FileMetadata.h>
-#include <wtf/FileSystem.h>
-
-namespace WebCore {
-
-FileListCreator::~FileListCreator()
-{
-    ASSERT(!m_completionHandler);
-}
-
-static void appendDirectoryFiles(const String& directory, const String& relativePath, Vector<Ref<File>>& fileObjects)
-{
-    for (auto& childPath : FileSystem::listDirectory(directory, "*")) {
-        auto metadata = FileSystem::fileMetadata(childPath);
-        if (!metadata)
-            continue;
-
-        if (metadata.value().isHidden)
-            continue;
-
-        String childRelativePath = relativePath + "/" + FileSystem::pathGetFileName(childPath);
-        if (metadata.value().type == FileMetadata::Type::Directory)
-            appendDirectoryFiles(childPath, childRelativePath, fileObjects);
-        else if (metadata.value().type == FileMetadata::Type::File)
-            fileObjects.append(File::createWithRelativePath(childPath, childRelativePath));
-    }
-}
-
-template<FileListCreator::ShouldResolveDirectories shouldResolveDirectories>
-static Ref<FileList> createFileList(const Vector<FileChooserFileInfo>& paths)
-{
-    Vector<Ref<File>> fileObjects;
-    for (auto& info : paths) {
-        if (shouldResolveDirectories == FileListCreator::ShouldResolveDirectories::Yes && FileSystem::fileIsDirectory(info.path, FileSystem::ShouldFollowSymbolicLinks::No))
-            appendDirectoryFiles(info.path, FileSystem::pathGetFileName(info.path), fileObjects);
-        else
-            fileObjects.append(File::create(info.path, info.displayName));
-    }
-    return FileList::create(WTFMove(fileObjects));
-}
-
-RefPtr<FileListCreator> FileListCreator::create(const Vector<FileChooserFileInfo>& paths, ShouldResolveDirectories shouldResolveDirectories, CompletionHandler&& completionHandler)
-{
-    if (shouldResolveDirectories == ShouldResolveDirectories::No) {
-        completionHandler(createFileList<ShouldResolveDirectories::No>(paths));
-        return nullptr;
-    }
-
-    return adoptRef(*new FileListCreator(paths, WTFMove(completionHandler)));
-}
-
-FileListCreator::FileListCreator(const Vector<FileChooserFileInfo>& paths, CompletionHandler&& completionHandler)
-    : m_workQueue(WorkQueue::create("FileListCreator Work Queue"))
-    , m_completionHandler(WTFMove(completionHandler))
-{
-    // Resolve directories on a background thread to avoid blocking the main thread.
-    m_workQueue->dispatch([this, protectedThis = makeRef(*this), paths = crossThreadCopy(paths)]() mutable {
-        auto fileList = createFileList<ShouldResolveDirectories::Yes>(paths);
-        callOnMainThread([this, protectedThis = WTFMove(protectedThis), fileList = WTFMove(fileList)]() mutable {
-            if (auto completionHandler = WTFMove(m_completionHandler))
-                completionHandler(WTFMove(fileList));
-        });
-    });
-}
-
-void FileListCreator::cancel()
-{
-    m_completionHandler = nullptr;
-    m_workQueue = nullptr;
-}
-
-} // namespace WebCore

Deleted: branches/safari-610.1.17-branch/Source/WebCore/html/FileListCreator.h (263213 => 263214)


--- branches/safari-610.1.17-branch/Source/WebCore/html/FileListCreator.h	2020-06-18 16:52:08 UTC (rev 263213)
+++ branches/safari-610.1.17-branch/Source/WebCore/html/FileListCreator.h	2020-06-18 16:52:12 UTC (rev 263214)
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2017-2020 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 <wtf/Forward.h>
-#include <wtf/Function.h>
-#include <wtf/Ref.h>
-#include <wtf/ThreadSafeRefCounted.h>
-#include <wtf/WorkQueue.h>
-
-namespace WebCore {
-
-struct FileChooserFileInfo;
-class FileList;
-
-class FileListCreator : public ThreadSafeRefCounted<FileListCreator> {
-public:
-    using CompletionHandler = Function<void(Ref<FileList>&&)>;
-
-    enum class ShouldResolveDirectories { No, Yes };
-    static RefPtr<FileListCreator> create(const Vector<FileChooserFileInfo>&, ShouldResolveDirectories, CompletionHandler&&);
-
-    ~FileListCreator();
-
-    void cancel();
-
-private:
-    FileListCreator(const Vector<FileChooserFileInfo>&, CompletionHandler&&);
-
-    RefPtr<WorkQueue> m_workQueue;
-    CompletionHandler m_completionHandler;
-};
-
-}
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to