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

« back to all changes in this revision

Viewing changes to Source/WebKit2/Shared/Plugins/Netscape/win/NetscapePluginModuleWin.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) 2010 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 INC. AND ITS CONTRIBUTORS ``AS IS''
 
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 
23
 * THE POSSIBILITY OF SUCH DAMAGE.
 
24
 */
 
25
 
 
26
#include "config.h"
 
27
#include "NetscapePluginModule.h"
 
28
 
 
29
#if ENABLE(NETSCAPE_PLUGIN_API)
 
30
 
 
31
#include <WebCore/FileSystem.h>
 
32
#include <wtf/OwnArrayPtr.h>
 
33
 
 
34
using namespace WebCore;
 
35
 
 
36
namespace WebKit {
 
37
 
 
38
static String getVersionInfo(const LPVOID versionInfoData, const String& info)
 
39
{
 
40
    LPVOID buffer;
 
41
    UINT bufferLength;
 
42
    String subInfo = "\\StringfileInfo\\040904E4\\" + info;
 
43
    if (!::VerQueryValueW(versionInfoData, const_cast<UChar*>(subInfo.charactersWithNullTermination()), &buffer, &bufferLength) || !bufferLength)
 
44
        return String();
 
45
 
 
46
    // Subtract 1 from the length; we don't want the trailing null character.
 
47
    return String(reinterpret_cast<UChar*>(buffer), bufferLength - 1);
 
48
}
 
49
 
 
50
static uint64_t fileVersion(DWORD leastSignificant, DWORD mostSignificant)
 
51
{
 
52
    ULARGE_INTEGER version;
 
53
    version.LowPart = leastSignificant;
 
54
    version.HighPart = mostSignificant;
 
55
    return version.QuadPart;
 
56
}
 
57
 
 
58
bool NetscapePluginModule::getPluginInfo(const String& pluginPath, PluginModuleInfo& plugin)
 
59
{
 
60
        String pathCopy = pluginPath;
 
61
    DWORD versionInfoSize = ::GetFileVersionInfoSizeW(pathCopy.charactersWithNullTermination(), 0);
 
62
    if (!versionInfoSize)
 
63
        return false;
 
64
 
 
65
    OwnArrayPtr<char> versionInfoData = adoptArrayPtr(new char[versionInfoSize]);
 
66
    if (!::GetFileVersionInfoW(pathCopy.charactersWithNullTermination(), 0, versionInfoSize, versionInfoData.get()))
 
67
        return false;
 
68
 
 
69
    String name = getVersionInfo(versionInfoData.get(), "ProductName");
 
70
    String description = getVersionInfo(versionInfoData.get(), "FileDescription");
 
71
    if (name.isNull() || description.isNull())
 
72
        return false;
 
73
 
 
74
    VS_FIXEDFILEINFO* info;
 
75
    UINT infoSize;
 
76
    if (!::VerQueryValueW(versionInfoData.get(), L"\\", reinterpret_cast<void**>(&info), &infoSize) || infoSize < sizeof(VS_FIXEDFILEINFO))
 
77
        return false;
 
78
 
 
79
    Vector<String> types;
 
80
    getVersionInfo(versionInfoData.get(), "MIMEType").split('|', types);
 
81
    Vector<String> extensionLists;
 
82
    getVersionInfo(versionInfoData.get(), "FileExtents").split('|', extensionLists);
 
83
    Vector<String> descriptions;
 
84
    getVersionInfo(versionInfoData.get(), "FileOpenName").split('|', descriptions);
 
85
 
 
86
    Vector<MimeClassInfo> mimes(types.size());
 
87
    for (size_t i = 0; i < types.size(); i++) {
 
88
        String type = types[i].lower();
 
89
        String description = i < descriptions.size() ? descriptions[i] : "";
 
90
        String extensionList = i < extensionLists.size() ? extensionLists[i] : "";
 
91
 
 
92
        Vector<String> extensionsVector;
 
93
        extensionList.split(',', extensionsVector);
 
94
 
 
95
        // Get rid of the extension list that may be at the end of the description string.
 
96
        int pos = description.find("(*");
 
97
        if (pos != -1) {
 
98
            // There might be a space that we need to get rid of.
 
99
            if (pos > 1 && description[pos - 1] == ' ')
 
100
                pos--;
 
101
            description = description.left(pos);
 
102
        }
 
103
 
 
104
        mimes[i].type = type;
 
105
        mimes[i].desc = description;
 
106
        mimes[i].extensions.swap(extensionsVector);
 
107
    }
 
108
 
 
109
    plugin.path = pluginPath;
 
110
    plugin.info.desc = description;
 
111
    plugin.info.name = name;
 
112
    plugin.info.file = pathGetFileName(pluginPath);
 
113
    plugin.info.mimes.swap(mimes);
 
114
    plugin.fileVersion = fileVersion(info->dwFileVersionLS, info->dwFileVersionMS);
 
115
 
 
116
    return true;
 
117
}
 
118
 
 
119
void NetscapePluginModule::determineQuirks()
 
120
{
 
121
    PluginModuleInfo plugin;
 
122
    getPluginInfo(m_pluginPath, plugin);
 
123
 
 
124
    Vector<MimeClassInfo> mimeTypes = plugin.info.mimes;
 
125
    for (size_t i = 0; i < mimeTypes.size(); ++i) {
 
126
        // FIXME: It seems strange to assume that any plugin that handles this MIME type needs this quirk. Should
 
127
        // we be be checking the plugin's name instead?
 
128
        if (mimeTypes[i].type == "application/x-shockwave-flash") {
 
129
            uint64_t flashTenVersion = fileVersion(0x00000000, 0x000a0000);
 
130
            uint64_t version = plugin.fileVersion;
 
131
 
 
132
            // Pre Flash v10 only requests windowless plugins if we use a Mozilla user agent.
 
133
            // For testing information, see: https://bugs.webkit.org/show_bug.cgi?id=60726.
 
134
            if (version < flashTenVersion)
 
135
                m_pluginQuirks.add(PluginQuirks::WantsMozillaUserAgent);
 
136
 
 
137
            break;
 
138
        }
 
139
    }
 
140
}
 
141
 
 
142
} // namespace WebKit
 
143
 
 
144
#endif // ENABLE(NETSCAPE_PLUGIN_API)