Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / fileapi / File.h
index 4b9dec7..9b195a3 100644 (file)
@@ -31,7 +31,7 @@
 #include "wtf/PassRefPtr.h"
 #include "wtf/text/WTFString.h"
 
-namespace WebCore {
+namespace blink {
 
 class ExceptionState;
 class ExecutionContext;
@@ -47,9 +47,13 @@ public:
         AllContentTypes,
     };
 
+    // The user should not be able to browse to some files, such as the ones
+    // generated by the Filesystem API.
+    enum UserVisibility { IsUserVisible, IsNotUserVisible };
+
     static PassRefPtrWillBeRawPtr<File> create(const String& path, ContentTypeLookupPolicy policy = WellKnownContentTypes)
     {
-        return adoptRefWillBeNoop(new File(path, policy));
+        return adoptRefWillBeNoop(new File(path, policy, File::IsUserVisible));
     }
 
     static PassRefPtrWillBeRawPtr<File> create(const String& name, double modificationTime, PassRefPtr<BlobDataHandle> blobDataHandle)
@@ -58,13 +62,13 @@ public:
     }
 
     // For deserialization.
-    static PassRefPtrWillBeRawPtr<File> create(const String& path, const String& name, const String& relativePath, bool hasSnaphotData, uint64_t size, double lastModified, PassRefPtr<BlobDataHandle> blobDataHandle)
+    static PassRefPtrWillBeRawPtr<File> createFromSerialization(const String& path, const String& name, const String& relativePath, UserVisibility userVisibility, bool hasSnaphotData, uint64_t size, double lastModified, PassRefPtr<BlobDataHandle> blobDataHandle)
     {
-        return adoptRefWillBeNoop(new File(path, name, relativePath, hasSnaphotData, size, lastModified, blobDataHandle));
+        return adoptRefWillBeNoop(new File(path, name, relativePath, userVisibility, hasSnaphotData, size, lastModified, blobDataHandle));
     }
-    static PassRefPtrWillBeRawPtr<File> create(const String& path, const String& name, uint64_t size, double lastModified, PassRefPtr<BlobDataHandle> blobDataHandle)
+    static PassRefPtrWillBeRawPtr<File> createFromIndexedSerialization(const String& path, const String& name, uint64_t size, double lastModified, PassRefPtr<BlobDataHandle> blobDataHandle)
     {
-        return adoptRefWillBeNoop(new File(path, name, String(), true, size, lastModified, blobDataHandle));
+        return adoptRefWillBeNoop(new File(path, name, String(), IsNotUserVisible, true, size, lastModified, blobDataHandle));
     }
 
     static PassRefPtrWillBeRawPtr<File> createWithRelativePath(const String& path, const String& relativePath);
@@ -85,11 +89,18 @@ public:
     KURL fileSystemURL() const { ASSERT(hasValidFileSystemURL()); return m_fileSystemURL; }
 
     // Create a file with a name exposed to the author (via File.name and associated DOM properties) that differs from the one provided in the path.
-    static PassRefPtrWillBeRawPtr<File> createWithName(const String& path, const String& name, ContentTypeLookupPolicy policy = WellKnownContentTypes)
+    static PassRefPtrWillBeRawPtr<File> createForUserProvidedFile(const String& path, const String& displayName)
+    {
+        if (displayName.isEmpty())
+            return adoptRefWillBeNoop(new File(path, File::AllContentTypes, File::IsUserVisible));
+        return adoptRefWillBeNoop(new File(path, displayName, File::AllContentTypes, File::IsUserVisible));
+    }
+
+    static PassRefPtrWillBeRawPtr<File> createForFileSystemFile(const String& path, const String& name, ContentTypeLookupPolicy policy = WellKnownContentTypes)
     {
         if (name.isEmpty())
-            return adoptRefWillBeNoop(new File(path, policy));
-        return adoptRefWillBeNoop(new File(path, name, policy));
+            return adoptRefWillBeNoop(new File(path, policy, File::IsNotUserVisible));
+        return adoptRefWillBeNoop(new File(path, name, policy, File::IsNotUserVisible));
     }
 
     virtual unsigned long long size() const OVERRIDE;
@@ -104,9 +115,16 @@ public:
     const String& path() const { ASSERT(hasValidFilePath()); return m_path; }
     const String name() const { return m_name; }
 
-    // This returns the current date and time if the file's last modification date is not known (per spec: http://www.w3.org/TR/FileAPI/#dfn-lastModifiedDate).
+    // Getter for the lastModified IDL attribute,
+    // http://dev.w3.org/2006/webapi/FileAPI/#file-attrs
+    long long lastModified() const;
+
+    // Getter for the lastModifiedDate IDL attribute,
+    // http://www.w3.org/TR/FileAPI/#dfn-lastModifiedDate
     double lastModifiedDate() const;
 
+    UserVisibility userVisibility() const { return m_userVisibility; }
+
     // Returns the relative path of this file in the context of a directory selection.
     const String& webkitRelativePath() const { return m_relativePath; }
 
@@ -117,22 +135,27 @@ public:
     bool hasValidSnapshotMetadata() const { return m_snapshotSize >= 0; }
 
 private:
-    File(const String& path, ContentTypeLookupPolicy);
-    File(const String& path, const String& name, ContentTypeLookupPolicy);
-    File(const String& path, const String& name, const String& relativePath, bool hasSnaphotData, uint64_t size, double lastModified, PassRefPtr<BlobDataHandle>);
+    File(const String& path, ContentTypeLookupPolicy, UserVisibility);
+    File(const String& path, const String& name, ContentTypeLookupPolicy, UserVisibility);
+    File(const String& path, const String& name, const String& relativePath, UserVisibility, bool hasSnaphotData, uint64_t size, double lastModified, PassRefPtr<BlobDataHandle>);
     File(const String& name, double modificationTime, PassRefPtr<BlobDataHandle>);
     File(const String& name, const FileMetadata&);
     File(const KURL& fileSystemURL, const FileMetadata&);
 
     void invalidateSnapshotMetadata() { m_snapshotSize = -1; }
 
-#ifndef NDEBUG
+    // Returns File's last modified time (in MS since Epoch.)
+    // If the modification time isn't known, the current time is returned.
+    double lastModifiedMS() const;
+
+#if ENABLE(ASSERT)
     bool hasValidFileSystemURL() const { return hasBackingFile(); }
     // Instances not backed by a file must have an empty path set.
     bool hasValidFilePath() const { return hasBackingFile() || m_path.isEmpty(); }
 #endif
 
     bool m_hasBackingFile;
+    UserVisibility m_userVisibility;
     String m_path;
     String m_name;
 
@@ -148,6 +171,6 @@ private:
 
 DEFINE_TYPE_CASTS(File, Blob, blob, blob->isFile(), blob.isFile());
 
-} // namespace WebCore
+} // namespace blink
 
 #endif // File_h