Changeset 168430 in webkit


Ignore:
Timestamp:
May 7, 2014 11:19:21 AM (10 years ago)
Author:
ap@apple.com
Message:

Eliminate "well known MIME type" support
https://bugs.webkit.org/show_bug.cgi?id=132654

Reviewed by Anders Carlsson.

Vestiges of FileSystem API.

  • dom/DataTransfer.cpp:

(WebCore::DataTransfer::files):
(WebCore::DataTransfer::hasFileOfType):

  • fileapi/File.cpp:

(WebCore::File::File):
(WebCore::File::contentTypeFromFilePathOrName):

  • fileapi/File.h:
  • html/FileInputType.cpp:

(WebCore::FileInputType::createFileList):

  • platform/MIMETypeRegistry.cpp:

(WebCore::initializeSupportedImageMIMETypes):
(WebCore::findMimeType): Deleted.
(WebCore::MIMETypeRegistry::getWellKnownMIMETypeForExtension): Deleted.

  • platform/MIMETypeRegistry.h:
Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r168428 r168430  
     12014-05-07  Alexey Proskuryakov  <ap@apple.com>
     2
     3        Eliminate "well known MIME type" support
     4        https://bugs.webkit.org/show_bug.cgi?id=132654
     5
     6        Reviewed by Anders Carlsson.
     7
     8        Vestiges of FileSystem API.
     9
     10        * dom/DataTransfer.cpp:
     11        (WebCore::DataTransfer::files):
     12        (WebCore::DataTransfer::hasFileOfType):
     13        * fileapi/File.cpp:
     14        (WebCore::File::File):
     15        (WebCore::File::contentTypeFromFilePathOrName):
     16        * fileapi/File.h:
     17        * html/FileInputType.cpp:
     18        (WebCore::FileInputType::createFileList):
     19        * platform/MIMETypeRegistry.cpp:
     20        (WebCore::initializeSupportedImageMIMETypes):
     21        (WebCore::findMimeType): Deleted.
     22        (WebCore::MIMETypeRegistry::getWellKnownMIMETypeForExtension): Deleted.
     23        * platform/MIMETypeRegistry.h:
     24
    1252014-05-07  Christophe Dumez  <ch.dumez@samsung.com>
    226
  • trunk/Source/WebCore/dom/DataTransfer.cpp

    r168333 r168430  
    180180    if (newlyCreatedFileList) {
    181181        for (const String& filename : m_pasteboard->readFilenames())
    182             m_fileList->append(File::create(filename, File::AllContentTypes));
     182            m_fileList->append(File::create(filename));
    183183    }
    184184    return m_fileList.get();
     
    190190
    191191    for (const String& filename : m_pasteboard->readFilenames()) {
    192         if (equalIgnoringCase(File::contentTypeFromFilePathOrName(filename, File::AllContentTypes), type))
     192        if (equalIgnoringCase(File::contentTypeFromFilePathOrName(filename), type))
    193193            return true;
    194194    }
  • trunk/Source/WebCore/fileapi/File.cpp

    r168333 r168430  
    3838namespace WebCore {
    3939
    40 File::File(const String& path, ContentTypeLookupPolicy policy)
     40File::File(const String& path)
    4141    : Blob(uninitializedContructor)
    4242    , m_path(path)
     
    4444{
    4545    m_internalURL = BlobURL::createInternalURL();
    46     m_type = contentTypeFromFilePathOrName(path, policy);
     46    m_type = contentTypeFromFilePathOrName(path);
    4747    m_size = -1;
    4848    ThreadableBlobRegistry::registerFileBlobURL(m_internalURL, path, m_type);
    4949}
    5050
    51 File::File(const String& path, const String& name, ContentTypeLookupPolicy policy)
     51File::File(const String& path, const String& name)
    5252    : Blob(uninitializedContructor)
    5353    , m_path(path)
     
    5555{
    5656    m_internalURL = BlobURL::createInternalURL();
    57     m_type = contentTypeFromFilePathOrName(name, policy);
     57    m_type = contentTypeFromFilePathOrName(name);
    5858    m_size = -1;
    5959    ThreadableBlobRegistry::registerFileBlobURL(m_internalURL, path, m_type);
     
    8888}
    8989
    90 String File::contentTypeFromFilePathOrName(const String& name, File::ContentTypeLookupPolicy policy)
     90String File::contentTypeFromFilePathOrName(const String& name)
    9191{
    9292    String type;
    9393    int index = name.reverseFind('.');
    9494    if (index != -1) {
    95         if (policy == File::WellKnownContentTypes)
    96             type = MIMETypeRegistry::getWellKnownMIMETypeForExtension(name.substring(index + 1));
    97         else {
    98             ASSERT(policy == File::AllContentTypes);
    99             type = MIMETypeRegistry::getMIMETypeForExtension(name.substring(index + 1));
    100         }
     95        type = MIMETypeRegistry::getMIMETypeForExtension(name.substring(index + 1));
    10196    }
    10297    return type;
  • trunk/Source/WebCore/fileapi/File.h

    r168333 r168430  
    3737class File final : public Blob {
    3838public:
    39     // AllContentTypes should only be used when the full path/name are trusted; otherwise, it could
    40     // allow arbitrary pages to determine what applications an user has installed.
    41     enum ContentTypeLookupPolicy {
    42         WellKnownContentTypes,
    43         AllContentTypes,
    44     };
    45 
    46     static PassRefPtr<File> create(const String& path, ContentTypeLookupPolicy policy = WellKnownContentTypes)
     39    static PassRefPtr<File> create(const String& path)
    4740    {
    48         return adoptRef(new File(path, policy));
     41        return adoptRef(new File(path));
    4942    }
    5043
     
    5548
    5649    // 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.
    57     static PassRefPtr<File> createWithName(const String& path, const String& name, ContentTypeLookupPolicy policy = WellKnownContentTypes)
     50    static PassRefPtr<File> createWithName(const String& path, const String& name)
    5851    {
    5952        if (name.isEmpty())
    60             return adoptRef(new File(path, policy));
    61         return adoptRef(new File(path, name, policy));
     53            return adoptRef(new File(path));
     54        return adoptRef(new File(path, name));
    6255    }
    6356
     
    7164    double lastModifiedDate() const;
    7265
    73     static String contentTypeFromFilePathOrName(const String&, ContentTypeLookupPolicy);
     66    static String contentTypeFromFilePathOrName(const String&);
    7467
    7568private:
    76     File(const String& path, ContentTypeLookupPolicy);
    77     File(const String& path, const String& name, ContentTypeLookupPolicy);
     69    explicit File(const String& path);
     70    File(const String& path, const String& name);
    7871
    7972    File(DeserializationContructor, const String& path, const URL& srcURL, const String& type);
  • trunk/Source/WebCore/html/FileInputType.cpp

    r167368 r168430  
    267267    Vector<RefPtr<File>> fileObjects;
    268268    for (const FileChooserFileInfo& info : files)
    269         fileObjects.append(File::createWithName(info.path, info.displayName, File::AllContentTypes));
     269        fileObjects.append(File::createWithName(info.path, info.displayName));
    270270
    271271    return FileList::create(std::move(fileObjects));
  • trunk/Source/WebCore/platform/MIMETypeRegistry.cpp

    r165676 r168430  
    144144static const char imageJpeg[] = "image/jpeg";
    145145static const char octetStream[] = "application/octet-stream";
    146 
    147 // A table of well known MIME types used when we don't want to leak to the
    148 // caller information about types known to underlying platform.
    149 static const TypeExtensionPair wellKnownMimeTypes[] = {
    150     { textPlain, "txt" },
    151     { textPlain, "text" },
    152     { textHtml, "html" },
    153     { textHtml, "htm" },
    154     { "text/css", "css" },
    155     { "text/xml", "xml" },
    156     { "text/xsl", "xsl" },
    157     { "image/gif", "gif" },
    158     { "image/png", "png" },
    159     { imageJpeg, "jpeg" },
    160     { imageJpeg, "jpg" },
    161     { imageJpeg, "jfif" },
    162     { imageJpeg, "pjpeg" },
    163     { "image/webp", "webp" },
    164     { "image/bmp", "bmp" },
    165     { "application/xhtml+xml", "xhtml" },
    166     { "application/x-javascript", "js" },
    167     { "application/json", "json" },
    168     { octetStream, "exe" },
    169     { octetStream, "com" },
    170     { octetStream, "bin" },
    171     { "application/zip", "zip" },
    172     { "application/gzip", "gz" },
    173     { "application/pdf", "pdf" },
    174     { "application/postscript", "ps" },
    175     { "image/x-icon", "ico" },
    176     { "image/tiff", "tiff" },
    177     { "image/x-xbitmap", "xbm" },
    178     { "image/svg+xml", "svg" },
    179     { "application/rss+xml", "rss" },
    180     { "application/rdf+xml", "rdf" },
    181     { "application/x-shockwave-flash", "swf" },
    182 };
    183146
    184147static HashSet<String>* supportedImageResourceMIMETypes;
     
    505468    unsupportedTextMIMETypes = new HashSet<String>;
    506469    initializeUnsupportedTextMIMETypes();
    507 }
    508 
    509 static String findMimeType(const TypeExtensionPair* pairs, unsigned numPairs, const String& extension)
    510 {
    511     if (!extension.isEmpty()) {
    512       for (unsigned i = 0; i < numPairs; ++i, ++pairs) {
    513           if (equalIgnoringCase(extension, pairs->extension))
    514               return String(pairs->type);
    515       }
    516     }
    517     return String();
    518 }
    519 
    520 String MIMETypeRegistry::getWellKnownMIMETypeForExtension(const String& extension)
    521 {
    522     // This method must be thread safe and should not consult the OS/registry.
    523     String found = findMimeType(wellKnownMimeTypes, sizeof(wellKnownMimeTypes) / sizeof(wellKnownMimeTypes[0]), extension);
    524     if (!found.isEmpty())
    525         return found;
    526     return findMimeType(commonMediaTypes, sizeof(commonMediaTypes) / sizeof(commonMediaTypes[0]), extension);
    527470}
    528471
  • trunk/Source/WebCore/platform/MIMETypeRegistry.h

    r165676 r168430  
    3737public:
    3838    static String getMIMETypeForExtension(const String& extension);
    39     static String getWellKnownMIMETypeForExtension(const String& extension);
    4039
    4140    static Vector<String> getExtensionsForMIMEType(const String& type);
Note: See TracChangeset for help on using the changeset viewer.