summaryrefslogtreecommitdiff
path: root/Source/WebCore/fileapi/File.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/fileapi/File.h')
-rw-r--r--Source/WebCore/fileapi/File.h90
1 files changed, 38 insertions, 52 deletions
diff --git a/Source/WebCore/fileapi/File.h b/Source/WebCore/fileapi/File.h
index edf485582..fbe357254 100644
--- a/Source/WebCore/fileapi/File.h
+++ b/Source/WebCore/fileapi/File.h
@@ -23,94 +23,80 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef File_h
-#define File_h
+#pragma once
#include "Blob.h"
-#include <wtf/PassRefPtr.h>
+#include <wtf/Optional.h>
+#include <wtf/Ref.h>
+#include <wtf/TypeCasts.h>
#include <wtf/text/WTFString.h>
namespace WebCore {
-struct FileMetadata;
class URL;
-class File : public Blob {
+class File final : public Blob {
public:
- // AllContentTypes should only be used when the full path/name are trusted; otherwise, it could
- // allow arbitrary pages to determine what applications an user has installed.
- enum ContentTypeLookupPolicy {
- WellKnownContentTypes,
- AllContentTypes,
+ struct PropertyBag : BlobPropertyBag {
+ std::optional<long long> lastModified;
};
- static PassRefPtr<File> create(const String& path, ContentTypeLookupPolicy policy = WellKnownContentTypes)
+ static Ref<File> create(const String& path)
{
- return adoptRef(new File(path, policy));
+ return adoptRef(*new File(path));
}
- // For deserialization.
- static PassRefPtr<File> create(const String& path, const URL& srcURL, const String& type)
+ // Create a File using the 'new File' constructor.
+ static Ref<File> create(Vector<BlobPartVariant>&& blobPartVariants, const String& filename, const PropertyBag& propertyBag)
{
- return adoptRef(new File(path, srcURL, type));
+ return adoptRef(*new File(WTFMove(blobPartVariants), filename, propertyBag));
}
-#if ENABLE(DIRECTORY_UPLOAD)
- static PassRefPtr<File> createWithRelativePath(const String& path, const String& relativePath);
-#endif
+ static Ref<File> deserialize(const String& path, const URL& srcURL, const String& type, const String& name)
+ {
+ return adoptRef(*new File(deserializationContructor, path, srcURL, type, name));
+ }
// 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.
- static PassRefPtr<File> createWithName(const String& path, const String& name, ContentTypeLookupPolicy policy = WellKnownContentTypes)
+ static Ref<File> createWithName(const String& path, const String& nameOverride)
{
- if (name.isEmpty())
- return adoptRef(new File(path, policy));
- return adoptRef(new File(path, name, policy));
+ if (nameOverride.isEmpty())
+ return adoptRef(*new File(path));
+ return adoptRef(*new File(path, nameOverride));
}
- virtual unsigned long long size() const override;
- virtual bool isFile() const override { return true; }
+ bool isFile() const override { return true; }
const String& path() const { return m_path; }
const String& name() const { return m_name; }
+ WEBCORE_EXPORT double lastModified() const;
- // This returns the current date and time if the file's last modifiecation date is not known (per spec: http://www.w3.org/TR/FileAPI/#dfn-lastModifiedDate).
- double lastModifiedDate() const;
+ static String contentTypeForFile(const String& path);
-#if ENABLE(DIRECTORY_UPLOAD)
- // Returns the relative path of this file in the context of a directory selection.
- const String& webkitRelativePath() const { return m_relativePath; }
+#if ENABLE(FILE_REPLACEMENT)
+ static bool shouldReplaceFile(const String& path);
#endif
- // Note that this involves synchronous file operation. Think twice before calling this function.
- void captureSnapshot(long long& snapshotSize, double& snapshotModificationTime) const;
-
private:
- File(const String& path, ContentTypeLookupPolicy);
+ WEBCORE_EXPORT explicit File(const String& path);
+ File(const String& path, const String& nameOverride);
+ File(Vector<BlobPartVariant>&& blobPartVariants, const String& filename, const PropertyBag&);
- // For deserialization.
- File(const String& path, const URL& srcURL, const String& type);
- File(const String& path, const String& name, ContentTypeLookupPolicy);
+ File(DeserializationContructor, const String& path, const URL& srcURL, const String& type, const String& name);
+
+ static void computeNameAndContentType(const String& path, const String& nameOverride, String& effectiveName, String& effectiveContentType);
+#if ENABLE(FILE_REPLACEMENT)
+ static void computeNameAndContentTypeForReplacedFile(const String& path, const String& nameOverride, String& effectiveName, String& effectiveContentType);
+#endif
String m_path;
String m_name;
-#if ENABLE(DIRECTORY_UPLOAD)
- String m_relativePath;
-#endif
+ std::optional<int64_t> m_overrideLastModifiedDate;
};
-inline File* toFile(Blob* blob)
-{
- ASSERT_WITH_SECURITY_IMPLICATION(!blob || blob->isFile());
- return static_cast<File*>(blob);
-}
-
-inline const File* toFile(const Blob* blob)
-{
- ASSERT_WITH_SECURITY_IMPLICATION(!blob || blob->isFile());
- return static_cast<const File*>(blob);
-}
-
} // namespace WebCore
-#endif // File_h
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::File)
+ static bool isType(const WebCore::Blob& blob) { return blob.isFile(); }
+SPECIALIZE_TYPE_TRAITS_END()