Chromium Code Reviews| 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 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 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 "wtf/PassRefPtr.h" | 30 #include "wtf/PassRefPtr.h" |
| 31 #include "wtf/text/WTFString.h" | 31 #include "wtf/text/WTFString.h" |
| 32 | 32 |
| 33 namespace WebCore { | 33 namespace WebCore { |
| 34 | 34 |
| 35 class ExecutionContext; | |
| 35 struct FileMetadata; | 36 struct FileMetadata; |
| 36 class KURL; | 37 class KURL; |
| 37 | 38 |
| 38 class File FINAL : public Blob { | 39 class File FINAL : public Blob { |
| 39 public: | 40 public: |
| 40 // AllContentTypes should only be used when the full path/name are trusted; otherwise, it could | 41 // AllContentTypes should only be used when the full path/name are trusted; otherwise, it could |
| 41 // allow arbitrary pages to determine what applications an user has installe d. | 42 // allow arbitrary pages to determine what applications an user has installe d. |
| 42 enum ContentTypeLookupPolicy { | 43 enum ContentTypeLookupPolicy { |
| 43 WellKnownContentTypes, | 44 WellKnownContentTypes, |
| 44 AllContentTypes, | 45 AllContentTypes, |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 68 static PassRefPtr<File> createForFileSystemFile(const String& name, const Fi leMetadata& metadata) | 69 static PassRefPtr<File> createForFileSystemFile(const String& name, const Fi leMetadata& metadata) |
| 69 { | 70 { |
| 70 return adoptRef(new File(name, metadata)); | 71 return adoptRef(new File(name, metadata)); |
| 71 } | 72 } |
| 72 | 73 |
| 73 static PassRefPtr<File> createForFileSystemFile(const KURL& url, const FileM etadata& metadata) | 74 static PassRefPtr<File> createForFileSystemFile(const KURL& url, const FileM etadata& metadata) |
| 74 { | 75 { |
| 75 return adoptRef(new File(url, metadata)); | 76 return adoptRef(new File(url, metadata)); |
| 76 } | 77 } |
| 77 | 78 |
| 78 KURL fileSystemURL() const { ASSERT(m_hasBackingFile); return m_fileSystemUR L; } | 79 KURL fileSystemURL() const { ASSERT(m_hasBackingFile); return m_fileSystemUR L; } |
|
michaeln
2014/02/18 18:59:54
That assertion looks like a landmine in a world wi
sof
2014/02/18 19:12:47
Yes, I'll see what I can do. The landmine is alrea
| |
| 79 | 80 |
| 80 // 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. | 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. |
| 81 static PassRefPtr<File> createWithName(const String& path, const String& nam e, ContentTypeLookupPolicy policy = WellKnownContentTypes) | 82 static PassRefPtr<File> createWithName(const String& path, const String& nam e, ContentTypeLookupPolicy policy = WellKnownContentTypes) |
| 82 { | 83 { |
| 83 if (name.isEmpty()) | 84 if (name.isEmpty()) |
| 84 return adoptRef(new File(path, policy)); | 85 return adoptRef(new File(path, policy)); |
| 85 return adoptRef(new File(path, name, policy)); | 86 return adoptRef(new File(path, name, policy)); |
| 86 } | 87 } |
| 87 | 88 |
| 88 virtual unsigned long long size() const OVERRIDE; | 89 virtual unsigned long long size() const OVERRIDE; |
| 89 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; | 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 void close(ExecutionContext*) OVERRIDE; | |
| 90 | 92 |
| 91 virtual bool isFile() const OVERRIDE { return true; } | 93 virtual bool isFile() const OVERRIDE { return true; } |
| 92 virtual bool hasBackingFile() const OVERRIDE { return m_hasBackingFile; } | 94 virtual bool hasBackingFile() const OVERRIDE { return m_hasBackingFile; } |
| 93 | 95 |
| 94 virtual void appendTo(BlobData&) const OVERRIDE; | 96 virtual void appendTo(BlobData&) const OVERRIDE; |
| 95 | 97 |
| 96 const String& path() const { ASSERT(m_hasBackingFile); return m_path; } | 98 const String& path() const { ASSERT(m_hasBackingFile); return m_path; } |
|
michaeln
2014/02/18 18:59:54
Ditto landmind.
sof
2014/02/19 11:47:39
I checked the call sites & they do check backing f
| |
| 97 const String& name() const { return m_name; } | 99 const String name() const { return m_name; } |
| 98 | 100 |
| 99 // This returns the current date and time if the file's last modifiecation d ate is not known (per spec: http://www.w3.org/TR/FileAPI/#dfn-lastModifiedDate). | 101 // 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). |
| 100 double lastModifiedDate() const; | 102 double lastModifiedDate() const; |
| 101 | 103 |
| 102 // Returns the relative path of this file in the context of a directory sele ction. | 104 // Returns the relative path of this file in the context of a directory sele ction. |
| 103 const String& webkitRelativePath() const { return m_relativePath; } | 105 const String& webkitRelativePath() const { return m_relativePath; } |
| 104 | 106 |
| 105 // Note that this involves synchronous file operation. Think twice before ca lling this function. | 107 // Note that this involves synchronous file operation. Think twice before ca lling this function. |
| 106 void captureSnapshot(long long& snapshotSize, double& snapshotModificationTi me) const; | 108 void captureSnapshot(long long& snapshotSize, double& snapshotModificationTi me) const; |
| 107 | 109 |
| 108 // Returns true if this has a valid snapshot metadata (i.e. m_snapshotSize > = 0). | 110 // Returns true if this has a valid snapshot metadata (i.e. m_snapshotSize > = 0). |
| 109 bool hasValidSnapshotMetadata() const { return m_snapshotSize >= 0; } | 111 bool hasValidSnapshotMetadata() const { return m_snapshotSize >= 0; } |
| 110 | 112 |
| 111 private: | 113 private: |
| 112 File(const String& path, ContentTypeLookupPolicy); | 114 File(const String& path, ContentTypeLookupPolicy); |
| 113 File(const String& path, const String& name, ContentTypeLookupPolicy); | 115 File(const String& path, const String& name, ContentTypeLookupPolicy); |
| 114 File(const String& path, const String& name, const String& relativePath, boo l hasSnaphotData, uint64_t size, double lastModified, PassRefPtr<BlobDataHandle> ); | 116 File(const String& path, const String& name, const String& relativePath, boo l hasSnaphotData, uint64_t size, double lastModified, PassRefPtr<BlobDataHandle> ); |
| 115 File(const String& name, double modificationTime, PassRefPtr<BlobDataHandle> ); | 117 File(const String& name, double modificationTime, PassRefPtr<BlobDataHandle> ); |
| 116 File(const String& name, const FileMetadata&); | 118 File(const String& name, const FileMetadata&); |
| 117 File(const KURL& fileSystemURL, const FileMetadata&); | 119 File(const KURL& fileSystemURL, const FileMetadata&); |
| 118 | 120 |
| 121 void invalidateSnapshotMetadata() { m_snapshotSize = -1; } | |
| 122 | |
| 119 bool m_hasBackingFile; | 123 bool m_hasBackingFile; |
| 120 String m_path; | 124 String m_path; |
| 121 String m_name; | 125 String m_name; |
| 122 | 126 |
| 123 KURL m_fileSystemURL; | 127 KURL m_fileSystemURL; |
| 124 | 128 |
| 125 // 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(). | 129 // 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(). |
| 126 // Otherwise, the snapshot metadata are used directly in those methods. | 130 // Otherwise, the snapshot metadata are used directly in those methods. |
| 127 const long long m_snapshotSize; | 131 long long m_snapshotSize; |
| 128 const double m_snapshotModificationTime; | 132 const double m_snapshotModificationTime; |
| 129 | 133 |
| 130 String m_relativePath; | 134 String m_relativePath; |
| 131 }; | 135 }; |
| 132 | 136 |
| 133 DEFINE_TYPE_CASTS(File, Blob, blob, blob->isFile(), blob.isFile()); | 137 DEFINE_TYPE_CASTS(File, Blob, blob, blob->isFile(), blob.isFile()); |
| 134 | 138 |
| 135 } // namespace WebCore | 139 } // namespace WebCore |
| 136 | 140 |
| 137 #endif // File_h | 141 #endif // File_h |
| OLD | NEW |