OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #ifndef File_h | 26 #ifndef File_h |
27 #define File_h | 27 #define File_h |
28 | 28 |
29 #include "core/fileapi/Blob.h" | 29 #include "core/fileapi/Blob.h" |
| 30 #include "heap/Handle.h" |
30 #include "wtf/PassRefPtr.h" | 31 #include "wtf/PassRefPtr.h" |
31 #include "wtf/text/WTFString.h" | 32 #include "wtf/text/WTFString.h" |
32 | 33 |
33 namespace WebCore { | 34 namespace WebCore { |
34 | 35 |
35 class ExecutionContext; | 36 class ExecutionContext; |
36 struct FileMetadata; | 37 struct FileMetadata; |
37 class KURL; | 38 class KURL; |
38 | 39 |
39 class File FINAL : public Blob { | 40 class File FINAL : public Blob { |
40 public: | 41 public: |
41 // AllContentTypes should only be used when the full path/name are trusted;
otherwise, it could | 42 // AllContentTypes should only be used when the full path/name are trusted;
otherwise, it could |
42 // allow arbitrary pages to determine what applications an user has installe
d. | 43 // allow arbitrary pages to determine what applications an user has installe
d. |
43 enum ContentTypeLookupPolicy { | 44 enum ContentTypeLookupPolicy { |
44 WellKnownContentTypes, | 45 WellKnownContentTypes, |
45 AllContentTypes, | 46 AllContentTypes, |
46 }; | 47 }; |
47 | 48 |
48 static PassRefPtr<File> create(const String& path, ContentTypeLookupPolicy p
olicy = WellKnownContentTypes) | 49 static PassRefPtrWillBeRawPtr<File> create(const String& path, ContentTypeLo
okupPolicy policy = WellKnownContentTypes) |
49 { | 50 { |
50 return adoptRef(new File(path, policy)); | 51 return adoptRefWillBeNoop(new File(path, policy)); |
51 } | 52 } |
52 | 53 |
53 static PassRefPtr<File> create(const String& name, double modificationTime,
PassRefPtr<BlobDataHandle> blobDataHandle) | 54 static PassRefPtrWillBeRawPtr<File> create(const String& name, double modifi
cationTime, PassRefPtr<BlobDataHandle> blobDataHandle) |
54 { | 55 { |
55 return adoptRef(new File(name, modificationTime, blobDataHandle)); | 56 return adoptRefWillBeNoop(new File(name, modificationTime, blobDataHandl
e)); |
56 } | 57 } |
57 | 58 |
58 // For deserialization. | 59 // For deserialization. |
59 static PassRefPtr<File> create(const String& path, const String& name, const
String& relativePath, bool hasSnaphotData, uint64_t size, double lastModified,
PassRefPtr<BlobDataHandle> blobDataHandle) | 60 static PassRefPtrWillBeRawPtr<File> create(const String& path, const String&
name, const String& relativePath, bool hasSnaphotData, uint64_t size, double la
stModified, PassRefPtr<BlobDataHandle> blobDataHandle) |
60 { | 61 { |
61 return adoptRef(new File(path, name, relativePath, hasSnaphotData, size,
lastModified, blobDataHandle)); | 62 return adoptRefWillBeNoop(new File(path, name, relativePath, hasSnaphotD
ata, size, lastModified, blobDataHandle)); |
62 } | 63 } |
63 | 64 |
64 static PassRefPtr<File> createWithRelativePath(const String& path, const Str
ing& relativePath); | 65 static PassRefPtrWillBeRawPtr<File> createWithRelativePath(const String& pat
h, const String& relativePath); |
65 | 66 |
66 // If filesystem files live in the remote filesystem, the port might pass th
e valid metadata (whose length field is non-negative) and cache in the File obje
ct. | 67 // If filesystem files live in the remote filesystem, the port might pass th
e valid metadata (whose length field is non-negative) and cache in the File obje
ct. |
67 // | 68 // |
68 // Otherwise calling size(), lastModifiedTime() and slice() will synchronous
ly query the file metadata. | 69 // Otherwise calling size(), lastModifiedTime() and slice() will synchronous
ly query the file metadata. |
69 static PassRefPtr<File> createForFileSystemFile(const String& name, const Fi
leMetadata& metadata) | 70 static PassRefPtrWillBeRawPtr<File> createForFileSystemFile(const String& na
me, const FileMetadata& metadata) |
70 { | 71 { |
71 return adoptRef(new File(name, metadata)); | 72 return adoptRefWillBeNoop(new File(name, metadata)); |
72 } | 73 } |
73 | 74 |
74 static PassRefPtr<File> createForFileSystemFile(const KURL& url, const FileM
etadata& metadata) | 75 static PassRefPtrWillBeRawPtr<File> createForFileSystemFile(const KURL& url,
const FileMetadata& metadata) |
75 { | 76 { |
76 return adoptRef(new File(url, metadata)); | 77 return adoptRefWillBeNoop(new File(url, metadata)); |
77 } | 78 } |
78 | 79 |
79 KURL fileSystemURL() const { ASSERT(hasValidFileSystemURL()); return m_fileS
ystemURL; } | 80 KURL fileSystemURL() const { ASSERT(hasValidFileSystemURL()); return m_fileS
ystemURL; } |
80 | 81 |
81 // Create a file with a name exposed to the author (via File.name and associ
ated DOM properties) that differs from the one provided in the path. | 82 // Create a file with a name exposed to the author (via File.name and associ
ated DOM properties) that differs from the one provided in the path. |
82 static PassRefPtr<File> createWithName(const String& path, const String& nam
e, ContentTypeLookupPolicy policy = WellKnownContentTypes) | 83 static PassRefPtrWillBeRawPtr<File> createWithName(const String& path, const
String& name, ContentTypeLookupPolicy policy = WellKnownContentTypes) |
83 { | 84 { |
84 if (name.isEmpty()) | 85 if (name.isEmpty()) |
85 return adoptRef(new File(path, policy)); | 86 return adoptRefWillBeNoop(new File(path, policy)); |
86 return adoptRef(new File(path, name, policy)); | 87 return adoptRefWillBeNoop(new File(path, name, policy)); |
87 } | 88 } |
88 | 89 |
89 virtual unsigned long long size() const OVERRIDE; | 90 virtual unsigned long long size() const OVERRIDE; |
90 virtual PassRefPtr<Blob> slice(long long start = 0, long long end = std::num
eric_limits<long long>::max(), const String& contentType = String()) const OVERR
IDE; | 91 virtual PassRefPtrWillBeRawPtr<Blob> slice(long long start = 0, long long en
d = std::numeric_limits<long long>::max(), const String& contentType = String())
const OVERRIDE; |
91 virtual void close(ExecutionContext*) OVERRIDE; | 92 virtual void close(ExecutionContext*) OVERRIDE; |
92 | 93 |
93 virtual bool isFile() const OVERRIDE { return true; } | 94 virtual bool isFile() const OVERRIDE { return true; } |
94 virtual bool hasBackingFile() const OVERRIDE { return m_hasBackingFile; } | 95 virtual bool hasBackingFile() const OVERRIDE { return m_hasBackingFile; } |
95 | 96 |
96 virtual void appendTo(BlobData&) const OVERRIDE; | 97 virtual void appendTo(BlobData&) const OVERRIDE; |
97 | 98 |
98 const String& path() const { ASSERT(hasValidFilePath()); return m_path; } | 99 const String& path() const { ASSERT(hasValidFilePath()); return m_path; } |
99 const String name() const { return m_name; } | 100 const String name() const { return m_name; } |
100 | 101 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 const double m_snapshotModificationTime; | 139 const double m_snapshotModificationTime; |
139 | 140 |
140 String m_relativePath; | 141 String m_relativePath; |
141 }; | 142 }; |
142 | 143 |
143 DEFINE_TYPE_CASTS(File, Blob, blob, blob->isFile(), blob.isFile()); | 144 DEFINE_TYPE_CASTS(File, Blob, blob, blob->isFile(), blob.isFile()); |
144 | 145 |
145 } // namespace WebCore | 146 } // namespace WebCore |
146 | 147 |
147 #endif // File_h | 148 #endif // File_h |
OLD | NEW |