diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-07-30 11:37:48 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-07-30 11:38:52 +0200 |
commit | 89e2486a48b739f8d771d69ede5a6a1b244a10fc (patch) | |
tree | 503b1a7812cf97d93704c32437eb5f62dc1a1ff9 /Source/WebCore/fileapi | |
parent | 625f028249cb37c55bbbd153f3902afd0b0756d9 (diff) | |
download | qtwebkit-89e2486a48b739f8d771d69ede5a6a1b244a10fc.tar.gz |
Imported WebKit commit 0282df8ca7c11d8c8a66ea18543695c69f545a27 (http://svn.webkit.org/repository/webkit/trunk@124002)
New snapshot with prospective Mountain Lion build fix
Diffstat (limited to 'Source/WebCore/fileapi')
-rw-r--r-- | Source/WebCore/fileapi/File.cpp | 32 | ||||
-rw-r--r-- | Source/WebCore/fileapi/File.h | 21 |
2 files changed, 33 insertions, 20 deletions
diff --git a/Source/WebCore/fileapi/File.cpp b/Source/WebCore/fileapi/File.cpp index 5f8b93b78..087895710 100644 --- a/Source/WebCore/fileapi/File.cpp +++ b/Source/WebCore/fileapi/File.cpp @@ -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 @@ static PassOwnPtr<BlobData> createBlobDataForFileWithType(const String& path, co 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 @@ static PassOwnPtr<BlobData> createBlobDataForFileWithMetadata(const String& file #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 @@ File::File(const String& path, const KURL& url, const String& type) // 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) diff --git a/Source/WebCore/fileapi/File.h b/Source/WebCore/fileapi/File.h index e3ca2a5a8..864c4388a 100644 --- a/Source/WebCore/fileapi/File.h +++ b/Source/WebCore/fileapi/File.h @@ -38,9 +38,16 @@ class KURL; 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 @@ public: #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 @@ public: 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&); |