Changeset 248538 in webkit


Ignore:
Timestamp:
Aug 12, 2019 12:13:17 PM (5 years ago)
Author:
youenn@apple.com
Message:

Make Blob::m_size an Optional
https://bugs.webkit.org/show_bug.cgi?id=200617

Reviewed by Alex Christensen.

Use an Optional instead of -1 to know that m_size is initialized or not.
No change of behavior.

Refactoring to make all Blob members private.
Remove one static Blob create method.

Covered by existing tests.

  • Modules/fetch/FetchBody.cpp:

(WebCore::FetchBody::fromFormData):

  • fileapi/Blob.cpp:

(WebCore::Blob::Blob):
(WebCore::Blob::size const):

  • fileapi/Blob.h:

(WebCore::Blob::setInternalURL):

  • fileapi/File.cpp:

(WebCore::File::create):
(WebCore::File::File):
(WebCore::File::computeNameAndContentType):

  • fileapi/File.h:
  • html/FileListCreator.cpp:

(WebCore::FileListCreator::createFileList):

Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r248532 r248538  
     12019-08-12  Youenn Fablet  <youenn@apple.com>
     2
     3        Make Blob::m_size an Optional
     4        https://bugs.webkit.org/show_bug.cgi?id=200617
     5
     6        Reviewed by Alex Christensen.
     7
     8        Use an Optional instead of -1 to know that m_size is initialized or not.
     9        No change of behavior.
     10
     11        Refactoring to make all Blob members private.
     12        Remove one static Blob create method.
     13
     14        Covered by existing tests.
     15
     16        * Modules/fetch/FetchBody.cpp:
     17        (WebCore::FetchBody::fromFormData):
     18        * fileapi/Blob.cpp:
     19        (WebCore::Blob::Blob):
     20        (WebCore::Blob::size const):
     21        * fileapi/Blob.h:
     22        (WebCore::Blob::setInternalURL):
     23        * fileapi/File.cpp:
     24        (WebCore::File::create):
     25        (WebCore::File::File):
     26        (WebCore::File::computeNameAndContentType):
     27        * fileapi/File.h:
     28        * html/FileListCreator.cpp:
     29        (WebCore::FileListCreator::createFileList):
     30
    1312019-08-12  Chris Dumez  <cdumez@apple.com>
    232
  • trunk/Source/WebCore/Modules/fetch/FetchBody.cpp

    r248503 r248538  
    8989    if (!url.isNull()) {
    9090        // FIXME: Properly set mime type and size of the blob.
    91         Ref<const Blob> blob = Blob::deserialize(sessionID, url, { }, 0, { });
     91        Ref<const Blob> blob = Blob::deserialize(sessionID, url, { }, { }, { });
    9292        return FetchBody { WTFMove(blob) };
    9393    }
  • trunk/Source/WebCore/fileapi/Blob.cpp

    r248503 r248538  
    7373}
    7474
    75 Blob::Blob(UninitializedContructor, PAL::SessionID sessionID)
    76     : m_sessionID(sessionID)
     75Blob::Blob(UninitializedContructor, PAL::SessionID sessionID, URL&& url, String&& type)
     76    : m_sessionID(sessionID)
     77    , m_internalURL(WTFMove(url))
     78    , m_type(WTFMove(type))
    7779{
    7880}
     
    9092    , m_internalURL(BlobURL::createInternalURL())
    9193    , m_type(normalizedContentType(propertyBag.type))
    92     , m_size(-1)
    9394{
    9495    BlobBuilder builder(propertyBag.endings);
     
    138139}
    139140
    140 Blob::Blob(DeserializationContructor, PAL::SessionID sessionID, const URL& srcURL, const String& type, long long size, const String& fileBackedPath)
     141Blob::Blob(DeserializationContructor, PAL::SessionID sessionID, const URL& srcURL, const String& type, Optional<unsigned long long> size, const String& fileBackedPath)
    141142    : m_sessionID(sessionID)
    142143    , m_type(normalizedContentType(type))
     
    153154    : m_sessionID(sessionID)
    154155    , m_type(normalizedContentType(type))
    155     , m_size(-1) // size is not necessarily equal to end - start.
     156    // m_size is not necessarily equal to end - start so we do not initialize it here.
    156157{
    157158    m_internalURL = BlobURL::createInternalURL();
     
    166167unsigned long long Blob::size() const
    167168{
    168     if (m_size < 0) {
     169    if (!m_size) {
    169170        // FIXME: JavaScript cannot represent sizes as large as unsigned long long, we need to
    170171        // come up with an exception to throw if file size is not representable.
    171172        unsigned long long actualSize = ThreadableBlobRegistry::blobSize(m_internalURL);
    172         m_size = WTF::isInBounds<long long>(actualSize) ? static_cast<long long>(actualSize) : 0;
    173     }
    174 
    175     return static_cast<unsigned long long>(m_size);
     173        m_size = WTF::isInBounds<long long>(actualSize) ? actualSize : 0;
     174    }
     175
     176    return *m_size;
    176177}
    177178
  • trunk/Source/WebCore/fileapi/Blob.h

    r248503 r248538  
    118118
    119119    enum UninitializedContructor { uninitializedContructor };
    120     Blob(UninitializedContructor, PAL::SessionID);
     120    Blob(UninitializedContructor, PAL::SessionID, URL&&, String&& type);
    121121
    122122    enum DeserializationContructor { deserializationContructor };
    123     Blob(DeserializationContructor, PAL::SessionID, const URL& srcURL, const String& type, long long size, const String& fileBackedPath);
     123    Blob(DeserializationContructor, PAL::SessionID, const URL& srcURL, const String& type, Optional<unsigned long long> size, const String& fileBackedPath);
    124124
    125125    // For slicing.
    126126    Blob(PAL::SessionID, const URL& srcURL, long long start, long long end, const String& contentType);
    127127
     128private:
    128129    PAL::SessionID m_sessionID;
     130
    129131    // This is an internal URL referring to the blob data associated with this object. It serves
    130132    // as an identifier for this blob. The internal URL is never used to source the blob's content
     
    133135
    134136    String m_type;
    135     mutable long long m_size;
     137
     138    mutable Optional<unsigned long long> m_size;
    136139};
    137140
  • trunk/Source/WebCore/fileapi/File.cpp

    r248503 r248538  
    4747}
    4848
    49 File::File(PAL::SessionID sessionID, const String& path)
    50     : Blob(uninitializedContructor, sessionID)
    51     , m_path(path)
     49Ref<File> File::create(PAL::SessionID sessionID, const String& path, const String& nameOverride)
    5250{
    53     m_internalURL = BlobURL::createInternalURL();
    54     m_size = -1;
    55     computeNameAndContentType(m_path, String(), m_name, m_type);
    56     ThreadableBlobRegistry::registerFileBlobURL(m_internalURL, path, m_type);
     51    String name;
     52    String type;
     53    computeNameAndContentType(path, nameOverride, name, type);
     54
     55    auto internalURL = BlobURL::createInternalURL();
     56    ThreadableBlobRegistry::registerFileBlobURL(internalURL, path, type);
     57
     58    return adoptRef(*new File(sessionID, WTFMove(internalURL), WTFMove(type), String { path }, WTFMove(name)));
    5759}
    5860
    59 File::File(PAL::SessionID sessionID, const String& path, const String& nameOverride)
    60     : Blob(uninitializedContructor, sessionID)
    61     , m_path(path)
     61File::File(PAL::SessionID sessionID, URL&& url, String&& type, String&& path, String&& name)
     62    : Blob(uninitializedContructor, sessionID, WTFMove(url), WTFMove(type))
     63    , m_path(WTFMove(path))
     64    , m_name(WTFMove(name))
    6265{
    63     m_internalURL = BlobURL::createInternalURL();
    64     m_size = -1;
    65     computeNameAndContentType(m_path, nameOverride, m_name, m_type);
    66     ThreadableBlobRegistry::registerFileBlobURL(m_internalURL, path, m_type);
    6766}
    6867
    6968File::File(DeserializationContructor, PAL::SessionID sessionID, const String& path, const URL& url, const String& type, const String& name, const Optional<int64_t>& lastModified)
    70     : Blob(deserializationContructor, sessionID, url, type, -1, path)
     69    : Blob(deserializationContructor, sessionID, url, type, { }, path)
    7170    , m_path(path)
    7271    , m_name(name)
     
    133132    }
    134133#endif
    135     effectiveName = nameOverride.isNull() ? FileSystem::pathGetFileName(path) : nameOverride;
     134    effectiveName = nameOverride.isEmpty() ? FileSystem::pathGetFileName(path) : nameOverride;
    136135    size_t index = effectiveName.reverseFind('.');
    137136    if (index != notFound)
  • trunk/Source/WebCore/fileapi/File.h

    r248503 r248538  
    4242    };
    4343
    44     static Ref<File> create(PAL::SessionID sessionID, const String& path)
    45     {
    46         return adoptRef(*new File(sessionID, path));
    47     }
     44    // Create a file with an optional name exposed to the author (via File.name and associated DOM properties) that differs from the one provided in the path.
     45    WEBCORE_EXPORT static Ref<File> create(PAL::SessionID, const String& path, const String& nameOverride = { });
    4846
    4947    // Create a File using the 'new File' constructor.
     
    5654    {
    5755        return adoptRef(*new File(deserializationContructor, sessionID, path, srcURL, type, name, lastModified));
    58     }
    59 
    60     // Create a file with a name exposed to the author (via File.name and associated DOM properties) that differs from the one provided in the path.
    61     static Ref<File> createWithName(PAL::SessionID sessionID, const String& path, const String& nameOverride)
    62     {
    63         if (nameOverride.isEmpty())
    64             return adoptRef(*new File(sessionID, path));
    65         return adoptRef(*new File(sessionID, path, nameOverride));
    6656    }
    6757
     
    9787private:
    9888    WEBCORE_EXPORT explicit File(PAL::SessionID, const String& path);
    99     File(PAL::SessionID, const String& path, const String& nameOverride);
     89    File(PAL::SessionID, URL&&, String&& type, String&& path, String&& name);
    10090    File(ScriptExecutionContext&, Vector<BlobPartVariant>&& blobPartVariants, const String& filename, const PropertyBag&);
    10191    File(const Blob&, const String& name);
  • trunk/Source/WebCore/html/FileListCreator.cpp

    r248503 r248538  
    8484            appendDirectoryFiles(sessionID, info.path, FileSystem::pathGetFileName(info.path), fileObjects);
    8585        else
    86             fileObjects.append(File::createWithName(sessionID, info.path, info.displayName));
     86            fileObjects.append(File::create(sessionID, info.path, info.displayName));
    8787    }
    8888    return FileList::create(WTFMove(fileObjects));
Note: See TracChangeset for help on using the changeset viewer.