summaryrefslogtreecommitdiff
path: root/Source/WebCore/fileapi/File.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/fileapi/File.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/fileapi/File.cpp')
-rw-r--r--Source/WebCore/fileapi/File.cpp126
1 files changed, 55 insertions, 71 deletions
diff --git a/Source/WebCore/fileapi/File.cpp b/Source/WebCore/fileapi/File.cpp
index 6f6dd0e61..1298e02a8 100644
--- a/Source/WebCore/fileapi/File.cpp
+++ b/Source/WebCore/fileapi/File.cpp
@@ -26,114 +26,98 @@
#include "config.h"
#include "File.h"
+#include "BlobURL.h"
#include "FileMetadata.h"
#include "FileSystem.h"
#include "MIMETypeRegistry.h"
+#include "ThreadableBlobRegistry.h"
#include <wtf/CurrentTime.h>
#include <wtf/DateMath.h>
#include <wtf/text/WTFString.h>
namespace WebCore {
-static String getContentTypeFromFileName(const String& name, File::ContentTypeLookupPolicy policy)
-{
- String type;
- int index = name.reverseFind('.');
- if (index != -1) {
- if (policy == File::WellKnownContentTypes)
- type = MIMETypeRegistry::getWellKnownMIMETypeForExtension(name.substring(index + 1));
- else {
- ASSERT(policy == File::AllContentTypes);
- type = MIMETypeRegistry::getMIMETypeForExtension(name.substring(index + 1));
- }
- }
- return type;
-}
-
-static std::unique_ptr<BlobData> createBlobDataForFileWithType(const String& path, const String& contentType)
+File::File(const String& path)
+ : Blob(uninitializedContructor)
+ , m_path(path)
{
- auto blobData = std::make_unique<BlobData>();
- ASSERT(Blob::isNormalizedContentType(contentType));
- blobData->setContentType(contentType);
- blobData->appendFile(path);
- return blobData;
+ m_internalURL = BlobURL::createInternalURL();
+ m_size = -1;
+ computeNameAndContentType(m_path, String(), m_name, m_type);
+ ThreadableBlobRegistry::registerFileBlobURL(m_internalURL, path, m_type);
}
-static std::unique_ptr<BlobData> createBlobDataForFile(const String& path, File::ContentTypeLookupPolicy policy)
+File::File(const String& path, const String& nameOverride)
+ : Blob(uninitializedContructor)
+ , m_path(path)
{
- return createBlobDataForFileWithType(path, getContentTypeFromFileName(path, policy));
+ m_internalURL = BlobURL::createInternalURL();
+ m_size = -1;
+ computeNameAndContentType(m_path, nameOverride, m_name, m_type);
+ ThreadableBlobRegistry::registerFileBlobURL(m_internalURL, path, m_type);
}
-static std::unique_ptr<BlobData> createBlobDataForFileWithName(const String& path, const String& fileSystemName, File::ContentTypeLookupPolicy policy)
+File::File(DeserializationContructor, const String& path, const URL& url, const String& type, const String& name)
+ : Blob(deserializationContructor, url, type, -1, path)
+ , m_path(path)
+ , m_name(name)
{
- return createBlobDataForFileWithType(path, getContentTypeFromFileName(fileSystemName, policy));
}
-#if ENABLE(DIRECTORY_UPLOAD)
-PassRefPtr<File> File::createWithRelativePath(const String& path, const String& relativePath)
+static BlobPropertyBag convertPropertyBag(const File::PropertyBag& initialBag)
{
- RefPtr<File> file = adoptRef(new File(path, AllContentTypes));
- file->m_relativePath = relativePath;
- return file.release();
+ BlobPropertyBag bag;
+ bag.type = initialBag.type;
+ return bag;
}
-#endif
-File::File(const String& path, ContentTypeLookupPolicy policy)
- : Blob(createBlobDataForFile(path, policy), -1)
- , m_path(path)
- , m_name(pathGetFileName(path))
+File::File(Vector<BlobPartVariant>&& blobPartVariants, const String& filename, const PropertyBag& propertyBag)
+ : Blob(WTFMove(blobPartVariants), convertPropertyBag(propertyBag))
+ , m_name(filename)
+ , m_overrideLastModifiedDate(propertyBag.lastModified.value_or(currentTimeMS()))
{
}
-File::File(const String& path, const URL& url, const String& type)
- : Blob(url, type, -1)
- , m_path(path)
+double File::lastModified() const
{
- m_name = pathGetFileName(path);
- // FIXME: File object serialization/deserialization does not include
- // newer file object data members: m_name and m_relativePath.
- // See SerializedScriptValue.cpp
-}
+ if (m_overrideLastModifiedDate)
+ return m_overrideLastModifiedDate.value();
-File::File(const String& path, const String& name, ContentTypeLookupPolicy policy)
- : Blob(createBlobDataForFileWithName(path, name, policy), -1)
- , m_path(path)
- , m_name(name)
-{
-}
+ double result;
-double File::lastModifiedDate() const
-{
+ // FIXME: This does sync-i/o on the main thread and also recalculates every time the method is called.
+ // The i/o should be performed on a background thread,
+ // and the result should be cached along with an asynchronous monitor for changes to the file.
time_t modificationTime;
if (getFileModificationTime(m_path, modificationTime) && isValidFileTime(modificationTime))
- return modificationTime * msPerSecond;
+ result = modificationTime * msPerSecond;
+ else
+ result = currentTime() * msPerSecond;
- return currentTime() * msPerSecond;
+ return WTF::timeClip(result);
}
-unsigned long long File::size() const
+void File::computeNameAndContentType(const String& path, const String& nameOverride, String& effectiveName, String& effectiveContentType)
{
- // FIXME: JavaScript cannot represent sizes as large as unsigned long long, we need to
- // come up with an exception to throw if file size is not representable.
- long long size;
- if (!getFileSize(m_path, size))
- return 0;
- return static_cast<unsigned long long>(size);
+#if ENABLE(FILE_REPLACEMENT)
+ if (shouldReplaceFile(path)) {
+ computeNameAndContentTypeForReplacedFile(path, nameOverride, effectiveName, effectiveContentType);
+ return;
+ }
+#endif
+ effectiveName = nameOverride.isNull() ? pathGetFileName(path) : nameOverride;
+ size_t index = effectiveName.reverseFind('.');
+ if (index != notFound)
+ effectiveContentType = MIMETypeRegistry::getMIMETypeForExtension(effectiveName.substring(index + 1));
}
-void File::captureSnapshot(long long& snapshotSize, double& snapshotModificationTime) const
+String File::contentTypeForFile(const String& path)
{
- // Obtains a snapshot of the file by capturing its current size and modification time. This is used when we slice a file for the first time.
- // If we fail to retrieve the size or modification time, probably due to that the file has been deleted, 0 size is returned.
- FileMetadata metadata;
- if (!getFileMetadata(m_path, metadata)) {
- snapshotSize = 0;
- snapshotModificationTime = invalidFileTime();
- return;
- }
+ String name;
+ String type;
+ computeNameAndContentType(path, String(), name, type);
- snapshotSize = metadata.length;
- snapshotModificationTime = metadata.modificationTime;
+ return type;
}
} // namespace WebCore