[Cleanup] Cleanup uses of the FileList class
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Sep 2017 16:22:07 +0000 (16:22 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Sep 2017 16:22:07 +0000 (16:22 +0000)
https://bugs.webkit.org/show_bug.cgi?id=176800

Patch by Sam Weinig <sam@webkit.org> on 2017-09-14
Reviewed by Alex Christensen.

* fileapi/FileList.cpp:
* fileapi/FileList.h:

    Store list of files as Refs, rather than RefPtrs.
    Add direct accessor to the underlying Vector for faster iteration.
    Add file(unsigned) function to allow direct indexing, rather than using
    the DOM exposed item function which always does a length check.

* Modules/entriesapi/HTMLInputElementEntriesAPI.cpp:

    Remove unused RuntimeEnabledFeatures.h #include.
    Use modern for loop and the new direct file vector access.

* bindings/js/SerializedScriptValue.cpp:
(WebCore::CloneSerializer::dumpIfTerminal):
(WebCore::CloneSerializer::write):
(WebCore::CloneDeserializer::readFile):
(WebCore::CloneDeserializer::readTerminal):

    Remove unnecessary #includes, adopt auto, and use modern for-loop
    for FileList.

* dom/DataTransfer.cpp:
(WebCore::DataTransfer::files const):
(WebCore::DataTransfer::hasFileOfType):

    Use auto.

(WebCore::DataTransfer::createForInputEvent):

    Use initializer list for the typeToStringMap.

* dom/DataTransferItemList.cpp:
(WebCore::DataTransferItemList::ensureItems const):

    Use auto and modern for-loop for FileList.

* html/FileInputType.cpp:
(WebCore::FileInputType::filesFromFormControlState):
(WebCore::FileInputType::saveFormControlState const):
(WebCore::FileInputType::appendFormData const):
(WebCore::FileInputType::handleDOMActivateEvent):
(WebCore::FileInputType::getTypeSpecificValue):
(WebCore::FileInputType::disabledAttributeChanged):
(WebCore::FileInputType::multipleAttributeChanged):
(WebCore::FileInputType::setFiles):
(WebCore::FileInputType::receiveDroppedFiles):
(WebCore::FileInputType::defaultToolTip const):

    Adopt auto, brace-initialization, and modern for-loops.

* html/FileListCreator.cpp:
(WebCore::appendDirectoryFiles):
(WebCore::FileListCreator::createFileList):

    Update to work in terms of Vector<Ref<File>>.

* html/FormController.h:
(WebCore::FormControlState::FormControlState):

    Re-format existing constructors and add one that takes an r-value
    Vector<String> to allow construction from a pre-created list (used
    in FileInputType::saveFormControlState)

* platform/DragData.h:
* platform/gtk/DragDataGtk.cpp:
(WebCore::DragData::asFilenames const):
* platform/mac/DragDataMac.mm:
(WebCore::DragData::asFilenames const):
* platform/win/DragDataWin.cpp:
(WebCore::DragData::asFilenames const):

    Convert asFilenames to return, rather than take, a Vector<String>.

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

14 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/entriesapi/HTMLInputElementEntriesAPI.cpp
Source/WebCore/bindings/js/SerializedScriptValue.cpp
Source/WebCore/dom/DataTransfer.cpp
Source/WebCore/dom/DataTransferItemList.cpp
Source/WebCore/fileapi/FileList.cpp
Source/WebCore/fileapi/FileList.h
Source/WebCore/html/FileInputType.cpp
Source/WebCore/html/FileListCreator.cpp
Source/WebCore/html/FormController.h
Source/WebCore/platform/DragData.h
Source/WebCore/platform/gtk/DragDataGtk.cpp
Source/WebCore/platform/mac/DragDataMac.mm
Source/WebCore/platform/win/DragDataWin.cpp

index bfe37d2..2d0334b 100644 (file)
@@ -1,3 +1,84 @@
+2017-09-14  Sam Weinig  <sam@webkit.org>
+
+        [Cleanup] Cleanup uses of the FileList class
+        https://bugs.webkit.org/show_bug.cgi?id=176800
+
+        Reviewed by Alex Christensen.
+
+        * fileapi/FileList.cpp:
+        * fileapi/FileList.h:
+
+            Store list of files as Refs, rather than RefPtrs.
+            Add direct accessor to the underlying Vector for faster iteration.
+            Add file(unsigned) function to allow direct indexing, rather than using
+            the DOM exposed item function which always does a length check.
+
+        * Modules/entriesapi/HTMLInputElementEntriesAPI.cpp:
+        
+            Remove unused RuntimeEnabledFeatures.h #include.
+            Use modern for loop and the new direct file vector access. 
+        
+        * bindings/js/SerializedScriptValue.cpp:
+        (WebCore::CloneSerializer::dumpIfTerminal):
+        (WebCore::CloneSerializer::write):
+        (WebCore::CloneDeserializer::readFile):
+        (WebCore::CloneDeserializer::readTerminal):
+        
+            Remove unnecessary #includes, adopt auto, and use modern for-loop
+            for FileList.
+        
+        * dom/DataTransfer.cpp:
+        (WebCore::DataTransfer::files const):
+        (WebCore::DataTransfer::hasFileOfType):
+        
+            Use auto.
+        
+        (WebCore::DataTransfer::createForInputEvent):
+        
+            Use initializer list for the typeToStringMap.
+        
+        * dom/DataTransferItemList.cpp:
+        (WebCore::DataTransferItemList::ensureItems const):
+        
+            Use auto and modern for-loop for FileList.
+        
+        * html/FileInputType.cpp:
+        (WebCore::FileInputType::filesFromFormControlState):
+        (WebCore::FileInputType::saveFormControlState const):
+        (WebCore::FileInputType::appendFormData const):
+        (WebCore::FileInputType::handleDOMActivateEvent):
+        (WebCore::FileInputType::getTypeSpecificValue):
+        (WebCore::FileInputType::disabledAttributeChanged):
+        (WebCore::FileInputType::multipleAttributeChanged):
+        (WebCore::FileInputType::setFiles):
+        (WebCore::FileInputType::receiveDroppedFiles):
+        (WebCore::FileInputType::defaultToolTip const):
+
+            Adopt auto, brace-initialization, and modern for-loops.
+
+        * html/FileListCreator.cpp:
+        (WebCore::appendDirectoryFiles):
+        (WebCore::FileListCreator::createFileList):
+        
+            Update to work in terms of Vector<Ref<File>>.
+
+        * html/FormController.h:
+        (WebCore::FormControlState::FormControlState):
+        
+            Re-format existing constructors and add one that takes an r-value
+            Vector<String> to allow construction from a pre-created list (used 
+            in FileInputType::saveFormControlState)
+        
+        * platform/DragData.h:
+        * platform/gtk/DragDataGtk.cpp:
+        (WebCore::DragData::asFilenames const):
+        * platform/mac/DragDataMac.mm:
+        (WebCore::DragData::asFilenames const):
+        * platform/win/DragDataWin.cpp:
+        (WebCore::DragData::asFilenames const):
+        
+            Convert asFilenames to return, rather than take, a Vector<String>.
+
 2017-09-14  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [Harfbuzz] Wrong offset returned by HarfBuzzShaper::offsetForPosition() when target point is at the middle of a character
 2017-09-14  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [Harfbuzz] Wrong offset returned by HarfBuzzShaper::offsetForPosition() when target point is at the middle of a character
index 20eea44..bbe92a0 100644 (file)
@@ -29,7 +29,6 @@
 #include "DOMFileSystem.h"
 #include "FileList.h"
 #include "HTMLInputElement.h"
 #include "DOMFileSystem.h"
 #include "FileList.h"
 #include "HTMLInputElement.h"
-#include "RuntimeEnabledFeatures.h"
 
 namespace WebCore {
 
 
 namespace WebCore {
 
@@ -42,15 +41,14 @@ Vector<Ref<FileSystemEntry>> HTMLInputElementEntriesAPI::webkitEntries(ScriptExe
     if (input.hasAttributeWithoutSynchronization(webkitdirectoryAttr))
         return { };
 
     if (input.hasAttributeWithoutSynchronization(webkitdirectoryAttr))
         return { };
 
-    auto* files = input.files();
-    if (!files)
+    auto* fileList = input.files();
+    if (!fileList)
         return { };
 
         return { };
 
-    unsigned length = files->length();
     Vector<Ref<FileSystemEntry>> entries;
     Vector<Ref<FileSystemEntry>> entries;
-    entries.reserveInitialCapacity(length);
-    for (unsigned i = 0; i < length; ++i)
-        entries.uncheckedAppend(DOMFileSystem::createEntryForFile(context, *files->item(i)));
+    entries.reserveInitialCapacity(fileList->files().size());
+    for (auto& file : fileList->files())
+        entries.uncheckedAppend(DOMFileSystem::createEntryForFile(context, file.copyRef()));
     return entries;
 }
 
     return entries;
 }
 
index 3c18a51..975c9c9 100644 (file)
@@ -27,7 +27,6 @@
 #include "config.h"
 #include "SerializedScriptValue.h"
 
 #include "config.h"
 #include "SerializedScriptValue.h"
 
-#include "Blob.h"
 #include "BlobRegistry.h"
 #include "CryptoKeyAES.h"
 #include "CryptoKeyEC.h"
 #include "BlobRegistry.h"
 #include "CryptoKeyAES.h"
 #include "CryptoKeyEC.h"
 #include "CryptoKeyRSA.h"
 #include "CryptoKeyRSAComponents.h"
 #include "CryptoKeyRaw.h"
 #include "CryptoKeyRSA.h"
 #include "CryptoKeyRSAComponents.h"
 #include "CryptoKeyRaw.h"
-#include "File.h"
-#include "FileList.h"
 #include "IDBValue.h"
 #include "IDBValue.h"
-#include "ImageData.h"
 #include "JSBlob.h"
 #include "JSCryptoKey.h"
 #include "JSDOMBinding.h"
 #include "JSBlob.h"
 #include "JSCryptoKey.h"
 #include "JSDOMBinding.h"
@@ -929,7 +925,7 @@ private:
             return false;
 
         if (value.isObject()) {
             return false;
 
         if (value.isObject()) {
-            JSObject* obj = asObject(value);
+            auto* obj = asObject(value);
             if (obj->inherits(vm, BooleanObject::info())) {
                 if (!startObjectInternal(obj)) // handle duplicates
                     return true;
             if (obj->inherits(vm, BooleanObject::info())) {
                 if (!startObjectInternal(obj)) // handle duplicates
                     return true;
@@ -951,20 +947,19 @@ private:
                 write(obj->internalValue().asNumber());
                 return true;
             }
                 write(obj->internalValue().asNumber());
                 return true;
             }
-            if (File* file = JSFile::toWrapped(vm, obj)) {
+            if (auto* file = JSFile::toWrapped(vm, obj)) {
                 write(FileTag);
                 write(FileTag);
-                write(file);
+                write(*file);
                 return true;
             }
                 return true;
             }
-            if (FileList* list = JSFileList::toWrapped(vm, obj)) {
+            if (auto* list = JSFileList::toWrapped(vm, obj)) {
                 write(FileListTag);
                 write(FileListTag);
-                unsigned length = list->length();
-                write(length);
-                for (unsigned i = 0; i < length; i++)
-                    write(list->item(i));
+                write(list->length());
+                for (auto& file : list->files())
+                    write(file.get());
                 return true;
             }
                 return true;
             }
-            if (Blob* blob = JSBlob::toWrapped(vm, obj)) {
+            if (auto* blob = JSBlob::toWrapped(vm, obj)) {
                 write(BlobTag);
                 m_blobURLs.append(blob->url());
                 write(blob->url());
                 write(BlobTag);
                 m_blobURLs.append(blob->url());
                 write(blob->url());
@@ -972,7 +967,7 @@ private:
                 write(blob->size());
                 return true;
             }
                 write(blob->size());
                 return true;
             }
-            if (ImageData* data = JSImageData::toWrapped(vm, obj)) {
+            if (auto* data = JSImageData::toWrapped(vm, obj)) {
                 write(ImageDataTag);
                 write(data->width());
                 write(data->height());
                 write(ImageDataTag);
                 write(data->width());
                 write(data->height());
@@ -981,7 +976,7 @@ private:
                 return true;
             }
             if (obj->inherits(vm, RegExpObject::info())) {
                 return true;
             }
             if (obj->inherits(vm, RegExpObject::info())) {
-                RegExpObject* regExp = asRegExpObject(obj);
+                auto* regExp = asRegExpObject(obj);
                 char flags[3];
                 int flagCount = 0;
                 if (regExp->regExp()->global())
                 char flags[3];
                 int flagCount = 0;
                 if (regExp->regExp()->global())
@@ -996,7 +991,7 @@ private:
                 return true;
             }
             if (obj->inherits(vm, JSMessagePort::info())) {
                 return true;
             }
             if (obj->inherits(vm, JSMessagePort::info())) {
-                ObjectPool::iterator index = m_transferredMessagePorts.find(obj);
+                auto index = m_transferredMessagePorts.find(obj);
                 if (index != m_transferredMessagePorts.end()) {
                     write(MessagePortReferenceTag);
                     write(index->value);
                 if (index != m_transferredMessagePorts.end()) {
                     write(MessagePortReferenceTag);
                     write(index->value);
@@ -1006,12 +1001,12 @@ private:
                 code = SerializationReturnCode::ValidationError;
                 return true;
             }
                 code = SerializationReturnCode::ValidationError;
                 return true;
             }
-            if (ArrayBuffer* arrayBuffer = toPossiblySharedArrayBuffer(vm, obj)) {
+            if (auto* arrayBuffer = toPossiblySharedArrayBuffer(vm, obj)) {
                 if (arrayBuffer->isNeutered()) {
                     code = SerializationReturnCode::ValidationError;
                     return true;
                 }
                 if (arrayBuffer->isNeutered()) {
                     code = SerializationReturnCode::ValidationError;
                     return true;
                 }
-                ObjectPool::iterator index = m_transferredArrayBuffers.find(obj);
+                auto index = m_transferredArrayBuffers.find(obj);
                 if (index != m_transferredArrayBuffers.end()) {
                     write(ArrayBufferTransferTag);
                     write(index->value);
                 if (index != m_transferredArrayBuffers.end()) {
                     write(ArrayBufferTransferTag);
                     write(index->value);
@@ -1020,8 +1015,7 @@ private:
                 if (!startObjectInternal(obj)) // handle duplicates
                     return true;
                 
                 if (!startObjectInternal(obj)) // handle duplicates
                     return true;
                 
-                if (arrayBuffer->isShared()
-                    && m_context == SerializationContext::WorkerPostMessage) {
+                if (arrayBuffer->isShared() && m_context == SerializationContext::WorkerPostMessage) {
                     uint32_t index = m_sharedBuffers.size();
                     ArrayBufferContents contents;
                     if (arrayBuffer->shareWith(contents)) {
                     uint32_t index = m_sharedBuffers.size();
                     ArrayBufferContents contents;
                     if (arrayBuffer->shareWith(contents)) {
@@ -1045,7 +1039,7 @@ private:
                 return success;
             }
 #if ENABLE(SUBTLE_CRYPTO)
                 return success;
             }
 #if ENABLE(SUBTLE_CRYPTO)
-            if (CryptoKey* key = JSCryptoKey::toWrapped(vm, obj)) {
+            if (auto* key = JSCryptoKey::toWrapped(vm, obj)) {
                 write(CryptoKeyTag);
                 Vector<uint8_t> serializedKey;
                 Vector<String> dummyBlobURLs;
                 write(CryptoKeyTag);
                 Vector<uint8_t> serializedKey;
                 Vector<String> dummyBlobURLs;
@@ -1241,13 +1235,13 @@ private:
         writeLittleEndian(m_buffer, vector.data(), size);
     }
 
         writeLittleEndian(m_buffer, vector.data(), size);
     }
 
-    void write(const File* file)
+    void write(const File& file)
     {
     {
-        m_blobURLs.append(file->url());
-        write(file->path());
-        write(file->url());
-        write(file->type());
-        write(file->name());
+        m_blobURLs.append(file.url());
+        write(file.path());
+        write(file.url());
+        write(file.type());
+        write(file.name());
     }
 
 #if ENABLE(SUBTLE_CRYPTO)
     }
 
 #if ENABLE(SUBTLE_CRYPTO)
@@ -2033,16 +2027,16 @@ private:
     {
         CachedStringRef path;
         if (!readStringData(path))
     {
         CachedStringRef path;
         if (!readStringData(path))
-            return 0;
+            return false;
         CachedStringRef url;
         if (!readStringData(url))
         CachedStringRef url;
         if (!readStringData(url))
-            return 0;
+            return false;
         CachedStringRef type;
         if (!readStringData(type))
         CachedStringRef type;
         if (!readStringData(type))
-            return 0;
+            return false;
         CachedStringRef name;
         if (!readStringData(name))
         CachedStringRef name;
         if (!readStringData(name))
-            return 0;
+            return false;
 
         // If the blob URL for this file has an associated blob file path, prefer that one over the "built-in" path.
         String filePath = blobFilePathForBlobURL(url->string());
 
         // If the blob URL for this file has an associated blob file path, prefer that one over the "built-in" path.
         String filePath = blobFilePathForBlobURL(url->string());
@@ -2697,13 +2691,13 @@ private:
             unsigned length = 0;
             if (!read(length))
                 return JSValue();
             unsigned length = 0;
             if (!read(length))
                 return JSValue();
-            Vector<RefPtr<File>> files;
+            Vector<Ref<File>> files;
             for (unsigned i = 0; i < length; i++) {
                 RefPtr<File> file;
                 if (!readFile(file))
                     return JSValue();
                 if (m_isDOMGlobalObject)
             for (unsigned i = 0; i < length; i++) {
                 RefPtr<File> file;
                 if (!readFile(file))
                     return JSValue();
                 if (m_isDOMGlobalObject)
-                    files.append(WTFMove(file));
+                    files.append(file.releaseNonNull());
             }
             if (!m_isDOMGlobalObject)
                 return jsNull();
             }
             if (!m_isDOMGlobalObject)
                 return jsNull();
index 0e6b57f..3d313e1 100644 (file)
@@ -193,7 +193,7 @@ FileList& DataTransfer::files() const
 #endif
 
     if (newlyCreatedFileList) {
 #endif
 
     if (newlyCreatedFileList) {
-        for (const String& filename : m_pasteboard->readFilenames())
+        for (auto& filename : m_pasteboard->readFilenames())
             m_fileList->append(File::create(filename));
     }
     return *m_fileList;
             m_fileList->append(File::create(filename));
     }
     return *m_fileList;
@@ -203,7 +203,7 @@ bool DataTransfer::hasFileOfType(const String& type)
 {
     ASSERT_WITH_SECURITY_IMPLICATION(canReadTypes());
 
 {
     ASSERT_WITH_SECURITY_IMPLICATION(canReadTypes());
 
-    for (const String& path : m_pasteboard->readFilenames()) {
+    for (auto& path : m_pasteboard->readFilenames()) {
         if (equalIgnoringASCIICase(File::contentTypeForFile(path), type))
             return true;
     }
         if (equalIgnoringASCIICase(File::contentTypeForFile(path), type))
             return true;
     }
@@ -220,9 +220,7 @@ bool DataTransfer::hasStringOfType(const String& type)
 
 Ref<DataTransfer> DataTransfer::createForInputEvent(const String& plainText, const String& htmlText)
 {
 
 Ref<DataTransfer> DataTransfer::createForInputEvent(const String& plainText, const String& htmlText)
 {
-    TypeToStringMap typeToStringMap;
-    typeToStringMap.set(ASCIILiteral("text/plain"), plainText);
-    typeToStringMap.set(ASCIILiteral("text/html"), htmlText);
+    TypeToStringMap typeToStringMap { { ASCIILiteral("text/plain"), plainText }, { ASCIILiteral("text/html"), htmlText } };
     return adoptRef(*new DataTransfer(StoreMode::Readonly, StaticPasteboard::create(WTFMove(typeToStringMap)), Type::InputEvent));
 }
 
     return adoptRef(*new DataTransfer(StoreMode::Readonly, StaticPasteboard::create(WTFMove(typeToStringMap)), Type::InputEvent));
 }
 
index fdfda27..0337a0b 100644 (file)
@@ -124,18 +124,16 @@ Vector<Ref<DataTransferItem>>& DataTransferItemList::ensureItems() const
         return *m_items;
 
     Vector<Ref<DataTransferItem>> items;
         return *m_items;
 
     Vector<Ref<DataTransferItem>> items;
-    for (String& type : m_dataTransfer.types()) {
-        String lowercasedType = type.convertToASCIILowercase();
+    for (auto& type : m_dataTransfer.types()) {
+        auto lowercasedType = type.convertToASCIILowercase();
         if (isSupportedType(lowercasedType))
             items.append(DataTransferItem::create(m_weakPtrFactory.createWeakPtr(), lowercasedType));
     }
 
         if (isSupportedType(lowercasedType))
             items.append(DataTransferItem::create(m_weakPtrFactory.createWeakPtr(), lowercasedType));
     }
 
-    FileList& files = m_dataTransfer.files();
-    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) || file.isDirectory())
-            items.append(DataTransferItem::create(m_weakPtrFactory.createWeakPtr(), type, file));
+    for (auto& file : m_dataTransfer.files().files()) {
+        auto type = File::contentTypeForFile(file->path()).convertToASCIILowercase();
+        if (isSupportedType(type) || file->isDirectory())
+            items.append(DataTransferItem::create(m_weakPtrFactory.createWeakPtr(), type, file.copyRef()));
     }
 
     m_items = WTFMove(items);
     }
 
     m_items = WTFMove(items);
index 809e253..7ca7f1b 100644 (file)
 #include "config.h"
 #include "FileList.h"
 
 #include "config.h"
 #include "FileList.h"
 
-#include "File.h"
-
 namespace WebCore {
 
 namespace WebCore {
 
-FileList::FileList()
-{
-}
-
 File* FileList::item(unsigned index) const
 {
     if (index >= m_files.size())
 File* FileList::item(unsigned index) const
 {
     if (index >= m_files.size())
-        return 0;
-    return m_files[index].get();
+        return nullptr;
+    return m_files[index].ptr();
 }
 
 Vector<String> FileList::paths() const
 {
     Vector<String> paths;
 }
 
 Vector<String> FileList::paths() const
 {
     Vector<String> paths;
-    for (unsigned i = 0; i < m_files.size(); ++i)
-        paths.append(m_files[i]->path());
-
+    paths.reserveInitialCapacity(m_files.size());
+    for (auto& file : m_files)
+        paths.uncheckedAppend(file->path());
     return paths;
 }
 
     return paths;
 }
 
index 7296bc5..c1c5ef1 100644 (file)
@@ -40,7 +40,7 @@ public:
         return adoptRef(*new FileList);
     }
 
         return adoptRef(*new FileList);
     }
 
-    static Ref<FileList> create(Vector<RefPtr<File>>&& files)
+    static Ref<FileList> create(Vector<Ref<File>>&& files)
     {
         return adoptRef(*new FileList(WTFMove(files)));
     }
     {
         return adoptRef(*new FileList(WTFMove(files)));
     }
@@ -51,19 +51,23 @@ public:
     bool isEmpty() const { return m_files.isEmpty(); }
     Vector<String> paths() const;
 
     bool isEmpty() const { return m_files.isEmpty(); }
     Vector<String> paths() const;
 
+    const Vector<Ref<File>>& files() const { return m_files; }
+    const File& file(unsigned index) const { return m_files[index].get(); }
+
 private:
 private:
-    FileList();
-    FileList(Vector<RefPtr<File>>&& files)
+    FileList() = default;
+    FileList(Vector<Ref<File>>&& files)
         : m_files(WTFMove(files))
         : m_files(WTFMove(files))
-    { }
+    {
+    }
 
     // FileLists can only be changed by their owners.
     friend class DataTransfer;
     friend class FileInputType;
 
     // FileLists can only be changed by their owners.
     friend class DataTransfer;
     friend class FileInputType;
-    void append(RefPtr<File>&& file) { m_files.append(WTFMove(file)); }
+    void append(Ref<File>&& file) { m_files.append(WTFMove(file)); }
     void clear() { m_files.clear(); }
 
     void clear() { m_files.clear(); }
 
-    Vector<RefPtr<File>> m_files;
+    Vector<Ref<File>> m_files;
 };
 
 } // namespace WebCore
 };
 
 } // namespace WebCore
index 72e13ee..50c0329 100644 (file)
@@ -115,9 +115,9 @@ Vector<FileChooserFileInfo> FileInputType::filesFromFormControlState(const FormC
     Vector<FileChooserFileInfo> files;
     for (size_t i = 0; i < state.valueSize(); i += 2) {
         if (!state[i + 1].isEmpty())
     Vector<FileChooserFileInfo> files;
     for (size_t i = 0; i < state.valueSize(); i += 2) {
         if (!state[i + 1].isEmpty())
-            files.append(FileChooserFileInfo(state[i], state[i + 1]));
+            files.append({ state[i], state[i + 1] });
         else
         else
-            files.append(FileChooserFileInfo(state[i]));
+            files.append({ state[i] });
     }
     return files;
 }
     }
     return files;
 }
@@ -130,14 +130,17 @@ const AtomicString& FileInputType::formControlType() const
 FormControlState FileInputType::saveFormControlState() const
 {
     if (m_fileList->isEmpty())
 FormControlState FileInputType::saveFormControlState() const
 {
     if (m_fileList->isEmpty())
-        return FormControlState();
-    FormControlState state;
-    unsigned numFiles = m_fileList->length();
-    for (unsigned i = 0; i < numFiles; ++i) {
-        state.append(m_fileList->item(i)->path());
-        state.append(m_fileList->item(i)->name());
+        return { };
+
+    auto length = Checked<size_t>(m_fileList->files().size()) * Checked<size_t>(2);
+
+    Vector<String> stateVector;
+    stateVector.reserveInitialCapacity(length.unsafeGet());
+    for (auto& file : m_fileList->files()) {
+        stateVector.uncheckedAppend(file->path());
+        stateVector.uncheckedAppend(file->name());
     }
     }
-    return state;
+    return FormControlState { WTFMove(stateVector) };
 }
 
 void FileInputType::restoreFormControlState(const FormControlState& state)
 }
 
 void FileInputType::restoreFormControlState(const FormControlState& state)
@@ -149,10 +152,11 @@ void FileInputType::restoreFormControlState(const FormControlState& state)
 
 bool FileInputType::appendFormData(DOMFormData& formData, bool multipart) const
 {
 
 bool FileInputType::appendFormData(DOMFormData& formData, bool multipart) const
 {
+    auto* fileList = element().files();
+    ASSERT(fileList);
+
     auto name = element().name();
 
     auto name = element().name();
 
-    auto* fileList = element().files();
-    unsigned numFiles = fileList->length();
     if (!multipart) {
         // Send only the basenames.
         // 4.10.16.4 and 4.10.16.6 sections in HTML5.
     if (!multipart) {
         // Send only the basenames.
         // 4.10.16.4 and 4.10.16.6 sections in HTML5.
@@ -161,20 +165,21 @@ bool FileInputType::appendFormData(DOMFormData& formData, bool multipart) const
         // fileList because Netscape doesn't support for non-multipart
         // submission of file inputs, and Firefox doesn't add "name=" query
         // parameter.
         // fileList because Netscape doesn't support for non-multipart
         // submission of file inputs, and Firefox doesn't add "name=" query
         // parameter.
-        for (unsigned i = 0; i < numFiles; ++i)
-            formData.append(name, fileList->item(i)->name());
+        for (auto& file : fileList->files())
+            formData.append(name, file->name());
         return true;
     }
 
     // If no filename at all is entered, return successful but empty.
     // Null would be more logical, but Netscape posts an empty file. Argh.
         return true;
     }
 
     // If no filename at all is entered, return successful but empty.
     // Null would be more logical, but Netscape posts an empty file. Argh.
-    if (!numFiles) {
+    if (fileList->isEmpty()) {
         formData.append(name, File::create(emptyString()));
         return true;
     }
 
         formData.append(name, File::create(emptyString()));
         return true;
     }
 
-    for (unsigned i = 0; i < numFiles; ++i)
-        formData.append(name, *fileList->item(i));
+
+    for (auto& file : fileList->files())
+        formData.append(name, file.get());
     return true;
 }
 
     return true;
 }
 
@@ -190,7 +195,9 @@ String FileInputType::valueMissingText() const
 
 void FileInputType::handleDOMActivateEvent(Event& event)
 {
 
 void FileInputType::handleDOMActivateEvent(Event& event)
 {
-    if (element().isDisabledFormControl())
+    auto& input = element();
+
+    if (input.isDisabledFormControl())
         return;
 
     if (!ScriptController::processingUserGesture())
         return;
 
     if (!ScriptController::processingUserGesture())
@@ -198,7 +205,6 @@ void FileInputType::handleDOMActivateEvent(Event& event)
 
     if (auto* chrome = this->chrome()) {
         FileChooserSettings settings;
 
     if (auto* chrome = this->chrome()) {
         FileChooserSettings settings;
-        HTMLInputElement& input = element();
         settings.allowsDirectories = allowsDirectories();
         settings.allowsMultipleFiles = input.hasAttributeWithoutSynchronization(multipleAttr);
         settings.acceptMIMETypes = input.acceptMIMETypes();
         settings.allowsDirectories = allowsDirectories();
         settings.allowsMultipleFiles = input.hasAttributeWithoutSynchronization(multipleAttr);
         settings.acceptMIMETypes = input.acceptMIMETypes();
@@ -241,7 +247,7 @@ bool FileInputType::canSetValue(const String& value)
 bool FileInputType::getTypeSpecificValue(String& value)
 {
     if (m_fileList->isEmpty()) {
 bool FileInputType::getTypeSpecificValue(String& value)
 {
     if (m_fileList->isEmpty()) {
-        value = String();
+        value = { };
         return true;
     }
 
         return true;
     }
 
@@ -251,7 +257,7 @@ bool FileInputType::getTypeSpecificValue(String& value)
     // decided to try to parse the value by looking for backslashes
     // (because that's what Windows file paths use). To be compatible
     // with that code, we make up a fake path for the file.
     // decided to try to parse the value by looking for backslashes
     // (because that's what Windows file paths use). To be compatible
     // with that code, we make up a fake path for the file.
-    value = "C:\\fakepath\\" + m_fileList->item(0)->name();
+    value = makeString("C:\\fakepath\\", m_fileList->file(0).name());
     return true;
 }
 
     return true;
 }
 
@@ -278,7 +284,7 @@ void FileInputType::disabledAttributeChanged()
 {
     ASSERT(element().shadowRoot());
 
 {
     ASSERT(element().shadowRoot());
 
-    ShadowRoot* root = element().userAgentShadowRoot();
+    auto* root = element().userAgentShadowRoot();
     if (!root)
         return;
     
     if (!root)
         return;
     
@@ -290,7 +296,7 @@ void FileInputType::multipleAttributeChanged()
 {
     ASSERT(element().shadowRoot());
 
 {
     ASSERT(element().shadowRoot());
 
-    ShadowRoot* root = element().userAgentShadowRoot();
+    auto* root = element().userAgentShadowRoot();
     if (!root)
         return;
 
     if (!root)
         return;
 
@@ -354,7 +360,7 @@ void FileInputType::setFiles(RefPtr<FileList>&& files, RequestIcon shouldRequest
         pathsChanged = true;
     else {
         for (unsigned i = 0; i < length; ++i) {
         pathsChanged = true;
     else {
         for (unsigned i = 0; i < length; ++i) {
-            if (files->item(i)->path() != m_fileList->item(i)->path()) {
+            if (files->file(i).path() != m_fileList->file(i).path()) {
                 pathsChanged = true;
                 break;
             }
                 pathsChanged = true;
                 break;
             }
@@ -369,8 +375,8 @@ void FileInputType::setFiles(RefPtr<FileList>&& files, RequestIcon shouldRequest
     if (shouldRequestIcon == RequestIcon::Yes) {
         Vector<String> paths;
         paths.reserveInitialCapacity(length);
     if (shouldRequestIcon == RequestIcon::Yes) {
         Vector<String> paths;
         paths.reserveInitialCapacity(length);
-        for (unsigned i = 0; i < length; ++i)
-            paths.uncheckedAppend(m_fileList->item(i)->path());
+        for (auto& file : m_fileList->files())
+            paths.uncheckedAppend(file->path());
         requestIcon(paths);
     }
 
         requestIcon(paths);
     }
 
@@ -422,24 +428,20 @@ void FileInputType::iconLoaded(RefPtr<Icon>&& icon)
 #if ENABLE(DRAG_SUPPORT)
 bool FileInputType::receiveDroppedFiles(const DragData& dragData)
 {
 #if ENABLE(DRAG_SUPPORT)
 bool FileInputType::receiveDroppedFiles(const DragData& dragData)
 {
-    Vector<String> paths;
-    dragData.asFilenames(paths);
+    auto paths = dragData.asFilenames();
     if (paths.isEmpty())
         return false;
 
     if (paths.isEmpty())
         return false;
 
-    HTMLInputElement* input = &element();
-
-    Vector<FileChooserFileInfo> files;
-    for (auto& path : paths)
-        files.append(FileChooserFileInfo(path));
+    if (element().hasAttributeWithoutSynchronization(multipleAttr)) {
+        Vector<FileChooserFileInfo> files;
+        files.reserveInitialCapacity(paths.size());
+        for (auto& path : paths)
+            files.uncheckedAppend({ path });
 
 
-    if (input->hasAttributeWithoutSynchronization(multipleAttr))
         filesChosen(files);
         filesChosen(files);
-    else {
-        Vector<FileChooserFileInfo> firstFileOnly;
-        firstFileOnly.append(files[0]);
-        filesChosen(firstFileOnly);
-    }
+    } else
+        filesChosen({ FileChooserFileInfo { paths[0] } });
+
     return true;
 }
 #endif // ENABLE(DRAG_SUPPORT)
     return true;
 }
 #endif // ENABLE(DRAG_SUPPORT)
@@ -460,7 +462,7 @@ String FileInputType::defaultToolTip() const
 
     StringBuilder names;
     for (unsigned i = 0; i < listSize; ++i) {
 
     StringBuilder names;
     for (unsigned i = 0; i < listSize; ++i) {
-        names.append(m_fileList->item(i)->name());
+        names.append(m_fileList->file(i).name());
         if (i != listSize - 1)
             names.append('\n');
     }
         if (i != listSize - 1)
             names.append('\n');
     }
index defa5eb..9106dad 100644 (file)
@@ -39,7 +39,7 @@ FileListCreator::~FileListCreator()
     ASSERT(!m_completionHander);
 }
 
     ASSERT(!m_completionHander);
 }
 
-static void appendDirectoryFiles(const String& directory, const String& relativePath, Vector<RefPtr<File>>& fileObjects)
+static void appendDirectoryFiles(const String& directory, const String& relativePath, Vector<Ref<File>>& fileObjects)
 {
     for (auto& childPath : listDirectory(directory, "*")) {
         auto metadata = fileMetadata(childPath);
 {
     for (auto& childPath : listDirectory(directory, "*")) {
         auto metadata = fileMetadata(childPath);
@@ -78,7 +78,7 @@ FileListCreator::FileListCreator(const Vector<FileChooserFileInfo>& paths, Shoul
 template<FileListCreator::ShouldResolveDirectories shouldResolveDirectories>
 Ref<FileList> FileListCreator::createFileList(const Vector<FileChooserFileInfo>& paths)
 {
 template<FileListCreator::ShouldResolveDirectories shouldResolveDirectories>
 Ref<FileList> FileListCreator::createFileList(const Vector<FileChooserFileInfo>& paths)
 {
-    Vector<RefPtr<File>> fileObjects;
+    Vector<Ref<File>> fileObjects;
     for (auto& info : paths) {
         if (shouldResolveDirectories == ShouldResolveDirectories::Yes && fileIsDirectory(info.path, ShouldFollowSymbolicLinks::No))
             appendDirectoryFiles(info.path, pathGetFileName(info.path), fileObjects);
     for (auto& info : paths) {
         if (shouldResolveDirectories == ShouldResolveDirectories::Yes && fileIsDirectory(info.path, ShouldFollowSymbolicLinks::No))
             appendDirectoryFiles(info.path, pathGetFileName(info.path), fileObjects);
index 92ad0e6..dc7daae 100644 (file)
@@ -37,8 +37,23 @@ class SavedFormState;
 
 class FormControlState {
 public:
 
 class FormControlState {
 public:
-    FormControlState() : m_type(TypeSkip) { }
-    explicit FormControlState(const String& value) : m_type(TypeRestore) { m_values.append(value); }
+    FormControlState()
+        : m_type(TypeSkip)
+    {
+    }
+
+    explicit FormControlState(const String& value)
+        : m_type(TypeRestore)
+    {
+        m_values.append(value);
+    }
+
+    explicit FormControlState(Vector<String>&& values)
+        : m_type(TypeSkip)
+        , m_values(WTFMove(values))
+    {
+    }
+
     static FormControlState deserialize(const Vector<String>& stateVector, size_t& index);
     FormControlState(const FormControlState& another) : m_type(another.m_type), m_values(another.m_values) { }
     FormControlState& operator=(const FormControlState&);
     static FormControlState deserialize(const Vector<String>& stateVector, size_t& index);
     FormControlState(const FormControlState& another) : m_type(another.m_type), m_values(another.m_values) { }
     FormControlState& operator=(const FormControlState&);
index acf322c..d430723 100644 (file)
@@ -100,7 +100,7 @@ public:
     bool containsCompatibleContent(DraggingPurpose = DraggingPurpose::ForEditing) const;
     String asURL(FilenameConversionPolicy = ConvertFilenames, String* title = nullptr) const;
     String asPlainText() const;
     bool containsCompatibleContent(DraggingPurpose = DraggingPurpose::ForEditing) const;
     String asURL(FilenameConversionPolicy = ConvertFilenames, String* title = nullptr) const;
     String asPlainText() const;
-    void asFilenames(Vector<String>&) const;
+    Vector<String> asFilenames() const;
     Color asColor() const;
     bool canSmartReplace() const;
     bool containsColor() const;
     Color asColor() const;
     bool canSmartReplace() const;
     bool containsColor() const;
index 265ef3c..5b8fc7e 100644 (file)
@@ -41,9 +41,9 @@ unsigned DragData::numberOfFiles() const
     return m_platformDragData->filenames().size();
 }
 
     return m_platformDragData->filenames().size();
 }
 
-void DragData::asFilenames(Vector<String>& result) const
+Vector<String> DragData::asFilenames() const
 {
 {
-    result = m_platformDragData->filenames();
+    return m_platformDragData->filenames();
 }
 
 bool DragData::containsPlainText() const
 }
 
 bool DragData::containsPlainText() const
index 8ff4132..9989605 100644 (file)
@@ -168,13 +168,15 @@ unsigned DragData::numberOfFiles() const
     return platformStrategies()->pasteboardStrategy()->getNumberOfFiles(m_pasteboardName);
 }
 
     return platformStrategies()->pasteboardStrategy()->getNumberOfFiles(m_pasteboardName);
 }
 
-void DragData::asFilenames(Vector<String>& result) const
+Vector<String> DragData::asFilenames() const
 {
 #if PLATFORM(MAC)
 {
 #if PLATFORM(MAC)
-    platformStrategies()->pasteboardStrategy()->getPathnamesForType(result, String(NSFilenamesPboardType), m_pasteboardName);
+    Vector<String> results;
+    platformStrategies()->pasteboardStrategy()->getPathnamesForType(results, String(NSFilenamesPboardType), m_pasteboardName);
+    if (!results.isEmpty())
+        return results;
 #endif
 #endif
-    if (!result.size())
-        result = fileNames();
+    return fileNames();
 }
 
 bool DragData::containsPlainText() const
 }
 
 bool DragData::containsPlainText() const
index a867086..40a0de9 100644 (file)
@@ -136,20 +136,22 @@ unsigned DragData::numberOfFiles() const
 #endif
 }
 
 #endif
 }
 
-void DragData::asFilenames(Vector<String>& result) const
+Vector<String> DragData::asFilenames() const
 {
 {
+    Vector<String> result;
+
 #if USE(CF)
     if (m_platformDragData) {
         WCHAR filename[MAX_PATH];
 
         STGMEDIUM medium;
         if (FAILED(m_platformDragData->GetData(cfHDropFormat(), &medium)))
 #if USE(CF)
     if (m_platformDragData) {
         WCHAR filename[MAX_PATH];
 
         STGMEDIUM medium;
         if (FAILED(m_platformDragData->GetData(cfHDropFormat(), &medium)))
-            return;
+            return result;
 
         HDROP hdrop = reinterpret_cast<HDROP>(GlobalLock(medium.hGlobal)); 
 
         if (!hdrop)
 
         HDROP hdrop = reinterpret_cast<HDROP>(GlobalLock(medium.hGlobal)); 
 
         if (!hdrop)
-            return;
+            return result;
 
         const unsigned numFiles = DragQueryFileW(hdrop, 0xFFFFFFFF, 0, 0);
         for (unsigned i = 0; i < numFiles; i++) {
 
         const unsigned numFiles = DragQueryFileW(hdrop, 0xFFFFFFFF, 0, 0);
         for (unsigned i = 0; i < numFiles; i++) {
@@ -162,10 +164,12 @@ void DragData::asFilenames(Vector<String>& result) const
         DragFinish(hdrop);
 
         GlobalUnlock(medium.hGlobal);
         DragFinish(hdrop);
 
         GlobalUnlock(medium.hGlobal);
-        return;
+        return result;
     }
     result = m_dragDataMap.get(cfHDropFormat()->cfFormat);
 #endif
     }
     result = m_dragDataMap.get(cfHDropFormat()->cfFormat);
 #endif
+
+    return result;
 }
 
 bool DragData::containsPlainText() const
 }
 
 bool DragData::containsPlainText() const