2
* Copyright (C) 2006, 2007 Apple 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
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
13
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
#include "MIMETypeRegistry.h"
29
#include "WindowsExtras.h"
30
#include <wtf/Assertions.h>
31
#include <wtf/HashMap.h>
32
#include <wtf/MainThread.h>
36
static String mimeTypeForExtension(const String& extension)
38
String ext = "." + extension;
39
WCHAR contentTypeStr[256];
40
DWORD contentTypeStrLen = sizeof(contentTypeStr);
43
HRESULT result = getRegistryValue(HKEY_CLASSES_ROOT, ext.charactersWithNullTermination(), L"Content Type", &keyType, contentTypeStr, &contentTypeStrLen);
45
if (result == ERROR_SUCCESS && keyType == REG_SZ)
46
return String(contentTypeStr, contentTypeStrLen / sizeof(contentTypeStr[0]) - 1);
51
String MIMETypeRegistry::getPreferredExtensionForMIMEType(const String& type)
53
String path = "MIME\\Database\\Content Type\\" + type;
54
WCHAR extStr[MAX_PATH];
55
DWORD extStrLen = sizeof(extStr);
58
HRESULT result = getRegistryValue(HKEY_CLASSES_ROOT, path.charactersWithNullTermination(), L"Extension", &keyType, extStr, &extStrLen);
60
if (result == ERROR_SUCCESS && keyType == REG_SZ)
61
return String(extStr + 1, extStrLen / sizeof(extStr[0]) - 2);
66
String MIMETypeRegistry::getMIMETypeForExtension(const String &ext)
68
ASSERT(isMainThread());
73
static HashMap<String, String> mimetypeMap;
74
if (mimetypeMap.isEmpty()) {
75
//fill with initial values
76
mimetypeMap.add("txt", "text/plain");
77
mimetypeMap.add("pdf", "application/pdf");
78
mimetypeMap.add("ps", "application/postscript");
79
mimetypeMap.add("html", "text/html");
80
mimetypeMap.add("htm", "text/html");
81
mimetypeMap.add("xml", "text/xml");
82
mimetypeMap.add("xsl", "text/xsl");
83
mimetypeMap.add("js", "application/x-javascript");
84
mimetypeMap.add("xhtml", "application/xhtml+xml");
85
mimetypeMap.add("rss", "application/rss+xml");
86
mimetypeMap.add("webarchive", "application/x-webarchive");
87
mimetypeMap.add("svg", "image/svg+xml");
88
mimetypeMap.add("svgz", "image/svg+xml");
89
mimetypeMap.add("jpg", "image/jpeg");
90
mimetypeMap.add("jpeg", "image/jpeg");
91
mimetypeMap.add("png", "image/png");
92
mimetypeMap.add("tif", "image/tiff");
93
mimetypeMap.add("tiff", "image/tiff");
94
mimetypeMap.add("ico", "image/ico");
95
mimetypeMap.add("cur", "image/ico");
96
mimetypeMap.add("bmp", "image/bmp");
97
mimetypeMap.add("wml", "text/vnd.wap.wml");
98
mimetypeMap.add("wmlc", "application/vnd.wap.wmlc");
99
mimetypeMap.add("m4a", "audio/x-m4a");
101
String result = mimetypeMap.get(ext);
102
if (result.isEmpty()) {
103
result = mimeTypeForExtension(ext);
104
if (!result.isEmpty())
105
mimetypeMap.add(ext, result);
110
bool MIMETypeRegistry::isApplicationPluginMIMEType(const String&)