Title: [133652] branches/chromium/1180/Source/WebCore
Revision
133652
Author
kar...@chromium.org
Date
2012-11-06 12:08:19 -0800 (Tue, 06 Nov 2012)

Log Message

Revert 123677 - Merge 123495 - Files from drag and file <input> should use getMIMETypeForExtension to determine content type.
https://bugs.webkit.org/show_bug.cgi?id=91702

Reviewed by Jian Li.

Awhile back, we changed File to only use getWellKnownMIMETypeForExtension to prevent web
pages from being able to detect what applications a user has installed indirectly through
the MIME types. However, some sites like YouTube's drag and drop uploader use MIME types
that aren't in WebKit's internal list, so we relax the restriction for Files that originate
from an user action.

* fileapi/File.cpp:
(WebCore::getContentTypeFromFileName):
(WebCore::createBlobDataForFile):
(WebCore::createBlobDataForFileWithName):
(WebCore::createBlobDataForFileWithMetadata):
(WebCore::File::createWithRelativePath):
(WebCore::File::File):
* fileapi/File.h:
(File):
(WebCore::File::create):
(WebCore::File::createWithName):
* html/FileInputType.cpp:
(WebCore::FileInputType::createFileList):
* platform/chromium/ChromiumDataObject.cpp:
(WebCore::ChromiumDataObject::addFilename):
* platform/gtk/ClipboardGtk.cpp:
(WebCore::ClipboardGtk::files):
* platform/mac/ClipboardMac.mm:
(WebCore::ClipboardMac::files):
* platform/qt/ClipboardQt.cpp:
(WebCore::ClipboardQt::files):
* platform/win/ClipboardWin.cpp:
(WebCore::ClipboardWin::files):

TBR=dch...@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10821032

TBR=kar...@chromium.org
Review URL: https://codereview.chromium.org/11370004

Modified Paths

Diff

Modified: branches/chromium/1180/Source/WebCore/fileapi/File.cpp (133651 => 133652)


--- branches/chromium/1180/Source/WebCore/fileapi/File.cpp	2012-11-06 20:03:39 UTC (rev 133651)
+++ branches/chromium/1180/Source/WebCore/fileapi/File.cpp	2012-11-06 20:08:19 UTC (rev 133652)
@@ -34,18 +34,12 @@
 
 namespace WebCore {
 
-static String getContentTypeFromFileName(const String& name, File::ContentTypeLookupPolicy policy)
+static String getContentTypeFromFileName(const String& name)
 {
     String type;
     int index = name.reverseFind('.');
-    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));
-        }
-    }
+    if (index != -1)
+        type = MIMETypeRegistry::getWellKnownMIMETypeForExtension(name.substring(index + 1));
     return type;
 }
 
@@ -57,21 +51,21 @@
     return blobData.release();
 }
 
-static PassOwnPtr<BlobData> createBlobDataForFile(const String& path, File::ContentTypeLookupPolicy policy)
+static PassOwnPtr<BlobData> createBlobDataForFile(const String& path)
 {
-    return createBlobDataForFileWithType(path, getContentTypeFromFileName(path, policy));
+    return createBlobDataForFileWithType(path, getContentTypeFromFileName(path));
 }
 
-static PassOwnPtr<BlobData> createBlobDataForFileWithName(const String& path, const String& fileSystemName, File::ContentTypeLookupPolicy policy)
+static PassOwnPtr<BlobData> createBlobDataForFileWithName(const String& path, const String& fileSystemName)
 {
-    return createBlobDataForFileWithType(path, getContentTypeFromFileName(fileSystemName, policy));
+    return createBlobDataForFileWithType(path, getContentTypeFromFileName(fileSystemName));
 }
 
 #if ENABLE(FILE_SYSTEM)
 static PassOwnPtr<BlobData> createBlobDataForFileWithMetadata(const String& fileSystemName, const FileMetadata& metadata)
 {
     OwnPtr<BlobData> blobData = BlobData::create();
-    blobData->setContentType(getContentTypeFromFileName(fileSystemName, File::WellKnownContentTypes));
+    blobData->setContentType(getContentTypeFromFileName(fileSystemName));
     blobData->appendFile(metadata.platformPath, 0, metadata.length, metadata.modificationTime);
     return blobData.release();
 }
@@ -80,14 +74,14 @@
 #if ENABLE(DIRECTORY_UPLOAD)
 PassRefPtr<File> File::createWithRelativePath(const String& path, const String& relativePath)
 {
-    RefPtr<File> file = adoptRef(new File(path, AllContentTypes));
+    RefPtr<File> file = adoptRef(new File(path));
     file->m_relativePath = relativePath;
     return file.release();
 }
 #endif
 
-File::File(const String& path, ContentTypeLookupPolicy policy)
-    : Blob(createBlobDataForFile(path, policy), -1)
+File::File(const String& path)
+    : Blob(createBlobDataForFile(path), -1)
     , m_path(path)
     , m_name(pathGetFileName(path))
 #if ENABLE(FILE_SYSTEM)
@@ -111,8 +105,8 @@
     // See SerializedScriptValue.cpp for js and v8.
 }
 
-File::File(const String& path, const String& name, ContentTypeLookupPolicy policy)
-    : Blob(createBlobDataForFileWithName(path, name, policy), -1)
+File::File(const String& path, const String& name)
+    : Blob(createBlobDataForFileWithName(path, name), -1)
     , m_path(path)
     , m_name(name)
 #if ENABLE(FILE_SYSTEM)

Modified: branches/chromium/1180/Source/WebCore/fileapi/File.h (133651 => 133652)


