2
* Copyright (C) 2010 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 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.
27
#include "NetscapePluginModule.h"
29
#if ENABLE(NETSCAPE_PLUGIN_API)
31
#include <WebCore/FileSystem.h>
32
#include <wtf/OwnArrayPtr.h>
34
using namespace WebCore;
38
static String getVersionInfo(const LPVOID versionInfoData, const String& info)
42
String subInfo = "\\StringfileInfo\\040904E4\\" + info;
43
if (!::VerQueryValueW(versionInfoData, const_cast<UChar*>(subInfo.charactersWithNullTermination()), &buffer, &bufferLength) || !bufferLength)
46
// Subtract 1 from the length; we don't want the trailing null character.
47
return String(reinterpret_cast<UChar*>(buffer), bufferLength - 1);
50
static uint64_t fileVersion(DWORD leastSignificant, DWORD mostSignificant)
52
ULARGE_INTEGER version;
53
version.LowPart = leastSignificant;
54
version.HighPart = mostSignificant;
55
return version.QuadPart;
58
bool NetscapePluginModule::getPluginInfo(const String& pluginPath, PluginModuleInfo& plugin)
60
String pathCopy = pluginPath;
61
DWORD versionInfoSize = ::GetFileVersionInfoSizeW(pathCopy.charactersWithNullTermination(), 0);
65
OwnArrayPtr<char> versionInfoData = adoptArrayPtr(new char[versionInfoSize]);
66
if (!::GetFileVersionInfoW(pathCopy.charactersWithNullTermination(), 0, versionInfoSize, versionInfoData.get()))
69
String name = getVersionInfo(versionInfoData.get(), "ProductName");
70
String description = getVersionInfo(versionInfoData.get(), "FileDescription");
71
if (name.isNull() || description.isNull())
74
VS_FIXEDFILEINFO* info;
76
if (!::VerQueryValueW(versionInfoData.get(), L"\\", reinterpret_cast<void**>(&info), &infoSize) || infoSize < sizeof(VS_FIXEDFILEINFO))
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);
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] : "";
92
Vector<String> extensionsVector;
93
extensionList.split(',', extensionsVector);
95
// Get rid of the extension list that may be at the end of the description string.
96
int pos = description.find("(*");
98
// There might be a space that we need to get rid of.
99
if (pos > 1 && description[pos - 1] == ' ')
101
description = description.left(pos);
104
mimes[i].type = type;
105
mimes[i].desc = description;
106
mimes[i].extensions.swap(extensionsVector);
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);
119
void NetscapePluginModule::determineQuirks()
121
PluginModuleInfo plugin;
122
getPluginInfo(m_pluginPath, plugin);
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;
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);
142
} // namespace WebKit
144
#endif // ENABLE(NETSCAPE_PLUGIN_API)