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

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

Issue 7356002: Merge 90308 (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/782/
Patch Set: Created 9 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/platform/MIMETypeRegistry.h » ('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 15 matching lines...) Expand all
26 #include "config.h" 26 #include "config.h"
27 #include "File.h" 27 #include "File.h"
28 28
29 #include "FileSystem.h" 29 #include "FileSystem.h"
30 #include "MIMETypeRegistry.h" 30 #include "MIMETypeRegistry.h"
31 #include <wtf/CurrentTime.h> 31 #include <wtf/CurrentTime.h>
32 #include <wtf/text/WTFString.h> 32 #include <wtf/text/WTFString.h>
33 33
34 namespace WebCore { 34 namespace WebCore {
35 35
36 static PassOwnPtr<BlobData> createBlobDataForFile(const String& path, const Stri ng& name = String()) 36 static PassOwnPtr<BlobData> createBlobDataForFileWithType(const String& path, co nst String& contentType)
37 { 37 {
38 String type;
39 const String& nameForMIMEType = !name.isEmpty() ? name : path;
40 int index = nameForMIMEType.reverseFind('.');
41 if (index != -1)
42 type = MIMETypeRegistry::getMIMETypeForExtension(nameForMIMEType.substri ng(index + 1));
43
44 OwnPtr<BlobData> blobData = BlobData::create(); 38 OwnPtr<BlobData> blobData = BlobData::create();
45 blobData->setContentType(type); 39 blobData->setContentType(contentType);
46 blobData->appendFile(path); 40 blobData->appendFile(path);
47 return blobData.release(); 41 return blobData.release();
48 } 42 }
49 43
44 static PassOwnPtr<BlobData> createBlobDataForFile(const String& path)
45 {
46 String type;
47 int index = path.reverseFind('.');
48 if (index != -1)
49 type = MIMETypeRegistry::getMIMETypeForExtension(path.substring(index + 1));
50 return createBlobDataForFileWithType(path, type);
51 }
52
53 #if ENABLE(FILE_SYSTEM)
54 static PassOwnPtr<BlobData> createBlobDataForFileSystemFile(const String& path, const String& fileSystemName)
55 {
56 String type;
57 int index = fileSystemName.reverseFind('.');
58 if (index != -1)
59 type = MIMETypeRegistry::getWellKnownMIMETypeForExtension(fileSystemName .substring(index + 1));
60 return createBlobDataForFileWithType(path, type);
61 }
62 #endif
63
50 #if ENABLE(DIRECTORY_UPLOAD) 64 #if ENABLE(DIRECTORY_UPLOAD)
51 PassRefPtr<File> File::createWithRelativePath(const String& path, const String& relativePath) 65 PassRefPtr<File> File::createWithRelativePath(const String& path, const String& relativePath)
52 { 66 {
53 RefPtr<File> file = adoptRef(new File(path)); 67 RefPtr<File> file = adoptRef(new File(path));
54 file->m_relativePath = relativePath; 68 file->m_relativePath = relativePath;
55 return file.release(); 69 return file.release();
56 } 70 }
57 #endif 71 #endif
58 72
59 File::File(const String& path) 73 File::File(const String& path)
60 : Blob(createBlobDataForFile(path), -1) 74 : Blob(createBlobDataForFile(path), -1)
61 , m_path(path) 75 , m_path(path)
62 , m_name(pathGetFileName(path)) 76 , m_name(pathGetFileName(path))
63 { 77 {
64 } 78 }
65 79
66 File::File(const String& path, const KURL& url, const String& type) 80 File::File(const String& path, const KURL& url, const String& type)
67 : Blob(url, type, -1) 81 : Blob(url, type, -1)
68 , m_path(path) 82 , m_path(path)
69 { 83 {
70 m_name = pathGetFileName(path); 84 m_name = pathGetFileName(path);
85 // FIXME: File object serialization/deserialization does not include
86 // newer file object data members: m_name and m_relativePath.
87 // See SerializedScriptValue.cpp for js and v8.
71 } 88 }
72 89
73 #if ENABLE(FILE_SYSTEM) 90 #if ENABLE(FILE_SYSTEM)
74 File::File(const String& path, const String& name) 91 File::File(const String& path, const String& name)
75 : Blob(createBlobDataForFile(path, name), -1) 92 : Blob(createBlobDataForFileSystemFile(path, name), -1)
76 , m_path(path) 93 , m_path(path)
77 , m_name(name) 94 , m_name(name)
78 { 95 {
79 } 96 }
80 #endif 97 #endif
81 98
82 double File::lastModifiedDate() const 99 double File::lastModifiedDate() const
83 { 100 {
84 time_t modificationTime; 101 time_t modificationTime;
85 if (!getFileModificationTime(m_path, modificationTime)) 102 if (!getFileModificationTime(m_path, modificationTime))
(...skipping 20 matching lines...) Expand all
106 // FIXME: Combine getFileSize and getFileModificationTime into one file syst em call. 123 // FIXME: Combine getFileSize and getFileModificationTime into one file syst em call.
107 time_t modificationTime; 124 time_t modificationTime;
108 if (!getFileSize(m_path, snapshotSize) || !getFileModificationTime(m_path, m odificationTime)) { 125 if (!getFileSize(m_path, snapshotSize) || !getFileModificationTime(m_path, m odificationTime)) {
109 snapshotSize = 0; 126 snapshotSize = 0;
110 snapshotModificationTime = 0; 127 snapshotModificationTime = 0;
111 } else 128 } else
112 snapshotModificationTime = modificationTime; 129 snapshotModificationTime = modificationTime;
113 } 130 }
114 131
115 } // namespace WebCore 132 } // namespace WebCore
OLDNEW
« no previous file with comments | « no previous file | Source/WebCore/platform/MIMETypeRegistry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698