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

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: Fixed visibility bug. 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
« no previous file with comments | « Source/bindings/core/v8/SerializedScriptValue.cpp ('k') | Source/core/fileapi/File.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
51 // generated by the Filesystem API.
52 enum UserVisibility { IsUserVisible, IsNotUserVisible };
53
50 static PassRefPtrWillBeRawPtr<File> create(const String& path, ContentTypeLo okupPolicy policy = WellKnownContentTypes) 54 static PassRefPtrWillBeRawPtr<File> create(const String& path, ContentTypeLo okupPolicy policy = WellKnownContentTypes)
51 { 55 {
52 return adoptRefWillBeNoop(new File(path, policy)); 56 return adoptRefWillBeNoop(new File(path, policy, File::IsUserVisible));
53 } 57 }
54 58
55 static PassRefPtrWillBeRawPtr<File> create(const String& name, double modifi cationTime, PassRefPtr<BlobDataHandle> blobDataHandle) 59 static PassRefPtrWillBeRawPtr<File> create(const String& name, double modifi cationTime, PassRefPtr<BlobDataHandle> blobDataHandle)
56 { 60 {
57 return adoptRefWillBeNoop(new File(name, modificationTime, blobDataHandl e)); 61 return adoptRefWillBeNoop(new File(name, modificationTime, blobDataHandl e));
58 } 62 }
59 63
60 // For deserialization. 64 // 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) 65 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 { 66 {
63 return adoptRefWillBeNoop(new File(path, name, relativePath, hasSnaphotD ata, size, lastModified, blobDataHandle)); 67 return adoptRefWillBeNoop(new File(path, name, relativePath, hasSnaphotD ata, size, lastModified, blobDataHandle));
64 } 68 }
65 static PassRefPtrWillBeRawPtr<File> create(const String& path, const String& name, uint64_t size, double lastModified, PassRefPtr<BlobDataHandle> blobDataHa ndle) 69 static PassRefPtrWillBeRawPtr<File> createFromIndexedSerialization(const Str ing& path, const String& name, uint64_t size, double lastModified, PassRefPtr<Bl obDataHandle> blobDataHandle)
66 { 70 {
67 return adoptRefWillBeNoop(new File(path, name, String(), true, size, las tModified, blobDataHandle)); 71 return adoptRefWillBeNoop(new File(path, name, String(), true, size, las tModified, blobDataHandle));
68 } 72 }
69 73
70 static PassRefPtrWillBeRawPtr<File> createWithRelativePath(const String& pat h, const String& relativePath); 74 static PassRefPtrWillBeRawPtr<File> createWithRelativePath(const String& pat h, const String& relativePath);
71 75
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. 76 // 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 // 77 //
74 // Otherwise calling size(), lastModifiedTime() and slice() will synchronous ly query the file metadata. 78 // 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) 79 static PassRefPtrWillBeRawPtr<File> createForFileSystemFile(const String& na me, const FileMetadata& metadata)
76 { 80 {
77 return adoptRefWillBeNoop(new File(name, metadata)); 81 return adoptRefWillBeNoop(new File(name, metadata));
78 } 82 }
79 83
80 static PassRefPtrWillBeRawPtr<File> createForFileSystemFile(const KURL& url, const FileMetadata& metadata) 84 static PassRefPtrWillBeRawPtr<File> createForFileSystemFile(const KURL& url, const FileMetadata& metadata)
81 { 85 {
82 return adoptRefWillBeNoop(new File(url, metadata)); 86 return adoptRefWillBeNoop(new File(url, metadata));
83 } 87 }
84 88
85 KURL fileSystemURL() const { ASSERT(hasValidFileSystemURL()); return m_fileS ystemURL; } 89 KURL fileSystemURL() const { ASSERT(hasValidFileSystemURL()); return m_fileS ystemURL; }
86 90
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. 91 // 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) 92 static PassRefPtrWillBeRawPtr<File> createWithName(const String& path, const String& name, ContentTypeLookupPolicy policy = WellKnownContentTypes)
89 { 93 {
90 if (name.isEmpty()) 94 if (name.isEmpty())
91 return adoptRefWillBeNoop(new File(path, policy)); 95 return adoptRefWillBeNoop(new File(path, policy, File::IsNotUserVisi ble));
92 return adoptRefWillBeNoop(new File(path, name, policy)); 96 return adoptRefWillBeNoop(new File(path, name, policy, File::IsNotUserVi sible));
97 }
98
99 static PassRefPtrWillBeRawPtr<File> createForFileSystemFile(const String& pa th, const String& name, ContentTypeLookupPolicy policy = WellKnownContentTypes)
100 {
101 if (name.isEmpty())
102 return adoptRefWillBeNoop(new File(path, policy, File::IsNotUserVisi ble));
103 return adoptRefWillBeNoop(new File(path, name, policy, File::IsNotUserVi sible));
93 } 104 }
94 105
95 virtual unsigned long long size() const OVERRIDE; 106 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; 107 virtual PassRefPtrWillBeRawPtr<Blob> slice(long long start, long long end, c onst String& contentType, ExceptionState&) const OVERRIDE;
97 virtual void close(ExecutionContext*, ExceptionState&) OVERRIDE; 108 virtual void close(ExecutionContext*, ExceptionState&) OVERRIDE;
98 109
99 virtual bool isFile() const OVERRIDE { return true; } 110 virtual bool isFile() const OVERRIDE { return true; }
100 virtual bool hasBackingFile() const OVERRIDE { return m_hasBackingFile; } 111 virtual bool hasBackingFile() const OVERRIDE { return m_hasBackingFile; }
101 112
102 virtual void appendTo(BlobData&) const OVERRIDE; 113 virtual void appendTo(BlobData&) const OVERRIDE;
103 114
104 const String& path() const { ASSERT(hasValidFilePath()); return m_path; } 115 const String& path() const { ASSERT(hasValidFilePath()); return m_path; }
105 const String name() const { return m_name; } 116 const String name() const { return m_name; }
106 117
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). 118 // 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; 119 double lastModifiedDate() const;
109 120
121 UserVisibility userVisibility() const { return m_userVisibility; }
122
110 // Returns the relative path of this file in the context of a directory sele ction. 123 // Returns the relative path of this file in the context of a directory sele ction.
111 const String& webkitRelativePath() const { return m_relativePath; } 124 const String& webkitRelativePath() const { return m_relativePath; }
112 125
113 // Note that this involves synchronous file operation. Think twice before ca lling this function. 126 // Note that this involves synchronous file operation. Think twice before ca lling this function.
114 void captureSnapshot(long long& snapshotSize, double& snapshotModificationTi me) const; 127 void captureSnapshot(long long& snapshotSize, double& snapshotModificationTi me) const;
115 128
116 // Returns true if this has a valid snapshot metadata (i.e. m_snapshotSize > = 0). 129 // Returns true if this has a valid snapshot metadata (i.e. m_snapshotSize > = 0).
117 bool hasValidSnapshotMetadata() const { return m_snapshotSize >= 0; } 130 bool hasValidSnapshotMetadata() const { return m_snapshotSize >= 0; }
118 131
119 private: 132 private:
120 File(const String& path, ContentTypeLookupPolicy); 133 File(const String& path, ContentTypeLookupPolicy, UserVisibility);
121 File(const String& path, const String& name, ContentTypeLookupPolicy); 134 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> ); 135 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> ); 136 File(const String& name, double modificationTime, PassRefPtr<BlobDataHandle> );
124 File(const String& name, const FileMetadata&); 137 File(const String& name, const FileMetadata&);
125 File(const KURL& fileSystemURL, const FileMetadata&); 138 File(const KURL& fileSystemURL, const FileMetadata&);
126 139
127 void invalidateSnapshotMetadata() { m_snapshotSize = -1; } 140 void invalidateSnapshotMetadata() { m_snapshotSize = -1; }
128 141
129 #if ENABLE(ASSERT) 142 #if ENABLE(ASSERT)
130 bool hasValidFileSystemURL() const { return hasBackingFile(); } 143 bool hasValidFileSystemURL() const { return hasBackingFile(); }
131 // Instances not backed by a file must have an empty path set. 144 // Instances not backed by a file must have an empty path set.
132 bool hasValidFilePath() const { return hasBackingFile() || m_path.isEmpty(); } 145 bool hasValidFilePath() const { return hasBackingFile() || m_path.isEmpty(); }
133 #endif 146 #endif
134 147
135 bool m_hasBackingFile; 148 bool m_hasBackingFile;
149 UserVisibility m_userVisibility;
136 String m_path; 150 String m_path;
137 String m_name; 151 String m_name;
138 152
139 KURL m_fileSystemURL; 153 KURL m_fileSystemURL;
140 154
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(). 155 // 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. 156 // Otherwise, the snapshot metadata are used directly in those methods.
143 long long m_snapshotSize; 157 long long m_snapshotSize;
144 const double m_snapshotModificationTime; 158 const double m_snapshotModificationTime;
145 159
146 String m_relativePath; 160 String m_relativePath;
147 }; 161 };
148 162
149 DEFINE_TYPE_CASTS(File, Blob, blob, blob->isFile(), blob.isFile()); 163 DEFINE_TYPE_CASTS(File, Blob, blob, blob->isFile(), blob.isFile());
150 164
151 } // namespace blink 165 } // namespace blink
152 166
153 #endif // File_h 167 #endif // File_h
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/SerializedScriptValue.cpp ('k') | Source/core/fileapi/File.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698