• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 Zack Rusin <zack@kde.org>
3  * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
4  * Copyright (C) 2007 Trolltech ASA
5  * Copyright (C) 2010 Stephan Aßmus <superstippi@gmx.de>
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include "config.h"
30 #include "MIMETypeRegistry.h"
31 
32 #include "PlatformString.h"
33 #include <MimeType.h>
34 #include <wtf/Assertions.h>
35 #include <wtf/MainThread.h>
36 #include <wtf/text/CString.h>
37 
38 namespace WebCore {
39 struct ExtensionMap {
40     const char* extension;
41     const char* mimeType;
42 };
43 
44 static const ExtensionMap extensionMap[] = {
45     { "bmp", "image/bmp" },
46     { "gif", "image/gif" },
47     { "html", "text/html" },
48     { "ico", "image/x-icon" },
49     { "jpeg", "image/jpeg" },
50     { "jpg", "image/jpeg" },
51     { "js", "application/x-javascript" },
52     { "pdf", "application/pdf" },
53     { "png", "image/png" },
54     { "rss", "application/rss+xml" },
55     { "svg", "image/svg+xml" },
56     { "text", "text/plain" },
57     { "txt", "text/plain" },
58     { "xbm", "image/x-xbitmap" },
59     { "xml", "text/xml" },
60     { "xsl", "text/xsl" },
61     { "xhtml", "application/xhtml+xml" },
62     { 0, 0 }
63 };
64 
getMIMETypeForExtension(const String & ext)65 String MIMETypeRegistry::getMIMETypeForExtension(const String& ext)
66 {
67     ASSERT(isMainThread());
68 
69     String str = ext.lower();
70 
71     // Try WebCore built-in types.
72     const ExtensionMap* extMap = extensionMap;
73     while (extMap->extension) {
74         if (str == extMap->extension)
75             return extMap->mimeType;
76         ++extMap;
77     }
78 
79     // Try system mime database.
80     String fakeFileName("filename.");
81     fakeFileName.append(str);
82 
83     BMimeType type;
84     if (BMimeType::GuessMimeType(fakeFileName.utf8().data(), &type) == B_OK)
85         return type.Type();
86 
87     // unknown
88     return String();
89 }
90 
isApplicationPluginMIMEType(const String &)91 bool MIMETypeRegistry::isApplicationPluginMIMEType(const String&)
92 {
93     return false;
94 }
95 
96 } // namespace WebCore
97 
98