--- branches/chromium/1180/Source/WebCore/fileapi/File.h	2012-11-06 20:03:39 UTC (rev 133651)
+++ branches/chromium/1180/Source/WebCore/fileapi/File.h	2012-11-06 20:08:19 UTC (rev 133652)
@@ -38,16 +38,9 @@
 
 class File : public Blob {
 public:
-    // 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)
+    static PassRefPtr<File> create(const String& path)
     {
-        return adoptRef(new File(path, policy));
+        return adoptRef(new File(path));
     }
 
     // For deserialization.
@@ -71,11 +64,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, ContentTypeLookupPolicy policy = WellKnownContentTypes)
+    static PassRefPtr<File> createWithName(const String& path, const String& name)
     {
         if (name.isEmpty())
-            return adoptRef(new File(path, policy));
-        return adoptRef(new File(path, name, policy));
+            return adoptRef(new File(path));
+        return adoptRef(new File(path, name));
     }
 
     virtual unsigned long long size() const;
@@ -96,11 +89,11 @@
     void captureSnapshot(long long& snapshotSize, double& snapshotModificationTime) const;
 
 private:
-    File(const String& path, ContentTypeLookupPolicy);
+    File(const String& path);
 
     // For deserialization.
     File(const String& path, const KURL& srcURL, const String& type);
-    File(const String& path, const String& name, ContentTypeLookupPolicy);
+    File(const String& path, const String& name);
 
 # if ENABLE(FILE_SYSTEM)
     File(const String& name, const FileMetadata&);

Modified: branches/chromium/1180/Source/WebCore/html/FileInputType.cpp (133651 => 133652)


--- branches/chromium/1180/Source/WebCore/html/FileInputType.cpp	2012-11-06 20:03:39 UTC (rev 133651)
+++ branches/chromium/1180/Source/WebCore/html/FileInputType.cpp	2012-11-06 20:08:19 UTC (rev 133652)
@@ -287,7 +287,7 @@
 #endif
 
     for (size_t i = 0; i < size; i++)
-        fileList->append(File::createWithName(files[i].path, files[i].displayName, File::AllContentTypes));
+        fileList->append(File::createWithName(files[i].path, files[i].displayName));
     return fileList;
 }
 

Modified: branches/chromium/1180/Source/WebCore/platform/chromium/ChromiumDataObject.cpp (133651 => 133652)


--- branches/chromium/1180/Source/WebCore/platform/chromium/ChromiumDataObject.cpp	2012-11-06 20:03:39 UTC (rev 133651)
+++ branches/chromium/1180/Source/WebCore/platform/chromium/ChromiumDataObject.cpp	2012-11-06 20:08:19 UTC (rev 133652)
@@ -209,7 +209,7 @@
 
 void ChromiumDataObject::addFilename(const String& filename, const String& displayName)
 {
-    internalAddFileItem(ChromiumDataObjectItem::createFromFile(File::createWithName(filename, displayName, File::AllContentTypes)));
+    internalAddFileItem(ChromiumDataObjectItem::createFromFile(File::createWithName(filename, displayName)));
 }
 
 void ChromiumDataObject::addSharedBuffer(const String& name, PassRefPtr<SharedBuffer> buffer)

Modified: branches/chromium/1180/Source/WebCore/platform/gtk/ClipboardGtk.cpp (133651 => 133652)


--- branches/chromium/1180/Source/WebCore/platform/gtk/ClipboardGtk.cpp	2012-11-06 20:03:39 UTC (rev 133651)
+++ branches/chromium/1180/Source/WebCore/platform/gtk/ClipboardGtk.cpp	2012-11-06 20:08:19 UTC (rev 133652)
@@ -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], File::AllContentTypes));
+        fileList->append(File::create(filenames[i]));
     return fileList.release();
 }
 

Modified: branches/chromium/1180/Source/WebCore/platform/mac/ClipboardMac.mm (133651 => 133652)


--- branches/chromium/1180/Source/WebCore/platform/mac/ClipboardMac.mm	2012-11-06 20:03:39 UTC (rev 133651)
+++ branches/chromium/1180/Source/WebCore/platform/mac/ClipboardMac.mm	2012-11-06 20:08:19 UTC (rev 133652)
@@ -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], File::AllContentTypes));
+        fileList->append(File::create([absoluteURL path]));
     }
     return fileList.release(); // We will always return a FileList, sometimes empty
 }

Modified: branches/chromium/1180/Source/WebCore/platform/qt/ClipboardQt.cpp (133651 => 133652)


--- branches/chromium/1180/Source/WebCore/platform/qt/ClipboardQt.cpp	2012-11-06 20:03:39 UTC (rev 133651)
+++ branches/chromium/1180/Source/WebCore/platform/qt/ClipboardQt.cpp	2012-11-06 20:08:19 UTC (rev 133652)
@@ -207,7 +207,7 @@
         QUrl url = ""
         if (url.scheme() != QLatin1String("file"))
             continue;
-        fileList->append(File::create(url.toLocalFile(), File::AllContentTypes));
+        fileList->append(File::create(url.toLocalFile()));
     }
 
     return fileList.release();

Modified: branches/chromium/1180/Source/WebCore/platform/win/ClipboardWin.cpp (133651 => 133652)


--- branches/chromium/1180/Source/WebCore/platform/win/ClipboardWin.cpp	2012-11-06 20:03:39 UTC (rev 133651)
+++ branches/chromium/1180/Source/WebCore/platform/win/ClipboardWin.cpp	2012-11-06 20:08:19 UTC (rev 133652)
@@ -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), File::AllContentTypes));
+            files->append(File::create(reinterpret_cast<UChar*>(filename)));
         }
 
         GlobalUnlock(medium.hGlobal);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to