~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/platform/win/MIMETypeRegistryWin.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2006, 2007 Apple Inc.  All rights reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions
 
6
 * are met:
 
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.
 
12
 *
 
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.
 
24
 */
 
25
 
 
26
#include "config.h"
 
27
#include "MIMETypeRegistry.h"
 
28
 
 
29
#include "WindowsExtras.h"
 
30
#include <wtf/Assertions.h>
 
31
#include <wtf/HashMap.h>
 
32
#include <wtf/MainThread.h>
 
33
 
 
34
namespace WebCore {
 
35
 
 
36
static String mimeTypeForExtension(const String& extension)
 
37
{
 
38
    String ext = "." + extension;
 
39
    WCHAR contentTypeStr[256];
 
40
    DWORD contentTypeStrLen = sizeof(contentTypeStr);
 
41
    DWORD keyType;
 
42
 
 
43
    HRESULT result = getRegistryValue(HKEY_CLASSES_ROOT, ext.charactersWithNullTermination(), L"Content Type", &keyType, contentTypeStr, &contentTypeStrLen);
 
44
 
 
45
    if (result == ERROR_SUCCESS && keyType == REG_SZ)
 
46
        return String(contentTypeStr, contentTypeStrLen / sizeof(contentTypeStr[0]) - 1);
 
47
 
 
48
    return String();
 
49
}
 
50
 
 
51
String MIMETypeRegistry::getPreferredExtensionForMIMEType(const String& type)
 
52
{
 
53
    String path = "MIME\\Database\\Content Type\\" + type;
 
54
    WCHAR extStr[MAX_PATH];
 
55
    DWORD extStrLen = sizeof(extStr);
 
56
    DWORD keyType;
 
57
 
 
58
    HRESULT result = getRegistryValue(HKEY_CLASSES_ROOT, path.charactersWithNullTermination(), L"Extension", &keyType, extStr, &extStrLen);
 
59
 
 
60
    if (result == ERROR_SUCCESS && keyType == REG_SZ)
 
61
        return String(extStr + 1, extStrLen / sizeof(extStr[0]) - 2);
 
62
 
 
63
    return String();
 
64
}
 
65
 
 
66
String MIMETypeRegistry::getMIMETypeForExtension(const String &ext)
 
67
{
 
68
    ASSERT(isMainThread());
 
69
 
 
70
    if (ext.isEmpty())
 
71
        return String();
 
72
 
 
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");
 
100
    }
 
101
    String result = mimetypeMap.get(ext);
 
102
    if (result.isEmpty()) {
 
103
        result = mimeTypeForExtension(ext);
 
104
        if (!result.isEmpty())
 
105
            mimetypeMap.add(ext, result);
 
106
    }
 
107
    return result;
 
108
}
 
109
 
 
110
bool MIMETypeRegistry::isApplicationPluginMIMEType(const String&)
 
111
{
 
112
    return false;
 
113
}
 
114
 
 
115
}