Changeset 248538 in webkit
- Timestamp:
- Aug 12, 2019 12:13:17 PM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r248532 r248538 1 2019-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 1 31 2019-08-12 Chris Dumez <cdumez@apple.com> 2 32 -
trunk/Source/WebCore/Modules/fetch/FetchBody.cpp
r248503 r248538 89 89 if (!url.isNull()) { 90 90 // 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, { }, { }, { }); 92 92 return FetchBody { WTFMove(blob) }; 93 93 } -
trunk/Source/WebCore/fileapi/Blob.cpp
r248503 r248538 73 73 } 74 74 75 Blob::Blob(UninitializedContructor, PAL::SessionID sessionID) 76 : m_sessionID(sessionID) 75 Blob::Blob(UninitializedContructor, PAL::SessionID sessionID, URL&& url, String&& type) 76 : m_sessionID(sessionID) 77 , m_internalURL(WTFMove(url)) 78 , m_type(WTFMove(type)) 77 79 { 78 80 } … … 90 92 , m_internalURL(BlobURL::createInternalURL()) 91 93 , m_type(normalizedContentType(propertyBag.type)) 92 , m_size(-1)93 94 { 94 95 BlobBuilder builder(propertyBag.endings); … … 138 139 } 139 140 140 Blob::Blob(DeserializationContructor, PAL::SessionID sessionID, const URL& srcURL, const String& type, long longsize, const String& fileBackedPath)141 Blob::Blob(DeserializationContructor, PAL::SessionID sessionID, const URL& srcURL, const String& type, Optional<unsigned long long> size, const String& fileBackedPath) 141 142 : m_sessionID(sessionID) 142 143 , m_type(normalizedContentType(type)) … … 153 154 : m_sessionID(sessionID) 154 155 , 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. 156 157 { 157 158 m_internalURL = BlobURL::createInternalURL(); … … 166 167 unsigned long long Blob::size() const 167 168 { 168 if ( m_size < 0) {169 if (!m_size) { 169 170 // FIXME: JavaScript cannot represent sizes as large as unsigned long long, we need to 170 171 // come up with an exception to throw if file size is not representable. 171 172 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; 176 177 } 177 178 -
trunk/Source/WebCore/fileapi/Blob.h
r248503 r248538 118 118 119 119 enum UninitializedContructor { uninitializedContructor }; 120 Blob(UninitializedContructor, PAL::SessionID );120 Blob(UninitializedContructor, PAL::SessionID, URL&&, String&& type); 121 121 122 122 enum DeserializationContructor { deserializationContructor }; 123 Blob(DeserializationContructor, PAL::SessionID, const URL& srcURL, const String& type, long longsize, const String& fileBackedPath);123 Blob(DeserializationContructor, PAL::SessionID, const URL& srcURL, const String& type, Optional<unsigned long long> size, const String& fileBackedPath); 124 124 125 125 // For slicing. 126 126 Blob(PAL::SessionID, const URL& srcURL, long long start, long long end, const String& contentType); 127 127 128 private: 128 129 PAL::SessionID m_sessionID; 130 129 131 // This is an internal URL referring to the blob data associated with this object. It serves 130 132 // as an identifier for this blob. The internal URL is never used to source the blob's content … … 133 135 134 136 String m_type; 135 mutable long long m_size; 137 138 mutable Optional<unsigned long long> m_size; 136 139 }; 137 140 -
trunk/Source/WebCore/fileapi/File.cpp
r248503 r248538 47 47 } 48 48 49 File::File(PAL::SessionID sessionID, const String& path) 50 : Blob(uninitializedContructor, sessionID) 51 , m_path(path) 49 Ref<File> File::create(PAL::SessionID sessionID, const String& path, const String& nameOverride) 52 50 { 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))); 57 59 } 58 60 59 File::File(PAL::SessionID sessionID, const String& path, const String& nameOverride) 60 : Blob(uninitializedContructor, sessionID) 61 , m_path(path) 61 File::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)) 62 65 { 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);67 66 } 68 67 69 68 File::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) 71 70 , m_path(path) 72 71 , m_name(name) … … 133 132 } 134 133 #endif 135 effectiveName = nameOverride.is Null() ? FileSystem::pathGetFileName(path) : nameOverride;134 effectiveName = nameOverride.isEmpty() ? FileSystem::pathGetFileName(path) : nameOverride; 136 135 size_t index = effectiveName.reverseFind('.'); 137 136 if (index != notFound) -
trunk/Source/WebCore/fileapi/File.h
r248503 r248538 42 42 }; 43 43 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 = { }); 48 46 49 47 // Create a File using the 'new File' constructor. … … 56 54 { 57 55 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));66 56 } 67 57 … … 97 87 private: 98 88 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); 100 90 File(ScriptExecutionContext&, Vector<BlobPartVariant>&& blobPartVariants, const String& filename, const PropertyBag&); 101 91 File(const Blob&, const String& name); -
trunk/Source/WebCore/html/FileListCreator.cpp
r248503 r248538 84 84 appendDirectoryFiles(sessionID, info.path, FileSystem::pathGetFileName(info.path), fileObjects); 85 85 else 86 fileObjects.append(File::create WithName(sessionID, info.path, info.displayName));86 fileObjects.append(File::create(sessionID, info.path, info.displayName)); 87 87 } 88 88 return FileList::create(WTFMove(fileObjects));
Note: See TracChangeset
for help on using the changeset viewer.