weinig@apple.com | 50bca61 | 2008-06-20 21:43:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
achristensen@apple.com | 760090a | 2016-08-22 15:51:58 +0000 | [diff] [blame] | 26 | #pragma once |
weinig@apple.com | 50bca61 | 2008-06-20 21:43:11 +0000 | [diff] [blame] | 27 | |
jianli@chromium.org | ec0183f | 2010-01-20 23:53:27 +0000 | [diff] [blame] | 28 | #include "Blob.h" |
beidson@apple.com | 07faaf9 | 2016-04-25 17:31:29 +0000 | [diff] [blame] | 29 | #include <wtf/Optional.h> |
akling@apple.com | ad2beb5 | 2014-12-25 07:50:20 +0000 | [diff] [blame] | 30 | #include <wtf/Ref.h> |
cdumez@apple.com | 2a73a5e | 2014-10-02 04:10:35 +0000 | [diff] [blame] | 31 | #include <wtf/TypeCasts.h> |
weinig@apple.com | 3f5ab02 | 2012-09-06 17:36:48 +0000 | [diff] [blame] | 32 | #include <wtf/text/WTFString.h> |
weinig@apple.com | 50bca61 | 2008-06-20 21:43:11 +0000 | [diff] [blame] | 33 | |
| 34 | namespace WebCore { |
| 35 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 36 | class URL; |
jianli@chromium.org | 42e36c7 | 2010-08-31 04:45:21 +0000 | [diff] [blame] | 37 | |
ap@apple.com | 701f986 | 2014-05-06 00:42:52 +0000 | [diff] [blame] | 38 | class File final : public Blob { |
jianli@chromium.org | ec0183f | 2010-01-20 23:53:27 +0000 | [diff] [blame] | 39 | public: |
akling@apple.com | ad2beb5 | 2014-12-25 07:50:20 +0000 | [diff] [blame] | 40 | static Ref<File> create(const String& path) |
jianli@chromium.org | ec0183f | 2010-01-20 23:53:27 +0000 | [diff] [blame] | 41 | { |
akling@apple.com | ad2beb5 | 2014-12-25 07:50:20 +0000 | [diff] [blame] | 42 | return adoptRef(*new File(path)); |
jianli@chromium.org | ec0183f | 2010-01-20 23:53:27 +0000 | [diff] [blame] | 43 | } |
weinig@apple.com | 50bca61 | 2008-06-20 21:43:11 +0000 | [diff] [blame] | 44 | |
beidson@apple.com | 07faaf9 | 2016-04-25 17:31:29 +0000 | [diff] [blame] | 45 | // Create a File using the 'new File' constructor. |
| 46 | static Ref<File> create(Vector<BlobPart> blobParts, const String& filename, const String& contentType, int64_t lastModified) |
| 47 | { |
| 48 | return adoptRef(*new File(WTFMove(blobParts), filename, contentType, lastModified)); |
| 49 | } |
| 50 | |
akling@apple.com | ad2beb5 | 2014-12-25 07:50:20 +0000 | [diff] [blame] | 51 | static Ref<File> deserialize(const String& path, const URL& srcURL, const String& type, const String& name) |
jianli@chromium.org | 51ceb75 | 2010-08-11 00:03:19 +0000 | [diff] [blame] | 52 | { |
akling@apple.com | ad2beb5 | 2014-12-25 07:50:20 +0000 | [diff] [blame] | 53 | return adoptRef(*new File(deserializationContructor, path, srcURL, type, name)); |
jianli@chromium.org | 51ceb75 | 2010-08-11 00:03:19 +0000 | [diff] [blame] | 54 | } |
| 55 | |
adamk@chromium.org | aee872b | 2011-05-23 20:47:06 +0000 | [diff] [blame] | 56 | // 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. |
akling@apple.com | ad2beb5 | 2014-12-25 07:50:20 +0000 | [diff] [blame] | 57 | static Ref<File> createWithName(const String& path, const String& nameOverride) |
johnnyg@google.com | 4b0a455 | 2010-07-15 20:36:40 +0000 | [diff] [blame] | 58 | { |
ap@apple.com | c559d64 | 2014-05-09 04:37:25 +0000 | [diff] [blame] | 59 | if (nameOverride.isEmpty()) |
akling@apple.com | ad2beb5 | 2014-12-25 07:50:20 +0000 | [diff] [blame] | 60 | return adoptRef(*new File(path)); |
| 61 | return adoptRef(*new File(path, nameOverride)); |
johnnyg@google.com | 4b0a455 | 2010-07-15 20:36:40 +0000 | [diff] [blame] | 62 | } |
johnnyg@google.com | 4b0a455 | 2010-07-15 20:36:40 +0000 | [diff] [blame] | 63 | |
darin@apple.com | 11ff47c | 2016-03-04 16:47:55 +0000 | [diff] [blame] | 64 | bool isFile() const override { return true; } |
jianli@chromium.org | d8be2d1 | 2010-04-16 00:50:18 +0000 | [diff] [blame] | 65 | |
jianli@chromium.org | 42e36c7 | 2010-08-31 04:45:21 +0000 | [diff] [blame] | 66 | const String& path() const { return m_path; } |
| 67 | const String& name() const { return m_name; } |
achristensen@apple.com | 760090a | 2016-08-22 15:51:58 +0000 | [diff] [blame] | 68 | WEBCORE_EXPORT double lastModified() const; |
kinuko@chromium.org | a492ad0 | 2012-05-30 09:08:43 +0000 | [diff] [blame] | 69 | |
ap@apple.com | c559d64 | 2014-05-09 04:37:25 +0000 | [diff] [blame] | 70 | static String contentTypeForFile(const String& path); |
| 71 | |
| 72 | #if ENABLE(FILE_REPLACEMENT) |
| 73 | static bool shouldReplaceFile(const String& path); |
| 74 | #endif |
ap@apple.com | 1fddc77 | 2014-04-25 00:48:38 +0000 | [diff] [blame] | 75 | |
jianli@chromium.org | ec0183f | 2010-01-20 23:53:27 +0000 | [diff] [blame] | 76 | private: |
weinig@apple.com | e798c25 | 2015-02-25 01:49:59 +0000 | [diff] [blame] | 77 | WEBCORE_EXPORT explicit File(const String& path); |
ap@apple.com | c559d64 | 2014-05-09 04:37:25 +0000 | [diff] [blame] | 78 | File(const String& path, const String& nameOverride); |
beidson@apple.com | 07faaf9 | 2016-04-25 17:31:29 +0000 | [diff] [blame] | 79 | File(Vector<BlobPart>&& blobParts, const String& filename, const String& contentType, int64_t lastModified); |
adamk@chromium.org | aee872b | 2011-05-23 20:47:06 +0000 | [diff] [blame] | 80 | |
ap@apple.com | 8512557 | 2014-05-09 21:24:01 +0000 | [diff] [blame] | 81 | File(DeserializationContructor, const String& path, const URL& srcURL, const String& type, const String& name); |
jianli@chromium.org | 51ceb75 | 2010-08-11 00:03:19 +0000 | [diff] [blame] | 82 | |
ap@apple.com | c559d64 | 2014-05-09 04:37:25 +0000 | [diff] [blame] | 83 | static void computeNameAndContentType(const String& path, const String& nameOverride, String& effectiveName, String& effectiveContentType); |
| 84 | #if ENABLE(FILE_REPLACEMENT) |
| 85 | static void computeNameAndContentTypeForReplacedFile(const String& path, const String& nameOverride, String& effectiveName, String& effectiveContentType); |
| 86 | #endif |
| 87 | |
jianli@chromium.org | 42e36c7 | 2010-08-31 04:45:21 +0000 | [diff] [blame] | 88 | String m_path; |
| 89 | String m_name; |
beidson@apple.com | 07faaf9 | 2016-04-25 17:31:29 +0000 | [diff] [blame] | 90 | |
utatane.tea@gmail.com | 4392696 | 2016-11-27 06:08:16 +0000 | [diff] [blame^] | 91 | std::optional<int64_t> m_overrideLastModifiedDate; |
jianli@chromium.org | ec0183f | 2010-01-20 23:53:27 +0000 | [diff] [blame] | 92 | }; |
weinig@apple.com | 50bca61 | 2008-06-20 21:43:11 +0000 | [diff] [blame] | 93 | |
| 94 | } // namespace WebCore |
| 95 | |
cdumez@apple.com | 2a73a5e | 2014-10-02 04:10:35 +0000 | [diff] [blame] | 96 | SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::File) |
| 97 | static bool isType(const WebCore::Blob& blob) { return blob.isFile(); } |
| 98 | SPECIALIZE_TYPE_TRAITS_END() |