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

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

Issue 10821032: Merge 123495 - Files from drag and file <input> should use getMIMETypeForExtension to determine con… (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1180/
Patch Set: Created 8 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 | « no previous file | Source/WebCore/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 20 matching lines...) Expand all
31 #include <wtf/PassRefPtr.h> 31 #include <wtf/PassRefPtr.h>
32 #include <wtf/RefCounted.h> 32 #include <wtf/RefCounted.h>
33 33
34 namespace WebCore { 34 namespace WebCore {
35 35
36 struct FileMetadata; 36 struct FileMetadata;
37 class KURL; 37 class KURL;
38 38
39 class File : public Blob { 39 class File : public Blob {
40 public: 40 public:
41 static PassRefPtr<File> create(const String& path) 41 // 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 enum ContentTypeLookupPolicy {
44 WellKnownContentTypes,
45 AllContentTypes,
46 };
47
48 static PassRefPtr<File> create(const String& path, ContentTypeLookupPolicy p olicy = WellKnownContentTypes)
42 { 49 {
43 return adoptRef(new File(path)); 50 return adoptRef(new File(path, policy));
44 } 51 }
45 52
46 // For deserialization. 53 // For deserialization.
47 static PassRefPtr<File> create(const String& path, const KURL& srcURL, const String& type) 54 static PassRefPtr<File> create(const String& path, const KURL& srcURL, const String& type)
48 { 55 {
49 return adoptRef(new File(path, srcURL, type)); 56 return adoptRef(new File(path, srcURL, type));
50 } 57 }
51 58
52 #if ENABLE(DIRECTORY_UPLOAD) 59 #if ENABLE(DIRECTORY_UPLOAD)
53 static PassRefPtr<File> createWithRelativePath(const String& path, const Str ing& relativePath); 60 static PassRefPtr<File> createWithRelativePath(const String& path, const Str ing& relativePath);
54 #endif 61 #endif
55 62
56 #if ENABLE(FILE_SYSTEM) 63 #if ENABLE(FILE_SYSTEM)
57 // 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. 64 // 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.
58 // 65 //
59 // Otherwise calling size(), lastModifiedTime() and slice() will synchronous ly query the file metadata. 66 // Otherwise calling size(), lastModifiedTime() and slice() will synchronous ly query the file metadata.
60 static PassRefPtr<File> createForFileSystemFile(const String& name, const Fi leMetadata& metadata) 67 static PassRefPtr<File> createForFileSystemFile(const String& name, const Fi leMetadata& metadata)
61 { 68 {
62 return adoptRef(new File(name, metadata)); 69 return adoptRef(new File(name, metadata));
63 } 70 }
64 #endif 71 #endif
65 72
66 // 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. 73 // 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.
67 static PassRefPtr<File> createWithName(const String& path, const String& nam e) 74 static PassRefPtr<File> createWithName(const String& path, const String& nam e, ContentTypeLookupPolicy policy = WellKnownContentTypes)
68 { 75 {
69 if (name.isEmpty()) 76 if (name.isEmpty())
70 return adoptRef(new File(path)); 77 return adoptRef(new File(path, policy));
71 return adoptRef(new File(path, name)); 78 return adoptRef(new File(path, name, policy));
72 } 79 }
73 80
74 virtual unsigned long long size() const; 81 virtual unsigned long long size() const;
75 virtual bool isFile() const { return true; } 82 virtual bool isFile() const { return true; }
76 83
77 const String& path() const { return m_path; } 84 const String& path() const { return m_path; }
78 const String& name() const { return m_name; } 85 const String& name() const { return m_name; }
79 86
80 // This may return NaN (which is converted to null Date in javascript layer) if getFileModificationTime() platform call has failed or the information is not available. 87 // This may return NaN (which is converted to null Date in javascript layer) if getFileModificationTime() platform call has failed or the information is not available.
81 double lastModifiedDate() const; 88 double lastModifiedDate() const;
82 89
83 #if ENABLE(DIRECTORY_UPLOAD) 90 #if ENABLE(DIRECTORY_UPLOAD)
84 // Returns the relative path of this file in the context of a directory sele ction. 91 // Returns the relative path of this file in the context of a directory sele ction.
85 const String& webkitRelativePath() const { return m_relativePath; } 92 const String& webkitRelativePath() const { return m_relativePath; }
86 #endif 93 #endif
87 94
88 // Note that this involves synchronous file operation. Think twice before ca lling this function. 95 // Note that this involves synchronous file operation. Think twice before ca lling this function.
89 void captureSnapshot(long long& snapshotSize, double& snapshotModificationTi me) const; 96 void captureSnapshot(long long& snapshotSize, double& snapshotModificationTi me) const;
90 97
91 private: 98 private:
92 File(const String& path); 99 File(const String& path, ContentTypeLookupPolicy);
93 100
94 // For deserialization. 101 // For deserialization.
95 File(const String& path, const KURL& srcURL, const String& type); 102 File(const String& path, const KURL& srcURL, const String& type);
96 File(const String& path, const String& name); 103 File(const String& path, const String& name, ContentTypeLookupPolicy);
97 104
98 # if ENABLE(FILE_SYSTEM) 105 # if ENABLE(FILE_SYSTEM)
99 File(const String& name, const FileMetadata&); 106 File(const String& name, const FileMetadata&);
100 107
101 // Returns true if this has a valid snapshot metadata (i.e. m_snapshotSize > = 0). 108 // Returns true if this has a valid snapshot metadata (i.e. m_snapshotSize > = 0).
102 bool hasValidSnapshotMetadata() const { return m_snapshotSize >= 0; } 109 bool hasValidSnapshotMetadata() const { return m_snapshotSize >= 0; }
103 #endif 110 #endif
104 111
105 String m_path; 112 String m_path;
106 String m_name; 113 String m_name;
(...skipping 18 matching lines...) Expand all
125 132
126 inline const File* toFile(const Blob* blob) 133 inline const File* toFile(const Blob* blob)
127 { 134 {
128 ASSERT(!blob || blob->isFile()); 135 ASSERT(!blob || blob->isFile());
129 return static_cast<const File*>(blob); 136 return static_cast<const File*>(blob);
130 } 137 }
131 138
132 } // namespace WebCore 139 } // namespace WebCore
133 140
134 #endif // File_h 141 #endif // File_h
OLDNEW
« no previous file with comments | « no previous file | Source/WebCore/fileapi/File.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698