Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(594)

Side by Side Diff: Source/core/fileapi/File.h

Issue 235373005: Handle JS-created files in <input type="file">. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 29 matching lines...) Expand all
40 40
41 class File FINAL : public Blob { 41 class File FINAL : public Blob {
42 public: 42 public:
43 // AllContentTypes should only be used when the full path/name are trusted; otherwise, it could 43 // AllContentTypes should only be used when the full path/name are trusted; otherwise, it could
44 // allow arbitrary pages to determine what applications an user has installe d. 44 // allow arbitrary pages to determine what applications an user has installe d.
45 enum ContentTypeLookupPolicy { 45 enum ContentTypeLookupPolicy {
46 WellKnownContentTypes, 46 WellKnownContentTypes,
47 AllContentTypes, 47 AllContentTypes,
48 }; 48 };
49 49
50 // The user should not be able to browse to some files, such as the ones gen erated by the Filesystem API.
tkent 2014/07/23 01:19:58 nit: I recommend to wrap code comments in 80 colu
pwnall-personal 2014/07/23 06:58:21 Done.
51 enum UserVisibility { IsUserVisible, IsNotUserVisible };
52
50 static PassRefPtrWillBeRawPtr<File> create(const String& path, ContentTypeLo okupPolicy policy = WellKnownContentTypes) 53 static PassRefPtrWillBeRawPtr<File> create(const String& path, ContentTypeLo okupPolicy policy = WellKnownContentTypes)
51 { 54 {
52 return adoptRefWillBeNoop(new File(path, policy)); 55 return adoptRefWillBeNoop(new File(path, policy, File::IsUserVisible));
53 } 56 }
54 57
55 static PassRefPtrWillBeRawPtr<File> create(const String& name, double modifi cationTime, PassRefPtr<BlobDataHandle> blobDataHandle) 58 static PassRefPtrWillBeRawPtr<File> create(const String& name, double modifi cationTime, PassRefPtr<BlobDataHandle> blobDataHandle)
56 { 59 {
57 return adoptRefWillBeNoop(new File(name, modificationTime, blobDataHandl e)); 60 return adoptRefWillBeNoop(new File(name, modificationTime, blobDataHandl e));
58 } 61 }
59 62
60 // For deserialization. 63 // For deserialization.
61 static PassRefPtrWillBeRawPtr<File> create(const String& path, const String& name, const String& relativePath, bool hasSnaphotData, uint64_t size, double la stModified, PassRefPtr<BlobDataHandle> blobDataHandle) 64 static PassRefPtrWillBeRawPtr<File> createFromSerialization(const String& pa th, const String& name, const String& relativePath, bool hasSnaphotData, uint64_ t size, double lastModified, PassRefPtr<BlobDataHandle> blobDataHandle)
62 { 65 {
63 return adoptRefWillBeNoop(new File(path, name, relativePath, hasSnaphotD ata, size, lastModified, blobDataHandle)); 66 return adoptRefWillBeNoop(new File(path, name, relativePath, hasSnaphotD ata, size, lastModified, blobDataHandle));
64 } 67 }
65 static PassRefPtrWillBeRawPtr<File> create(const String& path, const String& name, uint64_t size, double lastModified, PassRefPtr<BlobDataHandle> blobDataHa ndle) 68 static PassRefPtrWillBeRawPtr<File> createFromIndexedSerialization(const Str ing& path, const String& name, uint64_t size, double lastModified, PassRefPtr<Bl obDataHandle> blobDataHandle)
66 { 69 {
67 return adoptRefWillBeNoop(new File(path, name, String(), true, size, las tModified, blobDataHandle)); 70 return adoptRefWillBeNoop(new File(path, name, String(), true, size, las tModified, blobDataHandle));
68 } 71 }
69 72
70 static PassRefPtrWillBeRawPtr<File> createWithRelativePath(const String& pat h, const String& relativePath); 73 static PassRefPtrWillBeRawPtr<File> createWithRelativePath(const String& pat h, const String& relativePath);
71 74
72 // 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. 75 // 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.
73 // 76 //
74 // Otherwise calling size(), lastModifiedTime() and slice() will synchronous ly query the file metadata. 77 // Otherwise calling size(), lastModifiedTime() and slice() will synchronous ly query the file metadata.
75 static PassRefPtrWillBeRawPtr<File> createForFileSystemFile(const String& na me, const FileMetadata& metadata) 78 static PassRefPtrWillBeRawPtr<File> createForFileSystemFile(const String& na me, const FileMetadata& metadata)
76 { 79 {
77 return adoptRefWillBeNoop(new File(name, metadata)); 80 return adoptRefWillBeNoop(new File(name, metadata));
78 } 81 }
79 82
80 static PassRefPtrWillBeRawPtr<File> createForFileSystemFile(const KURL& url, const FileMetadata& metadata) 83 static PassRefPtrWillBeRawPtr<File> createForFileSystemFile(const KURL& url, const FileMetadata& metadata)
81 { 84 {
82 return adoptRefWillBeNoop(new File(url, metadata)); 85 return adoptRefWillBeNoop(new File(url, metadata));
83 } 86 }
84 87
85 KURL fileSystemURL() const { ASSERT(hasValidFileSystemURL()); return m_fileS ystemURL; } 88 KURL fileSystemURL() const { ASSERT(hasValidFileSystemURL()); return m_fileS ystemURL; }
86 89
87 // 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. 90 // 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.
88 static PassRefPtrWillBeRawPtr<File> createWithName(const String& path, const String& name, ContentTypeLookupPolicy policy = WellKnownContentTypes) 91 static PassRefPtrWillBeRawPtr<File> createWithName(const String& path, const String& name, ContentTypeLookupPolicy policy = WellKnownContentTypes)
89 { 92 {
90 if (name.isEmpty()) 93 if (name.isEmpty())
91 return adoptRefWillBeNoop(new File(path, policy)); 94 return adoptRefWillBeNoop(new File(path, policy, File::IsUserVisible ));
92 return adoptRefWillBeNoop(new File(path, name, policy)); 95 return adoptRefWillBeNoop(new File(path, name, policy, File::IsUserVisib le));
96 }
97
98 static PassRefPtrWillBeRawPtr<File> createForFileSystemFile(const String& pa th, const String& name, ContentTypeLookupPolicy policy = WellKnownContentTypes)
99 {
100 if (name.isEmpty())
101 return adoptRefWillBeNoop(new File(path, policy, File::IsNotUserVisi ble));
102 return adoptRefWillBeNoop(new File(path, name, policy, File::IsNotUserVi sible));
93 } 103 }
94 104
95 virtual unsigned long long size() const OVERRIDE; 105 virtual unsigned long long size() const OVERRIDE;
96 virtual PassRefPtrWillBeRawPtr<Blob> slice(long long start, long long end, c onst String& contentType, ExceptionState&) const OVERRIDE; 106 virtual PassRefPtrWillBeRawPtr<Blob> slice(long long start, long long end, c onst String& contentType, ExceptionState&) const OVERRIDE;
97 virtual void close(ExecutionContext*, ExceptionState&) OVERRIDE; 107 virtual void close(ExecutionContext*, ExceptionState&) OVERRIDE;
98 108
99 virtual bool isFile() const OVERRIDE { return true; } 109 virtual bool isFile() const OVERRIDE { return true; }
100 virtual bool hasBackingFile() const OVERRIDE { return m_hasBackingFile; } 110 virtual bool hasBackingFile() const OVERRIDE { return m_hasBackingFile; }
101 111
102 virtual void appendTo(BlobData&) const OVERRIDE; 112 virtual void appendTo(BlobData&) const OVERRIDE;
103 113
104 const String& path() const { ASSERT(hasValidFilePath()); return m_path; } 114 const String& path() const { ASSERT(hasValidFilePath()); return m_path; }
105 const String name() const { return m_name; } 115 const String name() const { return m_name; }
106 116
107 // This returns the current date and time if the file's last modification da te is not known (per spec: http://www.w3.org/TR/FileAPI/#dfn-lastModifiedDate). 117 // This returns the current date and time if the file's last modification da te is not known (per spec: http://www.w3.org/TR/FileAPI/#dfn-lastModifiedDate).
108 double lastModifiedDate() const; 118 double lastModifiedDate() const;
109 119
120 UserVisibility userVisibility() const { return m_userVisibility; }
121
110 // Returns the relative path of this file in the context of a directory sele ction. 122 // Returns the relative path of this file in the context of a directory sele ction.
111 const String& webkitRelativePath() const { return m_relativePath; } 123 const String& webkitRelativePath() const { return m_relativePath; }
112 124
113 // Note that this involves synchronous file operation. Think twice before ca lling this function. 125 // Note that this involves synchronous file operation. Think twice before ca lling this function.
114 void captureSnapshot(long long& snapshotSize, double& snapshotModificationTi me) const; 126 void captureSnapshot(long long& snapshotSize, double& snapshotModificationTi me) const;
115 127
116 // Returns true if this has a valid snapshot metadata (i.e. m_snapshotSize > = 0). 128 // Returns true if this has a valid snapshot metadata (i.e. m_snapshotSize > = 0).
117 bool hasValidSnapshotMetadata() const { return m_snapshotSize >= 0; } 129 bool hasValidSnapshotMetadata() const { return m_snapshotSize >= 0; }
118 130
119 private: 131 private:
120 File(const String& path, ContentTypeLookupPolicy); 132 File(const String& path, ContentTypeLookupPolicy, UserVisibility);
121 File(const String& path, const String& name, ContentTypeLookupPolicy); 133 File(const String& path, const String& name, ContentTypeLookupPolicy, UserVi sibility);
122 File(const String& path, const String& name, const String& relativePath, boo l hasSnaphotData, uint64_t size, double lastModified, PassRefPtr<BlobDataHandle> ); 134 File(const String& path, const String& name, const String& relativePath, boo l hasSnaphotData, uint64_t size, double lastModified, PassRefPtr<BlobDataHandle> );
123 File(const String& name, double modificationTime, PassRefPtr<BlobDataHandle> ); 135 File(const String& name, double modificationTime, PassRefPtr<BlobDataHandle> );
124 File(const String& name, const FileMetadata&); 136 File(const String& name, const FileMetadata&);
125 File(const KURL& fileSystemURL, const FileMetadata&); 137 File(const KURL& fileSystemURL, const FileMetadata&);
126 138
127 void invalidateSnapshotMetadata() { m_snapshotSize = -1; } 139 void invalidateSnapshotMetadata() { m_snapshotSize = -1; }
128 140
129 #if ENABLE(ASSERT) 141 #if ENABLE(ASSERT)
130 bool hasValidFileSystemURL() const { return hasBackingFile(); } 142 bool hasValidFileSystemURL() const { return hasBackingFile(); }
131 // Instances not backed by a file must have an empty path set. 143 // Instances not backed by a file must have an empty path set.
132 bool hasValidFilePath() const { return hasBackingFile() || m_path.isEmpty(); } 144 bool hasValidFilePath() const { return hasBackingFile() || m_path.isEmpty(); }
133 #endif 145 #endif
134 146
135 bool m_hasBackingFile; 147 bool m_hasBackingFile;
148 UserVisibility m_userVisibility;
136 String m_path; 149 String m_path;
137 String m_name; 150 String m_name;
138 151
139 KURL m_fileSystemURL; 152 KURL m_fileSystemURL;
140 153
141 // If m_snapshotSize is negative (initialized to -1 by default), the snapsho t metadata is invalid and we retrieve the latest metadata synchronously in size( ), lastModifiedTime() and slice(). 154 // If m_snapshotSize is negative (initialized to -1 by default), the snapsho t metadata is invalid and we retrieve the latest metadata synchronously in size( ), lastModifiedTime() and slice().
142 // Otherwise, the snapshot metadata are used directly in those methods. 155 // Otherwise, the snapshot metadata are used directly in those methods.
143 long long m_snapshotSize; 156 long long m_snapshotSize;
144 const double m_snapshotModificationTime; 157 const double m_snapshotModificationTime;
145 158
146 String m_relativePath; 159 String m_relativePath;
147 }; 160 };
148 161
149 DEFINE_TYPE_CASTS(File, Blob, blob, blob->isFile(), blob.isFile()); 162 DEFINE_TYPE_CASTS(File, Blob, blob, blob->isFile(), blob.isFile());
150 163
151 } // namespace WebCore 164 } // namespace WebCore
152 165
153 #endif // File_h 166 #endif // File_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698