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

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

Issue 11370004: Revert 123677 - Merge 123495 - Files from drag and file <input> should use getMIMETypeForExtension … (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1180/
Patch Set: Created 8 years, 1 month 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/WebCore/fileapi/File.h ('k') | Source/WebCore/html/FileInputType.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 16 matching lines...) Expand all
27 #include "File.h" 27 #include "File.h"
28 28
29 #include "FileMetadata.h" 29 #include "FileMetadata.h"
30 #include "FileSystem.h" 30 #include "FileSystem.h"
31 #include "MIMETypeRegistry.h" 31 #include "MIMETypeRegistry.h"
32 #include <wtf/CurrentTime.h> 32 #include <wtf/CurrentTime.h>
33 #include <wtf/text/WTFString.h> 33 #include <wtf/text/WTFString.h>
34 34
35 namespace WebCore { 35 namespace WebCore {
36 36
37 static String getContentTypeFromFileName(const String& name, File::ContentTypeLo okupPolicy policy) 37 static String getContentTypeFromFileName(const String& name)
38 { 38 {
39 String type; 39 String type;
40 int index = name.reverseFind('.'); 40 int index = name.reverseFind('.');
41 if (index != -1) { 41 if (index != -1)
42 if (policy == File::WellKnownContentTypes) 42 type = MIMETypeRegistry::getWellKnownMIMETypeForExtension(name.substring (index + 1));
43 type = MIMETypeRegistry::getWellKnownMIMETypeForExtension(name.subst ring(index + 1));
44 else {
45 ASSERT(policy == File::AllContentTypes);
46 type = MIMETypeRegistry::getMIMETypeForExtension(name.substring(inde x + 1));
47 }
48 }
49 return type; 43 return type;
50 } 44 }
51 45
52 static PassOwnPtr<BlobData> createBlobDataForFileWithType(const String& path, co nst String& contentType) 46 static PassOwnPtr<BlobData> createBlobDataForFileWithType(const String& path, co nst String& contentType)
53 { 47 {
54 OwnPtr<BlobData> blobData = BlobData::create(); 48 OwnPtr<BlobData> blobData = BlobData::create();
55 blobData->setContentType(contentType); 49 blobData->setContentType(contentType);
56 blobData->appendFile(path); 50 blobData->appendFile(path);
57 return blobData.release(); 51 return blobData.release();
58 } 52 }
59 53
60 static PassOwnPtr<BlobData> createBlobDataForFile(const String& path, File::Cont entTypeLookupPolicy policy) 54 static PassOwnPtr<BlobData> createBlobDataForFile(const String& path)
61 { 55 {
62 return createBlobDataForFileWithType(path, getContentTypeFromFileName(path, policy)); 56 return createBlobDataForFileWithType(path, getContentTypeFromFileName(path)) ;
63 } 57 }
64 58
65 static PassOwnPtr<BlobData> createBlobDataForFileWithName(const String& path, co nst String& fileSystemName, File::ContentTypeLookupPolicy policy) 59 static PassOwnPtr<BlobData> createBlobDataForFileWithName(const String& path, co nst String& fileSystemName)
66 { 60 {
67 return createBlobDataForFileWithType(path, getContentTypeFromFileName(fileSy stemName, policy)); 61 return createBlobDataForFileWithType(path, getContentTypeFromFileName(fileSy stemName));
68 } 62 }
69 63
70 #if ENABLE(FILE_SYSTEM) 64 #if ENABLE(FILE_SYSTEM)
71 static PassOwnPtr<BlobData> createBlobDataForFileWithMetadata(const String& file SystemName, const FileMetadata& metadata) 65 static PassOwnPtr<BlobData> createBlobDataForFileWithMetadata(const String& file SystemName, const FileMetadata& metadata)
72 { 66 {
73 OwnPtr<BlobData> blobData = BlobData::create(); 67 OwnPtr<BlobData> blobData = BlobData::create();
74 blobData->setContentType(getContentTypeFromFileName(fileSystemName, File::We llKnownContentTypes)); 68 blobData->setContentType(getContentTypeFromFileName(fileSystemName));
75 blobData->appendFile(metadata.platformPath, 0, metadata.length, metadata.mod ificationTime); 69 blobData->appendFile(metadata.platformPath, 0, metadata.length, metadata.mod ificationTime);
76 return blobData.release(); 70 return blobData.release();
77 } 71 }
78 #endif 72 #endif
79 73
80 #if ENABLE(DIRECTORY_UPLOAD) 74 #if ENABLE(DIRECTORY_UPLOAD)
81 PassRefPtr<File> File::createWithRelativePath(const String& path, const String& relativePath) 75 PassRefPtr<File> File::createWithRelativePath(const String& path, const String& relativePath)
82 { 76 {
83 RefPtr<File> file = adoptRef(new File(path, AllContentTypes)); 77 RefPtr<File> file = adoptRef(new File(path));
84 file->m_relativePath = relativePath; 78 file->m_relativePath = relativePath;
85 return file.release(); 79 return file.release();
86 } 80 }
87 #endif 81 #endif
88 82
89 File::File(const String& path, ContentTypeLookupPolicy policy) 83 File::File(const String& path)
90 : Blob(createBlobDataForFile(path, policy), -1) 84 : Blob(createBlobDataForFile(path), -1)
91 , m_path(path) 85 , m_path(path)
92 , m_name(pathGetFileName(path)) 86 , m_name(pathGetFileName(path))
93 #if ENABLE(FILE_SYSTEM) 87 #if ENABLE(FILE_SYSTEM)
94 , m_snapshotSize(-1) 88 , m_snapshotSize(-1)
95 , m_snapshotModificationTime(invalidFileTime()) 89 , m_snapshotModificationTime(invalidFileTime())
96 #endif 90 #endif
97 { 91 {
98 } 92 }
99 93
100 File::File(const String& path, const KURL& url, const String& type) 94 File::File(const String& path, const KURL& url, const String& type)
101 : Blob(url, type, -1) 95 : Blob(url, type, -1)
102 , m_path(path) 96 , m_path(path)
103 #if ENABLE(FILE_SYSTEM) 97 #if ENABLE(FILE_SYSTEM)
104 , m_snapshotSize(-1) 98 , m_snapshotSize(-1)
105 , m_snapshotModificationTime(invalidFileTime()) 99 , m_snapshotModificationTime(invalidFileTime())
106 #endif 100 #endif
107 { 101 {
108 m_name = pathGetFileName(path); 102 m_name = pathGetFileName(path);
109 // FIXME: File object serialization/deserialization does not include 103 // FIXME: File object serialization/deserialization does not include
110 // newer file object data members: m_name and m_relativePath. 104 // newer file object data members: m_name and m_relativePath.
111 // See SerializedScriptValue.cpp for js and v8. 105 // See SerializedScriptValue.cpp for js and v8.
112 } 106 }
113 107
114 File::File(const String& path, const String& name, ContentTypeLookupPolicy polic y) 108 File::File(const String& path, const String& name)
115 : Blob(createBlobDataForFileWithName(path, name, policy), -1) 109 : Blob(createBlobDataForFileWithName(path, name), -1)
116 , m_path(path) 110 , m_path(path)
117 , m_name(name) 111 , m_name(name)
118 #if ENABLE(FILE_SYSTEM) 112 #if ENABLE(FILE_SYSTEM)
119 , m_snapshotSize(-1) 113 , m_snapshotSize(-1)
120 , m_snapshotModificationTime(invalidFileTime()) 114 , m_snapshotModificationTime(invalidFileTime())
121 #endif 115 #endif
122 { 116 {
123 } 117 }
124 118
125 #if ENABLE(FILE_SYSTEM) 119 #if ENABLE(FILE_SYSTEM)
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 snapshotSize = 0; 174 snapshotSize = 0;
181 snapshotModificationTime = invalidFileTime(); 175 snapshotModificationTime = invalidFileTime();
182 return; 176 return;
183 } 177 }
184 178
185 snapshotSize = metadata.length; 179 snapshotSize = metadata.length;
186 snapshotModificationTime = metadata.modificationTime; 180 snapshotModificationTime = metadata.modificationTime;
187 } 181 }
188 182
189 } // namespace WebCore 183 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/WebCore/fileapi/File.h ('k') | Source/WebCore/html/FileInputType.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698