2 * Copyright (c) 2008, 2009, Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "MIMETypeRegistry.h"
34 #include "ChromiumBridge.h"
36 #include "MediaPlayer.h"
38 // NOTE: Unlike other ports, we don't use the shared implementation bits in
39 // MIMETypeRegistry.cpp. Instead, we need to route most functions via the
40 // ChromiumBridge to the embedder.
44 // Checks if any of the plugins handle this extension, and if so returns the
45 // plugin's mime type for this extension. Otherwise returns an empty string.
46 // See PluginsChromium.cpp for the implementation of this function.
47 String getPluginMimeTypeFromExtension(const String& extension);
49 String MIMETypeRegistry::getMIMETypeForExtension(const String &ext)
51 return ChromiumBridge::mimeTypeForExtension(ext);
54 // Returns the file extension if one is found. Does not include the dot in the
55 // filename. E.g., 'html'.
56 String MIMETypeRegistry::getPreferredExtensionForMIMEType(const String& type)
58 // Prune out any parameters in case they happen to have snuck in there...
59 // FIXME: Is this really necessary??
60 String mimeType = type.substring(0, static_cast<unsigned>(type.find(';')));
62 String ext = ChromiumBridge::preferredExtensionForMIMEType(type);
63 if (!ext.isEmpty() && ext[0] == '.')
64 ext = ext.substring(1);
69 String MIMETypeRegistry::getMIMETypeForPath(const String& path)
71 int pos = path.reverseFind('.');
73 return "application/octet-stream";
74 String extension = path.substring(pos + 1);
75 String mimeType = getMIMETypeForExtension(extension);
76 if (mimeType.isEmpty()) {
77 // If there's no mimetype registered for the extension, check to see
78 // if a plugin can handle the extension.
79 mimeType = getPluginMimeTypeFromExtension(extension);
84 bool MIMETypeRegistry::isSupportedImageMIMEType(const String& mimeType)
86 return ChromiumBridge::isSupportedImageMIMEType(mimeType);
89 bool MIMETypeRegistry::isSupportedImageResourceMIMEType(const String& mimeType)
91 return isSupportedImageMIMEType(mimeType);
94 bool MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(const String& mimeType)
96 // FIXME: Fill this out. See: http://trac.webkit.org/changeset/30888
97 return isSupportedImageMIMEType(mimeType);
100 bool MIMETypeRegistry::isSupportedJavaScriptMIMEType(const String& mimeType)
102 return ChromiumBridge::isSupportedJavaScriptMIMEType(mimeType);
105 bool MIMETypeRegistry::isSupportedNonImageMIMEType(const String& mimeType)
107 return ChromiumBridge::isSupportedNonImageMIMEType(mimeType);
110 bool MIMETypeRegistry::isSupportedMediaMIMEType(const String& mimeType)
112 HashSet<String> supportedMediaMIMETypes;
114 MediaPlayer::getSupportedTypes(supportedMediaMIMETypes);
116 return !mimeType.isEmpty() && supportedMediaMIMETypes.contains(mimeType);
119 bool MIMETypeRegistry::isJavaAppletMIMEType(const String& mimeType)
121 // Since this set is very limited and is likely to remain so we won't bother with the overhead
122 // of using a hash set.
123 // Any of the MIME types below may be followed by any number of specific versions of the JVM,
124 // which is why we use startsWith()
125 return mimeType.startsWith("application/x-java-applet", false)
126 || mimeType.startsWith("application/x-java-bean", false)
127 || mimeType.startsWith("application/x-java-vm", false);
130 static HashSet<String>& dummyHashSet()
132 ASSERT_NOT_REACHED();
133 static HashSet<String> dummy;
137 // NOTE: the following methods should never be reached
138 HashSet<String>& MIMETypeRegistry::getSupportedImageMIMETypes() { return dummyHashSet(); }
139 HashSet<String>& MIMETypeRegistry::getSupportedImageResourceMIMETypes() { return dummyHashSet(); }
140 HashSet<String>& MIMETypeRegistry::getSupportedImageMIMETypesForEncoding() { return dummyHashSet(); }
141 HashSet<String>& MIMETypeRegistry::getSupportedNonImageMIMETypes() { return dummyHashSet(); }
142 HashSet<String>& MIMETypeRegistry::getSupportedMediaMIMETypes() { return dummyHashSet(); }
144 } // namespace WebCore