Skip to content
Permalink
Browse files
Make sure WebKit2 only loads each plugin once
Fixes <http://webkit.org/b/47677> <rdar://problem/8552178> WebKit2 can
load the same plugin multiple times

Reviewed by Sam Weinig.

* UIProcess/Plugins/PluginInfoStore.cpp:
(WebKit::addFromVector): Helper function that adds all the elements
from a Vector to a HashSet.
(WebKit::PluginInfoStore::loadPluginsIfNecessary): Put all the plugin
paths into a HashSet, then load the plugins specified in the HashSet.
On Windows, the HashSet is case-insensitive, just like the file
system.

* UIProcess/Plugins/PluginInfoStore.h: Removed loadPluginsInDirectory,
which is no longer used.

* UIProcess/Plugins/win/PluginInfoStoreWin.cpp:
(WebKit::addPluginPathsFromRegistry):
(WebKit::PluginInfoStore::individualPluginPaths):
Changed to store the paths in a Vector instead of a HashSet now that
loadPluginsIfNecessary will handle duplicates for us.

Canonical link: https://commits.webkit.org/60377@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@69790 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
aroben committed Oct 14, 2010
1 parent 68b4d08 commit bd2037b0baed05c5aafd1f053d194a2f655e8204
Showing 4 changed files with 52 additions and 21 deletions.
@@ -1,3 +1,29 @@
2010-10-14 Adam Roben <aroben@apple.com>

Make sure WebKit2 only loads each plugin once

Fixes <http://webkit.org/b/47677> <rdar://problem/8552178> WebKit2 can
load the same plugin multiple times

Reviewed by Sam Weinig.

* UIProcess/Plugins/PluginInfoStore.cpp:
(WebKit::addFromVector): Helper function that adds all the elements
from a Vector to a HashSet.
(WebKit::PluginInfoStore::loadPluginsIfNecessary): Put all the plugin
paths into a HashSet, then load the plugins specified in the HashSet.
On Windows, the HashSet is case-insensitive, just like the file
system.

* UIProcess/Plugins/PluginInfoStore.h: Removed loadPluginsInDirectory,
which is no longer used.

* UIProcess/Plugins/win/PluginInfoStoreWin.cpp:
(WebKit::addPluginPathsFromRegistry):
(WebKit::PluginInfoStore::individualPluginPaths):
Changed to store the paths in a Vector instead of a HashSet now that
loadPluginsIfNecessary will handle duplicates for us.

2010-10-14 Adam Roben <aroben@apple.com>

Load plugins that are specified in the MozillaPlugins registry key
@@ -51,35 +51,45 @@ void PluginInfoStore::refresh()
m_pluginListIsUpToDate = false;
}

template <typename T, typename U, typename V, typename W>
static void addFromVector(HashSet<T, U, V>& hashSet, const W& vector)
{
for (size_t i = 0; i < vector.size(); ++i)
hashSet.add(vector[i]);
}

#if OS(WINDOWS)
typedef HashSet<String, CaseFoldingHash> PathHashSet;
#else
typedef HashSet<String> PathHashSet;
#endif

void PluginInfoStore::loadPluginsIfNecessary()
{
if (m_pluginListIsUpToDate)
return;

m_plugins.clear();

PathHashSet uniquePluginPaths;

// First, load plug-ins from the additional plug-ins directories specified.
for (size_t i = 0; i < m_additionalPluginsDirectories.size(); ++i)
loadPluginsInDirectory(m_additionalPluginsDirectories[i]);
addFromVector(uniquePluginPaths, pluginPathsInDirectory(m_additionalPluginsDirectories[i]));

// Then load plug-ins from the standard plug-ins directories.
Vector<String> directories = pluginsDirectories();
for (size_t i = 0; i < directories.size(); ++i)
loadPluginsInDirectory(directories[i]);
addFromVector(uniquePluginPaths, pluginPathsInDirectory(directories[i]));

// Then load plug-ins that are not in the standard plug-ins directories.
Vector<String> paths = individualPluginPaths();
for (size_t i = 0; i < paths.size(); ++i)
loadPlugin(paths[i]);
addFromVector(uniquePluginPaths, individualPluginPaths());

m_pluginListIsUpToDate = true;
}
PathHashSet::const_iterator end = uniquePluginPaths.end();
for (PathHashSet::const_iterator it = uniquePluginPaths.begin(); it != end; ++it)
loadPlugin(*it);

void PluginInfoStore::loadPluginsInDirectory(const String& directory)
{
Vector<String> pluginPaths = pluginPathsInDirectory(directory);
for (size_t i = 0; i < pluginPaths.size(); ++i)
loadPlugin(pluginPaths[i]);
m_pluginListIsUpToDate = true;
}

void PluginInfoStore::loadPlugin(const String& pluginPath)
@@ -68,7 +68,6 @@ class PluginInfoStore {
Plugin findPluginForExtension(const String& extension, String& mimeType);

void loadPluginsIfNecessary();
void loadPluginsInDirectory(const String& directory);
void loadPlugin(const String& pluginPath);

// Platform-specific member functions
@@ -29,9 +29,7 @@
#include "NotImplemented.h"
#include <WebCore/FileSystem.h>
#include <shlwapi.h>
#include <wtf/HashSet.h>
#include <wtf/OwnArrayPtr.h>
#include <wtf/text/StringHash.h>

using namespace WebCore;

@@ -305,7 +303,7 @@ Vector<String> PluginInfoStore::pluginPathsInDirectory(const String& directory)
return paths;
}

static void addPluginPathsFromRegistry(HKEY rootKey, HashSet<String, CaseFoldingHash>& paths)
static void addPluginPathsFromRegistry(HKEY rootKey, Vector<String>& paths)
{
HKEY key;
if (::RegOpenKeyExW(rootKey, L"Software\\MozillaPlugins", 0, KEY_ENUMERATE_SUB_KEYS, &key) != ERROR_SUCCESS)
@@ -326,22 +324,20 @@ static void addPluginPathsFromRegistry(HKEY rootKey, HashSet<String, CaseFolding
if (type != REG_SZ)
continue;

paths.add(path);
paths.append(path);
}

::RegCloseKey(key);
}

Vector<String> PluginInfoStore::individualPluginPaths()
{
HashSet<String, CaseFoldingHash> paths;
Vector<String> paths;

addPluginPathsFromRegistry(HKEY_LOCAL_MACHINE, paths);
addPluginPathsFromRegistry(HKEY_CURRENT_USER, paths);

Vector<String> result;
copyToVector(paths, result);
return result;
return paths;
}

static String getVersionInfo(const LPVOID versionInfoData, const String& info)

0 comments on commit bd2037b

Please sign in to comment.