Commit b360c5f8 authored by kenneth@webkit.org's avatar kenneth@webkit.org

Allow to explicitly choose a preferred plugin for a mimetype.

https://bugs.webkit.org/show_bug.cgi?id=27651

When the preferred plugin is set for a specific MIME type, it will be
always picked up, regardless of its version, quirks etc.

Client applications may want to use that API to resolve mimetype
ambiguity in a custom way, rather than in the default way that is
currently used in WebKit.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@46586 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c4e8143a
2009-07-30 Jakub Wieczorek <faw217@gmail.com>
Reviewed by Simon Hausmann.
Allow to explicitly choose a preferred plugin for a mimetype.
https://bugs.webkit.org/show_bug.cgi?id=27651
When the preferred plugin is set for a specific MIME type, it will be
always picked up, regardless of its version, quirks etc.
Client applications may want to use that API to resolve mimetype
ambiguity in a custom way, rather than in the default way that is
currently used in WebKit.
* plugins/PluginDatabase.cpp:
(WebCore::PluginDatabase::pluginForMIMEType):
(WebCore::PluginDatabase::MIMETypeForExtension):
(WebCore::PluginDatabase::setPreferredPluginForMIMEType): Added.
(WebCore::PluginDatabase::remove):
(WebCore::PluginDatabase::clear):
* plugins/PluginDatabase.h:
2009-07-30 Jakub Wieczorek <faw217@gmail.com>
[Qt] Fix build with Qt 4.4 after r46535.
......
......@@ -161,6 +161,12 @@ PluginPackage* PluginDatabase::pluginForMIMEType(const String& mimeType)
String key = mimeType.lower();
PluginSet::const_iterator end = m_plugins.end();
PluginPackage* preferredPlugin = m_preferredPlugins.get(key).get();
if (preferredPlugin
&& preferredPlugin->isEnabled()
&& preferredPlugin->mimeToDescriptions().contains(key)) {
return preferredPlugin;
}
Vector<PluginPackage*, 2> pluginChoices;
......@@ -199,13 +205,19 @@ String PluginDatabase::MIMETypeForExtension(const String& extension) const
MIMEToExtensionsMap::const_iterator mime_end = (*it)->mimeToExtensions().end();
for (MIMEToExtensionsMap::const_iterator mime_it = (*it)->mimeToExtensions().begin(); mime_it != mime_end; ++mime_it) {
mimeType = mime_it->first;
PluginPackage* preferredPlugin = m_preferredPlugins.get(mimeType).get();
const Vector<String>& extensions = mime_it->second;
bool foundMapping = false;
for (unsigned i = 0; i < extensions.size(); i++) {
if (equalIgnoringCase(extensions[i], extension)) {
PluginPackage* plugin = (*it).get();
if (preferredPlugin && PluginPackage::equal(*plugin, *preferredPlugin))
return mimeType;
pluginChoices.append(plugin);
mimeTypeForPlugin.add(plugin, mime_it->first);
mimeTypeForPlugin.add(plugin, mimeType);
foundMapping = true;
break;
}
......@@ -247,6 +259,12 @@ PluginPackage* PluginDatabase::findPlugin(const KURL& url, String& mimeType)
return plugin;
}
void PluginDatabase::setPreferredPluginForMIMEType(const String& mimeType, PluginPackage* plugin)
{
if (!plugin || plugin->mimeToExtensions().contains(mimeType))
m_preferredPlugins.set(mimeType.lower(), plugin);
}
void PluginDatabase::getDeletedPlugins(PluginSet& plugins) const
{
PluginSet::const_iterator end = m_plugins.end();
......@@ -271,6 +289,13 @@ bool PluginDatabase::add(PassRefPtr<PluginPackage> prpPackage)
void PluginDatabase::remove(PluginPackage* package)
{
MIMEToExtensionsMap::const_iterator it = package->mimeToExtensions().begin();
MIMEToExtensionsMap::const_iterator end = package->mimeToExtensions().end();
for ( ; it != end; ++it) {
if (m_preferredPlugins.contains(it->first) && m_preferredPlugins.get(it->first) == package)
m_preferredPlugins.remove(it->first);
}
m_plugins.remove(package);
m_pluginsByPath.remove(package->path());
}
......@@ -281,6 +306,7 @@ void PluginDatabase::clear()
m_pluginsByPath.clear();
m_pluginPathsWithTimes.clear();
m_registeredMIMETypes.clear();
m_preferredPlugins.clear();
}
#if !PLATFORM(WIN_OS) || PLATFORM(WX)
......
......@@ -64,6 +64,7 @@ namespace WebCore {
PluginPackage* findPlugin(const KURL&, String& mimeType);
PluginPackage* pluginForMIMEType(const String& mimeType);
void setPreferredPluginForMIMEType(const String& mimeType, PluginPackage* plugin);
void setPluginDirectories(const Vector<String>& directories)
{
......@@ -89,6 +90,7 @@ namespace WebCore {
PluginSet m_plugins;
HashMap<String, RefPtr<PluginPackage> > m_pluginsByPath;
HashMap<String, time_t> m_pluginPathsWithTimes;
HashMap<String, RefPtr<PluginPackage> > m_preferredPlugins;
};
} // namespace WebCore
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment