1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
|
/*
* Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
* Copyright (C) 2008 Collabora, Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "PluginDatabase.h"
#include "Frame.h"
#include "KURL.h"
#include "PluginPackage.h"
#include <windows.h>
#include <shlwapi.h>
namespace WebCore {
static inline void addPluginPathsFromRegistry(HKEY rootKey, HashSet<String>& paths)
{
HKEY key;
HRESULT result = RegOpenKeyExW(rootKey, L"Software\\MozillaPlugins", 0, KEY_ENUMERATE_SUB_KEYS, &key);
if (result != ERROR_SUCCESS)
return;
wchar_t name[128];
FILETIME lastModified;
// Enumerate subkeys
for (int i = 0;; i++) {
DWORD nameLen = _countof(name);
result = RegEnumKeyExW(key, i, name, &nameLen, 0, 0, 0, &lastModified);
if (result != ERROR_SUCCESS)
break;
WCHAR pathStr[_MAX_PATH];
DWORD pathStrSize = sizeof(pathStr);
DWORD type;
result = SHGetValue(key, name, TEXT("Path"), &type, (LPBYTE)pathStr, &pathStrSize);
if (result != ERROR_SUCCESS || type != REG_SZ)
continue;
paths.add(String(pathStr, pathStrSize / sizeof(WCHAR) - 1));
}
RegCloseKey(key);
}
void PluginDatabase::getPluginPathsInDirectories(HashSet<String>& paths) const
{
// FIXME: This should be a case insensitive set.
HashSet<String> uniqueFilenames;
HANDLE hFind = INVALID_HANDLE_VALUE;
WIN32_FIND_DATAW findFileData;
String oldWMPPluginPath;
String newWMPPluginPath;
Vector<String>::const_iterator end = m_pluginDirectories.end();
for (Vector<String>::const_iterator it = m_pluginDirectories.begin(); it != end; ++it) {
String pattern = *it + "\\*";
hFind = FindFirstFileW(pattern.charactersWithNullTermination(), &findFileData);
if (hFind == INVALID_HANDLE_VALUE)
continue;
do {
if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
continue;
String filename = String(findFileData.cFileName, wcslen(findFileData.cFileName));
if ((!filename.startsWith("np", false) || !filename.endsWith("dll", false)) &&
(!equalIgnoringCase(filename, "Plugin.dll") || !it->endsWith("Shockwave 10", false)))
continue;
String fullPath = *it + "\\" + filename;
if (!uniqueFilenames.add(fullPath).second)
continue;
paths.add(fullPath);
if (equalIgnoringCase(filename, "npdsplay.dll"))
oldWMPPluginPath = fullPath;
else if (equalIgnoringCase(filename, "np-mswmp.dll"))
newWMPPluginPath = fullPath;
} while (FindNextFileW(hFind, &findFileData) != 0);
FindClose(hFind);
}
addPluginPathsFromRegistry(HKEY_LOCAL_MACHINE, paths);
addPluginPathsFromRegistry(HKEY_CURRENT_USER, paths);
// If both the old and new WMP plugin are present in the plugins set,
// we remove the old one so we don't end up choosing the old one.
if (!oldWMPPluginPath.isEmpty() && !newWMPPluginPath.isEmpty())
paths.remove(oldWMPPluginPath);
}
static inline Vector<int> parseVersionString(const String& versionString)
{
Vector<int> version;
unsigned startPos = 0;
unsigned endPos;
while (startPos < versionString.length()) {
for (endPos = startPos; endPos < versionString.length(); ++endPos)
if (versionString[endPos] == '.' || versionString[endPos] == '_')
break;
int versionComponent = versionString.substring(startPos, endPos - startPos).toInt();
version.append(versionComponent);
startPos = endPos + 1;
}
return version;
}
// This returns whether versionA is higher than versionB
static inline bool compareVersions(const Vector<int>& versionA, const Vector<int>& versionB)
{
for (unsigned i = 0; i < versionA.size(); i++) {
if (i >= versionB.size())
return true;
if (versionA[i] > versionB[i])
return true;
else if (versionA[i] < versionB[i])
return false;
}
// If we come here, the versions are either the same or versionB has an extra component, just return false
return false;
}
static inline void addMozillaPluginDirectories(Vector<String>& directories)
{
// Enumerate all Mozilla plugin directories in the registry
HKEY key;
LONG result;
result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("Software\\Mozilla"), 0, KEY_READ, &key);
if (result == ERROR_SUCCESS) {
WCHAR name[128];
FILETIME lastModified;
// Enumerate subkeys
for (int i = 0;; i++) {
DWORD nameLen = sizeof(name) / sizeof(WCHAR);
result = RegEnumKeyExW(key, i, name, &nameLen, 0, 0, 0, &lastModified);
if (result != ERROR_SUCCESS)
break;
String extensionsPath = String(name, nameLen) + "\\Extensions";
HKEY extensionsKey;
// Try opening the key
result = RegOpenKeyEx(key, extensionsPath.charactersWithNullTermination(), 0, KEY_READ, &extensionsKey);
if (result == ERROR_SUCCESS) {
// Now get the plugins directory
WCHAR pluginsDirectoryStr[_MAX_PATH];
DWORD pluginsDirectorySize = sizeof(pluginsDirectoryStr);
DWORD type;
result = RegQueryValueEx(extensionsKey, TEXT("Plugins"), 0, &type, (LPBYTE)&pluginsDirectoryStr, &pluginsDirectorySize);
if (result == ERROR_SUCCESS && type == REG_SZ)
directories.append(String(pluginsDirectoryStr, pluginsDirectorySize / sizeof(WCHAR) - 1));
RegCloseKey(extensionsKey);
}
}
RegCloseKey(key);
}
}
static inline void addWindowsMediaPlayerPluginDirectory(Vector<String>& directories)
{
// The new WMP Firefox plugin is installed in \PFiles\Plugins if it can't find any Firefox installs
WCHAR pluginDirectoryStr[_MAX_PATH + 1];
DWORD pluginDirectorySize = ::ExpandEnvironmentStringsW(TEXT("%SYSTEMDRIVE%\\PFiles\\Plugins"), pluginDirectoryStr, _countof(pluginDirectoryStr));
if (pluginDirectorySize > 0 && pluginDirectorySize <= _countof(pluginDirectoryStr))
directories.append(String(pluginDirectoryStr, pluginDirectorySize - 1));
DWORD type;
WCHAR installationDirectoryStr[_MAX_PATH];
DWORD installationDirectorySize = sizeof(installationDirectoryStr);
HRESULT result = SHGetValue(HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\MediaPlayer"), TEXT("Installation Directory"), &type, (LPBYTE)&installationDirectoryStr, &installationDirectorySize);
if (result == ERROR_SUCCESS && type == REG_SZ)
directories.append(String(installationDirectoryStr, installationDirectorySize / sizeof(WCHAR) - 1));
}
static inline void addQuickTimePluginDirectory(Vector<String>& directories)
{
DWORD type;
WCHAR installationDirectoryStr[_MAX_PATH];
DWORD installationDirectorySize = sizeof(installationDirectoryStr);
HRESULT result = SHGetValue(HKEY_LOCAL_MACHINE, TEXT("Software\\Apple Computer, Inc.\\QuickTime"), TEXT("InstallDir"), &type, (LPBYTE)&installationDirectoryStr, &installationDirectorySize);
if (result == ERROR_SUCCESS && type == REG_SZ) {
String pluginDir = String(installationDirectoryStr, installationDirectorySize / sizeof(WCHAR) - 1) + "\\plugins";
directories.append(pluginDir);
}
}
static inline void addAdobeAcrobatPluginDirectory(Vector<String>& directories)
{
HKEY key;
HRESULT result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("Software\\Adobe\\Acrobat Reader"), 0, KEY_READ, &key);
if (result != ERROR_SUCCESS)
return;
WCHAR name[128];
FILETIME lastModified;
Vector<int> latestAcrobatVersion;
String latestAcrobatVersionString;
// Enumerate subkeys
for (int i = 0;; i++) {
DWORD nameLen = sizeof(name) / sizeof(WCHAR);
result = RegEnumKeyExW(key, i, name, &nameLen, 0, 0, 0, &lastModified);
if (result != ERROR_SUCCESS)
break;
Vector<int> acrobatVersion = parseVersionString(String(name, nameLen));
if (compareVersions(acrobatVersion, latestAcrobatVersion)) {
latestAcrobatVersion = acrobatVersion;
latestAcrobatVersionString = String(name, nameLen);
}
}
if (!latestAcrobatVersionString.isNull()) {
DWORD type;
WCHAR acrobatInstallPathStr[_MAX_PATH];
DWORD acrobatInstallPathSize = sizeof(acrobatInstallPathStr);
String acrobatPluginKeyPath = "Software\\Adobe\\Acrobat Reader\\" + latestAcrobatVersionString + "\\InstallPath";
result = SHGetValue(HKEY_LOCAL_MACHINE, acrobatPluginKeyPath.charactersWithNullTermination(), 0, &type, (LPBYTE)acrobatInstallPathStr, &acrobatInstallPathSize);
if (result == ERROR_SUCCESS) {
String acrobatPluginDirectory = String(acrobatInstallPathStr, acrobatInstallPathSize / sizeof(WCHAR) - 1) + "\\browser";
directories.append(acrobatPluginDirectory);
}
}
RegCloseKey(key);
}
static inline String safariPluginsDirectory()
{
WCHAR moduleFileNameStr[_MAX_PATH];
static String pluginsDirectory;
static bool cachedPluginDirectory = false;
if (!cachedPluginDirectory) {
cachedPluginDirectory = true;
int moduleFileNameLen = GetModuleFileName(0, moduleFileNameStr, _MAX_PATH);
if (!moduleFileNameLen || moduleFileNameLen == _MAX_PATH)
goto exit;
if (!PathRemoveFileSpec(moduleFileNameStr))
goto exit;
pluginsDirectory = String(moduleFileNameStr) + "\\Plugins";
}
exit:
return pluginsDirectory;
}
static inline void addMacromediaPluginDirectories(Vector<String>& directories)
{
WCHAR systemDirectoryStr[MAX_PATH];
if (GetSystemDirectory(systemDirectoryStr, _countof(systemDirectoryStr)) == 0)
return;
WCHAR macromediaDirectoryStr[MAX_PATH];
PathCombine(macromediaDirectoryStr, systemDirectoryStr, TEXT("macromed\\Flash"));
directories.append(macromediaDirectoryStr);
PathCombine(macromediaDirectoryStr, systemDirectoryStr, TEXT("macromed\\Shockwave 10"));
directories.append(macromediaDirectoryStr);
}
Vector<String> PluginDatabase::defaultPluginDirectories()
{
Vector<String> directories;
String ourDirectory = safariPluginsDirectory();
if (!ourDirectory.isNull())
directories.append(ourDirectory);
addQuickTimePluginDirectory(directories);
addAdobeAcrobatPluginDirectory(directories);
addMozillaPluginDirectories(directories);
addWindowsMediaPlayerPluginDirectory(directories);
addMacromediaPluginDirectories(directories);
return directories;
}
bool PluginDatabase::isPreferredPluginDirectory(const String& directory)
{
String ourDirectory = safariPluginsDirectory();
if (!ourDirectory.isNull() && !directory.isNull())
return ourDirectory == directory;
return false;
}
}
|