Diff
Modified: branches/chromium/1180/Source/WebCore/fileapi/File.cpp (123676 => 123677)
--- branches/chromium/1180/Source/WebCore/fileapi/File.cpp 2012-07-25 23:32:58 UTC (rev 123676)
+++ branches/chromium/1180/Source/WebCore/fileapi/File.cpp 2012-07-25 23:39:27 UTC (rev 123677)
@@ -34,12 +34,18 @@
namespace WebCore {
-static String getContentTypeFromFileName(const String& name)
+static String getContentTypeFromFileName(const String& name, File::ContentTypeLookupPolicy policy)
{
String type;
int index = name.reverseFind('.');
- if (index != -1)
- type = MIMETypeRegistry::getWellKnownMIMETypeForExtension(name.substring(index + 1));
+ if (index != -1) {
+ if (policy == File::WellKnownContentTypes)
+ type = MIMETypeRegistry::getWellKnownMIMETypeForExtension(name.substring(index + 1));
+ else {
+ ASSERT(policy == File::AllContentTypes);
+ type = MIMETypeRegistry::getMIMETypeForExtension(name.substring(index + 1));
+ }
+ }
return type;
}
@@ -51,21 +57,21 @@
return blobData.release();
}
-static PassOwnPtr<BlobData> createBlobDataForFile(const String& path)
+static PassOwnPtr<BlobData> createBlobDataForFile(const String& path, File::ContentTypeLookupPolicy policy)
{
- return createBlobDataForFileWithType(path, getContentTypeFromFileName(path));
+ return createBlobDataForFileWithType(path, getContentTypeFromFileName(path, policy));
}
-static PassOwnPtr<BlobData> createBlobDataForFileWithName(const String& path, const String& fileSystemName)
+static PassOwnPtr<BlobData> createBlobDataForFileWithName(const String& path, const String& fileSystemName, File::ContentTypeLookupPolicy policy)
{
- return createBlobDataForFileWithType(path, getContentTypeFromFileName(fileSystemName));
+ return createBlobDataForFileWithType(path, getContentTypeFromFileName(fileSystemName, policy));
}
#if ENABLE(FILE_SYSTEM)
static PassOwnPtr<BlobData> createBlobDataForFileWithMetadata(const String& fileSystemName, const FileMetadata& metadata)
{
OwnPtr<BlobData> blobData = BlobData::create();
- blobData->setContentType(getContentTypeFromFileName(fileSystemName));
+ blobData->setContentType(getContentTypeFromFileName(fileSystemName, File::WellKnownContentTypes));
blobData->appendFile(metadata.platformPath, 0, metadata.length, metadata.modificationTime);
return blobData.release();
}
@@ -74,14 +80,14 @@
#if ENABLE(DIRECTORY_UPLOAD)
PassRefPtr<File> File::createWithRelativePath(const String& path, const String& relativePath)
{
- RefPtr<File> file = adoptRef(new File(path));
+ RefPtr<File> file = adoptRef(new File(path, AllContentTypes));
file->m_relativePath = relativePath;
return file.release();
}
#endif
-File::File(const String& path)
- : Blob(createBlobDataForFile(path), -1)
+File::File(const String& path, ContentTypeLookupPolicy policy)
+ : Blob(createBlobDataForFile(path, policy), -1)
, m_path(path)
, m_name(pathGetFileName(path))
#if ENABLE(FILE_SYSTEM)
@@ -105,8 +111,8 @@
// See SerializedScriptValue.cpp for js and v8.
}
-File::File(const String& path, const String& name)
- : Blob(createBlobDataForFileWithName(path, name), -1)
+File::File(const String& path, const String& name, ContentTypeLookupPolicy policy)
+ : Blob(createBlobDataForFileWithName(path, name, policy), -1)
, m_path(path)
, m_name(name)
#if ENABLE(FILE_SYSTEM)
Modified: branches/chromium/1180/Source/WebCore/fileapi/File.h (123676 => 123677)
--- branches/chromium/1180/Source/WebCore/fileapi/File.h 2012-07-25 23:32:58 UTC (rev 123676)
+++ branches/chromium/1180/Source/WebCore/fileapi/File.h 2012-07-25 23:39:27 UTC (rev 123677)
@@ -38,9 +38,16 @@
class File : public Blob {
public:
- static PassRefPtr<File> create(const String& path)
+ // AllContentTypes should only be used when the full path/name are trusted; otherwise, it could
+ // allow arbitrary pages to determine what applications an user has installed.
+ enum ContentTypeLookupPolicy {
+ WellKnownContentTypes,
+ AllContentTypes,
+ };
+
+ static PassRefPtr<File> create(const String& path, ContentTypeLookupPolicy policy = WellKnownContentTypes)
{
- return adoptRef(new File(path));
+ return adoptRef(new File(path, policy));
}
// For deserialization.
@@ -64,11 +71,11 @@
#endif
// 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 PassRefPtr<File> createWithName(const String& path, const String& name)
+ static PassRefPtr<File> createWithName(const String& path, const String& name, ContentTypeLookupPolicy policy = WellKnownContentTypes)
{
if (name.isEmpty())
- return adoptRef(new File(path));
- return adoptRef(new File(path, name));
+ return adoptRef(new File(path, policy));
+ return adoptRef(new File(path, name, policy));
}
virtual unsigned long long size() const;
@@ -89,11 +96,11 @@
void captureSnapshot(long long& snapshotSize, double& snapshotModificationTime) const;
private:
- File(const String& path);
+ File(const String& path, ContentTypeLookupPolicy);
// For deserialization.
File(const String& path, const KURL& srcURL, const String& type);
- File(const String& path, const String& name);
+ File(const String& path, const String& name, ContentTypeLookupPolicy);
# if ENABLE(FILE_SYSTEM)
File(const String& name, const FileMetadata&);
Modified: branches/chromium/1180/Source/WebCore/html/FileInputType.cpp (123676 => 123677)
--- branches/chromium/1180/Source/WebCore/html/FileInputType.cpp 2012-07-25 23:32:58 UTC (rev 123676)
+++ branches/chromium/1180/Source/WebCore/html/FileInputType.cpp 2012-07-25 23:39:27 UTC (rev 123677)
@@ -287,7 +287,7 @@
#endif
for (size_t i = 0; i < size; i++)
- fileList->append(File::createWithName(files[i].path, files[i].displayName));
+ fileList->append(File::createWithName(files[i].path, files[i].displayName, File::AllContentTypes));
return fileList;
}
Modified: branches/chromium/1180/Source/WebCore/platform/chromium/ChromiumDataObject.cpp (123676 => 123677)
--- branches/chromium/1180/Source/WebCore/platform/chromium/ChromiumDataObject.cpp 2012-07-25 23:32:58 UTC (rev 123676)
+++ branches/chromium/1180/Source/WebCore/platform/chromium/ChromiumDataObject.cpp 2012-07-25 23:39:27 UTC (rev 123677)
@@ -209,7 +209,7 @@
void ChromiumDataObject::addFilename(const String& filename, const String& displayName)
{
- internalAddFileItem(ChromiumDataObjectItem::createFromFile(File::createWithName(filename, displayName)));
+ internalAddFileItem(ChromiumDataObjectItem::createFromFile(File::createWithName(filename, displayName, File::AllContentTypes)));
}
void ChromiumDataObject::addSharedBuffer(const String& name, PassRefPtr<SharedBuffer> buffer)
Modified: branches/chromium/1180/Source/WebCore/platform/gtk/ClipboardGtk.cpp (123676 => 123677)
--- branches/chromium/1180/Source/WebCore/platform/gtk/ClipboardGtk.cpp 2012-07-25 23:32:58 UTC (rev 123676)
+++ branches/chromium/1180/Source/WebCore/platform/gtk/ClipboardGtk.cpp 2012-07-25 23:39:27 UTC (rev 123677)
@@ -224,7 +224,7 @@
RefPtr<FileList> fileList = FileList::create();
const Vector<String>& filenames = m_dataObject->filenames();
for (size_t i = 0; i < filenames.size(); i++)
- fileList->append(File::create(filenames[i]));
+ fileList->append(File::create(filenames[i], File::AllContentTypes));
return fileList.release();
}
Modified: branches/chromium/1180/Source/WebCore/platform/mac/ClipboardMac.mm (123676 => 123677)
--- branches/chromium/1180/Source/WebCore/platform/mac/ClipboardMac.mm 2012-07-25 23:32:58 UTC (rev 123676)
+++ branches/chromium/1180/Source/WebCore/platform/mac/ClipboardMac.mm 2012-07-25 23:39:27 UTC (rev 123677)
@@ -321,7 +321,7 @@
for (size_t i = 0; i < absoluteURLs.size(); i++) {
NSURL *absoluteURL = [NSURL URLWithString:absoluteURLs[i]];
ASSERT([absoluteURL isFileURL]);
- fileList->append(File::create([absoluteURL path]));
+ fileList->append(File::create([absoluteURL path], File::AllContentTypes));
}
return fileList.release(); // We will always return a FileList, sometimes empty
}
Modified: branches/chromium/1180/Source/WebCore/platform/qt/ClipboardQt.cpp (123676 => 123677)
--- branches/chromium/1180/Source/WebCore/platform/qt/ClipboardQt.cpp 2012-07-25 23:32:58 UTC (rev 123676)
+++ branches/chromium/1180/Source/WebCore/platform/qt/ClipboardQt.cpp 2012-07-25 23:39:27 UTC (rev 123677)
@@ -207,7 +207,7 @@
QUrl url = ""
if (url.scheme() != QLatin1String("file"))
continue;
- fileList->append(File::create(url.toLocalFile()));
+ fileList->append(File::create(url.toLocalFile(), File::AllContentTypes));
}
return fileList.release();
Modified: branches/chromium/1180/Source/WebCore/platform/win/ClipboardWin.cpp (123676 => 123677)
--- branches/chromium/1180/Source/WebCore/platform/win/ClipboardWin.cpp 2012-07-25 23:32:58 UTC (rev 123676)
+++ branches/chromium/1180/Source/WebCore/platform/win/ClipboardWin.cpp 2012-07-25 23:39:27 UTC (rev 123677)
@@ -560,7 +560,7 @@
for (UINT i = 0; i < fileCount; i++) {
if (!DragQueryFileW(hdrop, i, filename, WTF_ARRAY_LENGTH(filename)))
continue;
- files->append(File::create(reinterpret_cast<UChar*>(filename)));
+ files->append(File::create(reinterpret_cast<UChar*>(filename), File::AllContentTypes));
}
GlobalUnlock(medium.hGlobal);